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

Support ESLint v8 #1488

Merged
merged 30 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e978f6c
Update ESLint to v8
fisker Aug 16, 2021
534ab97
Fix
fisker Aug 16, 2021
10eaf4f
Fix `prefer-number-properties`
fisker Aug 16, 2021
0241803
Use `--force` to install
fisker Aug 16, 2021
9a86e90
Fix `no-keyword-prefix`
fisker Aug 16, 2021
94a2bd5
Fix lint-on-codebase script
fisker Aug 16, 2021
03b6572
Ignores
fisker Aug 16, 2021
bb9827c
Remove `--force` flag
fisker Aug 16, 2021
04efa90
Fix integration test
fisker Aug 16, 2021
fedb848
Use `--legacy-peer-deps`
fisker Aug 16, 2021
02bf536
Fix `xo`
fisker Aug 16, 2021
8ebc4cd
Update `prefer-dom-node-text-content` snapshot
fisker Aug 16, 2021
15737ff
Update `prefer-module` snapshot
fisker Aug 16, 2021
e80d01d
Another integration error
fisker Aug 16, 2021
459a1fc
Style
fisker Aug 16, 2021
1ddccc6
Ignore more files
fisker Aug 16, 2021
b470d56
Fix ignore
fisker Aug 16, 2021
9d72e6a
Merge branch 'main' into eslint-8
fisker Sep 18, 2021
5d16a1b
eslint@8.0.0-beta.2
fisker Sep 18, 2021
5e2c671
Replace `SourceCodeFixer.applyFixes`
fisker Sep 18, 2021
4118c12
Fix test
fisker Sep 18, 2021
383b748
Style
fisker Sep 18, 2021
97f00bf
Extract `applyFix`
fisker Sep 18, 2021
0517f54
`eslint@8.0.0-rc.0`
fisker Sep 27, 2021
e64df4b
Revert unneeded change in integration test
fisker Sep 27, 2021
46f049b
Merge branch 'main' into eslint-8
fisker Sep 27, 2021
b3c1d1a
Remove outdated code
fisker Sep 27, 2021
1250c09
Update package.json
sindresorhus Oct 11, 2021
271754c
Merge branch 'main' into eslint-8
fisker Oct 11, 2021
aed2bfe
Update `peerDependencies`
fisker Oct 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install --legacy-peer-deps
- run: npx ava
lint-test:
runs-on: ubuntu-latest
Expand All @@ -33,8 +33,8 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm install
- run: npx xo
- run: npm install --legacy-peer-deps
# - run: npx xo
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
- run: npx nyc ava --update-snapshots
env:
Expand All @@ -45,17 +45,19 @@ jobs:
- uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
# `xo` can't work on ESLint 8
- run: npm install eslint@7 && npx xo
run-rules-on-codebase:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run run-rules-on-codebase
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run integration
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"ava": "^3.15.0",
"chalk": "^4.1.2",
"enquirer": "2.3.6",
"eslint": "^7.32.0",
"eslint": "^8.0.0",
"eslint-ava-rule-tester": "^4.0.0",
"eslint-plugin-eslint-plugin": "^3.5.3",
"eslint-remote-tester": "^1.3.0",
Expand All @@ -79,7 +79,7 @@
"xo": "^0.44.0"
},
"peerDependencies": {
"eslint": ">=7.32.0"
"eslint": ">=8.0.0"
},
"ava": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const readPkgUp = require('read-pkg-up');
const semver = require('semver');
const ci = require('ci-info');
const baseRule = require('eslint/lib/rules/no-warning-comments');
const baseRule = require('eslint/use-at-your-own-risk').builtinRules.get('no-warning-comments');

// `unicorn/` prefix is added to avoid conflicts with core rule
const MESSAGE_ID_AVOID_MULTIPLE_DATES = 'unicorn/avoidMultipleDates';
Expand Down
2 changes: 2 additions & 0 deletions rules/no-keyword-prefix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const isShorthandPropertyAssignmentPatternLeft = require('./utils/is-shorthand-property-assignment-pattern-left.js');

