File tree Expand file tree Collapse file tree 5 files changed +21
-18
lines changed
packages/eslint-plugin-react-hooks Expand file tree Collapse file tree 5 files changed +21
-18
lines changed Original file line number Diff line number Diff line change 55 * LICENSE file in the root directory of this source tree.
66 */
77
8- import { ErrorSeverity } from 'babel-plugin-react-compiler/src ' ;
8+ import { ErrorSeverity } from 'babel-plugin-react-compiler' ;
99import { RuleTester as ESLintTester } from 'eslint' ;
10- import ReactCompilerRule from '../src/rules/ReactCompilerRule ' ;
10+ import ReactCompilerRule from '../src/rules/ReactCompiler ' ;
1111
1212/**
1313 * A string template tag that removes padding from the left side of multi-line strings
1414 * @param {Array } strings array of code strings (only one expected)
1515 */
1616function normalizeIndent ( strings : TemplateStringsArray ) : string {
17- const codeLines = strings [ 0 ] . split ( '\n' ) ;
18- const leftPadding = codeLines [ 1 ] . match ( / \s + / ) ! [ 0 ] ;
17+ const codeLines = strings [ 0 ] ? .split ( '\n' ) ?? [ ] ;
18+ const leftPadding = codeLines [ 1 ] ? .match ( / \s + / ) ! [ 0 ] ?? '' ;
1919 return codeLines . map ( line => line . slice ( leftPadding . length ) ) . join ( '\n' ) ;
2020}
2121
Original file line number Diff line number Diff line change 66 */
77
88import { RuleTester } from 'eslint' ;
9- import ReactCompilerRule from '../src/rules/ReactCompilerRule ' ;
9+ import ReactCompilerRule from '../src/rules/ReactCompiler ' ;
1010
1111/**
1212 * A string template tag that removes padding from the left side of multi-line strings
1313 * @param {Array } strings array of code strings (only one expected)
1414 */
1515function normalizeIndent ( strings : TemplateStringsArray ) : string {
16- const codeLines = strings [ 0 ] . split ( '\n' ) ;
17- const leftPadding = codeLines [ 1 ] . match ( / \s + / ) [ 0 ] ;
16+ const codeLines = strings [ 0 ] ? .split ( '\n' ) ?? [ ] ;
17+ const leftPadding = codeLines [ 1 ] ? .match ( / \s + / ) ! [ 0 ] ?? '' ;
1818 return codeLines . map ( line => line . slice ( leftPadding . length ) ) . join ( '\n' ) ;
1919}
2020
Original file line number Diff line number Diff line change 44 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
66 */
7- import RulesOfHooks from './rules/RulesOfHooks' ;
8- import ExhaustiveDeps from './rules/ExhaustiveDeps' ;
97import type { ESLint , Linter , Rule } from 'eslint' ;
108
9+ import ExhaustiveDeps from './rules/ExhaustiveDeps' ;
10+ import ReactCompiler from './rules/ReactCompiler' ;
11+ import RulesOfHooks from './rules/RulesOfHooks' ;
12+
1113// All rules
1214const rules = {
13- 'rules-of-hooks' : RulesOfHooks ,
1415 'exhaustive-deps' : ExhaustiveDeps ,
16+ 'react-compiler' : ReactCompiler ,
17+ 'rules-of-hooks' : RulesOfHooks ,
1518} satisfies Record < string , Rule . RuleModule > ;
1619
1720// Config rules
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import BabelPluginReactCompiler, {
1717 validateEnvironmentConfig ,
1818 OPT_OUT_DIRECTIVES ,
1919 type Logger ,
20+ type LoggerEvent ,
2021 type PluginOptions ,
2122} from 'babel-plugin-react-compiler' ;
2223import type { Rule } from 'eslint' ;
@@ -180,10 +181,10 @@ const rule: Rule.RuleModule = {
180181 endLoc = {
181182 line : event . fnLoc . start . line ,
182183 // Babel loc line numbers are 1-indexed
183- column : sourceCode . text . split (
184- / \r ? \n | \r | \n / g,
185- event . fnLoc . start . line ,
186- ) [ event . fnLoc . start . line - 1 ] . length ,
184+ column :
185+ sourceCode . text . split ( / \r ? \n | \r | \n / g) [
186+ event . fnLoc . start . line - 1
187+ ] ? .length ?? 0 ,
187188 } ;
188189 }
189190 const firstLineLoc = {
@@ -226,8 +227,8 @@ const rule: Rule.RuleModule = {
226227 options . environment = validateEnvironmentConfig (
227228 options . environment ?? { } ,
228229 ) ;
229- } catch ( err ) {
230- options . logger ?. logEvent ( '' , err ) ;
230+ } catch ( err : unknown ) {
231+ options . logger ?. logEvent ( '' , err as LoggerEvent ) ;
231232 }
232233
233234 function hasFlowSuppression (
Original file line number Diff line number Diff line change 1212 "babel-plugin-react-compiler" : [" ../../compiler/packages/babel-plugin-react-compiler/src/index.ts" ]
1313 }
1414 },
15- "exclude" : [" node_modules" ],
16- "include" : [" src/**/*.ts" ]
15+ "include" : [" src/**/*.ts" , " __tests__/**/*.ts" ]
1716}
You can’t perform that action at this time.
0 commit comments