File tree Expand file tree Collapse file tree 5 files changed +36
-34
lines changed
.pkgs/eslint-plugin-local/src/utils Expand file tree Collapse file tree 5 files changed +36
-34
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export function isInitializedFromSource(
3333 // check for: `variable = require('source')` or `variable = require('source').variable`
3434 const args = getRequireExpressionArguments ( init ) ;
3535 const arg0 = args ?. [ 0 ] ;
36- if ( arg0 == null || ! AST . isKindOfLiteral ( arg0 , "string" ) ) {
36+ if ( arg0 == null || ! AST . isLiteral ( arg0 , "string" ) ) {
3737 return false ;
3838 }
3939 // check for: `require('source')` or `require('source/...')`
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export function isInitializedFromReact(
4949 // check for: `variable = require('react')` or `variable = require('react').variable`
5050 const args = getRequireExpressionArguments ( init ) ;
5151 const arg0 = args ?. [ 0 ] ;
52- if ( arg0 == null || ! AST . isKindOfLiteral ( arg0 , "string" ) ) {
52+ if ( arg0 == null || ! AST . isLiteral ( arg0 , "string" ) ) {
5353 return false ;
5454 }
5555 // check for: `require('react')` or `require('react/...')`
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ export * from "./get-top-level-identifier";
1313export * from "./is" ;
1414export * from "./is-array-map-call" ;
1515export * from "./is-empty-function" ;
16- export * from "./is-kind-of-literal" ;
1716export * from "./is-line-break" ;
17+ export * from "./is-literal" ;
1818export * from "./is-multi-line" ;
1919export * from "./is-node-equal" ;
2020export * from "./is-this-expression" ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ /* eslint-disable local/prefer-eqeq-nullish-comparison */
2+ import type { TSESTree } from "@typescript-eslint/types" ;
3+ import { AST_NODE_TYPES as T } from "@typescript-eslint/types" ;
4+
5+ type LiteralType =
6+ | "boolean"
7+ | "null"
8+ | "number"
9+ | "regexp"
10+ | "string" ;
11+
12+ export function isLiteral ( node : TSESTree . Node ) : node is TSESTree . Literal ;
13+ export function isLiteral ( node : TSESTree . Node , type : "boolean" ) : node is TSESTree . BooleanLiteral ;
14+ export function isLiteral ( node : TSESTree . Node , type : "null" ) : node is TSESTree . NullLiteral ;
15+ export function isLiteral ( node : TSESTree . Node , type : "number" ) : node is TSESTree . NumberLiteral ;
16+ export function isLiteral ( node : TSESTree . Node , type : "regexp" ) : node is TSESTree . RegExpLiteral ;
17+ export function isLiteral ( node : TSESTree . Node , type : "string" ) : node is TSESTree . StringLiteral ;
18+ export function isLiteral ( node : TSESTree . Node , type ?: LiteralType ) {
19+ if ( node . type !== T . Literal ) return false ;
20+ if ( type == null ) return true ;
21+ switch ( type ) {
22+ case "boolean" :
23+ return typeof node . value === "boolean" ;
24+ case "null" :
25+ return node . value === null ;
26+ case "number" :
27+ return typeof node . value === "number" ;
28+ case "regexp" :
29+ return "regex" in node ;
30+ case "string" :
31+ return typeof node . value === "string" ;
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments