From 05c3ae13fd90c61a116eb0a5d8afd1ad7e0a3841 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Mon, 25 Oct 2021 19:42:39 -0500 Subject: [PATCH] feat: support ESLint v8 --- .README/README.md | 17 ++++------------- .eslintrc | 1 - README.md | 17 ++++------------- package.json | 8 +++++--- src/configs/recommended.json | 10 +++++++++- tests/rules/assertions/defineFlowType.js | 16 ++++++++++++++-- tests/rules/assertions/useFlowType.js | 24 +++++++++++++++++++++--- tests/rules/index.js | 14 ++++++++++++-- 8 files changed, 69 insertions(+), 38 deletions(-) diff --git a/.README/README.md b/.README/README.md index 83347eb8..2f94bbcc 100644 --- a/.README/README.md +++ b/.README/README.md @@ -10,24 +10,15 @@ ## Installation -1. Install [ESLint](https://www.github.com/eslint/eslint). -1. Install [`babel-eslint`](https://github.com/babel/babel-eslint) parser (ESLint parser [does not support type annotations](https://github.com/eslint/eslint/issues/2157)). -1. Install [`eslint-plugin-flowtype`](https://github.com/gajus/eslint-plugin-flowtype) plugin. - - - -```sh +```bash npm install eslint --save-dev -npm install babel-eslint --save-dev +npm install @babel/eslint-parser --save-dev npm install eslint-plugin-flowtype --save-dev - -# Or all at once: -npm install eslint babel-eslint eslint-plugin-flowtype --save-dev ``` ## Configuration -1. Set `parser` property to `babel-eslint`. +1. Set `parser` property to `@babel/eslint-parser`. 1. Add `plugins` section and specify `eslint-plugin-flowtype` as a plugin. 1. Enable rules. @@ -35,7 +26,7 @@ npm install eslint babel-eslint eslint-plugin-flowtype --save-dev ```json { - "parser": "babel-eslint", + "parser": "@babel/eslint-parser", "plugins": [ "flowtype" ], diff --git a/.eslintrc b/.eslintrc index e6e3f91a..7c9b2e73 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,7 +6,6 @@ "rules": { "eslint-plugin/require-meta-schema": 0, "eslint-plugin/require-meta-type": 0, - "unicorn/prevent-abbreviations": 0 } } diff --git a/README.md b/README.md index 0d461547..42e5e916 100644 --- a/README.md +++ b/README.md @@ -67,25 +67,16 @@ ## Installation -1. Install [ESLint](https://www.github.com/eslint/eslint). -1. Install [`babel-eslint`](https://github.com/babel/babel-eslint) parser (ESLint parser [does not support type annotations](https://github.com/eslint/eslint/issues/2157)). -1. Install [`eslint-plugin-flowtype`](https://github.com/gajus/eslint-plugin-flowtype) plugin. - - - -```sh +```bash npm install eslint --save-dev -npm install babel-eslint --save-dev +npm install @babel/eslint-parser --save-dev npm install eslint-plugin-flowtype --save-dev - -# Or all at once: -npm install eslint babel-eslint eslint-plugin-flowtype --save-dev ``` ## Configuration -1. Set `parser` property to `babel-eslint`. +1. Set `parser` property to `@babel/eslint-parser`. 1. Add `plugins` section and specify `eslint-plugin-flowtype` as a plugin. 1. Enable rules. @@ -93,7 +84,7 @@ npm install eslint babel-eslint eslint-plugin-flowtype --save-dev ```json { - "parser": "babel-eslint", + "parser": "@babel/eslint-parser", "plugins": [ "flowtype" ], diff --git a/package.json b/package.json index f9aaeff8..ce1218c7 100644 --- a/package.json +++ b/package.json @@ -12,16 +12,18 @@ "devDependencies": { "@babel/cli": "^7.15.4", "@babel/core": "^7.15.5", + "@babel/eslint-parser": "^7.15.8", "@babel/node": "^7.15.4", "@babel/plugin-proposal-object-rest-spread": "^7.15.6", + "@babel/plugin-syntax-flow": "^7.14.5", + "@babel/plugin-transform-react-jsx": "^7.14.9", "@babel/preset-env": "^7.15.6", "@babel/register": "^7.15.3", "ajv": "^8.6.3", - "babel-eslint": "^10.1.0", "babel-plugin-add-module-exports": "^1.0.4", "chai": "^4.3.4", "eclint": "^2.8.1", - "eslint": "^7.32.0", + "eslint": "^8.1.0", "eslint-config-canonical": "^27.0.1", "eslint-plugin-eslint-plugin": "^4.0.1", "gitdown": "^3.1.4", @@ -49,7 +51,7 @@ "main": "./dist/index.js", "name": "eslint-plugin-flowtype", "peerDependencies": { - "eslint": "^7.32.0" + "eslint": "^7.0.0 || ^8.0.0" }, "repository": { "type": "git", diff --git a/src/configs/recommended.json b/src/configs/recommended.json index 13cc76ec..90a0d690 100644 --- a/src/configs/recommended.json +++ b/src/configs/recommended.json @@ -1,5 +1,13 @@ { - "parser": "babel-eslint", + "parser": "@babel/eslint", + "parserOptions": { + "babelOptions": { + "plugins": [ + "@babel/plugin-transform-react-jsx", + "@babel/plugin-syntax-flow" + ] + } + }, "plugins": [ "flowtype" ], diff --git a/tests/rules/assertions/defineFlowType.js b/tests/rules/assertions/defineFlowType.js index d8fb46b5..11287cc3 100644 --- a/tests/rules/assertions/defineFlowType.js +++ b/tests/rules/assertions/defineFlowType.js @@ -202,7 +202,13 @@ const ALWAYS_VALID = [ */ { const ruleTester = new RuleTester({ - parser: require.resolve('babel-eslint'), + parser: require.resolve('@babel/eslint-parser'), + parserOptions: { + babelOptions: { + plugins: ['@babel/plugin-syntax-flow'], + }, + requireConfigFile: false, + }, }); ruleTester.run('no-undef must not trigger an error in these cases', noUndefRule, { @@ -213,7 +219,13 @@ const ALWAYS_VALID = [ { const ruleTester = new RuleTester({ - parser: require.resolve('babel-eslint'), + parser: require.resolve('@babel/eslint-parser'), + parserOptions: { + babelOptions: { + plugins: ['@babel/plugin-syntax-flow'], + }, + requireConfigFile: false, + }, }); ruleTester.run('no-undef must trigger an error when define-flow-type is not used in these cases', noUndefRule, { diff --git a/tests/rules/assertions/useFlowType.js b/tests/rules/assertions/useFlowType.js index b0ef5dbe..46e30c53 100644 --- a/tests/rules/assertions/useFlowType.js +++ b/tests/rules/assertions/useFlowType.js @@ -96,7 +96,13 @@ const ALWAYS_VALID = [ */ { const ruleTester = new RuleTester({ - parser: require.resolve('babel-eslint'), + parser: require.resolve('@babel/eslint-parser'), + parserOptions: { + babelOptions: { + plugins: ['@babel/plugin-syntax-flow'], + }, + requireConfigFile: false, + }, }); ruleTester.run('no-unused-vars must not trigger an error in these cases', noUnusedVarsRule, { @@ -107,7 +113,13 @@ const ALWAYS_VALID = [ { const ruleTester = new RuleTester({ - parser: require.resolve('babel-eslint'), + parser: require.resolve('@babel/eslint-parser'), + parserOptions: { + babelOptions: { + plugins: ['@babel/plugin-syntax-flow'], + }, + requireConfigFile: false, + }, }); ruleTester.run('no-unused-vars must trigger an error in these cases', noUnusedVarsRule, { @@ -121,7 +133,13 @@ const ALWAYS_VALID = [ { const ruleTester = new RuleTester({ - parser: require.resolve('babel-eslint'), + parser: require.resolve('@babel/eslint-parser'), + parserOptions: { + babelOptions: { + plugins: ['@babel/plugin-syntax-flow'], + }, + requireConfigFile: false, + }, rules: { 'use-flow-type': 1, }, diff --git a/tests/rules/index.js b/tests/rules/index.js index 87d0a7ab..3204ca96 100644 --- a/tests/rules/index.js +++ b/tests/rules/index.js @@ -8,7 +8,17 @@ import { } from 'lodash'; import plugin from '../../src'; -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + parserOptions: { + babelOptions: { + plugins: [ + '@babel/plugin-transform-react-jsx', + '@babel/plugin-syntax-flow' + ], + }, + requireConfigFile: false, + }, +}); const reportingRules = [ 'array-style-complex-type', @@ -60,7 +70,7 @@ const reportingRules = [ 'valid-syntax', ]; -const parser = require.resolve('babel-eslint'); +const parser = require.resolve('@babel/eslint-parser'); const ajv = new Ajv({ verbose: true, });