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

Fix report lint issues not on first char of file for .svelte and support ESLint fixes and suggestions #2736

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 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
fad64c4
more
dimaMachina Nov 20, 2024
87a0304
aa
dimaMachina Nov 20, 2024
9ac20d5
aa
dimaMachina Nov 20, 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
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,11 @@ module.exports = {
'no-undef': 'off',
},
},
{
files: ['website/**/*.mdx/**'],
rules: {
'import/no-default-export': 'off',
},
},
],
};
20 changes: 15 additions & 5 deletions examples/svelte-code-file/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import svelteParser from 'svelte-eslint-parser';
import { mergeProcessors } from 'eslint-merge-processors';
import eslintPluginSvelte from 'eslint-plugin-svelte';
import processorVueBlocks from 'eslint-processor-vue-blocks';
import js from '@eslint/js';
import graphqlPlugin from '@graphql-eslint/eslint-plugin';

export default [
{
files: ['**/*.js', '**/*.svelte'],
files: ['**/*.js'],
processor: graphqlPlugin.processor,
rules: js.configs.recommended.rules,
},
...eslintPluginSvelte.configs['flat/recommended'],
{
files: ['**/*.svelte'],
languageOptions: {
parser: svelteParser,
},
// `eslint-plugin-svelte` will set a default processor for `.svelte` files
// we use `eslint-merge-processors` to extend it
processor: mergeProcessors([
eslintPluginSvelte.processors.svelte,
processorVueBlocks({
blocks: {
script: true,
},
}),
]),
},
{
files: ['**/*.graphql'],
Expand Down
6 changes: 3 additions & 3 deletions examples/svelte-code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"devDependencies": {
"@graphql-eslint/eslint-plugin": "workspace:*",
"eslint": "9.14.0",
"svelte": "5.2.4",
"svelte-eslint-parser": "0.43.0",
"svelte2tsx": "0.7.26"
"eslint-merge-processors": "^0.1.0",
"eslint-plugin-svelte": "^2.46.0",
"eslint-processor-vue-blocks": "^0.1.2"
}
}
2 changes: 0 additions & 2 deletions examples/svelte-code-file/test.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script>
/* eslint-disable no-unused-vars */

const GET_USER = /* GraphQL */ `
query {
user {
Expand Down
23 changes: 18 additions & 5 deletions examples/vue-code-file/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
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: {
styles: false,
customBlocks: true,
script: true,
template: false,
},
}),
]),
},
{
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"
}
}
2 changes: 0 additions & 2 deletions examples/vue-code-file/test.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<span>test</span>
</template>
<script>
/* eslint-disable no-unused-vars */

const GET_USER = /* GraphQL */ `
query {
user {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"prettier": "3.3.3",
"prettier-plugin-tailwindcss": "0.6.9",
"rimraf": "6.0.1",
"tsup": "^8.0.0",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"turbo": "2.3.0",
"typescript": "5.6.3",
Expand Down
160 changes: 152 additions & 8 deletions packages/plugin/__tests__/__snapshots__/examples.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,21 +572,71 @@ exports[`Examples > should work in svelte 1`] = `
filePath: examples/svelte-code-file/test.svelte,
messages: [
{
column: 0,
line: 1,
column: 8,
endColumn: 16,
endLine: 2,
line: 2,
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: 3,
line: 3,
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: 10,
line: 10,
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: 11,
line: 11,
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 @@ -615,6 +665,28 @@ exports[`Examples > should work in svelte 2`] = `
ruleId: @graphql-eslint/naming-convention,
severity: 2,
},
{
column: 7,
endColumn: 15,
endLine: 2,
line: 2,
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: 10,
line: 10,
message: 'GET_ANOTHER_USER' is assigned a value but never used.,
messageId: unusedVar,
nodeType: Identifier,
ruleId: no-unused-vars,
severity: 2,
},
],
},
]
Expand All @@ -626,21 +698,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: 5,
line: 5,
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: 6,
line: 6,
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: 13,
line: 13,
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: 14,
line: 14,
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 +791,28 @@ exports[`Examples > should work in vue 2`] = `
ruleId: @graphql-eslint/naming-convention,
severity: 2,
},
{
column: 7,
endColumn: 15,
endLine: 5,
line: 5,
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: 13,
line: 13,
message: 'GET_ANOTHER_USER' is assigned a value but never used.,
messageId: unusedVar,
nodeType: Identifier,
ruleId: no-unused-vars,
severity: 2,
},
],
},
]
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/__tests__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ describe('Examples', () => {

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

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
Loading