Skip to content

Commit 257c7dc

Browse files
atti187TrySoundmarkbrouchbugs181frankieshen
authored
chore(repo): migrate @TrySound/rollup-plugin-eslint (#575)
* Initial * Add documentation * Add npm files filter * 1.0.0 * Clear dist folder * Fix documentation * 1.0.1 * Fix build * 1.0.2 * Upgrade eslint * 2.0.0 * Tidy up * Return a name * 2.0.2 * Upgrade to eslint 3 * Add buble back * v3.0.0 * Add lockfile * Move to jest * Build with babel * Upgrade dependencies * Add throwOnError and throwOnWarnings options. Remove throwError option * 4.0.0 * Document config file usage Adds documentation on how to use a config file at project root, mentioned in TrySound/rollup-plugin-eslint#20. * Update config file documentation * Update README.md * Remove node4 support and remove babel * Add prettier * Change api to named export * Upgrade eslint * Clean up gitignore * 5.0.0 * Fix tests warning * PR for optional config string PR to allow a string to be passed for specific config files; primarily to allow different Rollup configs to have different linting rules. * Fixed bug where .eslintrc files were still being used * v5.1.0 * feat: options.fix can change files * feat: add test case * Upgrade dependencies and tests * v6.0.0 * Fix travis * Upgrade to ESLint 6.0.0 * v7.0.0 * Preparing move to rollup/plugins * feat(eslint): fixed TrySound/rollup-plugin-eslint#38 * chore: update after review * chore: lint readme Co-authored-by: Bogdan Chadkin <[email protected]> Co-authored-by: Mark Brouch <[email protected]> Co-authored-by: Levi Roberts <[email protected]> Co-authored-by: frankieshen <[email protected]> Co-authored-by: Shenfq <[email protected]> Co-authored-by: Stéphane Goetz <[email protected]> Co-authored-by: shellscape <[email protected]>
1 parent 1459cf0 commit 257c7dc

22 files changed

+949
-225
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This repository houses plugins that Rollup considers critical to every day use o
2525
| [commonjs](packages/commonjs) | Convert CommonJS modules to ES6 |
2626
| [data-uri](packages/data-uri) | Import modules from Data URIs |
2727
| [dsv](packages/dsv) | Convert .csv and .tsv files into JavaScript modules with d3-dsv |
28+
| [eslint](packages/eslint) | Verify entry point and all imported files with ESLint |
2829
| [html](packages/html) | Create HTML files to serve Rollup bundles |
2930
| [image](packages/image) | Import JPG, PNG, GIF, SVG, and WebP files |
3031
| [inject](packages/inject) | Scan modules for global variables and injects `import` statements where necessary |

packages/eslint/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures/ignored.js

packages/eslint/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!/test/fixtures/node_modules

packages/eslint/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @rollup/plugin-eslint ChangeLog
2+
3+
## v8.0.0
4+
5+
_2020-10-25_
6+
7+
- Moved into repo from https://github.com/TrySound/rollup-plugin-eslint, see https://github.com/TrySound/rollup-plugin-eslint/pull/38

packages/eslint/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

packages/eslint/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[npm]: https://img.shields.io/npm/v/@rollup/plugin-alias
2+
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-alias
3+
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-alias
4+
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-alias
5+
6+
[![npm][npm]][npm-url]
7+
[![size][size]][size-url]
8+
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
9+
10+
# @rollup/plugin-eslint
11+
12+
🍣 A Rollup plugin to lint entry points and all imported files with ESLint.
13+
14+
## Install
15+
16+
Using npm:
17+
18+
```console
19+
npm install @rollup/plugin-eslint --save-dev
20+
# or
21+
yarn add -D @rollup/plugin-eslint
22+
```
23+
24+
## Usage
25+
26+
```js
27+
import eslint from '@rollup/plugin-eslint';
28+
29+
export default {
30+
input: 'main.js',
31+
plugins: [
32+
eslint({
33+
/* your options */
34+
})
35+
]
36+
};
37+
```
38+
39+
## Options
40+
41+
See more options here [eslint-config](http://eslint.org/docs/developer-guide/nodejs-api#cliengine).
42+
43+
You can also use eslint configuration in the form of a `.eslintrc.*` file in your project's root. It will be loaded automatically.
44+
45+
### fix
46+
47+
Type: `Boolean`<br>
48+
Default: `false`
49+
50+
If true, will auto fix source code.
51+
52+
### throwOnError
53+
54+
Type: `Boolean`<br>
55+
Default: `false`
56+
57+
If true, will throw an error if any errors were found.
58+
59+
### throwOnWarning
60+
61+
Type: `Boolean`<br>
62+
Default: `false`
63+
64+
If true, will throw an error if any warnings were found.
65+
66+
### include
67+
68+
Type: `Array | String`<br>
69+
Default: `[]`
70+
71+
A single file, or array of files, to include when linting.
72+
73+
### exclude
74+
75+
Type: `Array | String`<br>
76+
Default: `node_modules/**`
77+
78+
A single file, or array of files, to exclude when linting.
79+
80+
### formatter
81+
82+
Type: `Function | String`<br>
83+
Default: `stylish`
84+
85+
Custom error formatter or the name of a built-in formatter.
86+
87+
## Meta
88+
89+
[CONTRIBUTING](/.github/CONTRIBUTING.md)
90+
91+
[LICENSE (MIT)](/LICENSE)

packages/eslint/package.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"name": "@rollup/plugin-eslint",
3+
"version": "8.0.0",
4+
"publishConfig": {
5+
"access": "public"
6+
},
7+
"description": "Verify entry point and all imported files with ESLint",
8+
"license": "MIT",
9+
"repository": "rollup/plugins",
10+
"author": "Bogdan Chadkin <[email protected]>",
11+
"homepage": "https://github.com/rollup/plugins/tree/master/packages/eslint#readme",
12+
"bugs": "https://github.com/rollup/plugins/issues",
13+
"main": "dist/index.js",
14+
"module": "dist/index.es.js",
15+
"engines": {
16+
"node": ">= 10.0.0"
17+
},
18+
"scripts": {
19+
"build": "rollup -c",
20+
"ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov",
21+
"ci:lint": "pnpm run build && pnpm run lint",
22+
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
23+
"ci:test": "pnpm run test -- --verbose",
24+
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
25+
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
26+
"lint:js": "eslint --fix --cache src test types --ext .js,.ts",
27+
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
28+
"prebuild": "del-cli dist",
29+
"prepare": "pnpm run build",
30+
"prepublishOnly": "pnpm run lint && pnpm run test",
31+
"pretest": "pnpm run build",
32+
"test": "ava"
33+
},
34+
"files": [
35+
"dist",
36+
"types",
37+
"README.md",
38+
"LICENSE"
39+
],
40+
"keywords": [
41+
"rollup",
42+
"plugin",
43+
"rollup-plugin",
44+
"eslint",
45+
"es2015",
46+
"es6",
47+
"lint"
48+
],
49+
"peerDependencies": {
50+
"rollup": "^1.20.0||^2.0.0"
51+
},
52+
"dependencies": {
53+
"@rollup/pluginutils": "^4.0.0",
54+
"eslint": "^7.12.0"
55+
},
56+
"devDependencies": {
57+
"@rollup/plugin-node-resolve": "^9.0.0",
58+
"@rollup/plugin-typescript": "^6.0.0",
59+
"@types/eslint": "^7.2.2",
60+
"rollup": "^2.23.0"
61+
},
62+
"types": "types/index.d.ts",
63+
"ava": {
64+
"babel": {
65+
"compileEnhancements": false
66+
},
67+
"extensions": [
68+
"ts"
69+
],
70+
"require": [
71+
"ts-node/register"
72+
],
73+
"files": [
74+
"!**/fixtures/**",
75+
"!**/helpers/**",
76+
"!**/recipes/**",
77+
"!**/types.ts"
78+
]
79+
},
80+
"contributors": [
81+
"Andrew Powell <[email protected]>",
82+
"Mattias Ekstrand <[email protected]>"
83+
]
84+
}

packages/eslint/rollup.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
3+
import pkg from './package.json';
4+
5+
export default {
6+
input: 'src/index.ts',
7+
external: [...Object.keys(pkg.dependencies), 'path'],
8+
output: [
9+
{ file: pkg.main, format: 'cjs', exports: 'auto' },
10+
{ file: pkg.module, format: 'es' }
11+
],
12+
plugins: [typescript({ sourceMap: false })]
13+
};

packages/eslint/src/index.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import * as path from 'path';
2+
3+
import { Plugin } from 'rollup';
4+
import { createFilter } from 'rollup-pluginutils';
5+
import { CLIEngine } from 'eslint';
6+
7+
import { RollupEslintOptions } from '../types';
8+
9+
function normalizePath(id: string) {
10+
return path
11+
.relative(process.cwd(), id)
12+
.split(path.sep)
13+
.join('/');
14+
}
15+
16+
export default function eslint(options = {} as RollupEslintOptions): Plugin {
17+
if (typeof options === 'string') {
18+
const configFile = path.resolve(process.cwd(), options);
19+
// eslint-disable-next-line global-require, import/no-dynamic-require, no-param-reassign
20+
options = require(configFile);
21+
// Tell eslint not to look for configuration files.
22+
// eslint-disable-next-line no-param-reassign
23+
options.useEslintrc = false;
24+
}
25+
26+
const cli = new CLIEngine(options);
27+
let formatter: CLIEngine.Formatter;
28+
29+
switch (typeof options.formatter) {
30+
case 'string':
31+
formatter = cli.getFormatter(options.formatter);
32+
break;
33+
case 'function':
34+
({ formatter } = options);
35+
break;
36+
default:
37+
formatter = cli.getFormatter('stylish');
38+
}
39+
40+
const filter = createFilter(options.include, options.exclude || /node_modules/);
41+
42+
return {
43+
name: 'eslint',
44+
45+
// eslint-disable-next-line consistent-return
46+
transform(code, id) {
47+
const file = normalizePath(id);
48+
if (!filter(id) || cli.isPathIgnored(file)) {
49+
return null;
50+
}
51+
52+
const report = cli.executeOnText(code, file);
53+
const hasWarnings = options.throwOnWarning && report.warningCount !== 0;
54+
const hasErrors = options.throwOnError && report.errorCount !== 0;
55+
56+
if (options.fix && report) {
57+
CLIEngine.outputFixes(report);
58+
}
59+
60+
if (report.warningCount === 0 && report.errorCount === 0) {
61+
return null;
62+
}
63+
64+
const result = formatter(report.results);
65+
66+
if (result) {
67+
// eslint-disable-next-line no-console
68+
console.log(result);
69+
}
70+
71+
if (hasWarnings && hasErrors) {
72+
throw Error('Warnings or errors were found');
73+
}
74+
75+
if (hasWarnings) {
76+
throw Error('Warnings were found');
77+
}
78+
79+
if (hasErrors) {
80+
throw Error('Errors were found');
81+
}
82+
}
83+
};
84+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
root: true
2+
3+
env:
4+
browser: true
5+
node: true
6+
7+
rules:
8+
no-alert: 2
9+
no-bitwise: 1
10+
camelcase: 1
11+
curly: 1
12+
eqeqeq: 0
13+
no-eq-null: 0
14+
guard-for-in: 1
15+
no-empty: 1
16+
no-use-before-define: 0
17+
object-curly-spacing: 0
18+
no-obj-calls: 2
19+
no-unused-vars: 0
20+
new-cap: 1
21+
no-shadow: 0
22+
strict: 2
23+
global-strict: 0
24+
no-invalid-regexp: 2
25+
comma-dangle: 2
26+
no-undef: 1
27+
no-new: 1
28+
no-extra-semi: 1
29+
no-debugger: 2
30+
no-caller: 1
31+
semi: 1
32+
quotes: 0
33+
no-unreachable: 2
34+
eol-last: 0
35+
36+
parserOptions:
37+
ecmaVersion: 2015
38+
sourceType: 'module'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true,
6+
},
7+
ignorePatterns: process.env.NODE_ENV === 'test' ? ["ignored.js"] : ["**/*.js"],
8+
rules: {
9+
"no-alert": 2,
10+
"no-bitwise": 1,
11+
"camelcase": 1,
12+
"curly": 1,
13+
"eqeqeq": 0,
14+
"no-eq-null": 0,
15+
"guard-for-in": 1,
16+
"no-empty": 1,
17+
"no-use-before-define": 0,
18+
"object-curly-spacing": 0,
19+
"no-obj-calls": 2,
20+
"no-unused-vars": 0,
21+
"new-cap": 1,
22+
"no-shadow": 0,
23+
"strict": 2,
24+
"global-strict": 0,
25+
"no-invalid-regexp": 2,
26+
"comma-dangle": 2,
27+
"no-undef": 1,
28+
"no-new": 1,
29+
"no-extra-semi": 1,
30+
"no-debugger": 2,
31+
"no-caller": 1,
32+
"semi": 1,
33+
"quotes": 0,
34+
"no-unreachable": 2,
35+
"eol-last": 0,
36+
},
37+
};

0 commit comments

Comments
 (0)