Skip to content

Commit

Permalink
🎱 feat: support ESLint 8 (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri POSTOLOV committed Oct 20, 2021
1 parent c7a8b33 commit ed6644b
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 163 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-buses-wonder.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

feat: support ESLint 8
17 changes: 10 additions & 7 deletions .github/workflows/tests.yml
Expand Up @@ -64,13 +64,14 @@ jobs:
path: packages/plugin/dist

test:
name: Testing on Node ${{matrix.node_version}}
name: Testing on Node ${{matrix.node_version}} with ESLint v${{matrix.eslint_version}}
timeout-minutes: 60
runs-on: ubuntu-latest
needs: [lint, typecheck]
strategy:
matrix:
node_version: [12, 16]
eslint_version: [7.32.0, 8]
steps:
- name: Checkout Master
uses: actions/checkout@v2
Expand All @@ -84,20 +85,22 @@ jobs:
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{matrix.node_version}}-node-modules-${{ hashFiles('yarn.lock') }}
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-node-modules-${{hashFiles('yarn.lock')}}
restore-keys: |
${{ runner.os }}-${{matrix.node_version}}-node-modules-${{ hashFiles('yarn.lock') }}
${{ runner.os }}-${{matrix.node_version}}-node-modules-
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-node-modules-
- name: Use ESLint v${{matrix.eslint_version}}
run: node scripts/match-eslint.mjs ${{matrix.eslint_version}}
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
- name: Cache Jest
uses: actions/cache@v2
with:
path: .cache/jest
key: ${{ runner.os }}-${{matrix.node_version}}-jest-${{ hashFiles('yarn.lock') }}
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-jest-${{hashFiles('yarn.lock')}}
restore-keys: |
${{ runner.os }}-${{matrix.node_version}}-jest-${{ hashFiles('yarn.lock') }}
${{ runner.os }}-${{matrix.node_version}}-jest-
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-jest-${{hashFiles('yarn.lock')}}
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-jest-
# We need build for examples.spec.ts test
# Otherwise we'll get error - Cannot find module 'node_modules/@graphql-eslint/eslint-plugin/dist/index.js'
- name: Download build artifact
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/package.json
Expand Up @@ -12,7 +12,7 @@
"graphql": "15.5.3"
},
"devDependencies": {
"eslint": "7.32.0",
"@graphql-eslint/eslint-plugin": "2.2.0"
"@graphql-eslint/eslint-plugin": "2.2.0",
"eslint": "8.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/code-file/package.json
Expand Up @@ -12,7 +12,7 @@
"graphql": "15.5.3"
},
"devDependencies": {
"eslint": "7.32.0",
"@graphql-eslint/eslint-plugin": "2.2.0"
"@graphql-eslint/eslint-plugin": "2.2.0",
"eslint": "8.0.0"
}
}
2 changes: 1 addition & 1 deletion examples/graphql-config-code-file/package.json
Expand Up @@ -14,6 +14,6 @@
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "2.2.0",
"eslint": "7.32.0"
"eslint": "8.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/graphql-config/package.json
Expand Up @@ -12,7 +12,7 @@
"graphql": "15.5.3"
},
"devDependencies": {
"eslint": "7.32.0",
"@graphql-eslint/eslint-plugin": "2.2.0"
"@graphql-eslint/eslint-plugin": "2.2.0",
"eslint": "8.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/prettier/package.json
Expand Up @@ -12,10 +12,10 @@
"graphql": "15.5.3"
},
"devDependencies": {
"eslint": "7.32.0",
"@graphql-eslint/eslint-plugin": "2.2.0",
"eslint": "8.0.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"@graphql-eslint/eslint-plugin": "2.2.0",
"prettier": "2.4.1"
}
}
11 changes: 7 additions & 4 deletions jest.config.js
Expand Up @@ -3,7 +3,10 @@ const { compilerOptions } = require('./tsconfig.json');

module.exports = {
testEnvironment: 'node',
modulePathIgnorePatterns: ["/dist/"],
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' })
};
modulePathIgnorePatterns: ['/dist/'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
'@eslint/eslintrc/universal': '@eslint/eslintrc/dist/eslintrc-universal.cjs',
},
};
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -30,11 +30,11 @@
"@types/dedent": "0.7.0",
"@types/jest": "27.0.2",
"@types/node": "14.17.27",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.0.0",
"bob-the-bundler": "1.5.1",
"dedent": "0.7.0",
"eslint": "7.32.0",
"eslint": "8.0.0",
"eslint-config-prettier": "8.3.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-eslint-plugin": "3.6.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/estree-parser/estree-ast.ts
Expand Up @@ -6,7 +6,7 @@ export type SafeGraphQLType<T extends ASTNode | ValueNode> = Omit<
'loc'
>;

