11import * as AST from "@eslint-react/ast" ;
22import { AST_NODE_TYPES , ESLintUtils } from "@typescript-eslint/utils" ;
3- import { unit } from "@eslint-react/eff" ;
4- import { findVariable } from "@eslint-react/var" ;
5- import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/types" ;
63import { NullThrowsReasons , nullThrows } from "@typescript-eslint/utils/eslint-utils" ;
74
85//#region package.json
@@ -16,87 +13,28 @@ function getDocsUrl() {
1613}
1714const createRule = ESLintUtils . RuleCreator ( getDocsUrl ) ;
1815
19- //#endregion
20- //#region src/utils/is-initialized-from-source.ts
21- /**
22- * Check if an identifier is initialized from the given source
23- * @param name The top-level identifier's name
24- * @param source The import source to check against
25- * @param initialScope Initial scope to search for the identifier
26- * @returns Whether the identifier is initialized from the given source
27- */
28- function isInitializedFromSource ( name$1 , source , initialScope ) {
29- const latestDef = findVariable ( name$1 , initialScope ) ?. defs . at ( - 1 ) ;
30- if ( latestDef == null ) return false ;
31- const { node, parent } = latestDef ;
32- if ( node . type === AST_NODE_TYPES$1 . VariableDeclarator && node . init != null ) {
33- const { init } = node ;
34- if ( init . type === AST_NODE_TYPES$1 . MemberExpression && init . object . type === AST_NODE_TYPES$1 . Identifier ) return isInitializedFromSource ( init . object . name , source , initialScope ) ;
35- if ( init . type === AST_NODE_TYPES$1 . Identifier ) return isInitializedFromSource ( init . name , source , initialScope ) ;
36- const arg0 = getRequireExpressionArguments ( init ) ?. [ 0 ] ;
37- if ( arg0 == null || ! AST . isLiteral ( arg0 , "string" ) ) return false ;
38- return arg0 . value === source || arg0 . value . startsWith ( `${ source } /` ) ;
39- }
40- return parent ?. type === AST_NODE_TYPES$1 . ImportDeclaration && parent . source . value === source ;
41- }
42- function getRequireExpressionArguments ( node ) {
43- switch ( true ) {
44- case node . type === AST_NODE_TYPES$1 . CallExpression && node . callee . type === AST_NODE_TYPES$1 . Identifier && node . callee . name === "require" : return node . arguments ;
45- case node . type === AST_NODE_TYPES$1 . MemberExpression : return getRequireExpressionArguments ( node . object ) ;
46- }
47- return unit ;
48- }
49-
5016//#endregion
5117//#region src/rules/avoid-multiline-template-expression.ts
52- const RULE_NAME$2 = "avoid-multiline-template-expression" ;
53- const RULE_FEATURES$1 = [ ] ;
18+ const RULE_NAME$1 = "avoid-multiline-template-expression" ;
19+ const RULE_FEATURES = [ ] ;
5420var avoid_multiline_template_expression_default = createRule ( {
5521 meta : {
5622 type : "problem" ,
5723 docs : {
5824 description : "disallow multiline template expressions" ,
59- [ Symbol . for ( "rule_features" ) ] : RULE_FEATURES$1
60- } ,
61- messages : { avoidMultilineTemplateExpression : "Avoid multiline template expressions." } ,
62- schema : [ ]
63- } ,
64- name : RULE_NAME$2 ,
65- create : create$2 ,
66- defaultOptions : [ ]
67- } ) ;
68- function create$2 ( context ) {
69- return { TemplateLiteral : ( node ) => {
70- if ( AST . isMultiLine ( node ) ) context . report ( {
71- messageId : "avoidMultilineTemplateExpression" ,
72- node
73- } ) ;
74- } } ;
75- }
76-
77- //#endregion
78- //#region src/rules/no-shadow-underscore.ts
79- const RULE_NAME$1 = "no-shadow-underscore" ;
80- const RULE_FEATURES = [ ] ;
81- var no_shadow_underscore_default = createRule ( {
82- meta : {
83- type : "problem" ,
84- docs : {
85- description : "disallow shadowing of the underscore identifier" ,
8625 [ Symbol . for ( "rule_features" ) ] : RULE_FEATURES
8726 } ,
88- messages : { noShadowUnderscore : "In this codebase, '_' is used to represent the undefined. Avoid shadowing it ." } ,
27+ messages : { avoidMultilineTemplateExpression : "Avoid multiline template expressions ." } ,
8928 schema : [ ]
9029 } ,
9130 name : RULE_NAME$1 ,
9231 create : create$1 ,
9332 defaultOptions : [ ]
9433} ) ;
9534function create$1 ( context ) {
96- return { "Identifier[name='_']" ( node ) {
97- const initialScope = context . sourceCode . getScope ( node ) ;
98- if ( ! isInitializedFromSource ( "_" , "@eslint-react/eff" , initialScope ) ) context . report ( {
99- messageId : "noShadowUnderscore" ,
35+ return { TemplateLiteral : ( node ) => {
36+ if ( AST . isMultiLine ( node ) ) context . report ( {
37+ messageId : "avoidMultilineTemplateExpression" ,
10038 node
10139 } ) ;
10240 } } ;
@@ -162,7 +100,6 @@ const plugin = {
162100 } ,
163101 rules : {
164102 "avoid-multiline-template-expression" : avoid_multiline_template_expression_default ,
165- "no-shadow-underscore" : no_shadow_underscore_default ,
166103 "prefer-eqeq-nullish-comparison" : prefer_eqeq_nullish_comparison_default
167104 }
168105} ;
0 commit comments