@@ -9,11 +9,11 @@ import globals from "globals";
99
1010export class BaseConfigFactory {
1111 private readonly engineConfig : ESLintEngineConfig ;
12-
12+
1313 constructor ( engineConfig : ESLintEngineConfig ) {
1414 this . engineConfig = engineConfig ;
1515 }
16-
16+
1717 createBaseConfigArray ( ) : Linter . Config [ ] {
1818 const configArray : Linter . Config [ ] = [ {
1919 linterOptions : {
@@ -28,7 +28,7 @@ export class BaseConfigFactory {
2828 "$Label" : "readonly" , // ^
2929 "$Locale" : "readonly" , // ^
3030 "$Resource" : "readonly" , // ^
31-
31+
3232 // ESLint doesn't natively know about various browser and node globals. So we add them here to
3333 // remove false positives for our users.
3434 ... globals . node ,
@@ -37,7 +37,7 @@ export class BaseConfigFactory {
3737 }
3838 }
3939 } ] ;
40-
40+
4141 if ( this . useJsBaseConfig ( ) && this . useLwcBaseConfig ( ) ) {
4242 configArray . push ( ...this . createJavascriptPlusLwcConfigArray ( ) ) ;
4343 } else if ( this . useJsBaseConfig ( ) ) {
@@ -56,22 +56,22 @@ export class BaseConfigFactory {
5656 }
5757 return configArray ;
5858 }
59-
59+
6060 private createJavascriptPlusLwcConfigArray ( ) : Linter . Config [ ] {
6161 let configs : Linter . Config [ ] = validateAndGetRawLwcConfigArray ( ) ;
62-
62+
6363 // TODO: Remove the For the following 2 updates when https://github.com/salesforce/eslint-config-lwc/issues/158 is fixed
6464 // 1) Turn off the babel parser's configFile option from the lwc base plugin
65- configs [ 0 ] . languageOptions ! . parserOptions ! . babelOptions . configFile = false ;
65+ ( configs [ 0 ] . languageOptions ! . parserOptions as Linter . ParserOptions ) . babelOptions . configFile = false ;
6666 // 2) For some reason babel doesn't like .cjs files unless we explicitly set this to undefined because I think
6767 // ESLint 9 is setting it to "commonjs" automatically when the field doesn't exist in the parserOptions (and for
6868 // babel "commonjs" isn't a valid option)
69- configs [ 0 ] . languageOptions ! . parserOptions ! . sourceType = undefined ;
70-
69+ ( configs [ 0 ] . languageOptions ! . parserOptions as Linter . ParserOptions ) . sourceType = undefined ;
70+
7171 // Swap out eslintJs.configs.recommended with eslintJs.configs.all
7272 configs [ 1 ] = eslintJs . configs . all ;
73-
74- // This one rule makes eslint throw an exception if the user doesn't have jest installed (which should be
73+
74+ // This one rule makes eslint throw an exception if the user doesn't have jest installed (which should be
7575 // optional), so we turn it off for now. See https://github.com/salesforce/eslint-config-lwc/issues/161
7676 configs [ 3 ] . rules = {
7777 ...configs [ 3 ] . rules ,
@@ -84,41 +84,41 @@ export class BaseConfigFactory {
8484 ...configs [ 5 ] . rules ,
8585 '@lwc/lwc-platform/valid-offline-wire' : 'off'
8686 }
87-
87+
8888 // Restrict these configs to just javascript files
8989 configs = configs . map ( config => {
9090 return {
9191 ...config ,
9292 files : this . engineConfig . file_extensions . javascript . map ( ext => `**/*${ ext } ` )
9393 }
9494 } ) ;
95-
95+
9696 return configs ;
9797 }
98-
98+
9999 private createLwcConfigArray ( ) : Linter . Config [ ] {
100100 const configs : Linter . Config [ ] = this . createJavascriptPlusLwcConfigArray ( ) ;
101-
101+
102102 // Remove any explicitly listed rule that is a base javascript rule from the recommended LWC/Lightning rules.
103103 // Note the modified base rules don't have namespace like jest/*, @lwc/*, etc (and thus has no '/').
104104 configs [ 4 ] . rules = Object . fromEntries (
105105 Object . entries ( configs [ 4 ] . rules as Linter . RulesRecord ) . filter ( ( [ key ] ) => key . includes ( '/' ) )
106106 ) ;
107-
107+
108108 // Remove the eslintJs.configs.all (at element 1). Note that this delete is after the configs[4] update above so
109109 // we can work with the original index [4] instead of [3] to avoid confusion.
110110 configs . splice ( 1 , 1 ) ;
111-
111+
112112 return configs ;
113113 }
114-
114+
115115 private createJavascriptConfigArray ( ) : Linter . Config [ ] {
116116 return [ {
117117 ... eslintJs . configs . all ,
118118 files : this . engineConfig . file_extensions . javascript . map ( ext => `**/*${ ext } ` )
119119 } ] ;
120120 }
121-
121+
122122 private createSldsHTMLConfigArray ( ) : Linter . Config [ ] {
123123 return sldsEslintPlugin . configs [ 'flat/recommended-html' ] . map ( ( htmlConfig : Linter . Config ) => {
124124 return {
@@ -127,16 +127,16 @@ export class BaseConfigFactory {
127127 } ;
128128 } ) ;
129129 }
130-
131- private createSldsCSSConfigArray ( ) : Linter . Config [ ] {
130+
131+ private createSldsCSSConfigArray ( ) : Linter . Config [ ] {
132132 return sldsEslintPlugin . configs [ 'flat/recommended-css' ] . map ( ( cssConfig : Linter . Config ) => {
133133 return {
134134 ...cssConfig ,
135135 files : this . engineConfig . file_extensions . css . map ( ext => `**/*${ ext } ` )
136136 } ;
137137 } ) ;
138138 }
139-
139+
140140 private createTypescriptConfigArray ( ) : Linter . Config [ ] {
141141 const configs : Linter . Config [ ] = [ ] ;
142142 for ( const conf of ( [ eslintJs . configs . all , ...eslintTs . configs . all ] as Linter . Config [ ] ) ) {
@@ -147,7 +147,7 @@ export class BaseConfigFactory {
147147 ... ( conf . languageOptions ?? { } ) ,
148148 parserOptions : {
149149 ... ( conf . languageOptions ?. parserOptions ?? { } ) ,
150-
150+
151151 // Finds the tsconfig.json file nearest to each source file. This should work for most users.
152152 // If not, then we may consider letting user specify this via config or alternatively users can
153153 // just set disable_typescript_base_config=true and configure typescript in their own eslint
@@ -159,23 +159,23 @@ export class BaseConfigFactory {
159159 }
160160 return configs ;
161161 }
162-
162+
163163 private useJsBaseConfig ( ) : boolean {
164164 return ! this . engineConfig . disable_javascript_base_config && this . engineConfig . file_extensions . javascript . length > 0 ;
165165 }
166-
166+
167167 private useLwcBaseConfig ( ) : boolean {
168168 return ! this . engineConfig . disable_lwc_base_config && this . engineConfig . file_extensions . javascript . length > 0 ;
169169 }
170-
170+
171171 private useSldsCSSBaseConfig ( ) : boolean {
172172 return ! this . engineConfig . disable_slds_base_config && this . engineConfig . file_extensions . css . length > 0 ;
173173 }
174-
174+
175175 private useSldsHTMLBaseConfig ( ) : boolean {
176176 return ! this . engineConfig . disable_slds_base_config && this . engineConfig . file_extensions . html . length > 0 ;
177177 }
178-
178+
179179 private useTsBaseConfig ( ) : boolean {
180180 return ! this . engineConfig . disable_typescript_base_config && this . engineConfig . file_extensions . typescript . length > 0 ;
181181 }
@@ -206,13 +206,13 @@ function validateAndGetRawLwcConfigArray(): Linter.Config[] {
206206 // - and lib/configs/recommended.js of https://www.npmjs.com/package/@lwc/eslint-plugin-lwc-platform?activeTab=code
207207 throw new Error ( "INTERNAL ERROR: The recommended config for @salesforce/eslint-config-lwc or @lwc/eslint-plugin-lwc-platform must have changed." ) ;
208208 }
209-
209+
210210 // Return a shallow copy since we will be making modifications
211211 return rawLwcConfigs . map ( config => { return { ... config } } ) ;
212212}
213213
214214function containsBabelOptions ( config : Linter . Config ) : boolean {
215- return config . languageOptions ?. parserOptions ?. babelOptions !== undefined ;
215+ return ( config . languageOptions ?. parserOptions as Linter . ParserOptions ) ?. babelOptions !== undefined ;
216216}
217217
218218function hasRule ( config : Linter . Config , ruleName : string ) : boolean {
0 commit comments