const MESSAGE_ID = 'noKeywordPrefix';
const messages = {
Expand Down Expand Up @@ -130,6 +131,7 @@ const create = context => {
Boolean(keyword)
&& !ALLOWED_PARENT_TYPES.has(effectiveParent.type)
&& !(parent.right === node)
&& !isShorthandPropertyAssignmentPatternLeft(node)
) {
report(node, keyword);
}
Expand Down
2 changes: 1 addition & 1 deletion rules/selectors/reference-identifier-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const nonReferenceSelectors = [
// `const Identifier = 1`
'VariableDeclarator > .id',
// `const foo = {Identifier: 1}`
'ObjectExpression > Property[shorthand!=true][computed!=true].properties > .key',
'ObjectExpression > Property[computed!=true].properties > .key',
// `const {Identifier} = {}`
// `const {Identifier: foo} = {}`
'ObjectPattern > Property[computed!=true].properties > .key',
Expand Down
65 changes: 5 additions & 60 deletions test/snapshots/prefer-dom-node-text-content.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #4
1 | const {innerText} = node;

> Error 1/2

`␊
> 1 | const {innerText} = node;␊
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`.textContent\`.␊
1 | const {textContent: innerText} = node;␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | const {innerText} = node;␊
Expand All @@ -74,18 +63,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #5
1 | const {innerText,} = node;

> Error 1/2

`␊
> 1 | const {innerText,} = node;␊
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`.textContent\`.␊
1 | const {textContent: innerText,} = node;␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | const {innerText,} = node;␊
Expand Down Expand Up @@ -113,18 +91,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #7
1 | ({innerText} = node);

> Error 1/2

`␊
> 1 | ({innerText} = node);␊
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`.textContent\`.␊
1 | ({textContent: innerText} = node);␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | ({innerText} = node);␊
Expand Down Expand Up @@ -152,18 +119,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #9
1 | function foo({innerText}) {return innerText}

> Error 1/2

`␊
> 1 | function foo({innerText}) {return innerText}␊
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`.textContent\`.␊
1 | function foo({textContent: innerText}) {return innerText}␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | function foo({innerText}) {return innerText}␊
Expand All @@ -177,18 +133,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #10
1 | for (const [{innerText}] of elements);

> Error 1/2

`␊
> 1 | for (const [{innerText}] of elements);␊
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`.textContent\`.␊
1 | for (const [{textContent: innerText}] of elements);␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | for (const [{innerText}] of elements);␊
Expand Down
Binary file modified test/snapshots/prefer-dom-node-text-content.mjs.snap
Binary file not shown.
26 changes: 2 additions & 24 deletions test/snapshots/prefer-module.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #3
1 | const foo = { __dirname};

> Error 1/2

`␊
> 1 | const foo = { __dirname};␊
| ^^^^^^^^^ Do not use "__dirname".␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Replace "__dirname" with \`"…(import.meta.url)"\`.␊
1 | const foo = { __dirname: path.dirname(url.fileURLToPath(import.meta.url))};␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | const foo = { __dirname};␊
Expand All @@ -144,18 +133,7 @@ Generated by [AVA](https://avajs.dev).
## Invalid #4
1 | const foo = {__filename, };

> Error 1/2

`␊
> 1 | const foo = {__filename, };␊
| ^^^^^^^^^^ Do not use "__filename".␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Replace "__filename" with \`"…(import.meta.url)"\`.␊
1 | const foo = {__filename: url.fileURLToPath(import.meta.url), };␊
`

> Error 2/2
> Error 1/1

`␊
> 1 | const foo = {__filename, };␊
Expand Down
Binary file modified test/snapshots/prefer-module.mjs.snap
Binary file not shown.
8 changes: 6 additions & 2 deletions test/utils/snapshot-rule-tester.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {createRequire} from 'node:module';
import {Linter, SourceCodeFixer} from 'eslint/lib/linter/index.js';
import {Linter} from 'eslint';
import {codeFrameColumns} from '@babel/code-frame';
import outdent from 'outdent';

const require = createRequire(import.meta.url);
const codeFrameColumnsOptions = {linesAbove: Number.POSITIVE_INFINITY, linesBelow: Number.POSITIVE_INFINITY};
// A simple version of `SourceCodeFixer.applyFixes`
// https://github.com/eslint/eslint/issues/14936#issuecomment-906746754
const applyFix = (code, {fix}) => `${code.slice(0, fix.range[0])}${fix.text}${code.slice(fix.range[1])}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a lot of noise to concat 3 variables, I'd use

Suggested change
const applyFix = (code, {fix}) => `${code.slice(0, fix.range[0])}${fix.text}${code.slice(fix.range[1])}`;
const applyFix = (code, {fix}) => code.slice(0, fix.range[0]) + fix.text + code.slice(fix.range[1]);


function visualizeRange(text, location, message) {
return codeFrameColumns(
Expand Down Expand Up @@ -184,7 +187,8 @@ class SnapshotRuleTester {
}

for (const [index, suggestion] of suggestions.entries()) {
const {output} = SourceCodeFixer.applyFixes(code, [suggestion]);
const output = applyFix(code, suggestion);

messageForSnapshot += outdent`
\n
${'-'.repeat(80)}
Expand Down