Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
20dd47d
move
dimaMachina Nov 19, 2024
6772e70
rename
dimaMachina Nov 19, 2024
ab18555
more
dimaMachina Nov 19, 2024
0a153a9
more
dimaMachina Nov 19, 2024
d11846f
more
dimaMachina Nov 19, 2024
7e92103
more
dimaMachina Nov 19, 2024
2a72f5d
more
dimaMachina Nov 19, 2024
8d6f413
more
dimaMachina Nov 19, 2024
24b1c7f
more
dimaMachina Nov 19, 2024
c01f82e
moree
dimaMachina Nov 19, 2024
b667b1f
moree
dimaMachina Nov 19, 2024
62e0e17
moree
dimaMachina Nov 19, 2024
20a864d
moree
dimaMachina Nov 19, 2024
06be501
more
dimaMachina Nov 19, 2024
7c231d4
more
dimaMachina Nov 19, 2024
af3406b
more
dimaMachina Nov 19, 2024
3622a37
[skip ci]
dimaMachina Nov 19, 2024
57928e2
more
dimaMachina Nov 19, 2024
6ab54ef
fix icons
dimaMachina Nov 19, 2024
9b1bf71
update docs to use Nextra 4
dimaMachina Nov 19, 2024
1683055
[skip ci]
dimaMachina Nov 19, 2024
c0a6fe2
fix lint [skip ci]
dimaMachina Nov 19, 2024
a168de8
more [skip ci]
dimaMachina Nov 19, 2024
1b43738
more
dimaMachina Nov 20, 2024
16f4e86
upd
dimaMachina Nov 20, 2024
45cc040
pnpm dedupe
dimaMachina Nov 20, 2024
7c7011c
Merge branch 'master' into upd-components-v8
dimaMachina Nov 20, 2024
30191fe
yoyo
dimaMachina Nov 20, 2024
8b8eab0
Merge branch 'master' into upd-components-v8
dimaMachina Nov 20, 2024
493bd14
aa
dimaMachina Nov 20, 2024
fcb929d
aa
dimaMachina Nov 20, 2024
3bff0d1
Merge branch 'master' into upd-components-v8
dimaMachina Nov 20, 2024
6b27f22
build pass
dimaMachina Nov 20, 2024
d1721cf
more
dimaMachina Nov 20, 2024
e0d9a8b
aa
dimaMachina Nov 20, 2024
6c3f049
aa
dimaMachina Nov 20, 2024
eb630e8
[skip ci]
dimaMachina Nov 21, 2024
0169353
Merge branch 'master' into upd-components-v8
dimaMachina Nov 21, 2024
13db26f
Update examples/vue-code-file/test.vue [skip ci]
dimaMachina Nov 21, 2024
dde6dd8
Merge branch 'upd-components-v8' into better-vue-processor
dimaMachina Nov 21, 2024
dac487b
polish
dimaMachina Nov 21, 2024
d70923c
Merge branch 'master' into better-vue-processor
dimaMachina Nov 21, 2024
253e17c
add changeset
dimaMachina Nov 21, 2024
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/fast-fishes-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix reporting lint issues not on first char of file for `.vue` and support ESLint fixes and suggestions for them. Use [new official example](https://github.com/dimaMachina/graphql-eslint/blob/master/examples/vue-code-file/eslint.config.js)
22 changes: 17 additions & 5 deletions examples/vue-code-file/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import vueParser from 'vue-eslint-parser';
import { mergeProcessors } from 'eslint-merge-processors';
import pluginVue from 'eslint-plugin-vue';
import processorVueBlocks from 'eslint-processor-vue-blocks';
import js from '@eslint/js';
import graphqlPlugin from '@graphql-eslint/eslint-plugin';

export default [
{
files: ['**/*.js', '**/*.vue'],
files: ['**/*.js'],
processor: graphqlPlugin.processor,
rules: js.configs.recommended.rules,
},
...pluginVue.configs['flat/recommended'],
{
files: ['**/*.vue'],
languageOptions: {
parser: vueParser,
},
// `eslint-plugin-vue` will set a default processor for `.vue` files
// we use `eslint-merge-processors` to extend it
processor: mergeProcessors([
pluginVue.processors.vue,
processorVueBlocks({
blocks: {
script: true,
scriptSetup: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script setup is essentially the new standard, best practice way to write Vue components. Almost all my code is in that, or migrating to it. Should certainly be supported.

customBlocks: true,
},
}),
]),
},
{
files: ['**/*.graphql'],
Expand Down
5 changes: 3 additions & 2 deletions examples/vue-code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "workspace:*",
"@vue/compiler-sfc": "3.5.13",
"eslint": "9.14.0",
"vue-eslint-parser": "9.4.3"
"eslint-merge-processors": "^0.1.0",
"eslint-plugin-vue": "^9.31.0",
"eslint-processor-vue-blocks": "^0.1.2"
}
}
6 changes: 3 additions & 3 deletions examples/vue-code-file/test.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<span>test</span>
<!-- use the variables to satisfy the no-unused-vars lint -->
<span>{{ GET_USER }}</span>
<span>{{ GET_ANOTHER_USER }}</span>
</template>
<script>
/* eslint-disable no-unused-vars */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only found one bug, can't understand but the ESLint directives no longer works in script tags

If I have this directive I have

image

If I remove

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it wouldn't be the first time I see a lint disabling a rule and also disabling the unused-directive check hah.

You could easily just use the variables, though. I'll post code above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, because it's upstream issue from merge-processors antfu/eslint-processor-vue-blocks#8 (comment)


const GET_USER = /* GraphQL */ `
query {
user {
Expand Down
80 changes: 76 additions & 4 deletions packages/plugin/__tests__/__snapshots__/examples.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -626,21 +626,71 @@ exports[`Examples > should work in vue 1`] = `
filePath: examples/vue-code-file/test.vue,
messages: [
{
column: 0,
line: 1,
column: 8,
endColumn: 16,
endLine: 7,
line: 7,
message: 'GET_USER' is assigned a value but never used.,
messageId: unusedVar,
nodeType: Identifier,
ruleId: no-unused-vars,
severity: 2,
},
{
column: 4,
endColumn: 9,
endLine: 8,
line: 8,
message: Anonymous GraphQL operations are forbidden. Make sure to name your query!,
messageId: no-anonymous-operations,
nodeType: null,
ruleId: @graphql-eslint/no-anonymous-operations,
severity: 2,
suggestions: [
{
desc: Rename to \`user\`,
fix: {
range: [
40,
40,
],
text: user,
},
},
],
},
{
column: 0,
line: 1,
column: 8,
endColumn: 24,
endLine: 15,
line: 15,
message: 'GET_ANOTHER_USER' is assigned a value but never used.,
messageId: unusedVar,
nodeType: Identifier,
ruleId: no-unused-vars,
severity: 2,
},
{
column: 10,
endColumn: 19,
endLine: 16,
line: 16,
message: Operation "UserQuery" should not have "Query" suffix,
nodeType: Name,
ruleId: @graphql-eslint/naming-convention,
severity: 2,
suggestions: [
{
desc: Rename to \`User\`,
fix: {
range: [
128,
137,
],
text: User,
},
},
],
},
],
},
Expand Down Expand Up @@ -669,6 +719,28 @@ exports[`Examples > should work in vue 2`] = `
ruleId: @graphql-eslint/naming-convention,
severity: 2,
},
{
column: 7,
endColumn: 15,
endLine: 7,
line: 7,
message: 'GET_USER' is assigned a value but never used.,
messageId: unusedVar,
nodeType: Identifier,
ruleId: no-unused-vars,
severity: 2,
},
{
column: 7,
endColumn: 23,
endLine: 15,
line: 15,
message: 'GET_ANOTHER_USER' is assigned a value but never used.,
messageId: unusedVar,
nodeType: Identifier,
ruleId: no-unused-vars,
severity: 2,
},
],
},
]
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/__tests__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Examples', () => {

it('should work in vue', () => {
const cwd = path.join(CWD, 'examples', 'vue-code-file');
testESLintOutput(cwd, 2);
testESLintOutput(cwd, 4);
});

it('should work in multiple projects', () => {
Expand Down
14 changes: 13 additions & 1 deletion packages/plugin/src/graphql-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import debugFactory from 'debug';
import { GraphQLConfig, GraphQLExtensionDeclaration, loadConfigSync } from 'graphql-config';
Expand All @@ -7,10 +8,21 @@ import { ParserOptions } from './types.js';
const debug = debugFactory('graphql-eslint:graphql-config');
let graphQLConfig: GraphQLConfig;

/**
* Filepath can be a virtual file, so we need to find the first existing path
*
*/
export function getFirstExistingPath(filePath: string): string {
while (!fs.existsSync(filePath)) {
filePath = path.dirname(filePath);
}
return filePath;
}

export function loadOnDiskGraphQLConfig(filePath: string): GraphQLConfig {
return loadConfigSync({
// load config relative to the file being linted
rootDir: path.dirname(filePath),
rootDir: getFirstExistingPath(path.dirname(filePath)),
throwOnMissing: false,
extensions: [codeFileLoaderExtension],
});
Expand Down
8 changes: 3 additions & 5 deletions packages/plugin/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { GraphQLProjectConfig, IGraphQLProject } from 'graphql-config';
import { parseGraphQLSDL, Source } from '@graphql-tools/utils';
import { getDocuments } from './documents.js';
import { convertToESTree, extractComments, extractTokens } from './estree-converter/index.js';
import { loadGraphQLConfig } from './graphql-config.js';
import { getFirstExistingPath, loadGraphQLConfig } from './graphql-config.js';
import { version } from './meta.js';
import { getSchema } from './schema.js';
import { getSiblings } from './siblings.js';
import { GraphQLESLintParseResult, ParserOptions, Schema } from './types.js';
import { CWD, VIRTUAL_DOCUMENT_REGEX } from './utils.js';
import { CWD } from './utils.js';

const debug = debugFactory('graphql-eslint:parser');

Expand Down Expand Up @@ -44,11 +44,9 @@ export function parseForESLint(code: string, options: ParserOptions): GraphQLESL
const { document } = parseGraphQLSDL(filePath, code, { noLocation: false });
let project: GraphQLProjectConfig;
let schema: Schema, documents: Source[];

if (typeof window === 'undefined') {
const gqlConfig = loadGraphQLConfig(options);
const realFilepath = filePath.replace(VIRTUAL_DOCUMENT_REGEX, '');
project = gqlConfig.getProjectForFile(realFilepath);
project = gqlConfig.getProjectForFile(getFirstExistingPath(filePath));
documents = getDocuments(project);
} else {
documents = [
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export const processor = {
},
supportsAutofix: true,
preprocess(code, filePath) {
if (process.env.ESLINT_USE_FLAT_CONFIG !== 'false' && filePath.endsWith('.vue')) {
throw new Error(
"Processing of `.vue` files is no longer supported, follow the new official vue example for ESLint's flat config https://github.com/dimaMachina/graphql-eslint/tree/master/examples/vue-code-file",
);
}
if (!onDiskConfigLoaded) {
onDiskConfig = loadOnDiskGraphQLConfig(filePath);
onDiskConfigLoaded = true;
Expand Down
Loading
Loading