@fenge/eslint-config 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +8 -5
  3. package/dist/config/javascript.d.ts +11 -0
  4. package/dist/config/javascript.d.ts.map +1 -1
  5. package/dist/config/js/base.d.ts +7 -0
  6. package/dist/config/js/base.d.ts.map +1 -1
  7. package/dist/config/js/base.js +10 -2
  8. package/dist/config/js/cli.d.ts +3 -0
  9. package/dist/config/js/cli.d.ts.map +1 -1
  10. package/dist/config/js/cli.js +5 -1
  11. package/dist/config/js/test.d.ts +1 -0
  12. package/dist/config/js/test.d.ts.map +1 -1
  13. package/dist/config/js/test.js +2 -1
  14. package/dist/config/packagejson.d.ts +1 -1
  15. package/dist/config/packagejson.js +2 -2
  16. package/dist/config/ts/base.d.ts +8 -1
  17. package/dist/config/ts/base.d.ts.map +1 -1
  18. package/dist/config/ts/base.js +3 -4
  19. package/dist/config/ts/cli.d.ts +3 -0
  20. package/dist/config/ts/cli.d.ts.map +1 -1
  21. package/dist/config/ts/declaration.d.ts +4 -0
  22. package/dist/config/ts/declaration.d.ts.map +1 -1
  23. package/dist/config/ts/declaration.js +5 -1
  24. package/dist/config/ts/test.d.ts +1 -0
  25. package/dist/config/ts/test.d.ts.map +1 -1
  26. package/dist/config/typescript.d.ts +16 -1
  27. package/dist/config/typescript.d.ts.map +1 -1
  28. package/dist/eslint.config.d.ts +11 -4
  29. package/dist/eslint.config.d.ts.map +1 -1
  30. package/dist/eslint.config.js +17 -10
  31. package/package.json +6 -6
  32. package/src/config/js/base.ts +9 -1
  33. package/src/config/js/cli.ts +4 -0
  34. package/src/config/js/test.ts +1 -0
  35. package/src/config/packagejson.ts +1 -1
  36. package/src/config/ts/base.ts +2 -3
  37. package/src/config/ts/declaration.ts +4 -0
  38. package/src/eslint.config.ts +30 -29
