-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <trysound@yandex.ru> Co-authored-by: Mark Brouch <mark.brouch@gmail.com> Co-authored-by: Levi Roberts <bugs181@gmail.com> Co-authored-by: frankieshen <frankieshen@tencent.com> Co-authored-by: Shenfq <shenfq95@foxmail.com> Co-authored-by: Stéphane Goetz <stephane.goetz@swissquote.ch> Co-authored-by: shellscape <andrew@shellscape.org>
- Loading branch information
1 parent
1459cf0
commit 257c7dc
Showing
22 changed files
with
949 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/fixtures/ignored.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!/test/fixtures/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# @rollup/plugin-eslint ChangeLog | ||
|
||
## v8.0.0 | ||
|
||
_2020-10-25_ | ||
|
||
- Moved into repo from https://github.com/TrySound/rollup-plugin-eslint, see https://github.com/TrySound/rollup-plugin-eslint/pull/38 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
[npm]: https://img.shields.io/npm/v/@rollup/plugin-alias | ||
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-alias | ||
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-alias | ||
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-alias | ||
|
||
[![npm][npm]][npm-url] | ||
[![size][size]][size-url] | ||
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com) | ||
|
||
# @rollup/plugin-eslint | ||
|
||
🍣 A Rollup plugin to lint entry points and all imported files with ESLint. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```console | ||
npm install @rollup/plugin-eslint --save-dev | ||
# or | ||
yarn add -D @rollup/plugin-eslint | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import eslint from '@rollup/plugin-eslint'; | ||
|
||
export default { | ||
input: 'main.js', | ||
plugins: [ | ||
eslint({ | ||
/* your options */ | ||
}) | ||
] | ||
}; | ||
``` | ||
|
||
## Options | ||
|
||
See more options here [eslint-config](http://eslint.org/docs/developer-guide/nodejs-api#cliengine). | ||
|
||
You can also use eslint configuration in the form of a `.eslintrc.*` file in your project's root. It will be loaded automatically. | ||
|
||
### fix | ||
|
||
Type: `Boolean`<br> | ||
Default: `false` | ||
|
||
If true, will auto fix source code. | ||
|
||
### throwOnError | ||
|
||
Type: `Boolean`<br> | ||
Default: `false` | ||
|
||
If true, will throw an error if any errors were found. | ||
|
||
### throwOnWarning | ||
|
||
Type: `Boolean`<br> | ||
Default: `false` | ||
|
||
If true, will throw an error if any warnings were found. | ||
|
||
### include | ||
|
||
Type: `Array | String`<br> | ||
Default: `[]` | ||
|
||
A single file, or array of files, to include when linting. | ||
|
||
### exclude | ||
|
||
Type: `Array | String`<br> | ||
Default: `node_modules/**` | ||
|
||
A single file, or array of files, to exclude when linting. | ||
|
||
### formatter | ||
|
||
Type: `Function | String`<br> | ||
Default: `stylish` | ||
|
||
Custom error formatter or the name of a built-in formatter. | ||
|
||
## Meta | ||
|
||
[CONTRIBUTING](/.github/CONTRIBUTING.md) | ||
|
||
[LICENSE (MIT)](/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"name": "@rollup/plugin-eslint", | ||
"version": "8.0.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Verify entry point and all imported files with ESLint", | ||
"license": "MIT", | ||
"repository": "rollup/plugins", | ||
"author": "Bogdan Chadkin <trysound@yandex.ru>", | ||
"homepage": "https://github.com/rollup/plugins/tree/master/packages/eslint#readme", | ||
"bugs": "https://github.com/rollup/plugins/issues", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"engines": { | ||
"node": ">= 10.0.0" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov", | ||
"ci:lint": "pnpm run build && pnpm run lint", | ||
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", | ||
"ci:test": "pnpm run test -- --verbose", | ||
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", | ||
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md", | ||
"lint:js": "eslint --fix --cache src test types --ext .js,.ts", | ||
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package", | ||
"prebuild": "del-cli dist", | ||
"prepare": "pnpm run build", | ||
"prepublishOnly": "pnpm run lint && pnpm run test", | ||
"pretest": "pnpm run build", | ||
"test": "ava" | ||
}, | ||
"files": [ | ||
"dist", | ||
"types", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"keywords": [ | ||
"rollup", | ||
"plugin", | ||
"rollup-plugin", | ||
"eslint", | ||
"es2015", | ||
"es6", | ||
"lint" | ||
], | ||
"peerDependencies": { | ||
"rollup": "^1.20.0||^2.0.0" | ||
}, | ||
"dependencies": { | ||
"@rollup/pluginutils": "^4.0.0", | ||
"eslint": "^7.12.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-typescript": "^6.0.0", | ||
"@types/eslint": "^7.2.2", | ||
"rollup": "^2.23.0" | ||
}, | ||
"types": "types/index.d.ts", | ||
"ava": { | ||
"babel": { | ||
"compileEnhancements": false | ||
}, | ||
"extensions": [ | ||
"ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"files": [ | ||
"!**/fixtures/**", | ||
"!**/helpers/**", | ||
"!**/recipes/**", | ||
"!**/types.ts" | ||
] | ||
}, | ||
"contributors": [ | ||
"Andrew Powell <andrew@shellscape.org>", | ||
"Mattias Ekstrand <mattias.ekstrand@gmail.com>" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
|
||
import pkg from './package.json'; | ||
|
||
export default { | ||
input: 'src/index.ts', | ||
external: [...Object.keys(pkg.dependencies), 'path'], | ||
output: [ | ||
{ file: pkg.main, format: 'cjs', exports: 'auto' }, | ||
{ file: pkg.module, format: 'es' } | ||
], | ||
plugins: [typescript({ sourceMap: false })] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import * as path from 'path'; | ||
|
||
import { Plugin } from 'rollup'; | ||
import { createFilter } from 'rollup-pluginutils'; | ||
import { CLIEngine } from 'eslint'; | ||
|
||
import { RollupEslintOptions } from '../types'; | ||
|
||
function normalizePath(id: string) { | ||
return path | ||
.relative(process.cwd(), id) | ||
.split(path.sep) | ||
.join('/'); | ||
} | ||
|
||
export default function eslint(options = {} as RollupEslintOptions): Plugin { | ||
if (typeof options === 'string') { | ||
const configFile = path.resolve(process.cwd(), options); | ||
// eslint-disable-next-line global-require, import/no-dynamic-require, no-param-reassign | ||
options = require(configFile); | ||
// Tell eslint not to look for configuration files. | ||
// eslint-disable-next-line no-param-reassign | ||
options.useEslintrc = false; | ||
} | ||
|
||
const cli = new CLIEngine(options); | ||
let formatter: CLIEngine.Formatter; | ||
|
||
switch (typeof options.formatter) { | ||
case 'string': | ||
formatter = cli.getFormatter(options.formatter); | ||
break; | ||
case 'function': | ||
({ formatter } = options); | ||
break; | ||
default: | ||
formatter = cli.getFormatter('stylish'); | ||
} | ||
|
||
const filter = createFilter(options.include, options.exclude || /node_modules/); | ||
|
||
return { | ||
name: 'eslint', | ||
|
||
// eslint-disable-next-line consistent-return | ||
transform(code, id) { | ||
const file = normalizePath(id); | ||
if (!filter(id) || cli.isPathIgnored(file)) { | ||
return null; | ||
} | ||
|
||
const report = cli.executeOnText(code, file); | ||
const hasWarnings = options.throwOnWarning && report.warningCount !== 0; | ||
const hasErrors = options.throwOnError && report.errorCount !== 0; | ||
|
||
if (options.fix && report) { | ||
CLIEngine.outputFixes(report); | ||
} | ||
|
||
if (report.warningCount === 0 && report.errorCount === 0) { | ||
return null; | ||
} | ||
|
||
const result = formatter(report.results); | ||
|
||
if (result) { | ||
// eslint-disable-next-line no-console | ||
console.log(result); | ||
} | ||
|
||
if (hasWarnings && hasErrors) { | ||
throw Error('Warnings or errors were found'); | ||
} | ||
|
||
if (hasWarnings) { | ||
throw Error('Warnings were found'); | ||
} | ||
|
||
if (hasErrors) { | ||
throw Error('Errors were found'); | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
root: true | ||
|
||
env: | ||
browser: true | ||
node: true | ||
|
||
rules: | ||
no-alert: 2 | ||
no-bitwise: 1 | ||
camelcase: 1 | ||
curly: 1 | ||
eqeqeq: 0 | ||
no-eq-null: 0 | ||
guard-for-in: 1 | ||
no-empty: 1 | ||
no-use-before-define: 0 | ||
object-curly-spacing: 0 | ||
no-obj-calls: 2 | ||
no-unused-vars: 0 | ||
new-cap: 1 | ||
no-shadow: 0 | ||
strict: 2 | ||
global-strict: 0 | ||
no-invalid-regexp: 2 | ||
comma-dangle: 2 | ||
no-undef: 1 | ||
no-new: 1 | ||
no-extra-semi: 1 | ||
no-debugger: 2 | ||
no-caller: 1 | ||
semi: 1 | ||
quotes: 0 | ||
no-unreachable: 2 | ||
eol-last: 0 | ||
|
||
parserOptions: | ||
ecmaVersion: 2015 | ||
sourceType: 'module' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
browser: true, | ||
node: true, | ||
}, | ||
ignorePatterns: process.env.NODE_ENV === 'test' ? ["ignored.js"] : ["**/*.js"], | ||
rules: { | ||
"no-alert": 2, | ||
"no-bitwise": 1, | ||
"camelcase": 1, | ||
"curly": 1, | ||
"eqeqeq": 0, | ||
"no-eq-null": 0, | ||
"guard-for-in": 1, | ||
"no-empty": 1, | ||
"no-use-before-define": 0, | ||
"object-curly-spacing": 0, | ||
"no-obj-calls": 2, | ||
"no-unused-vars": 0, | ||
"new-cap": 1, | ||
"no-shadow": 0, | ||
"strict": 2, | ||
"global-strict": 0, | ||
"no-invalid-regexp": 2, | ||
"comma-dangle": 2, | ||
"no-undef": 1, | ||
"no-new": 1, | ||
"no-extra-semi": 1, | ||
"no-debugger": 2, | ||
"no-caller": 1, | ||
"semi": 1, | ||
"quotes": 0, | ||
"no-unreachable": 2, | ||
"eol-last": 0, | ||
}, | ||
}; |
Oops, something went wrong.