Skip to content

Commit f193b5e

Browse files
authored
extract GraphQL documents from *.vue/*.svelte code-files as well (#1200)
* support extracting GraphQL documents from `*.vue`/`*.svelte` code-files * fix prettier * adjust svelte location
1 parent 2886adf commit f193b5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+614
-145
lines changed

.changeset/config.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
"access": "restricted",
66
"baseBranch": "master",
77
"updateInternalDependencies": "patch",
8-
"ignore": [
9-
"@graphql-eslint/example-code-file",
10-
"@graphql-eslint/example-basic",
11-
"@graphql-eslint/example-graphql-config",
12-
"@graphql-eslint/example-graphql-config-code-file",
13-
"@graphql-eslint/example-prettier"
8+
"ignore": ["@graphql-eslint/example-*"],
9+
"changelog": [
10+
"@changesets/changelog-github",
11+
{
12+
"repo": "B2o5T/graphql-eslint"
13+
}
1414
],
15-
"changelog": ["@changesets/changelog-github", { "repo": "B2o5T/graphql-eslint" }],
1615
"snapshot": {
1716
"useCalculatedVersion": true,
1817
"prereleaseTemplate": "{tag}-{datetime}-{commit}"

.changeset/tame-baboons-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': minor
3+
---
4+
5+
support extracting GraphQL documents from `*.vue`/`*.svelte` code-files

.prettierrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
trailingComma: 'es5',
2+
trailingComma: 'all',
33
printWidth: 100,
44
singleQuote: true,
55
arrowParens: 'avoid',

examples/graphql-config-code-file/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": "https://github.com/B2o5T/graphql-eslint",
66
"author": "Dotan Simha <[email protected]>",
77
"scripts": {
8-
"lint": "eslint --ext graphql,js ."
8+
"lint": "eslint ."
99
},
1010
"dependencies": {
1111
"graphql": "16.6.0",

examples/monorepo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "monorepo",
2+
"name": "@graphql-eslint/example-monorepo",
33
"version": "0.0.0",
44
"private": true,
55
"author": "Dimitri POSTOLOV",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
root: true,
3+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
4+
// and to move all configurations into the overrides section. Since JavaScript rules
5+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
6+
// they will try to also execute for all overrides, as ESLint's configs cascade
7+
overrides: [
8+
{
9+
files: ['*.js', '*.svelte'],
10+
parser: 'svelte-eslint-parser',
11+
processor: '@graphql-eslint/graphql',
12+
extends: ['eslint:recommended'],
13+
env: {
14+
es6: true,
15+
},
16+
},
17+
{
18+
files: ['*.graphql'],
19+
parser: '@graphql-eslint/eslint-plugin',
20+
plugins: ['@graphql-eslint'],
21+
rules: {
22+
'@graphql-eslint/no-anonymous-operations': 'error',
23+
'@graphql-eslint/no-duplicate-fields': 'error',
24+
'@graphql-eslint/naming-convention': [
25+
'error',
26+
{
27+
OperationDefinition: {
28+
style: 'PascalCase',
29+
forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'],
30+
forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'],
31+
},
32+
},
33+
],
34+
},
35+
},
36+
],
37+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@graphql-eslint/example-svelte-code-file",
3+
"version": "0.0.0",
4+
"private": true,
5+
"author": "Dimitri POSTOLOV",
6+
"scripts": {
7+
"lint": "eslint ."
8+
},
9+
"dependencies": {
10+
"graphql": "16.6.0"
11+
},
12+
"devDependencies": {
13+
"@graphql-eslint/eslint-plugin": "3.11.2",
14+
"eslint": "8.24.0",
15+
"svelte": "3.50.1",
16+
"svelte-eslint-parser": "0.18.4",
17+
"svelte2tsx": "0.5.19"
18+
}
19+
}

examples/svelte-code-file/test.svelte

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
/* eslint-disable no-unused-vars */
3+
4+
const GET_USER = /* GraphQL */ `
5+
query {
6+
user {
7+
name
8+
}
9+
}
10+
`;
11+
12+
const GET_ANOTHER_USER = /* GraphQL */ `
13+
query UserQuery {
14+
user {
15+
name
16+
}
17+
}
18+
`;
19+
</script>

examples/vue-code-file/.eslintrc.cjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
root: true,
3+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
4+
// and to move all configurations into the overrides section. Since JavaScript rules
5+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
6+
// they will try to also execute for all overrides, as ESLint's configs cascade
7+
overrides: [
8+
{
9+
files: ['*.js', '*.vue'],
10+
parser: 'vue-eslint-parser',
11+
processor: '@graphql-eslint/graphql',
12+
extends: ['eslint:recommended'],
13+
env: {
14+
es6: true,
15+
},
16+
},
17+
{
18+
files: ['*.graphql'],
19+
parser: '@graphql-eslint/eslint-plugin',
20+
plugins: ['@graphql-eslint'],
21+
rules: {
22+
'@graphql-eslint/no-anonymous-operations': 'error',
23+
'@graphql-eslint/no-duplicate-fields': 'error',
24+
'@graphql-eslint/naming-convention': [
25+
'error',
26+
{
27+
OperationDefinition: {
28+
style: 'PascalCase',
29+
forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'],
30+
forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'],
31+
},
32+
},
33+
],
34+
},
35+
},
36+
],
37+
};

examples/vue-code-file/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@graphql-eslint/example-vue-code-file",
3+
"version": "0.0.0",
4+
"private": true,
5+
"author": "Dimitri POSTOLOV",
6+
"scripts": {
7+
"lint": "eslint ."
8+
},
9+
"dependencies": {
10+
"graphql": "16.6.0"
11+
},
12+
"devDependencies": {
13+
"@graphql-eslint/eslint-plugin": "3.11.2",
14+
"@vue/compiler-sfc": "3.2.40",
15+
"eslint": "8.24.0",
16+
"vue-eslint-parser": "9.1.0"
17+
}
18+
}

0 commit comments

Comments
 (0)