@so1ve/eslint-config 1.0.0-alpha.13 → 1.0.0-alpha.15

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.
package/dist/index.cjs CHANGED
@@ -360,9 +360,7 @@ const html = () => [
360
360
  }
361
361
  ];
362
362
 
363
- const ignores = () => [
364
- { ignores: GLOB_EXCLUDE }
365
- ];
363
+ const ignores = () => [{ ignores: GLOB_EXCLUDE }];
366
364
 
367
365
  const imports = (options = {}) => [
368
366
  {
@@ -883,9 +881,7 @@ const sortImports = () => [
883
881
  }
884
882
  ];
885
883
 
886
- const test = ({
887
- overrides
888
- } = {}) => [
884
+ const test = ({ overrides } = {}) => [
889
885
  {
890
886
  plugins: {
891
887
  "no-only-tests": pluginNoOnlyTests__default["default"],
@@ -919,9 +915,7 @@ const test = ({
919
915
  }
920
916
  ];
921
917
 
922
- const toml = ({
923
- overrides
924
- } = {}) => [
918
+ const toml = ({ overrides } = {}) => [
925
919
  {
926
920
  plugins: {
927
921
  toml: pluginToml__default["default"]
@@ -985,7 +979,8 @@ function warnUnnecessaryOffRules() {
985
979
  function typescript({
986
980
  componentExts = [],
987
981
  parserOptions,
988
- overrides
982
+ overrides,
983
+ tsconfigPath
989
984
  } = {}) {
990
985
  const typeAwareRules = {
991
986
  "etc/no-assign-mutated-array": "error",
@@ -1038,7 +1033,13 @@ function typescript({
1038
1033
  parserOptions: {
1039
1034
  sourceType: "module",
1040
1035
  extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1041
- EXPERIMENTAL_useProjectService: true,
1036
+ // Disable this because it doesn't work well with vue
1037
+ // EXPERIMENTAL_useProjectService: true,
1038
+ ...tsconfigPath ? {
1039
+ project: [tsconfigPath],
1040
+ tsconfigRootDir: process.cwd()
1041
+ } : {},
1042
+ // eslint-disable-next-line ts/no-unnecessary-type-assertion
1042
1043
  ...parserOptions
1043
1044
  }
1044
1045
  },
@@ -1131,7 +1132,15 @@ function typescript({
1131
1132
  "ts/prefer-ts-expect-error": "error",
1132
1133
  "ts/no-require-imports": "error",
1133
1134
  "ts/method-signature-style": ["error", "property"],
1134
- "ts/explicit-member-accessibility": "error",
1135
+ "ts/explicit-member-accessibility": [
1136
+ "error",
1137
+ {
1138
+ accessibility: "explicit",
1139
+ overrides: {
1140
+ constructors: "no-public"
1141
+ }
1142
+ }
1143
+ ],
1135
1144
  // Override JS
1136
1145
  "no-useless-constructor": "off",
1137
1146
  "no-invalid-this": "off",
@@ -1175,7 +1184,7 @@ function typescript({
1175
1184
  "ts/no-non-null-asserted-nullish-coalescing": "error",
1176
1185
  // handled by unused-imports/no-unused-imports
1177
1186
  "ts/no-unused-vars": "off",
1178
- ...typeAwareRules,
1187
+ ...tsconfigPath ? typeAwareRules : {},
1179
1188
  ...overrides
1180
1189
  }
1181
1190
  },
@@ -1457,9 +1466,7 @@ const vue = ({
1457
1466
  }
1458
1467
  ];
1459
1468
 
1460
- const yaml = ({
1461
- overrides
1462
- } = {}) => [
1469
+ const yaml = ({ overrides } = {}) => [
1463
1470
  {
1464
1471
  plugins: {
1465
1472
  yaml: pluginYaml__default["default"]
@@ -1494,11 +1501,11 @@ function so1ve(options = {}, ...userConfigs) {
1494
1501
  const {
1495
1502
  vue: enableVue = VuePackages.some((i) => localPkg.isPackageExists(i)),
1496
1503
  solid: enableSolid = localPkg.isPackageExists("solid-js"),
1497
- typescript: enableTypeScript = localPkg.isPackageExists("typescript"),
1498
1504
  gitignore: enableGitignore = true,
1499
1505
  overrides = {},
1500
1506
  componentExts = []
1501
1507
  } = options;
1508
+ let { typescript: enableTypeScript = localPkg.isPackageExists("typescript") } = options;
1502
1509
  const configs = [];
1503
1510
  if (enableGitignore) {
1504
1511
  if (typeof enableGitignore === "boolean") {
@@ -1526,10 +1533,16 @@ function so1ve(options = {}, ...userConfigs) {
1526
1533
  componentExts.push("vue");
1527
1534
  }
1528
1535
  if (enableTypeScript) {
1536
+ if (typeof enableTypeScript !== "object") {
1537
+ enableTypeScript = {
1538
+ tsconfigPath: "tsconfig.json"
1539
+ };
1540
+ }
1529
1541
  configs.push(
1530
1542
  typescript({
1531
1543
  componentExts,
1532
- overrides: overrides.typescript
1544
+ overrides: overrides.typescript,
1545
+ ...enableTypeScript
1533
1546
  })
1534
1547
  );
1535
1548
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { FlatESLintConfigItem } from 'eslint-define-config';
1
+ import so1vePlugin from '@so1ve/eslint-plugin';
2
+ export { default as pluginSo1ve } from '@so1ve/eslint-plugin';
2
3
  import { ParserOptions } from '@typescript-eslint/parser';
3
4
  export { default as parserTs } from '@typescript-eslint/parser';
4
5
  import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
6
+ import { Rules, FlatESLintConfigItem } from 'eslint-define-config';
5
7
  export { default as pluginComments } from '@eslint-community/eslint-plugin-eslint-comments';
6
8
  export { default as pluginHtml } from '@html-eslint/eslint-plugin';
7
9
  export { default as parserHtml } from '@html-eslint/parser';
8
- export { default as pluginSo1ve } from '@so1ve/eslint-plugin';
9
10
  export { default as pluginSortImports } from '@so1ve/eslint-plugin-sort-imports';
10
11
  export { default as pluginTs } from '@typescript-eslint/eslint-plugin';
11
12
  export { default as parserMdx } from 'eslint-mdx';
@@ -34,21 +35,25 @@ export { default as parserToml } from 'toml-eslint-parser';
34
35
  export { default as parserVue } from 'vue-eslint-parser';
35
36
  export { default as parserYaml } from 'yaml-eslint-parser';
36
37
 
37
- declare const comments: () => FlatESLintConfigItem[];
38
-
39
38
  interface OptionsComponentExts {
40
39
  /** Additional extensions for components. */
41
40
  componentExts?: string[];
42
41
  }
43
- interface OptionsTypeScriptParserOptions {
42
+ interface OptionsTypeScript {
44
43
  /** Additional parser options for TypeScript. */
45
44
  parserOptions?: Partial<ParserOptions>;
45
+ /**
46
+ * Path to `tsconfig.json`.
47
+ *
48
+ * @default "tsconfig.json"
49
+ */
50
+ tsconfigPath?: string;
46
51
  }
47
52
  interface OptionsHasTypeScript {
48
53
  typescript?: boolean;
49
54
  }
50
55
  interface OptionsOverrides {
51
- overrides?: FlatESLintConfigItem["rules"];
56
+ overrides?: ConfigItem["rules"];
52
57
  }
53
58
  interface Options extends OptionsComponentExts {
54
59
  /**
@@ -67,7 +72,7 @@ interface Options extends OptionsComponentExts {
67
72
  *
68
73
  * @default auto-detect based on the dependencies
69
74
  */
70
- typescript?: boolean;
75
+ typescript?: boolean | OptionsTypeScript;
71
76
  /**
72
77
  * Enable test support.
73
78
  *
@@ -118,56 +123,73 @@ interface Options extends OptionsComponentExts {
118
123
  formatting?: boolean;
119
124
  /** Provide overrides for rules for each integration. */
120
125
  overrides?: {
121
- javascript?: FlatESLintConfigItem["rules"];
122
- typescript?: FlatESLintConfigItem["rules"];
123
- test?: FlatESLintConfigItem["rules"];
124
- vue?: FlatESLintConfigItem["rules"];
125
- solid?: FlatESLintConfigItem["rules"];
126
- jsonc?: FlatESLintConfigItem["rules"];
127
- mdx?: FlatESLintConfigItem["rules"];
128
- yaml?: FlatESLintConfigItem["rules"];
129
- toml?: FlatESLintConfigItem["rules"];
126
+ javascript?: ConfigItem["rules"];
127
+ typescript?: ConfigItem["rules"];
128
+ test?: ConfigItem["rules"];
129
+ vue?: ConfigItem["rules"];
130
+ solid?: ConfigItem["rules"];
131
+ jsonc?: ConfigItem["rules"];
132
+ mdx?: ConfigItem["rules"];
133
+ yaml?: ConfigItem["rules"];
134
+ toml?: ConfigItem["rules"];
130
135
  };
131
136
  }
137
+ type Unprefix<T extends Record<string, any>, Pre extends string> = {
138
+ [K in keyof T as K extends `${Pre}${infer U}` ? U : never]: T[K];
139
+ };
140
+ type Prefix<T extends Record<string, any>, Pre extends string> = {
141
+ [K in keyof T as `${Pre}${K & string}`]: T[K];
142
+ };
143
+ type RenamePrefix<T extends Record<string, any>, Old extends string, New extends string> = Prefix<Unprefix<T, Old>, New>;
144
+ type MergeIntersection<T extends Record<any, any>> = {
145
+ [K in keyof T]: T[K];
146
+ };
147
+ type RenamedRules = MergeIntersection<Rules & RenamePrefix<Rules, "@typescript-eslint/", "ts/"> & RenamePrefix<Rules, "yml/", "yaml/"> & RenamePrefix<Rules, "n/", "node/"> & Prefix<Partial<(typeof so1vePlugin)["rules"]>, "so1ve/">>;
148
+ type ConfigItem = Omit<FlatESLintConfigItem, "plugins" | "rules"> & {
149
+ plugins?: Record<string, any>;
150
+ rules?: RenamedRules | Record<string, any>;
151
+ };
152
+
153
+ declare const comments: () => ConfigItem[];
132
154
 
133
- declare const formatting: (options: Options) => FlatESLintConfigItem[];
155
+ declare const formatting: (options: Options) => ConfigItem[];
134
156
 
135
- declare const html: () => FlatESLintConfigItem[];
157
+ declare const html: () => ConfigItem[];
136
158
 
137
- declare const ignores: () => FlatESLintConfigItem[];
159
+ declare const ignores: () => ConfigItem[];
138
160
 
139
- declare const imports: (options?: Options) => FlatESLintConfigItem[];
161
+ declare const imports: (options?: Options) => ConfigItem[];
140
162
 
141
- declare const javascript: ({ overrides, }?: OptionsOverrides) => FlatESLintConfigItem[];
163
+ declare const javascript: ({ overrides, }?: OptionsOverrides) => ConfigItem[];
142
164
 
143
- declare const jsonc: () => FlatESLintConfigItem[];
165
+ declare const jsonc: () => ConfigItem[];
144
166
 
145
- declare const mdx: ({ componentExts, overrides, }?: OptionsComponentExts & OptionsOverrides) => FlatESLintConfigItem[];
167
+ declare const mdx: ({ componentExts, overrides, }?: OptionsComponentExts & OptionsOverrides) => ConfigItem[];
146
168
 
147
- declare const node: () => FlatESLintConfigItem[];
169
+ declare const node: () => ConfigItem[];
148
170
 
149
- declare const onlyError: () => FlatESLintConfigItem[];
171
+ declare const onlyError: () => ConfigItem[];
150
172
 
151
- declare const promise: () => FlatESLintConfigItem[];
173
+ declare const promise: () => ConfigItem[];
152
174
 
153
- declare const solid: ({ overrides, typescript, }?: OptionsHasTypeScript & OptionsOverrides) => FlatESLintConfigItem[];
175
+ declare const solid: ({ overrides, typescript, }?: OptionsHasTypeScript & OptionsOverrides) => ConfigItem[];
154
176
 
155
- declare const sortImports: () => FlatESLintConfigItem[];
177
+ declare const sortImports: () => ConfigItem[];
156
178
 
157
- declare const test: ({ overrides, }?: OptionsOverrides) => FlatESLintConfigItem[];
179
+ declare const test: ({ overrides }?: OptionsOverrides) => ConfigItem[];
158
180
 
159
- declare const toml: ({ overrides, }?: OptionsOverrides) => FlatESLintConfigItem[];
181
+ declare const toml: ({ overrides }?: OptionsOverrides) => ConfigItem[];
160
182
 
161
- declare function typescript({ componentExts, parserOptions, overrides, }?: OptionsTypeScriptParserOptions & OptionsComponentExts & OptionsOverrides): FlatESLintConfigItem[];
183
+ declare function typescript({ componentExts, parserOptions, overrides, tsconfigPath, }?: OptionsTypeScript & OptionsComponentExts & OptionsOverrides): ConfigItem[];
162
184
 
163
- declare const unicorn: () => FlatESLintConfigItem[];
185
+ declare const unicorn: () => ConfigItem[];
164
186
 
165
- declare const vue: ({ overrides, typescript, }?: OptionsHasTypeScript & OptionsOverrides) => FlatESLintConfigItem[];
187
+ declare const vue: ({ overrides, typescript, }?: OptionsHasTypeScript & OptionsOverrides) => ConfigItem[];
166
188
 
167
- declare const yaml: ({ overrides, }?: OptionsOverrides) => FlatESLintConfigItem[];
189
+ declare const yaml: ({ overrides }?: OptionsOverrides) => ConfigItem[];
168
190
 
169
191
  /** Construct an array of ESLint flat config items. */
170
- declare function so1ve(options?: Options, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
192
+ declare function so1ve(options?: Options, ...userConfigs: (ConfigItem | ConfigItem[])[]): ConfigItem[];
171
193
 
172
194
  declare const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
173
195
  declare const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
@@ -197,12 +219,12 @@ declare const GLOB_ALL_SRC: string[];
197
219
  declare const GLOB_EXCLUDE: string[];
198
220
 
199
221
  /** Combine array and non-array configs into a single array. */
200
- declare const combine: (...configs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]) => FlatESLintConfigItem[];
222
+ declare const combine: (...configs: (ConfigItem | ConfigItem[])[]) => ConfigItem[];
201
223
  declare const renameRules: (rules: Record<string, any>, from: string, to: string) => {
202
224
  [k: string]: any;
203
225
  };
204
- declare function recordRulesStateConfigs(configs: FlatESLintConfigItem[]): FlatESLintConfigItem[];
205
- declare function recordRulesState(rules: FlatESLintConfigItem["rules"]): FlatESLintConfigItem["rules"];
226
+ declare function recordRulesStateConfigs(configs: ConfigItem[]): ConfigItem[];
227
+ declare function recordRulesState(rules: ConfigItem["rules"]): ConfigItem["rules"];
206
228
  declare function warnUnnecessaryOffRules(): void;
207
229
 
208
- export { GLOB_ALL_SRC, GLOB_CSS, GLOB_DTS, GLOB_ESLINTRC, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_PACKAGEJSON, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSCONFIG, GLOB_TSX, GLOB_VUE, GLOB_YAML, Options, OptionsComponentExts, OptionsHasTypeScript, OptionsOverrides, OptionsTypeScriptParserOptions, combine, comments, formatting, html, ignores, imports, javascript, jsonc, mdx, node, onlyError, promise, recordRulesState, recordRulesStateConfigs, renameRules, so1ve, solid, sortImports, test, toml, typescript, unicorn, vue, warnUnnecessaryOffRules, yaml };
230
+ export { ConfigItem, GLOB_ALL_SRC, GLOB_CSS, GLOB_DTS, GLOB_ESLINTRC, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_PACKAGEJSON, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSCONFIG, GLOB_TSX, GLOB_VUE, GLOB_YAML, Options, OptionsComponentExts, OptionsHasTypeScript, OptionsOverrides, OptionsTypeScript, RenamedRules, combine, comments, formatting, html, ignores, imports, javascript, jsonc, mdx, node, onlyError, promise, recordRulesState, recordRulesStateConfigs, renameRules, so1ve, solid, sortImports, test, toml, typescript, unicorn, vue, warnUnnecessaryOffRules, yaml };
package/dist/index.mjs CHANGED
@@ -349,9 +349,7 @@ const html = () => [
349
349
  }
350
350
  ];
351
351
 
352
- const ignores = () => [
353
- { ignores: GLOB_EXCLUDE }
354
- ];
352
+ const ignores = () => [{ ignores: GLOB_EXCLUDE }];
355
353
 
356
354
  const imports = (options = {}) => [
357
355
  {
@@ -872,9 +870,7 @@ const sortImports = () => [
872
870
  }
873
871
  ];
874
872
 
875
- const test = ({
876
- overrides
877
- } = {}) => [
873
+ const test = ({ overrides } = {}) => [
878
874
  {
879
875
  plugins: {
880
876
  "no-only-tests": pluginNoOnlyTests,
@@ -908,9 +904,7 @@ const test = ({
908
904
  }
909
905
  ];
910
906
 
911
- const toml = ({
912
- overrides
913
- } = {}) => [
907
+ const toml = ({ overrides } = {}) => [
914
908
  {
915
909
  plugins: {
916
910
  toml: pluginToml
@@ -974,7 +968,8 @@ function warnUnnecessaryOffRules() {
974
968
  function typescript({
975
969
  componentExts = [],
976
970
  parserOptions,
977
- overrides
971
+ overrides,
972
+ tsconfigPath
978
973
  } = {}) {
979
974
  const typeAwareRules = {
980
975
  "etc/no-assign-mutated-array": "error",
@@ -1027,7 +1022,13 @@ function typescript({
1027
1022
  parserOptions: {
1028
1023
  sourceType: "module",
1029
1024
  extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1030
- EXPERIMENTAL_useProjectService: true,
1025
+ // Disable this because it doesn't work well with vue
1026
+ // EXPERIMENTAL_useProjectService: true,
1027
+ ...tsconfigPath ? {
1028
+ project: [tsconfigPath],
1029
+ tsconfigRootDir: process.cwd()
1030
+ } : {},
1031
+ // eslint-disable-next-line ts/no-unnecessary-type-assertion
1031
1032
  ...parserOptions
1032
1033
  }
1033
1034
  },
@@ -1120,7 +1121,15 @@ function typescript({
1120
1121
  "ts/prefer-ts-expect-error": "error",
1121
1122
  "ts/no-require-imports": "error",
1122
1123
  "ts/method-signature-style": ["error", "property"],
1123
- "ts/explicit-member-accessibility": "error",
1124
+ "ts/explicit-member-accessibility": [
1125
+ "error",
1126
+ {
1127
+ accessibility: "explicit",
1128
+ overrides: {
1129
+ constructors: "no-public"
1130
+ }
1131
+ }
1132
+ ],
1124
1133
  // Override JS
1125
1134
  "no-useless-constructor": "off",
1126
1135
  "no-invalid-this": "off",
@@ -1164,7 +1173,7 @@ function typescript({
1164
1173
  "ts/no-non-null-asserted-nullish-coalescing": "error",
1165
1174
  // handled by unused-imports/no-unused-imports
1166
1175
  "ts/no-unused-vars": "off",
1167
- ...typeAwareRules,
1176
+ ...tsconfigPath ? typeAwareRules : {},
1168
1177
  ...overrides
1169
1178
  }
1170
1179
  },
@@ -1446,9 +1455,7 @@ const vue = ({
1446
1455
  }
1447
1456
  ];
1448
1457
 
1449
- const yaml = ({
1450
- overrides
1451
- } = {}) => [
1458
+ const yaml = ({ overrides } = {}) => [
1452
1459
  {
1453
1460
  plugins: {
1454
1461
  yaml: pluginYaml
@@ -1483,11 +1490,11 @@ function so1ve(options = {}, ...userConfigs) {
1483
1490
  const {
1484
1491
  vue: enableVue = VuePackages.some((i) => isPackageExists(i)),
1485
1492
  solid: enableSolid = isPackageExists("solid-js"),
1486
- typescript: enableTypeScript = isPackageExists("typescript"),
1487
1493
  gitignore: enableGitignore = true,
1488
1494
  overrides = {},
1489
1495
  componentExts = []
1490
1496
  } = options;
1497
+ let { typescript: enableTypeScript = isPackageExists("typescript") } = options;
1491
1498
  const configs = [];
1492
1499
  if (enableGitignore) {
1493
1500
  if (typeof enableGitignore === "boolean") {
@@ -1515,10 +1522,16 @@ function so1ve(options = {}, ...userConfigs) {
1515
1522
  componentExts.push("vue");
1516
1523
  }
1517
1524
  if (enableTypeScript) {
1525
+ if (typeof enableTypeScript !== "object") {
1526
+ enableTypeScript = {
1527
+ tsconfigPath: "tsconfig.json"
1528
+ };
1529
+ }
1518
1530
  configs.push(
1519
1531
  typescript({
1520
1532
  componentExts,
1521
- overrides: overrides.typescript
1533
+ overrides: overrides.typescript,
1534
+ ...enableTypeScript
1522
1535
  })
1523
1536
  );
1524
1537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-config",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve/)",
5
5
  "description": "Ray's eslint config.",
6
6
  "keywords": [
@@ -70,8 +70,8 @@
70
70
  "toml-eslint-parser": "^0.6.0",
71
71
  "vue-eslint-parser": "^9.3.1",
72
72
  "yaml-eslint-parser": "^1.2.2",
73
- "@so1ve/eslint-plugin": "1.0.0-alpha.13",
74
- "@so1ve/eslint-plugin-sort-imports": "1.0.0-alpha.13"
73
+ "@so1ve/eslint-plugin": "1.0.0-alpha.15",
74
+ "@so1ve/eslint-plugin-sort-imports": "1.0.0-alpha.15"
75
75
  },
76
76
  "devDependencies": {
77
77
  "eslint": "^8.46.0"