Skip to content

Commit

Permalink
Support ESLint v8 (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Oct 11, 2021
1 parent 9feb181 commit e97ab7e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 95 deletions.
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])}`;

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

0 comments on commit e97ab7e

Please sign in to comment.