55 * Tells eslint to lint certain nodes (lintCallExpression, lintMemberExpression, lintNewExpression)
66 * Gets protochain for the ESLint nodes the plugin is interested in
77 */
8- import fs from "fs " ;
8+ import { Rule } from "eslint " ;
99import findUp from "find-up" ;
10+ import fs from "fs" ;
1011import memoize from "lodash.memoize" ;
11- import { Rule } from "eslint" ;
1212import {
13+ determineTargetsFromConfig ,
1314 lintCallExpression ,
15+ lintExpressionStatement ,
16+ lintLiteral ,
1417 lintMemberExpression ,
1518 lintNewExpression ,
16- lintExpressionStatement ,
1719 parseBrowsersListVersion ,
18- determineTargetsFromConfig ,
1920} from "../helpers" ; // will be deprecated and introduced to this file
21+ import { nodes } from "../providers" ;
2022import {
21- ESLintNode ,
2223 AstMetadataApiWithTargetsResolver ,
2324 BrowserListConfig ,
24- HandleFailingRule ,
25- Context ,
2625 BrowsersListOpts ,
26+ Context ,
27+ ESLintNode ,
28+ HandleFailingRule ,
2729} from "../types" ;
28- import { nodes } from "../providers" ;
2930
3031type ESLint = {
3132 [ astNodeTypeName : string ] : ( node : ESLintNode ) => void ;
@@ -45,6 +46,9 @@ function getName(node: ESLintNode): string {
4546 case "CallExpression" : {
4647 return node . callee ! . name ;
4748 }
49+ case "Literal" : {
50+ return node . type ;
51+ }
4852 default :
4953 throw new Error ( "not found" ) ;
5054 }
@@ -110,6 +114,7 @@ type RulesFilteredByTargets = {
110114 NewExpression : AstMetadataApiWithTargetsResolver [ ] ;
111115 MemberExpression : AstMetadataApiWithTargetsResolver [ ] ;
112116 ExpressionStatement : AstMetadataApiWithTargetsResolver [ ] ;
117+ Literal : AstMetadataApiWithTargetsResolver [ ] ;
113118} ;
114119
115120/**
@@ -124,6 +129,7 @@ const getRulesForTargets = memoize(
124129 NewExpression : [ ] as AstMetadataApiWithTargetsResolver [ ] ,
125130 MemberExpression : [ ] as AstMetadataApiWithTargetsResolver [ ] ,
126131 ExpressionStatement : [ ] as AstMetadataApiWithTargetsResolver [ ] ,
132+ Literal : [ ] as AstMetadataApiWithTargetsResolver [ ] ,
127133 } ;
128134 const targets = JSON . parse ( targetsJSON ) ;
129135
@@ -248,6 +254,13 @@ export default {
248254 ] ,
249255 sourceCode
250256 ) ,
257+ Literal : lintLiteral . bind (
258+ null ,
259+ context ,
260+ handleFailingRule ,
261+ targetedRules . Literal ,
262+ sourceCode
263+ ) ,
251264 // Keep track of all the defined variables. Do not report errors for nodes that are not defined
252265 Identifier ( node : ESLintNode ) {
253266 if ( node . parent ) {
0 commit comments