@@ -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,85 +37,99 @@ export class BaseConfigFactory {
3737 }
3838 }
3939 } ] ;
40-
40+
4141 if ( this . useJsBaseConfig ( ) && this . useLwcBaseConfig ( ) ) {
4242 configArray . push ( ...this . createJavascriptPlusLwcConfigArray ( ) ) ;
4343 } else if ( this . useJsBaseConfig ( ) ) {
4444 configArray . push ( ...this . createJavascriptConfigArray ( ) ) ;
4545 } else if ( this . useLwcBaseConfig ( ) ) {
4646 configArray . push ( ...this . createLwcConfigArray ( ) ) ;
4747 }
48- if ( this . useSldsBaseConfig ( ) ) {
49- configArray . push ( ...this . createSldsConfigArray ( ) ) ;
48+ if ( this . useSldsCSSBaseConfig ( ) ) {
49+ configArray . push ( ...this . createSldsCSSConfigArray ( ) ) ;
50+ }
51+ if ( this . useSldsHTMLBaseConfig ( ) ) {
52+ configArray . push ( ...this . createSldsHTMLConfigArray ( ) ) ;
5053 }
5154 if ( this . useTsBaseConfig ( ) ) {
5255 configArray . push ( ...this . createTypescriptConfigArray ( ) ) ;
5356 }
5457 return configArray ;
5558 }
56-
59+
5760 private createJavascriptPlusLwcConfigArray ( ) : Linter . Config [ ] {
5861 let configs : Linter . Config [ ] = validateAndGetRawLwcConfigArray ( ) ;
59-
62+
6063 // TODO: Remove the For the following 2 updates when https://github.com/salesforce/eslint-config-lwc/issues/158 is fixed
6164 // 1) Turn off the babel parser's configFile option from the lwc base plugin
6265 configs [ 0 ] . languageOptions ! . parserOptions ! . babelOptions . configFile = false ;
6366 // 2) For some reason babel doesn't like .cjs files unless we explicitly set this to undefined because I think
6467 // ESLint 9 is setting it to "commonjs" automatically when the field doesn't exist in the parserOptions (and for
6568 // babel "commonjs" isn't a valid option)
6669 configs [ 0 ] . languageOptions ! . parserOptions ! . sourceType = undefined ;
67-
70+
6871 // Swap out eslintJs.configs.recommended with eslintJs.configs.all
6972 configs [ 1 ] = eslintJs . configs . all ;
70-
73+
7174 // This one rule is broken and thus, we need to turn it off for now.
7275 // See https://git.soma.salesforce.com/lwc/eslint-plugin-lwc-platform/issues/152
7376 configs [ 5 ] . rules = {
7477 ...configs [ 5 ] . rules ,
7578 '@lwc/lwc-platform/valid-offline-wire' : 'off'
7679 }
77-
80+
7881 // Restrict these configs to just javascript files
7982 configs = configs . map ( config => {
8083 return {
8184 ...config ,
8285 files : this . engineConfig . file_extensions . javascript . map ( ext => `**/*${ ext } ` )
8386 }
8487 } ) ;
85-
88+
8689 return configs ;
8790 }
88-
91+
8992 private createLwcConfigArray ( ) : Linter . Config [ ] {
9093 const configs : Linter . Config [ ] = this . createJavascriptPlusLwcConfigArray ( ) ;
91-
94+
9295 // Remove any explicitly listed rule that is a base javascript rule from the recommended LWC/Lightning rules.
9396 // Note the modified base rules don't have namespace like jest/*, @lwc/*, etc (and thus has no '/').
9497 configs [ 4 ] . rules = Object . fromEntries (
9598 Object . entries ( configs [ 4 ] . rules as Linter . RulesRecord ) . filter ( ( [ key ] ) => key . includes ( '/' ) )
9699 ) ;
97-
100+
98101 // Remove the eslintJs.configs.all (at element 1). Note that this delete is after the configs[4] update above so
99102 // we can work with the original index [4] instead of [3] to avoid confusion.
100103 configs . splice ( 1 , 1 ) ;
101-
104+
102105 return configs ;
103106 }
104-
107+
105108 private createJavascriptConfigArray ( ) : Linter . Config [ ] {
106109 return [ {
107110 ... eslintJs . configs . all ,
108111 files : this . engineConfig . file_extensions . javascript . map ( ext => `**/*${ ext } ` )
109112 } ] ;
110113 }
111-
112- private createSldsConfigArray ( ) : Linter . Config [ ] {
113- return sldsEslintPlugin . configs [ 'flat/recommended' ] . map ( conf => ( {
114- ...conf ,
115- files : this . engineConfig . file_extensions . html . map ( ext => `**/*${ ext } ` )
116- } ) ) ;
114+
115+ private createSldsHTMLConfigArray ( ) : Linter . Config [ ] {
116+ return sldsEslintPlugin . configs [ 'flat/recommended-html' ] . map ( ( htmlConfig : Linter . Config ) => {
117+ return {
118+ ...htmlConfig ,
119+ files : this . engineConfig . file_extensions . html . map ( ext => `**/*${ ext } ` )
120+ } ;
121+ } ) ;
117122 }
118-
123+
124+ private createSldsCSSConfigArray ( ) : Linter . Config [ ] {
125+ return sldsEslintPlugin . configs [ 'flat/recommended-css' ] . map ( ( cssConfig : Linter . Config ) => {
126+ return {
127+ ...cssConfig ,
128+ files : this . engineConfig . file_extensions . css . map ( ext => `**/*${ ext } ` )
129+ } ;
130+ } ) ;
131+ }
132+
119133 private createTypescriptConfigArray ( ) : Linter . Config [ ] {
120134 const configs : Linter . Config [ ] = [ ] ;
121135 for ( const conf of ( [ eslintJs . configs . all , ...eslintTs . configs . all ] as Linter . Config [ ] ) ) {
@@ -126,7 +140,7 @@ export class BaseConfigFactory {
126140 ... ( conf . languageOptions ?? { } ) ,
127141 parserOptions : {
128142 ... ( conf . languageOptions ?. parserOptions ?? { } ) ,
129-
143+
130144 // Finds the tsconfig.json file nearest to each source file. This should work for most users.
131145 // If not, then we may consider letting user specify this via config or alternatively users can
132146 // just set disable_typescript_base_config=true and configure typescript in their own eslint
@@ -138,19 +152,23 @@ export class BaseConfigFactory {
138152 }
139153 return configs ;
140154 }
141-
155+
142156 private useJsBaseConfig ( ) : boolean {
143157 return ! this . engineConfig . disable_javascript_base_config && this . engineConfig . file_extensions . javascript . length > 0 ;
144158 }
145-
159+
146160 private useLwcBaseConfig ( ) : boolean {
147161 return ! this . engineConfig . disable_lwc_base_config && this . engineConfig . file_extensions . javascript . length > 0 ;
148162 }
149-
150- private useSldsBaseConfig ( ) : boolean {
163+
164+ private useSldsCSSBaseConfig ( ) : boolean {
165+ return ! this . engineConfig . disable_slds_base_config && this . engineConfig . file_extensions . css . length > 0 ;
166+ }
167+
168+ private useSldsHTMLBaseConfig ( ) : boolean {
151169 return ! this . engineConfig . disable_slds_base_config && this . engineConfig . file_extensions . html . length > 0 ;
152170 }
153-
171+
154172 private useTsBaseConfig ( ) : boolean {
155173 return ! this . engineConfig . disable_typescript_base_config && this . engineConfig . file_extensions . typescript . length > 0 ;
156174 }
@@ -181,7 +199,7 @@ function validateAndGetRawLwcConfigArray(): Linter.Config[] {
181199 // - and lib/configs/recommended.js of https://www.npmjs.com/package/@lwc/eslint-plugin-lwc-platform?activeTab=code
182200 throw new Error ( "INTERNAL ERROR: The recommended config for @salesforce/eslint-config-lwc or @lwc/eslint-plugin-lwc-platform must have changed." ) ;
183201 }
184-
202+
185203 // Return a shallow copy since we will be making modifications
186204 return rawLwcConfigs . map ( config => { return { ... config } } ) ;
187205}
0 commit comments