Skip to content

Commit

Permalink
Fix broken report highlighting when processor is used (#1040)
Browse files Browse the repository at this point in the history
* fix processor report on code files

* remove tests on eslint 7

* apply fix

* more errors

* fix `message.endLine`

* fix parser error column location

* add changeset
  • Loading branch information
dimaMachina committed Apr 23, 2022
1 parent 651451d commit 8a3b584
Show file tree
Hide file tree
Showing 16 changed files with 625 additions and 163 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-zoos-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix broken report highlighting when processor is used
8 changes: 4 additions & 4 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ jobs:
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{runner.os}}-16-8-16-node-modules-${{hashFiles('yarn.lock')}}
key: ${{runner.os}}-16-16-node-modules-${{hashFiles('yarn.lock')}}
restore-keys: |
${{runner.os}}-16-8-16-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-8-16-node-modules-
${{runner.os}}-16-16-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-16-node-modules-
- name: Install Dependencies
run: yarn

- name: Release Canary
id: canary
uses: kamilkisiela/release-canary@master
if: github.repository == 'B2o5T/graphql-eslint'
if: github.repository == B2o5T/graphql-eslint
with:
npm-token: ${{secrets.NODE_AUTH_TOKEN}}
npm-script: 'yarn release:canary'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Release
on:
push:
branches:
- master
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -40,10 +40,10 @@ jobs:
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{runner.os}}-16-8-16-node-modules-${{hashFiles('yarn.lock')}}
key: ${{runner.os}}-16-16-node-modules-${{hashFiles('yarn.lock')}}
restore-keys: |
${{runner.os}}-16-8-16-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-8-16-node-modules-
${{runner.os}}-16-16-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-16-node-modules-
- name: Install Dependencies
run: yarn
Expand Down
30 changes: 13 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{runner.os}}-16-8-16-node-modules-${{hashFiles('yarn.lock')}}
key: ${{runner.os}}-16-16-node-modules-${{hashFiles('yarn.lock')}}
restore-keys: |
${{runner.os}}-16-8-16-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-8-16-node-modules-
${{runner.os}}-16-16-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-16-node-modules-
- name: Install Dependencies
run: yarn
Expand Down Expand Up @@ -58,10 +58,10 @@ jobs:
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{runner.os}}-16-8-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
key: ${{runner.os}}-16-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
restore-keys: |
${{runner.os}}-16-8-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-8-${{matrix.graphql_version}}-node-modules-
${{runner.os}}-16-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-16-${{matrix.graphql_version}}-node-modules-
- name: Use GraphQL v${{matrix.graphql_version}}
run: node ./scripts/match-graphql.mjs ${{matrix.graphql_version}}
Expand All @@ -79,14 +79,13 @@ jobs:
path: packages/plugin/dist

test:
name: Testing on Node ${{matrix.node_version}} with ESLint v${{matrix.eslint_version}} and GraphQL v${{matrix.graphql_version}}
name: Testing on Node ${{matrix.node_version}} with GraphQL v${{matrix.graphql_version}} and ESLint v8
timeout-minutes: 60
runs-on: ubuntu-latest
needs: [typecheck]
strategy:
matrix:
node_version: [12, 16]
eslint_version: [7.32.0, 8]
graphql_version: [15, 16]

steps:
Expand All @@ -104,28 +103,25 @@ jobs:
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
restore-keys: |
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-${{matrix.graphql_version}}-node-modules-
${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-node-modules-${{hashFiles('yarn.lock')}}
${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-node-modules-
- name: Use GraphQL v${{matrix.graphql_version}}
run: node scripts/match-graphql.mjs ${{matrix.graphql_version}}

- name: Use ESLint v${{matrix.eslint_version}}
run: node scripts/match-eslint.mjs ${{matrix.eslint_version}}

- name: Install Dependencies
run: yarn

- name: Cache Jest
uses: actions/cache@v3
with:
path: .cache/jest
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-jest-${{hashFiles('yarn.lock')}}
key: ${{runner.os}}-${{matrix.node_version}}-jest-${{hashFiles('yarn.lock')}}
restore-keys: |
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-jest-${{hashFiles('yarn.lock')}}
${{runner.os}}-${{matrix.node_version}}-${{matrix.eslint_version}}-jest-
${{runner.os}}-${{matrix.node_version}}-jest-${{hashFiles('yarn.lock')}}
${{runner.os}}-${{matrix.node_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'
Expand Down
3 changes: 0 additions & 3 deletions examples/basic/.eslintrc.js → examples/basic/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ module.exports = {
{
files: ['*.js'],
extends: ['eslint:recommended'],
env: {
node: true,
},
},
{
files: ['*.graphql'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
processor: '@graphql-eslint/graphql',
extends: ['eslint:recommended'],
env: {
node: true,
es6: true,
},
rules: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
processor: '@graphql-eslint/graphql',
extends: ['eslint:recommended'],
env: {
node: true,
es6: true,
},
},
Expand Down
1 change: 0 additions & 1 deletion examples/graphql-config-code-file/query.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const gql = require('graphql-tag');

// eslint-disable-next-line no-unused-vars
const GET_USER = gql`
query {
user {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ module.exports = {
{
files: ['*.js'],
extends: ['eslint:recommended'],
env: {
node: true,
},
},
{
files: ['*.graphql'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
processor: '@graphql-eslint/graphql',
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
env: {
node: true,
es6: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function parseForESLint(code: string, options: ParserOptions = {}): Graph
const eslintError = {
index: error.positions[0],
lineNumber: error.locations[0].line,
column: error.locations[0].column,
column: error.locations[0].column - 1,
message: error.message,
};
throw eslintError;
Expand Down
9 changes: 6 additions & 3 deletions packages/plugin/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Block = Linter.ProcessorFile & {
offset: number;
};

const RELEVANT_KEYWORDS = ['gql`', 'graphql`', '/* GraphQL */'] as const;
const RELEVANT_KEYWORDS = ['gql', 'graphql', '/* GraphQL */'] as const;
const blocksMap = new Map<string, Block[]>();

export const processor: Linter.Processor<Block | string> = {
Expand All @@ -32,7 +32,7 @@ export const processor: Linter.Processor<Block | string> = {
}));
blocksMap.set(filePath, blocks);

return [code, ...blocks];
return [...blocks, code /* source code must be provided and be last */];
},
postprocess(messages, filePath) {
const blocks = blocksMap.get(filePath) || [];
Expand All @@ -41,7 +41,10 @@ export const processor: Linter.Processor<Block | string> = {

for (const message of messages[i]) {
message.line += lineOffset;
message.endLine += lineOffset;
// endLine can not exist if only `loc: { start, column }` was provided to context.report
if (typeof message.endLine === 'number') {
message.endLine += lineOffset;
}
if (message.fix) {
message.fix.range[0] += offset;
message.fix.range[1] += offset;
Expand Down

0 comments on commit 8a3b584

Please sign in to comment.