From d705983a72c7b91e26abce82890ba88a13f5098a Mon Sep 17 00:00:00 2001 From: zanminkian Date: Fri, 20 Dec 2024 17:20:28 +0000 Subject: [PATCH] refactor: remove `append` property for Builder. user can use append method --- .changeset/small-kiwis-shop.md | 6 +++ packages/eslint-config/README.md | 9 +++-- packages/eslint-config/src/eslint.config.ts | 26 +++++++------ packages/fenge/README.md | 43 ++++++++++++--------- 4 files changed, 50 insertions(+), 34 deletions(-) create mode 100644 .changeset/small-kiwis-shop.md diff --git a/.changeset/small-kiwis-shop.md b/.changeset/small-kiwis-shop.md new file mode 100644 index 00000000..35aa6536 --- /dev/null +++ b/.changeset/small-kiwis-shop.md @@ -0,0 +1,6 @@ +--- +"@fenge/eslint-config": minor +"fenge": minor +--- + +refactor: remove `append` property for Builder. user can use append method diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md index f40c2b3c..14166876 100644 --- a/packages/eslint-config/README.md +++ b/packages/eslint-config/README.md @@ -73,9 +73,12 @@ export default new Builder() .enableJavascript({ omit: ["no-var"], // these rules will not work for js files }) - .enableTypescript({ - // apply additional rules or override the built-in rules for ts files - append: { + .enableTypescript() + // apply additional rules or override the built-in rules for ts files + .append({ + name: "strictest", + files: ["**/*.{ts,cts,mts,tsx}"], + rules: { "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/consistent-type-assertions": [ "error", diff --git a/packages/eslint-config/src/eslint.config.ts b/packages/eslint-config/src/eslint.config.ts index d88d9593..5d9e4fd1 100644 --- a/packages/eslint-config/src/eslint.config.ts +++ b/packages/eslint-config/src/eslint.config.ts @@ -43,11 +43,8 @@ export class Builder { } private setup( - [mainConfig, ...otherConfigs]: readonly [ - { plugins: object; rules: object }, - ...object[], - ], - { pick, omit, append = {} }: Options, + configItems: readonly { rules: object }[], + { pick, omit }: Options, ) { const select = (ruleKey: string) => { if (!pick && !omit) { @@ -60,13 +57,18 @@ export class Builder { throw new Error("You cannot specify both pick and omit"); } }; - const rules = Object.fromEntries( - Object.entries(mainConfig.rules).filter(([ruleKey]) => select(ruleKey)), - ); - this.configs.push( - { ...mainConfig, rules: { ...rules, ...append } }, - ...otherConfigs, - ); + const result = configItems.map((configItem) => ({ + ...configItem, + rules: { + ...Object.fromEntries( + Object.entries(configItem.rules).filter(([ruleKey]) => + select(ruleKey), + ), + ), + }, + })); + this.configs.push(...result); + return this; } diff --git a/packages/fenge/README.md b/packages/fenge/README.md index 4a7340ab..05e83040 100644 --- a/packages/fenge/README.md +++ b/packages/fenge/README.md @@ -233,26 +233,31 @@ export default { }, lint: async () => { // See https://www.npmjs.com/package/@fenge/eslint-config for eslint-config detail usage - const Builder = (await import("fenge/eslint-config")).Builder; - return new Builder() - .enablePackagejson({ - pick: ["packagejson/top-types"], // only these rules will work for package.json files - }) - .enableJavascript({ - omit: ["no-var"], // these rules will not work for js files - }) - .enableTypescript({ + const { Builder } = await import("fenge/eslint-config"); + return ( + new Builder() + .enablePackagejson({ + pick: ["packagejson/top-types"], // only these rules will work for package.json files + }) + .enableJavascript({ + omit: ["no-var"], // these rules will not work for js files + }) + .enableTypescript() // apply additional rules or override the built-in rules for ts files - append: { - "@typescript-eslint/no-explicit-any": "error", - "@typescript-eslint/consistent-type-assertions": [ - "error", - { assertionStyle: "never" }, - ], - "@typescript-eslint/no-non-null-assertion": "error", - }, - }) - .toConfig(); + .append({ + name: "strictest", + files: ["**/*.{ts,cts,mts,tsx}"], + rules: { + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/consistent-type-assertions": [ + "error", + { assertionStyle: "never" }, + ], + "@typescript-eslint/no-non-null-assertion": "error", + }, + }) + .toConfig() + ); }, }; ```