@@ -15,6 +15,7 @@ export function packagejson() {
15
15
  "pkg-json/bottom-default": "error",
16
16
  "pkg-json/exact-dependency-version": "error",
17
17
  "pkg-json/no-conflict-types": "error",
18
+ "pkg-json/no-dependencies-in-workspace-root": "error",
18
19
  "pkg-json/no-lifecycle-script": "error",
19
20
  "pkg-json/no-nonstandard-property": "error",
20
21
  "pkg-json/no-types-dependency-in-workspace-root": "error",
@@ -24,7 +25,6 @@ export function packagejson() {
24
25
  "pkg-json/required-hashbang": "error",
25
26
  "pkg-json/required-repository": "error",
26
27
  "pkg-json/type-module": "error",
27
- "pkg-json/no-dependencies-in-workspace-root": "error",
28
28
  // "publint/suggestion": "error",
29
29
  "publint/warning": "error",
30
30
  "publint/error": "error",
@@ -81,9 +81,8 @@ export function getTsBase() {
81
81
  parserOptions: {
82
82
  ...jsBase.languageOptions.parserOptions,
83
83
  // Setting `projectService: true` or `project: true` is pretty slow when lint a monorepo with many tsconfig.json files in each sub-app.
84
- // For a better performance, we are recommended using one tsconfig.json file in a project.
85
- // Waiting for typescript-eslint to officially provide a better way to use `projectService`.
86
- project: "tsconfig.json",
84
+ // But setting `project: "tsconfig.json"` will cause parser error when the project root tsconfig.json is `{ extends: "fenge/tsconfig" }`
85
+ projectService: true,
87
86
  },
88
87
  },
89
88
  plugins: {
@@ -3,6 +3,10 @@ export function getTsDeclaration() {
3
3
  name: "fenge/typescript/declaration",
4
4
  files: ["**/*.d.{ts,cts,mts,tsx}"],
5
5
  rules: {
6
+ "esm/no-empty-exports": "off",
7
+ "esm/no-side-effect-imports": "off",
8
+ "esm/no-ts-file-imports": "off",
9
+ "esm/required-exports": "off",
6
10
  "import/no-default-export": "off",
7
11
  },
8
12
  } as const;
@@ -15,20 +15,18 @@ type JsRuleKey = keyof ReturnType<typeof javascript>[0]["rules"];
15
15
  type TsRuleKey = keyof ReturnType<typeof typescript>[0]["rules"];
16
16
  type PkgRuleKey = keyof ReturnType<typeof packagejson>[0]["rules"];
17
17
 
18
+ type RuleValue = "error" | "warn" | "off" | ["error" | "warn", ...unknown[]];
18
19
  interface Options<T extends string[]> {
19
20
  pick?: NoDuplicate<T>;
20
21
  omit?: NoDuplicate<T>;
21
- append?:
22
- | Partial<
23
- Record<
24
- T[number],
25
- "error" | "warn" | "off" | ["error" | "warn", ...unknown[]]
26
- >
27
- >
28
- | Record<
29
- string,
30
- "error" | "warn" | "off" | ["error" | "warn", ...unknown[]]
31
- >;
22
+ }
23
+ interface ConfigItem {
24
+ name: string;
25
+ files: string[];
26
+ plugins?: Record<string, object>;
27
+ rules:
28
+ | Partial<Record<PkgRuleKey | JsRuleKey | TsRuleKey, RuleValue>>
29
+ | Record<string, RuleValue>;
32
30
  }
33
31
 
34
32
  export type BuilderOptions = LinterOptions;
@@ -44,11 +42,8 @@ export class Builder {
44
42
  }
45
43
 
46
44
  private setup(
47
- [mainConfig, ...otherConfigs]: readonly [
48
- { plugins: object; rules: object },
49
- ...object[],
50
- ],
51
- { pick, omit, append = {} }: Options<string[]>,
45
+ configItems: readonly { rules: object }[],
46
+ { pick, omit }: Options<string[]>,
52
47
  ) {
53
48
  const select = (ruleKey: string) => {
54
49
  if (!pick && !omit) {
@@ -61,31 +56,37 @@ export class Builder {
61
56
  throw new Error("You cannot specify both pick and omit");
62
57
  }
63
58
  };
64
- const rules = Object.fromEntries(
65
- Object.entries(mainConfig.rules).filter(([ruleKey]) => select(ruleKey)),
66
- );
67
- this.configs.push(
68
- { ...mainConfig, rules: { ...rules, ...append } },
69
- ...otherConfigs,
70
- );
59
+ const result = configItems.map((configItem) => ({
60
+ ...configItem,
61
+ rules: Object.fromEntries(
62
+ Object.entries(configItem.rules).filter(([ruleKey]) => select(ruleKey)),
63
+ ),
64
+ }));
65
+ this.configs.push(...result);
66
+
71
67
  return this;
72
68
  }
73
69
 
74
- enableTypescript<T extends TsRuleKey[]>(options: Options<T> = {}) {
70
+ enableTypeScript<T extends TsRuleKey[]>(options: Options<T> = {}) {
75
71
  return this.setup(typescript(), options);
76
72
  }
77
73
 
78
- enableJavascript<T extends JsRuleKey[]>(options: Options<T> = {}) {
74
+ enableJavaScript<T extends JsRuleKey[]>(options: Options<T> = {}) {
79
75
  return this.setup(javascript(), options);
80
76
  }
81
77
 
82
- enablePackagejson<T extends PkgRuleKey[]>(options: Options<T> = {}) {
78
+ enablePackageJson<T extends PkgRuleKey[]>(options: Options<T> = {}) {
83
79
  return this.setup(packagejson(), options);
84
80
  }
81
+
82
+ append(config: ConfigItem) {
83
+ this.configs.push(config);
84
+ return this;
85
+ }
85
86
  }
86
87
 
87
88
  export default new Builder()
88
- .enablePackagejson()
89
- .enableJavascript()
90
- .enableTypescript()
89
+ .enablePackageJson()
90
+ .enableJavaScript()
91
+ .enableTypeScript()
91
92
  .toConfig();