11import * as AST from '@eslint-react/ast' ;
22import { ESLintUtils , AST_NODE_TYPES } from '@typescript-eslint/utils' ;
3- import * as VAR from '@eslint-react/var' ;
3+ import { _ } 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' ;
46import { nullThrows , NullThrowsReasons } from '@typescript-eslint/utils/eslint-utils' ;
57
68// package.json
@@ -10,6 +12,40 @@ function getDocsUrl() {
1012 return "TODO: add docs for local ESLint rules" ;
1113}
1214var createRule = ESLintUtils . RuleCreator ( getDocsUrl ) ;
15+ function isInitializedFromSource ( name2 , source , initialScope ) {
16+ const latestDef = findVariable ( name2 , initialScope ) ?. defs . at ( - 1 ) ;
17+ if ( latestDef == null ) return false ;
18+ const { node, parent } = latestDef ;
19+ if ( node . type === AST_NODE_TYPES$1 . VariableDeclarator && node . init != null ) {
20+ const { init } = node ;
21+ if ( init . type === AST_NODE_TYPES$1 . MemberExpression && init . object . type === AST_NODE_TYPES$1 . Identifier ) {
22+ return isInitializedFromSource ( init . object . name , source , initialScope ) ;
23+ }
24+ if ( init . type === AST_NODE_TYPES$1 . Identifier ) {
25+ return isInitializedFromSource ( init . name , source , initialScope ) ;
26+ }
27+ const args = getRequireExpressionArguments ( init ) ;
28+ const arg0 = args ?. [ 0 ] ;
29+ if ( arg0 == null || ! AST . isStringLiteral ( arg0 ) ) {
30+ return false ;
31+ }
32+ return arg0 . value === source || arg0 . value . startsWith ( `${ source } /` ) ;
33+ }
34+ return parent ?. type === AST_NODE_TYPES$1 . ImportDeclaration && parent . source . value === source ;
35+ }
36+ function getRequireExpressionArguments ( node ) {
37+ switch ( true ) {
38+ // require('source')
39+ case ( node . type === AST_NODE_TYPES$1 . CallExpression && node . callee . type === AST_NODE_TYPES$1 . Identifier && node . callee . name === "require" ) : {
40+ return node . arguments ;
41+ }
42+ // require('source').variable
43+ case node . type === AST_NODE_TYPES$1 . MemberExpression : {
44+ return getRequireExpressionArguments ( node . object ) ;
45+ }
46+ }
47+ return _ ;
48+ }
1349
1450// src/rules/avoid-multiline-template-expression.ts
1551var RULE_NAME = "avoid-multiline-template-expression" ;
@@ -43,6 +79,8 @@ var avoid_multiline_template_expression_default = createRule({
4379 } ,
4480 defaultOptions : [ ]
4581} ) ;
82+
83+ // src/rules/no-shadow-underscore.ts
4684var RULE_NAME2 = "no-shadow-underscore" ;
4785var RULE_FEATURES2 = [
4886 "CHK"
@@ -64,7 +102,7 @@ var no_shadow_underscore_default = createRule({
64102 return {
65103 "Identifier[name='_']" ( node ) {
66104 const initialScope = context . sourceCode . getScope ( node ) ;
67- const isFromImport = VAR . isInitializedFromSource ( "_" , "@eslint-react/eff" , initialScope ) ;
105+ const isFromImport = isInitializedFromSource ( "_" , "@eslint-react/eff" , initialScope ) ;
68106 if ( ! isFromImport ) {
69107 context . report ( {
70108 messageId : "noShadowUnderscore" ,
0 commit comments