Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32fee71

Browse files
GatsbyJS Botwardpeet
andauthored
fix(gatsby): eslint linting (#29796) (#29814)
(cherry picked from commit 2d52a55) Co-authored-by: Ward Peeters <[email protected]>
1 parent bca7951 commit 32fee71

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

packages/gatsby/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"ansi-html": "^0.0.7",
3232
"autoprefixer": "^9.8.4",
3333
"axios": "^0.21.1",
34-
"babel-eslint": "^10.1.0",
3534
"babel-loader": "^8.2.2",
3635
"babel-plugin-add-module-exports": "^1.0.4",
3736
"babel-plugin-dynamic-import-node": "^2.3.3",
@@ -262,4 +261,4 @@
262261
"yargs": {
263262
"boolean-negation": false
264263
}
265-
}
264+
}

packages/gatsby/src/utils/eslint-config.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { printSchema, GraphQLSchema } from "graphql"
2-
import { CLIEngine } from "eslint"
2+
import { ESLint } from "eslint"
33
import path from "path"
44

55
const eslintRulePaths = path.resolve(`${__dirname}/eslint-rules`)
66
const eslintRequirePreset = require.resolve(`./eslint/required`)
77

8-
export const eslintRequiredConfig: CLIEngine.Options = {
8+
export const eslintRequiredConfig: ESLint.Options = {
99
rulePaths: [eslintRulePaths],
1010
useEslintrc: false,
1111
allowInlineConfig: false,
@@ -19,6 +19,12 @@ export const eslintRequiredConfig: CLIEngine.Options = {
1919
ecmaFeatures: {
2020
jsx: true,
2121
},
22+
// TODO proper check for custom babel & plugins config
23+
// Currently when a babelrc is added to the project, it will override our babelOptions
24+
babelOptions: {
25+
presets: [`babel-preset-gatsby`],
26+
},
27+
requireConfigFile: false,
2228
},
2329
globals: {
2430
graphql: true,
@@ -32,7 +38,7 @@ export const eslintRequiredConfig: CLIEngine.Options = {
3238
export const eslintConfig = (
3339
schema: GraphQLSchema,
3440
usingJsxRuntime: boolean
35-
): CLIEngine.Options => {
41+
): ESLint.Options => {
3642
return {
3743
useEslintrc: false,
3844
resolvePluginsRelativeTo: __dirname,
@@ -47,6 +53,20 @@ export const eslintConfig = (
4753
require.resolve(`eslint-config-react-app`),
4854
eslintRequirePreset,
4955
],
56+
parser: require.resolve(`@babel/eslint-parser`),
57+
parserOptions: {
58+
ecmaVersion: 2020,
59+
sourceType: `module`,
60+
ecmaFeatures: {
61+
jsx: true,
62+
},
63+
// TODO proper check for custom babel & plugins config
64+
// Currently when a babelrc is added to the project, it will override our babelOptions
65+
babelOptions: {
66+
presets: [`babel-preset-gatsby`],
67+
},
68+
requireConfigFile: false,
69+
},
5070
plugins: [`graphql`],
5171
rules: {
5272
// New versions of react use a special jsx runtime that remove the requirement
@@ -75,13 +95,12 @@ export const eslintConfig = (
7595
"jsx-a11y/aria-proptypes": `warn`,
7696
"jsx-a11y/aria-role": `warn`,
7797
"jsx-a11y/aria-unsupported-elements": `warn`,
78-
// TODO: It looks like the `autocomplete-valid` rule hasn't been published yet
79-
// "jsx-a11y/autocomplete-valid": [
80-
// "warn",
81-
// {
82-
// inputComponents: [],
83-
// },
84-
// ],
98+
"jsx-a11y/autocomplete-valid": [
99+
`warn`,
100+
{
101+
inputComponents: [],
102+
},
103+
],
85104
"jsx-a11y/click-events-have-key-events": `warn`,
86105
"jsx-a11y/control-has-associated-label": [
87106
`warn`,

0 commit comments

Comments
 (0)