Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎱 feat: support ESLint 8 #683

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-buses-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

feat: support ESLint 8
17 changes: 10 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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',
},
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
"@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",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-standard": "5.0.0",
"eslint-plugin-unicorn": "36.0.0",
"eslint-plugin-unicorn": "37.0.1",
"husky": "7.0.2",
"jest": "27.3.1",
"json-schema-to-markdown": "1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/estree-parser/estree-ast.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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');
}
Loading