Skip to content

Commit a0ed3ae

Browse files
committed
Addressing comments for gating the react enable/disable variable
1 parent 70f077a commit a0ed3ae

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/code-analyzer-eslint-engine/src/base-config.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,28 @@ export class BaseConfigFactory {
6565
private createJavascriptPlusLwcConfigArray(): Linter.Config[] {
6666
let configs: Linter.Config[] = validateAndGetRawLwcConfigArray();
6767

68-
// Deep clone the languageOptions to avoid mutating the original shared config from the LWC package
68+
// Reconstruct languageOptions to avoid mutating the original shared config from the LWC package
69+
// TODO: Remove configFile and sourceType overrides when https://github.com/salesforce/eslint-config-lwc/issues/158 is fixed
6970
const originalParserOptions = configs[0].languageOptions!.parserOptions as Linter.ParserOptions;
70-
const clonedBabelOptions = JSON.parse(JSON.stringify(originalParserOptions.babelOptions));
71+
const originalBabelOptions = originalParserOptions.babelOptions || {};
7172
configs[0].languageOptions = {
7273
...configs[0].languageOptions,
7374
parserOptions: {
7475
...originalParserOptions,
75-
babelOptions: clonedBabelOptions
76+
// For some reason babel doesn't like .cjs files unless we explicitly set this to undefined
77+
// because ESLint 9 is setting it to "commonjs" automatically when the field doesn't exist
78+
// in the parserOptions (and for babel "commonjs" isn't a valid option)
79+
sourceType: undefined,
80+
babelOptions: {
81+
...originalBabelOptions,
82+
// Turn off the babel parser's configFile option from the lwc base plugin
83+
configFile: false,
84+
// Add @babel/preset-react to enable JSX parsing for React/JSX files
85+
presets: [...(originalBabelOptions.presets || []), '@babel/preset-react']
86+
}
7687
}
7788
};
7889

79-
// TODO: Remove the For the following 2 updates when https://github.com/salesforce/eslint-config-lwc/issues/158 is fixed
80-
// 1) Turn off the babel parser's configFile option from the lwc base plugin
81-
clonedBabelOptions.configFile = false;
82-
// 2) For some reason babel doesn't like .cjs files unless we explicitly set this to undefined because I think
83-
// ESLint 9 is setting it to "commonjs" automatically when the field doesn't exist in the parserOptions (and for
84-
// babel "commonjs" isn't a valid option)
85-
(configs[0].languageOptions!.parserOptions as Linter.ParserOptions).sourceType = undefined;
86-
87-
// 3) Add @babel/preset-react to enable JSX parsing for React/JSX files
88-
const existingPresets = clonedBabelOptions.presets || [];
89-
clonedBabelOptions.presets = [...existingPresets, '@babel/preset-react'];
90-
9190
// Swap out eslintJs.configs.recommended with eslintJs.configs.all
9291
configs[1] = eslintJs.configs.all;
9392

packages/code-analyzer-eslint-engine/src/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ export const LEGACY_ESLINT_IGNORE_FILE: string = '.eslintignore';
143143

144144

145145
export function validateAndNormalizeConfig(configValueExtractor: ConfigValueExtractor): ESLintEngineConfig {
146-
// Note: disable_react_base_config is intentionally excluded - React support is gated
147-
// TODO: Add 'disable_react_base_config' when React support is released
146+
// disable_react_base_config bypasses validation - React support is gated but we need it for internal testing
147+
// TODO: Move 'disable_react_base_config' to validateContainsOnlySpecifiedKeys when React support is released
148+
configValueExtractor.addKeysThatBypassValidation(['disable_react_base_config']);
148149
configValueExtractor.validateContainsOnlySpecifiedKeys(['eslint_config_file', 'eslint_ignore_file',
149150
'auto_discover_eslint_config', 'disable_javascript_base_config', 'disable_lwc_base_config',
150151
'disable_slds_base_config', 'disable_typescript_base_config', 'file_extensions']);

0 commit comments

Comments
 (0)