File tree Expand file tree Collapse file tree 4 files changed +52
-25
lines changed
packages/plugin/src/rules Expand file tree Collapse file tree 4 files changed +52
-25
lines changed Original file line number Diff line number Diff line change 4
4
5
5
This project integrates GraphQL AST parser and ESLint.
6
6
7
- ## Key Features:
7
+ ## Key Features
8
8
9
9
- 🚀 Integrates with ESLint core (as a ESTree parser).
10
10
- 🚀 Works on ` .graphql ` files, ` gql ` usages and ` /* GraphQL */ ` magic comments.
11
11
- 🚀 Lints both GraphQL schema and GraphQL operations.
12
12
- 🚀 Extended type info for more advanced usages
13
13
- 🚀 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 .
15
15
16
16
Special thanks to [ ilyavolodin] ( https://github.com/ilyavolodin ) for his work on a similar project!
17
17
Original file line number Diff line number Diff line change 9
9
},
10
10
"plugins" : [" @graphql-eslint" ],
11
11
"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" }]
35
13
}
36
14
}
37
15
]
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import avoidOperationNamePrefix from './avoid-operation-name-prefix';
6
6
import noCaseInsensitiveEnumValuesDuplicates from './no-case-insensitive-enum-values-duplicates' ;
7
7
import requireDescription from './require-description' ;
8
8
import requireIdWhenAvailable from './require-id-when-available' ;
9
+ import descriptionStyle from './description-style' ;
9
10
10
11
export const rules = {
11
12
'validate-against-schema' : validate ,
@@ -16,4 +17,5 @@ export const rules = {
16
17
'no-case-insensitive-enum-values-duplicates' : noCaseInsensitiveEnumValuesDuplicates ,
17
18
'require-description' : requireDescription ,
18
19
'require-id-when-available' : requireIdWhenAvailable ,
20
+ 'description-style' : descriptionStyle
19
21
} ;
You can’t perform that action at this time.
0 commit comments