Skip to content

Commit

Permalink
fix(gatsby): eslint linting (#29796) (#29814)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2d52a55)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
GatsbyJS Bot and wardpeet authored Feb 27, 2021
1 parent bca7951 commit 32fee71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"ansi-html": "^0.0.7",
"autoprefixer": "^9.8.4",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-dynamic-import-node": "^2.3.3",
Expand Down Expand Up @@ -262,4 +261,4 @@
"yargs": {
"boolean-negation": false
}
}
}
39 changes: 29 additions & 10 deletions packages/gatsby/src/utils/eslint-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { printSchema, GraphQLSchema } from "graphql"
import { CLIEngine } from "eslint"
import { ESLint } from "eslint"
import path from "path"

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

export const eslintRequiredConfig: CLIEngine.Options = {
export const eslintRequiredConfig: ESLint.Options = {
rulePaths: [eslintRulePaths],
useEslintrc: false,
allowInlineConfig: false,
Expand All @@ -19,6 +19,12 @@ export const eslintRequiredConfig: CLIEngine.Options = {
ecmaFeatures: {
jsx: true,
},
// TODO proper check for custom babel & plugins config
// Currently when a babelrc is added to the project, it will override our babelOptions
babelOptions: {
presets: [`babel-preset-gatsby`],
},
requireConfigFile: false,
},
globals: {
graphql: true,
Expand All @@ -32,7 +38,7 @@ export const eslintRequiredConfig: CLIEngine.Options = {
export const eslintConfig = (
schema: GraphQLSchema,
usingJsxRuntime: boolean
): CLIEngine.Options => {
): ESLint.Options => {
return {
useEslintrc: false,
resolvePluginsRelativeTo: __dirname,
Expand All @@ -47,6 +53,20 @@ export const eslintConfig = (
require.resolve(`eslint-config-react-app`),
eslintRequirePreset,
],
parser: require.resolve(`@babel/eslint-parser`),
parserOptions: {
ecmaVersion: 2020,
sourceType: `module`,
ecmaFeatures: {
jsx: true,
},
// TODO proper check for custom babel & plugins config
// Currently when a babelrc is added to the project, it will override our babelOptions
babelOptions: {
presets: [`babel-preset-gatsby`],
},
requireConfigFile: false,
},
plugins: [`graphql`],
rules: {
// New versions of react use a special jsx runtime that remove the requirement
Expand Down Expand Up @@ -75,13 +95,12 @@ export const eslintConfig = (
"jsx-a11y/aria-proptypes": `warn`,
"jsx-a11y/aria-role": `warn`,
"jsx-a11y/aria-unsupported-elements": `warn`,
// TODO: It looks like the `autocomplete-valid` rule hasn't been published yet
// "jsx-a11y/autocomplete-valid": [
// "warn",
// {
// inputComponents: [],
// },
// ],
"jsx-a11y/autocomplete-valid": [
`warn`,
{
inputComponents: [],
},
],
"jsx-a11y/click-events-have-key-events": `warn`,
"jsx-a11y/control-has-associated-label": [
`warn`,
Expand Down

0 comments on commit 32fee71

Please sign in to comment.