export type SingleESTreeNode<T extends any, WithTypeInfo extends boolean> = T extends ASTNode | ValueNode
export type SingleESTreeNode<T, WithTypeInfo extends boolean> = T extends ASTNode | ValueNode
? SafeGraphQLType<T> &
Pick<BaseNode, 'leadingComments' | 'loc' | 'range'> & {
type: T['kind'];
Expand All @@ -28,7 +28,7 @@ export type SingleESTreeNode<T extends any, WithTypeInfo extends boolean> = T ex
: {})
: T;

export type GraphQLESTreeNode<T extends any, WithTypeInfo extends boolean = false> = T extends ASTNode | ValueNode
export type GraphQLESTreeNode<T, WithTypeInfo extends boolean = false> = T extends ASTNode | ValueNode
? { rawNode: () => T } & {
[K in keyof SingleESTreeNode<T, WithTypeInfo>]: SingleESTreeNode<T, WithTypeInfo>[K] extends ReadonlyArray<
infer Nested
Expand Down
9 changes: 5 additions & 4 deletions patches/eslint+7.32.0.patch → patches/eslint+8.0.0.patch
@@ -1,23 +1,24 @@
diff --git a/node_modules/eslint/lib/rule-tester/rule-tester.js b/node_modules/eslint/lib/rule-tester/rule-tester.js
index 2b55249..08547f3 100644
index 324af7b..e771420 100644
--- a/node_modules/eslint/lib/rule-tester/rule-tester.js
+++ b/node_modules/eslint/lib/rule-tester/rule-tester.js
@@ -911,7 +911,17 @@ class RuleTester {
@@ -943,8 +943,18 @@ class RuleTester {
"Expected no autofixes to be suggested"
);
} else {
- assert.strictEqual(result.output, item.output, "Output is incorrect.");
+ if (item.output.includes('# normalize graphql')) {
+ const graphql = require('graphql');
+
+
+ function normalize(value) {
+ return graphql.print(graphql.parse(value.replace('# normalize graphql', '')));
+ }
+
+
+ assert.strictEqual(normalize(result.output), normalize(item.output), 'Output is incorrect.');
+ } else {
+ assert.strictEqual(result.output, item.output, 'Output is incorrect.');
+ }
}
} else {
assert.strictEqual(
result.output,
46 changes: 46 additions & 0 deletions scripts/match-eslint.mjs
@@ -0,0 +1,46 @@
import { readFileSync, writeFileSync, readdirSync, unlinkSync } from 'fs';
import { resolve } from 'path';

const version = process.argv[2];

if (version && !version.startsWith('8')) {
if (version.startsWith('7')) {
const eslint7Patch = `
diff --git a/node_modules/eslint/lib/rule-tester/rule-tester.js b/node_modules/eslint/lib/rule-tester/rule-tester.js
index 2b55249..08547f3 100644
--- a/node_modules/eslint/lib/rule-tester/rule-tester.js
+++ b/node_modules/eslint/lib/rule-tester/rule-tester.js
@@ -911,7 +911,17 @@ class RuleTester {
"Expected no autofixes to be suggested"
);
} else {
- assert.strictEqual(result.output, item.output, "Output is incorrect.");
+ if (item.output.includes('# normalize graphql')) {
+ const graphql = require('graphql');
+
+ function normalize(value) {
+ return graphql.print(graphql.parse(value.replace('# normalize graphql', '')));
+ }
+
+ assert.strictEqual(normalize(result.output), normalize(item.output), 'Output is incorrect.');
+ } else {
+ assert.strictEqual(result.output, item.output, 'Output is incorrect.');
+ }
}
} else {
assert.strictEqual(
`.trimStart();
writeFileSync(resolve(process.cwd(), `patches/eslint+${version}.patch`), eslint7Patch, 'utf8');

const eslint8PatchFilename = readdirSync(resolve(process.cwd(), 'patches')).find(filename =>
filename.startsWith('eslint+8')
);
unlinkSync(resolve(process.cwd(), 'patches', eslint8PatchFilename));
}

const pkgPath = resolve(process.cwd(), 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath));
pkg.resolutions.eslint = `^${version}`;

writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf8');
}

0 comments on commit ed6644b

Please sign in to comment.