Skip to content

Commit

Permalink
[New] support eslint 8.x
Browse files Browse the repository at this point in the history
Co-authored-by: Michaël De Boey <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
  • Loading branch information
MichaelDeBoey and ljharb committed Aug 30, 2021
1 parent e5b9f35 commit 3addf52
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"prefer-object-spread": 0, // until node 8 is required
"prefer-rest-params": 0, // until node 6 is required
"prefer-spread": 0, // until node 6 is required
"function-call-argument-newline": 1, // TODO: enable
"function-paren-newline": 0,
"no-plusplus": 1,
"no-param-reassign": 1,
"no-unreachable-loop": 1, // TODO: enable
"no-restricted-syntax": [2, {
"selector": "ObjectPattern",
"message": "Object destructuring is not compatible with Node v4"
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/node-4+.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
eslint:
- 8
- 7
- 6
- 5
Expand All @@ -45,24 +46,46 @@ jobs:
babel-eslint: 10
- node-version: 4
babel-eslint: 9
- node-version: 15
eslint: 8
- node-version: 13
eslint: 8
- node-version: 11
eslint: 8
- node-version: 11
eslint: 7
- node-version: 10
eslint: 8
- node-version: 9
eslint: 8
- node-version: 9
eslint: 7
- node-version: 8
eslint: 8
- node-version: 8
eslint: 7
- node-version: 7
eslint: 8
- node-version: 7
eslint: 7
- node-version: 7
eslint: 6
- node-version: 6
eslint: 8
- node-version: 6
eslint: 7
- node-version: 6
eslint: 6
- node-version: 5
eslint: 8
- node-version: 5
eslint: 7
- node-version: 5
eslint: 6
- node-version: 5
eslint: 5
- node-version: 4
eslint: 8
- node-version: 4
eslint: 7
- node-version: 4
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
## Unreleased

### Added
* support eslint 8.x ([#3059][] @MichaelDeBoey @ljharb)
* [`no-unused-class-component-methods`]: Handle unused class component methods ([#2166][] @jakeleventhal @pawelnvk)
* add [`no-arrow-function-lifecycle`] ([#1980][] @ngtan)
* add support for `@typescript-eslint/parser` v5 (@ljharb)
Expand Down Expand Up @@ -37,6 +38,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
[#3110]: https://github.com/yannickcr/eslint-plugin-react/pull/3110
[#3102]: https://github.com/yannickcr/eslint-plugin-react/issue/3102
[#3092]: https://github.com/yannickcr/eslint-plugin-react/pull/3092
[#3059]: https://github.com/yannickcr/eslint-plugin-react/pull/3059
[#2863]: https://github.com/yannickcr/eslint-plugin-react/pull/2863
[#2166]: https://github.com/yannickcr/eslint-plugin-react/pull/2166
[#1980]: https://github.com/yannickcr/eslint-plugin-react/pull/1980
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-equals-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = {
const spacedAfter = sourceCode.isSpaceBetweenTokens(equalToken, attrNode.value);

switch (config) {
default:
case 'never':
if (spacedBefore) {
report(context, messages.noSpaceBefore, 'noSpaceBefore', {
Expand Down Expand Up @@ -106,6 +105,7 @@ module.exports = {
});
}
break;
default:
}
});
},
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "React specific linting rules for ESLint",
"main": "index.js",
"scripts": {
"lint": "eslint ./",
"lint": "eslint .",
"postlint": "npm run type-check",
"pretest": "npm run lint",
"test": "npm run unit-test",
Expand Down Expand Up @@ -56,8 +56,8 @@
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4.0.0 || ^5.0.0",
"aud": "^1.1.5",
"babel-eslint": "^8 || ^9 || ^10.1.0",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7",
"eslint-config-airbnb-base": "^14.2.1",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-remote-tester": "^2.0.1",
Expand All @@ -73,7 +73,7 @@
"typescript-eslint-parser": "^20.1.1"
},
"peerDependencies": {
"eslint": "^3 || ^4 || ^5 || ^6 || ^7"
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8"
},
"engines": {
"node": ">=4"
Expand Down
11 changes: 11 additions & 0 deletions tests/helpers/getESLintCoreRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const version = require('eslint/package.json').version;
const semver = require('semver');

const isESLintV8 = semver.major(version) >= 8;

// eslint-disable-next-line global-require, import/no-dynamic-require, import/no-unresolved
const getESLintCoreRule = (ruleId) => (isESLintV8 ? require('eslint/use-at-your-own-risk').builtinRules.get(ruleId) : require(`eslint/lib/rules/${ruleId}`));

module.exports = getESLintCoreRule;
11 changes: 9 additions & 2 deletions tests/helpers/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const parsers = {
const es = test.parserOptions && test.parserOptions.ecmaVersion;

function addComment(testObject, parser) {
const extraComment = `\n// features: [${Array.from(features).join(',')}], parser: ${parser}, parserOptions: ${testObject.parserOptions}`;
const extraComment = `\n// features: [${Array.from(features).join(',')}], parser: ${parser}, parserOptions: ${JSON.stringify(testObject.parserOptions)}`;
return Object.assign(
{},
testObject,
Expand Down Expand Up @@ -98,7 +98,14 @@ const parsers = {
const tsNew = !skipTS && !features.has('no-ts-new');

return [].concat(
skipBase ? [] : addComment(test, 'default'),
skipBase ? [] : addComment(
Object.assign({}, test, features.has('class fields') && {
parserOptions: Object.assign({}, test.parserOptions, {
ecmaVersion: Math.max((test.parserOptions && test.parserOptions.ecmaVersion) || 0, 2022),
}),
}),
'default'
),
skipOldBabel ? [] : addComment(Object.assign({}, test, {
parser: parsers.BABEL_ESLINT,
parserOptions: parsers.babelParserOptions(test, features),
Expand Down
3 changes: 0 additions & 3 deletions tests/lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ ruleTester.run('destructuring-assignment', rule, {
);
};
`,
parser: parsers.BABEL_ESLINT,
errors: [
{
messageId: 'useDestructAssignment',
Expand Down Expand Up @@ -675,7 +674,6 @@ ruleTester.run('destructuring-assignment', rule, {
},
};
`,
parser: parsers.BABEL_ESLINT,
errors: [
{
messageId: 'useDestructAssignment',
Expand Down Expand Up @@ -704,7 +702,6 @@ ruleTester.run('destructuring-assignment', rule, {
};
}
`,
parser: parsers.BABEL_ESLINT,
errors: [
{
messageId: 'useDestructAssignment',
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-no-undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const parserOptions = {
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions });
const linter = ruleTester.linter || eslint.linter;
linter.defineRule('no-undef', require('eslint/lib/rules/no-undef'));
const linter = ruleTester.linter || eslint.linter || eslint.Linter;
linter.defineRule('no-undef', require('../../helpers/getESLintCoreRule')('no-undef'));

ruleTester.run('jsx-no-undef', rule, {
valid: parsers.all([
Expand Down
4 changes: 1 addition & 3 deletions tests/lib/rules/jsx-no-useless-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
// Requirements
// -----------------------------------------------------------------------------

const eslint = require('eslint');
const RuleTester = require('eslint').RuleTester;
const rule = require('../../../lib/rules/jsx-no-useless-fragment');
const parsers = require('../../helpers/parsers');

const RuleTester = eslint.RuleTester;

const parserOptions = {
ecmaVersion: 2018,
ecmaFeatures: {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-uses-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// -----------------------------------------------------------------------------

const eslint = require('eslint');
const rule = require('eslint/lib/rules/no-unused-vars');
const rule = require('../../helpers/getESLintCoreRule')('no-unused-vars');

const RuleTester = eslint.RuleTester;

Expand All @@ -35,7 +35,7 @@ const settings = {
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions });
const linter = ruleTester.linter || eslint.linter;
const linter = ruleTester.linter || eslint.linter || eslint.Linter;
linter.defineRule('jsx-uses-react', require('../../../lib/rules/jsx-uses-react'));

ruleTester.run('no-unused-vars', rule, {
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/jsx-uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// -----------------------------------------------------------------------------

const eslint = require('eslint');
const ruleNoUnusedVars = require('eslint/lib/rules/no-unused-vars');
const rulePreferConst = require('eslint/lib/rules/prefer-const');
const ruleNoUnusedVars = require('../../helpers/getESLintCoreRule')('no-unused-vars');
const rulePreferConst = require('../../helpers/getESLintCoreRule')('prefer-const');

const RuleTester = eslint.RuleTester;

Expand All @@ -30,7 +30,7 @@ const parserOptions = {
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions });
const linter = ruleTester.linter || eslint.linter;
const linter = ruleTester.linter || eslint.linter || eslint.Linter;
linter.defineRule('jsx-uses-vars', require('../../../lib/rules/jsx-uses-vars'));

ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
Expand Down
6 changes: 0 additions & 6 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ ruleTester.run('no-unused-prop-types', rule, {
}
`,
features: ['class fields', 'optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down Expand Up @@ -775,9 +772,6 @@ ruleTester.run('no-unused-prop-types', rule, {
}
`,
features: ['class fields', 'optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down

0 comments on commit 3addf52

Please sign in to comment.