Skip to content

Commit

Permalink
feat: support ESLint v8
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 26, 2021
1 parent 9deb04d commit 05c3ae1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 38 deletions.
17 changes: 4 additions & 13 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,23 @@

## 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.

<!-- -->

```json
{
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"plugins": [
"flowtype"
],
Expand Down
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"rules": {
"eslint-plugin/require-meta-schema": 0,
"eslint-plugin/require-meta-type": 0,

"unicorn/prevent-abbreviations": 0
}
}
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,24 @@
<a name="eslint-plugin-flowtype-installation"></a>
## 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
```

<a name="eslint-plugin-flowtype-configuration"></a>
## 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.

<!-- -->

```json
{
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"plugins": [
"flowtype"
],
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion src/configs/recommended.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"parser": "babel-eslint",
"parser": "@babel/eslint",
"parserOptions": {
"babelOptions": {
"plugins": [
"@babel/plugin-transform-react-jsx",
"@babel/plugin-syntax-flow"
]
}
},
"plugins": [
"flowtype"
],
Expand Down
16 changes: 14 additions & 2 deletions tests/rules/assertions/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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, {
Expand Down
24 changes: 21 additions & 3 deletions tests/rules/assertions/useFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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, {
Expand All @@ -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,
},
Expand Down
14 changes: 12 additions & 2 deletions tests/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
});
Expand Down

0 comments on commit 05c3ae1

Please sign in to comment.