Skip to content

Commit cf50ed5

Browse files
committed
migrate description-style
1 parent 82c930b commit cf50ed5

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
This project integrates GraphQL AST parser and ESLint.
66

7-
## Key Features:
7+
## Key Features
88

99
- 🚀 Integrates with ESLint core (as a ESTree parser).
1010
- 🚀 Works on `.graphql` files, `gql` usages and `/* GraphQL */` magic comments.
1111
- 🚀 Lints both GraphQL schema and GraphQL operations.
1212
- 🚀 Extended type info for more advanced usages
1313
- 🚀 Supports ESLint directives (for example: `disable-next-line`)
14-
- 🚀 Easily extendable - supports custom rules.
14+
- 🚀 Easily extendable - supports custom rules based on GraphQL's AST and ESLint API.
1515

1616
Special thanks to [ilyavolodin](https://github.com/ilyavolodin) for his work on a similar project!
1717

example/.eslintrc.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,7 @@
99
},
1010
"plugins": ["@graphql-eslint"],
1111
"rules": {
12-
"@graphql-eslint/require-id-when-available": [
13-
"error",
14-
{
15-
"fieldName": "_id"
16-
}
17-
],
18-
"@graphql-eslint/validate-against-schema": "error",
19-
"@graphql-eslint/no-anonymous-operations": "warn",
20-
"@graphql-eslint/no-operation-name-suffix": "error",
21-
"@graphql-eslint/deprecation-must-have-reason": "error",
22-
"@graphql-eslint/avoid-operation-name-prefix": [
23-
"error",
24-
{
25-
"keywords": ["get"]
26-
}
27-
],
28-
"@graphql-eslint/no-case-insensitive-enum-values-duplicates": ["error"],
29-
"@graphql-eslint/require-description": [
30-
"warn",
31-
{
32-
"on": ["SchemaDefinition", "FieldDefinition"]
33-
}
34-
]
12+
"@graphql-eslint/description-style": ["error", { "style": "block" }]
3513
}
3614
}
3715
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { GraphQLESLintRule } from '../types';
2+
3+
type DescriptionStyleRuleConfig = {
4+
style: 'inline' | 'block';
5+
};
6+
7+
const rule: GraphQLESLintRule<DescriptionStyleRuleConfig> = {
8+
meta: {
9+
type: 'suggestion',
10+
docs: {
11+
description: 'Require all comments to follow the same style',
12+
category: 'Stylistic Issues',
13+
recommended: false,
14+
url: 'https://github.com/ilyavolodin/graphql-eslint/blob/master/docs/rules/description-style.md',
15+
},
16+
schema: [
17+
{
18+
type: 'object',
19+
properties: {
20+
style: {
21+
type: 'string',
22+
enum: ['block', 'inline'],
23+
default: 'inline',
24+
},
25+
},
26+
additionalProperties: false,
27+
},
28+
],
29+
},
30+
create(context) {
31+
const { style } = context.options[0] || { style: 'inline' };
32+
const wrongDescriptionType = style === 'block' ? 'inline' : 'block';
33+
34+
return {
35+
'[description.type="StringValue"]': node => {
36+
if (node.description.block !== (style === 'block')) {
37+
context.report({
38+
node: node.description,
39+
message: `Unexpected ${wrongDescriptionType} description`,
40+
});
41+
}
42+
},
43+
};
44+
},
45+
};
46+
47+
export default rule;

packages/plugin/src/rules/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import avoidOperationNamePrefix from './avoid-operation-name-prefix';
66
import noCaseInsensitiveEnumValuesDuplicates from './no-case-insensitive-enum-values-duplicates';
77
import requireDescription from './require-description';
88
import requireIdWhenAvailable from './require-id-when-available';
9+
import descriptionStyle from './description-style';
910

1011
export const rules = {
1112
'validate-against-schema': validate,
@@ -16,4 +17,5 @@ export const rules = {
1617
'no-case-insensitive-enum-values-duplicates': noCaseInsensitiveEnumValuesDuplicates,
1718
'require-description': requireDescription,
1819
'require-id-when-available': requireIdWhenAvailable,
20+
'description-style': descriptionStyle
1921
};

0 commit comments

Comments
 (0)