Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(repo): migrate @TrySound/rollup-plugin-eslint #575

Merged
merged 53 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2174c68
Initial
TrySound Jan 31, 2016
d24b703
Add documentation
TrySound Jan 31, 2016
a57ebfd
Add npm files filter
TrySound Jan 31, 2016
8d93f67
1.0.0
TrySound Jan 31, 2016
6a43cde
Clear dist folder
TrySound Jan 31, 2016
66a8b91
Fix documentation
TrySound Jan 31, 2016
a76dc51
1.0.1
TrySound Jan 31, 2016
fc48b9f
Fix build
TrySound Feb 1, 2016
f83b07c
1.0.2
TrySound Feb 1, 2016
beea4a5
Upgrade eslint
TrySound Feb 13, 2016
8ab1689
2.0.0
TrySound Feb 13, 2016
37a8ac8
Tidy up
TrySound Jun 12, 2016
1a4f911
Return a name
TrySound Jun 23, 2016
79aa74b
2.0.2
TrySound Jun 23, 2016
52240a6
Upgrade to eslint 3
TrySound Sep 8, 2016
b46eba4
Add buble back
TrySound Sep 8, 2016
5693a22
v3.0.0
TrySound Sep 8, 2016
0a24a4e
Add lockfile
TrySound Jul 1, 2017
23486ce
Move to jest
TrySound Jul 1, 2017
61c0c1b
Build with babel
TrySound Jul 1, 2017
a1a0c2c
Upgrade dependencies
TrySound Jul 1, 2017
3e60dae
Add throwOnError and throwOnWarnings options. Remove throwError option
TrySound Jul 1, 2017
e2d3dcb
4.0.0
TrySound Jul 1, 2017
0a56873
Document config file usage
markbrouch Mar 9, 2018
b677da3
Update config file documentation
markbrouch Mar 10, 2018
3af75bf
Merge pull request #21 from markbrouch/patch-1
TrySound Mar 12, 2018
9a09d0b
Update README.md
TrySound Mar 12, 2018
002102c
Remove node4 support and remove babel
TrySound Jul 20, 2018
f4a9aae
Add prettier
TrySound Jul 20, 2018
9b7d10a
Change api to named export
TrySound Jul 20, 2018
7ba0743
Upgrade eslint
TrySound Jul 20, 2018
64659df
Clean up gitignore
TrySound Jul 20, 2018
9f07aa8
5.0.0
TrySound Jul 20, 2018
459bc20
Fix tests warning
TrySound Jul 20, 2018
e838619
PR for optional config string
bugs181 Mar 2, 2019
07d1b2c
Fixed bug where .eslintrc files were still being used
bugs181 Mar 5, 2019
6a7da9e
Merge pull request #26 from bugs181/master
TrySound Mar 22, 2019
223d2f2
v5.1.0
TrySound Mar 22, 2019
8ed450c
feat: options.fix can change files
May 8, 2019
237c7f5
feat: add test case
Shenfq May 12, 2019
3ef74c4
Merge pull request #27 from Shenfq/feature/fix-source-code
TrySound May 22, 2019
4a6aa9f
Upgrade dependencies and tests
TrySound May 22, 2019
f83bf3c
v6.0.0
TrySound May 22, 2019
b65047f
Fix travis
TrySound May 22, 2019
389e74d
Upgrade to ESLint 6.0.0
onigoetz Jun 24, 2019
b672ef3
Merge pull request #28 from onigoetz/master
TrySound Jun 24, 2019
8c5aba3
v7.0.0
TrySound Jun 24, 2019
f71ab79
Preparing move to rollup/plugins
atti187 Sep 15, 2020
04a794e
Merge remote-tracking branch 'rollup-plugin-eslint/master'
atti187 Sep 15, 2020
8b7bc58
feat(eslint): fixed https://github.com/TrySound/rollup-plugin-eslint/…
atti187 Sep 15, 2020
f88bf21
chore: update after review
shellscape Oct 26, 2020
93a4ef2
Merge remote-tracking branch 'upstream/master'
shellscape Oct 26, 2020
507b9d4
chore: lint readme
shellscape Oct 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This repository houses plugins that Rollup considers critical to every day use o
| [commonjs](packages/commonjs) | Convert CommonJS modules to ES6 |
| [data-uri](packages/data-uri) | Import modules from Data URIs |
| [dsv](packages/dsv) | Convert .csv and .tsv files into JavaScript modules with d3-dsv |
| [eslint](packages/eslint) | Verify entry point and all imported files with ESLint |
| [html](packages/html) | Create HTML files to serve Rollup bundles |
| [image](packages/image) | Import JPG, PNG, GIF, SVG, and WebP files |
| [inject](packages/inject) | Scan modules for global variables and injects `import` statements where necessary |
Expand Down
1 change: 1 addition & 0 deletions packages/eslint/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/fixtures/ignored.js
1 change: 1 addition & 0 deletions packages/eslint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!/test/fixtures/node_modules
7 changes: 7 additions & 0 deletions packages/eslint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @rollup/plugin-eslint ChangeLog

## v8.0.0

_2020-09-15_

- Moved into repo from https://github.com/TrySound/rollup-plugin-eslint, see https://github.com/TrySound/rollup-plugin-eslint/pull/38
21 changes: 21 additions & 0 deletions packages/eslint/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)
Copyright (c) 2020 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid mentioning 2020, let's skip straight to 2021


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.
92 changes: 92 additions & 0 deletions packages/eslint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[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 verify entry point 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 { rollup } from 'rollup';
import eslint from '@rollup/plugin-eslint';

export default {
input: 'main.js',
plugins: [
eslint({
/* your options */
}),
],
};
```

## Options

See more options here [eslint-config].

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`
Default: `false`

If true, will auto fix source code.

### throwOnError

Type: `boolean`
Default: `false`

If true, will throw an error if any errors were found.

### throwOnWarning

Type: `boolean`
Default: `false`

If true, will throw an error if any warnings were found.

### include

Type: `array` or `string`
Default: `[]`

A single file, or array of files, to include when linting.

### exclude

Type: `array` or `string`
Default: `node_modules/**`

A single file, or array of files, to exclude when linting.

### formatter

Type: `function` or `string`
Default: `stylish`

Custom error formatter or the name of a built-in formatter.

## Meta

[CONTRIBUTING](/.github/CONTRIBUTING.md)

[LICENSE (MIT)](/LICENSE)
83 changes: 83 additions & 0 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"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": {
"eslint": "^6.0.0",
"rollup-pluginutils": "^2.7.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be @rollup/pluginutils

},
"devDependencies": {
"@rollup/plugin-node-resolve": "^8.4.0",
"@rollup/plugin-typescript": "5.0.2",
"@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": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably should not be a part of ava config

"Mattias Ekstrand <mattias.ekstrand@gmail.com>"
]
}
}
13 changes: 13 additions & 0 deletions packages/eslint/rollup.config.js
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 })]
};
84 changes: 84 additions & 0 deletions packages/eslint/src/index.ts
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');
}
}
};
}
38 changes: 38 additions & 0 deletions packages/eslint/test/fixtures/.eslintrc-babel
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'
37 changes: 37 additions & 0 deletions packages/eslint/test/fixtures/.eslintrc.js
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,
},
};