File tree Expand file tree Collapse file tree 8 files changed +64
-0
lines changed
resources/eslint-internal-rules Expand file tree Collapse file tree 8 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 22
22
23
23
internal-rules/only-ascii : error
24
24
internal-rules/no-dir-import : error
25
+ internal-rules/require-to-string-tag : off
25
26
26
27
# #############################################################################
27
28
# `eslint-plugin-istanbul` rule list based on `v0.1.2`
@@ -610,8 +611,12 @@ overrides:
610
611
' @typescript-eslint/space-before-function-paren ' : off
611
612
' @typescript-eslint/space-infix-ops ' : off
612
613
' @typescript-eslint/type-annotation-spacing ' : off
614
+ - files : ' src/**'
615
+ rules :
616
+ internal-rules/require-to-string-tag : error
613
617
- files : ' src/**/__*__/**'
614
618
rules :
619
+ internal-rules/require-to-string-tag : off
615
620
node/no-unpublished-import : [error, { allowModules: ['chai', 'mocha'] }]
616
621
import/no-restricted-paths : off
617
622
import/no-extraneous-dependencies : [error, { devDependencies: true }]
Original file line number Diff line number Diff line change 2
2
3
3
const onlyASCII = require ( './only-ascii.js' ) ;
4
4
const noDirImport = require ( './no-dir-import.js' ) ;
5
+ const requireToStringTag = require ( './require-to-string-tag.js' ) ;
5
6
6
7
module . exports = {
7
8
rules : {
8
9
'only-ascii' : onlyASCII ,
9
10
'no-dir-import' : noDirImport ,
11
+ 'require-to-string-tag' : requireToStringTag ,
10
12
} ,
11
13
} ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ module . exports = function requireToStringTag ( context ) {
4
+ const sourceCode = context . getSourceCode ( ) ;
5
+
6
+ return {
7
+ 'ExportNamedDeclaration > ClassDeclaration' : ( classNode ) => {
8
+ const hasToStringTag = classNode . body . body . some ( ( property ) => {
9
+ if ( property . type !== 'MethodDefinition' || property . kind !== 'get' ) {
10
+ return false ;
11
+ }
12
+ const keyText = sourceCode . getText ( property . key ) ;
13
+ return keyText === 'Symbol.toStringTag' ;
14
+ } ) ;
15
+
16
+ if ( ! hasToStringTag ) {
17
+ context . report ( {
18
+ node : classNode ,
19
+ message :
20
+ 'All exported classes required to have [Symbol.toStringTag] method' ,
21
+ } ) ;
22
+ }
23
+ } ,
24
+ } ;
25
+ } ;
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ export class Location {
42
42
toJSON ( ) : { start : number ; end : number } {
43
43
return { start : this . start , end : this . end } ;
44
44
}
45
+
46
+ get [ Symbol . toStringTag ] ( ) {
47
+ return 'Location' ;
48
+ }
45
49
}
46
50
47
51
/**
@@ -121,6 +125,10 @@ export class Token {
121
125
column : this . column ,
122
126
} ;
123
127
}
128
+
129
+ get [ Symbol . toStringTag ] ( ) {
130
+ return 'Token' ;
131
+ }
124
132
}
125
133
126
134
/**
Original file line number Diff line number Diff line change @@ -79,6 +79,10 @@ export class Lexer {
79
79
}
80
80
return token ;
81
81
}
82
+
83
+ get [ Symbol . toStringTag ] ( ) {
84
+ return 'Lexer' ;
85
+ }
82
86
}
83
87
84
88
/**
Original file line number Diff line number Diff line change @@ -1520,6 +1520,10 @@ export class Parser {
1520
1520
} while ( this . expectOptionalToken ( delimiterKind ) ) ;
1521
1521
return nodes ;
1522
1522
}
1523
+
1524
+ get [ Symbol . toStringTag ] ( ) {
1525
+ return 'Parser' ;
1526
+ }
1523
1527
}
1524
1528
1525
1529
/**
Original file line number Diff line number Diff line change @@ -292,6 +292,10 @@ export class TypeInfo {
292
292
break ;
293
293
}
294
294
}
295
+
296
+ get [ Symbol . toStringTag ] ( ) {
297
+ return 'TypeInfo' ;
298
+ }
295
299
}
296
300
297
301
type GetFieldDefFn = (
Original file line number Diff line number Diff line change @@ -131,6 +131,10 @@ export class ASTValidationContext {
131
131
}
132
132
return fragments ;
133
133
}
134
+
135
+ get [ Symbol . toStringTag ] ( ) {
136
+ return 'ASTValidationContext' ;
137
+ }
134
138
}
135
139
136
140
export type ASTValidationRule = ( context : ASTValidationContext ) => ASTVisitor ;
@@ -150,6 +154,10 @@ export class SDLValidationContext extends ASTValidationContext {
150
154
getSchema ( ) : Maybe < GraphQLSchema > {
151
155
return this . _schema ;
152
156
}
157
+
158
+ get [ Symbol . toStringTag ] ( ) {
159
+ return 'SDLValidationContext' ;
160
+ }
153
161
}
154
162
155
163
export type SDLValidationRule = ( context : SDLValidationContext ) => ASTVisitor ;
@@ -253,6 +261,10 @@ export class ValidationContext extends ASTValidationContext {
253
261
getEnumValue ( ) : Maybe < GraphQLEnumValue > {
254
262
return this . _typeInfo . getEnumValue ( ) ;
255
263
}
264
+
265
+ get [ Symbol . toStringTag ] ( ) {
266
+ return 'ValidationContext' ;
267
+ }
256
268
}
257
269
258
270
export type ValidationRule = ( context : ValidationContext ) => ASTVisitor ;
You can’t perform that action at this time.
0 commit comments