Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
giseburt committed May 1, 2024
1 parent 57a8a23 commit ca9bea9
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/javascript/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export class Eslint extends Component {
node: true,
},
root: true,
plugins: () => this.renderPlugins(),
plugins: this._plugins,
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2018,
Expand Down Expand Up @@ -540,43 +540,51 @@ export class Eslint extends Component {
].map(
(
config:
| string
| string // this is for plugin-provided configs, expands to something like `...externalConfigs`
| (unknown & {
parser?: string;
parserOptions?: never;
env?: never;
ignorePatterns?: Array<string>;
noInlineConfig?: never;
reportUnusedDisableDirectives?: never;
plugins?: Set<string> | Array<string>;
})
) => {
if (typeof config === "string") {
return config;
}
return {
...config,
parser: undefined,
parserOptions: undefined,
env: undefined,
plugins: this.renderPlugins(config.plugins),
root: undefined,
overrides: undefined,
extends: undefined,
noInlineConfig: undefined,
reportUnusedDisableDirectives: undefined,

ignorePatterns: undefined,
ignores:
// if it starts with a !, has a /, or has a **, then leve it alone
// otherwise, add a **/ prefix
config.ignorePatterns?.map((p) =>
p.match(/(\/|\*\*|^\!)/) ? p : `**/${p}`
),
languageOptions: config.parser
? {
parser: this.renderParser(config.parser),
parserOptions: config.parserOptions,
globals: config.env,
}
: undefined,
overrides: undefined,
extends: undefined,
noInlineConfig: undefined,
reportUnusedDisableDirectives: undefined,

parser: undefined,
parserOptions: undefined,
env: undefined,
languageOptions:
config.parser || config.env
? {
parser: config.parser
? this.renderParser(config.parser)
: undefined,
parserOptions: config.parserOptions,
globals: config.env,
}
: undefined,

...(config.noInlineConfig ||
config.reportUnusedDisableDirectives
? {
Expand Down Expand Up @@ -732,8 +740,13 @@ export class Eslint extends Component {
}
}

private renderPlugins(): Record<string, string> | Array<string> | undefined {
const plugins = this._plugins;
private renderPlugins(
plugins: Set<string> | Array<string> | undefined
): Record<string, string> | Array<string> | undefined {
if (!plugins) {
return undefined;
}

if (
this.fileFormat === EslintConfigFileFormat.JAVASCRIPT_FLAT_ESM ||
this.fileFormat === EslintConfigFileFormat.JAVASCRIPT_FLAT_CJS
Expand Down

0 comments on commit ca9bea9

Please sign in to comment.