Skip to content

Commit 2f6f977

Browse files
committed
adjust packages
initial README
1 parent 2a672ec commit 2f6f977

32 files changed

+278
-355
lines changed

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,79 @@
1-
# graphql-eslint
2-
graphql-eslint
1+
This project integrates GraphQL AST parser and ESLint.
2+
3+
## Key Features:
4+
5+
🚀 Integrates with ESLint core (as a ESTree parser).
6+
🚀 Works on `.graphql` files, `gql` usages and `/* GraphQL */` magic comments.
7+
🚀 Lints both GraphQL schema and GraphQL operations.
8+
🚀 Extended type info for more advanced usages
9+
🚀 Supports ESLint directives (for example: `disable-next-line`)
10+
🚀 Easily extendable - supports custom rules.
11+
12+
## Getting Started
13+
14+
### Installation
15+
16+
Start by installing the plugin package, which includes everything you need:
17+
18+
```
19+
yarn add -D @graphql-eslint/eslint-plugin
20+
```
21+
22+
Or, with NPM:
23+
24+
```
25+
npm install --save-dev @graphql-eslint/eslint-plugin
26+
```
27+
28+
> Also, make sure you have `graphql` dependency in your project.
29+
30+
### Configuration
31+
32+
To get started, create an override configuration for your ESLint, while applying it to to `.graphql` files (do that even if you are declaring your operations in code files):
33+
34+
```json
35+
{
36+
"overrides": [
37+
{
38+
"files": ["*.graphql"],
39+
"parser": "@graphql-eslint/eslint-plugin",
40+
"plugins": ["@graphql-eslint"],
41+
"rules": {
42+
...
43+
}
44+
}
45+
]
46+
}
47+
```
48+
49+
If you are using code files to store your GraphQL schema or your GraphQL operations, you can extend the behaviour of ESLint and extract those, by adding the following to your setup:
50+
51+
```json
52+
{
53+
"processor": "@graphql-eslint/graphql",
54+
"overrides": [ ... ]
55+
}
56+
```
57+
58+
#### Extended linting with GraphQL Schema
59+
60+
If you are using [`graphql-config`](https://graphql-config.com/) - you are good to go. This package integrates with it automatically, and will use it to load your schema!
61+
62+
Linting process can be enriched and extended with GraphQL type information, if you are able to provide your GraphQL schema.
63+
64+
The parser allow you to specify a json file / graphql files(s) / url / raw string to locate your schema (We are using `graphql-tools` to do that). Just add `parserOptions.schema` to your configuration file:
65+
66+
```json
67+
{
68+
"files": ["*.graphql"],
69+
"parser": "@graphql-eslint/eslint-plugin",
70+
"plugins": ["@graphql-eslint"],
71+
"parserOptions": {
72+
"schema": "./schema.graphql"
73+
}
74+
}
75+
```
76+
77+
> Some rules requires type information to operate, it's marked in the docs of each plugin!
78+
79+
### Available Rules

example/.eslintrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{
1+
{
22
"processor": "@graphql-eslint/graphql",
33
"overrides": [
44
{
5-
"files": ["./**/*.graphql"],
6-
"parser": "@graphql-eslint/parser",
5+
"files": ["*.graphql"],
6+
"parser": "@graphql-eslint/eslint-plugin",
77
"parserOptions": {
88
"schema": "./**/schema.graphql"
99
},

example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
},
1111
"dependencies": {
1212
"eslint": "7.8.1",
13-
"@graphql-eslint/parser": "0.0.1",
1413
"@graphql-eslint/eslint-plugin": "0.0.1",
1514
"graphql": "15.3.0",
1615
"typescript": "4.0.2"

example/query.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ const myQuery = gql`
1111
`;
1212

1313
const myOther2Query = /* GraphQL */ `
14-
15-
16-
17-
18-
1914
query {
2015
user {
2116
name

packages/graphql-estree/package.json

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/graphql-estree/src/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/parser/package.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/parser/src/index.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/plugin/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
"prepack": "bob prepack"
1717
},
1818
"dependencies": {
19-
"@graphql-eslint/types": "0.0.1",
20-
"@graphql-tools/graphql-tag-pluck": "6.2.5"
19+
"@graphql-tools/utils": "~6.0.0",
20+
"@graphql-tools/load": "~6.0.0",
21+
"@graphql-tools/graphql-file-loader": "~6.0.0",
22+
"@graphql-tools/json-file-loader": "~6.0.0",
23+
"@graphql-tools/url-loader": "~6.0.0",
24+
"@graphql-tools/graphql-tag-pluck": "6.2.5",
25+
"graphql-config": "^3.0.0"
2126
},
2227
"devDependencies": {
2328
"@types/eslint": "7.2.2",

packages/graphql-estree/src/converter.ts renamed to packages/plugin/src/estree-parser/converter.ts

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import {
22
convertDescription,
3-
GraphQLESTreeNode,
4-
SafeGraphQLType,
53
convertLocation,
64
convertRange,
7-
} from "@graphql-eslint/types";
5+
extractCommentsFromAst,
6+
} from "./utils";
7+
import { GraphQLESTreeNode, SafeGraphQLType } from "./estree-ast";
88
import {
99
ASTNode,
1010
TypeNode,
1111
TypeInfo,
1212
visit,
1313
visitWithTypeInfo,
14-
TokenKind,
1514
Location,
1615
} from "graphql";
1716
import { Comment } from "estree";
@@ -100,39 +99,3 @@ const convertNode = (typeInfo?: TypeInfo) => <T extends ASTNode>(
10099
return estreeNode;
101100
}
102101
};
103-
104-
export function extractCommentsFromAst(node: ASTNode): Comment[] {
105-
const loc = node.loc;
106-
107-
if (!loc) {
108-
return [];
109-
}
110-
111-
const comments: Comment[] = [];
112-
let token = loc.startToken;
113-
114-
while (token !== null) {
115-
if (token.kind === TokenKind.COMMENT) {
116-
const value = String(token.value);
117-
comments.push({
118-
type: "Block",
119-
value: " " + value + " ",
120-
loc: {
121-
start: {
122-
line: token.line,
123-
column: token.column,
124-
},
125-
end: {
126-
line: token.line,
127-
column: token.column,
128-
},
129-
},
130-
range: [token.start, token.end],
131-
});
132-
}
133-
134-
token = token.next;
135-
}
136-
137-
return comments;
138-
}

0 commit comments

Comments
 (0)