@jsse/eslint-config 0.3.7 → 0.4.1

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 (48) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cli.js +3 -3
  3. package/dist/esm/config-fns.d.ts +114 -34
  4. package/dist/esm/config-fns.js +117 -35
  5. package/dist/esm/configs/{comments.d.ts → de-morgan.d.ts} +1 -1
  6. package/dist/esm/configs/de-morgan.js +9 -0
  7. package/dist/esm/configs/eslint-comments.d.ts +2 -0
  8. package/dist/esm/configs/{comments.js → eslint-comments.js} +1 -1
  9. package/dist/esm/configs/gql.d.ts +2 -2
  10. package/dist/esm/configs/markdown.js +1 -1
  11. package/dist/esm/configs/pnpm.d.ts +2 -0
  12. package/dist/esm/configs/pnpm.js +34 -0
  13. package/dist/esm/configs/prettier.d.ts +2 -2
  14. package/dist/esm/configs/react.d.ts +3 -3
  15. package/dist/esm/configs/stylistic.js +1 -1
  16. package/dist/esm/configs/tailwind.d.ts +1 -2
  17. package/dist/esm/configs/tailwind.js +81 -48
  18. package/dist/esm/configs/ts/parser.d.ts +2 -2
  19. package/dist/esm/configs/ts/parser.js +7 -5
  20. package/dist/esm/configs/ts/typescript-rules.d.ts +9 -4
  21. package/dist/esm/configs/ts/typescript-rules.js +26 -62
  22. package/dist/esm/configs/ts/typescript.js +56 -43
  23. package/dist/esm/define-config.d.ts +3 -3
  24. package/dist/esm/define-config.js +47 -28
  25. package/dist/esm/fixable.d.ts +2 -1
  26. package/dist/esm/fixable.js +3 -395
  27. package/dist/esm/generated/fixable-rules-map.d.ts +2 -0
  28. package/dist/esm/generated/fixable-rules-map.js +443 -0
  29. package/dist/esm/generated/version.d.ts +1 -1
  30. package/dist/esm/generated/version.js +1 -1
  31. package/dist/esm/index.d.ts +1 -1
  32. package/dist/esm/index.js +0 -1
  33. package/dist/esm/lager.d.ts +1 -1
  34. package/dist/esm/lager.js +1 -1
  35. package/dist/esm/plugins-all.d.ts +11 -8
  36. package/dist/esm/plugins-all.js +103 -10
  37. package/dist/esm/plugins.d.ts +2 -6
  38. package/dist/esm/plugins.js +2 -16
  39. package/dist/esm/presets.d.ts +16 -0
  40. package/dist/esm/presets.js +65 -2
  41. package/dist/esm/types.d.ts +47 -22
  42. package/dist/esm/utils.d.ts +5 -5
  43. package/dist/esm/utils.js +1 -1
  44. package/dist/index.d.ts +3907 -2560
  45. package/dist/index.js +275 -751
  46. package/package.json +29 -37
  47. package/dist/esm/plugindex.d.ts +0 -7
  48. package/dist/esm/plugindex.js +0 -60
@@ -1,4 +1,3 @@
1
- import { err, ok } from "neverthrow";
2
1
  /* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/explicit-function-return-type */
3
2
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
3
  // @ts-nocheck
@@ -8,9 +7,11 @@ export { default as pluginEslintComments } from "@eslint-community/eslint-plugin
8
7
  export { default as pluginTs } from "@typescript-eslint/eslint-plugin";
9
8
  export * as parserTs from "@typescript-eslint/parser";
10
9
  export { default as pluginAntfu } from "eslint-plugin-antfu";
10
+ export { default as pluginDeMorgan } from "eslint-plugin-de-morgan";
11
11
  export * as pluginImport from "eslint-plugin-import-x";
12
12
  export { default as pluginN } from "eslint-plugin-n";
13
13
  export { default as pluginPerfectionist } from "eslint-plugin-perfectionist";
14
+ export { default as pluginPnpm } from "eslint-plugin-pnpm";
14
15
  export { default as pluginUnicorn } from "eslint-plugin-unicorn";
15
16
  export { default as pluginUnusedImports } from "eslint-plugin-unused-imports";
16
17
  export async function importPluginUnicorn() {
@@ -94,18 +95,3 @@ export async function importPluginStylistic() {
94
95
  const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
95
96
  return { pluginStylistic };
96
97
  }
97
- export async function importPluginTailwind() {
98
- const pluginTailwind = await interopDefault(
99
- // @ts-expect-error - bad types
100
- import("eslint-plugin-tailwindcss"));
101
- return { pluginTailwind };
102
- }
103
- export async function safeImportPluginTailwind() {
104
- try {
105
- const plugin = await importPluginTailwind();
106
- return ok(plugin);
107
- }
108
- catch (e) {
109
- return err(new Error(`Failed to import \`eslint-plugin-tailwindcss\`. You might need to install it. ${e}`));
110
- }
111
- }
@@ -1,2 +1,18 @@
1
+ import type { Config } from "./types.js";
1
2
  import { type DefineConfig } from "./define-config.js";
2
3
  export declare const jsseReact: DefineConfig;
4
+ /** Ignore common files and include javascript support */
5
+ export declare const presetJavascript: () => Promise<Config[]>;
6
+ /** Includes markdown, yaml + `presetJsonc` support */
7
+ export declare const presetLangsExtensions: () => Promise<Config[]>;
8
+ /** Includes `presetJavaScript` and typescript support */
9
+ export declare const presetBasic: () => Promise<Config[]>;
10
+ /**
11
+ * Includes
12
+ * - `presetBasic` (JS+TS) support
13
+ * - `presetLangsExtensions` (markdown, yaml, jsonc) support
14
+ * - Vue support
15
+ * - UnoCSS support (`uno.config.ts` is required)
16
+ * - Prettier support
17
+ */
18
+ export declare const presetAll: () => Promise<Config[]>;
@@ -1,12 +1,75 @@
1
+ import { command, eslintComments, ignores, imports, javascript, jsdoc, jsonc, markdown, n, sortPackageJson, sortTsconfig, typescript, unicorn, yml, } from "./config-fns.js";
2
+ import { deMorgan } from "./configs/de-morgan.js";
1
3
  import { jsse } from "./define-config.js";
4
+ const makePresetFn = (cfgFunctions) => {
5
+ return async () => {
6
+ const results = await Promise.allSettled(cfgFunctions.map((fn) => fn()));
7
+ const ok = [];
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ const err = [];
10
+ for (const result of results) {
11
+ if (result.status === "fulfilled") {
12
+ ok.push(...result.value);
13
+ }
14
+ else {
15
+ err.push(result.reason);
16
+ }
17
+ }
18
+ if (err.length > 0) {
19
+ const errorMessage = `Some preset functions failed: ${err
20
+ .map((e) => {
21
+ return e instanceof Error ? e.message : JSON.stringify(e);
22
+ })
23
+ .join(", ")}`;
24
+ throw new Error(errorMessage);
25
+ }
26
+ return ok;
27
+ };
28
+ };
2
29
  export const jsseReact = (options, ...configs) => {
3
30
  return jsse({
4
31
  react: true,
5
32
  reactRefresh: true,
6
- tailwind: true,
7
33
  typescript: {
8
34
  tsconfig: ["./tsconfig.json", "./tsconfig.eslint.json"],
9
35
  },
10
36
  ...options,
11
- }, ...configs);
37
+ },
38
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
39
+ ...configs);
12
40
  };
41
+ /** Ignore common files and include javascript support */
42
+ export const presetJavascript = makePresetFn([
43
+ ignores,
44
+ javascript,
45
+ eslintComments,
46
+ imports,
47
+ unicorn,
48
+ n,
49
+ jsdoc,
50
+ deMorgan,
51
+ ]);
52
+ /** Includes basic json(c) file support and sorting json keys */
53
+ const presetJsonc = makePresetFn([
54
+ jsonc,
55
+ sortPackageJson,
56
+ sortTsconfig,
57
+ // ...sortPnpmWorkspace(),
58
+ ]);
59
+ /** Includes markdown, yaml + `presetJsonc` support */
60
+ export const presetLangsExtensions = makePresetFn([markdown, yml, presetJsonc]);
61
+ /** Includes `presetJavaScript` and typescript support */
62
+ export const presetBasic = makePresetFn([presetJavascript, typescript]);
63
+ /**
64
+ * Includes
65
+ * - `presetBasic` (JS+TS) support
66
+ * - `presetLangsExtensions` (markdown, yaml, jsonc) support
67
+ * - Vue support
68
+ * - UnoCSS support (`uno.config.ts` is required)
69
+ * - Prettier support
70
+ */
71
+ export const presetAll = makePresetFn([
72
+ presetBasic,
73
+ presetLangsExtensions,
74
+ command,
75
+ ]);
@@ -1,16 +1,8 @@
1
1
  import type { ParserOptions } from "@typescript-eslint/parser";
2
2
  import type { Linter } from "eslint";
3
3
  import type { FlatGitignoreOptions } from "eslint-config-flat-gitignore";
4
- import type { RuleOptionsUnion as RuleOptions } from "./generated/rule-options.js";
5
- export type Awaitable<T> = T | Promise<T>;
6
- export type UnPromise<T> = T extends Promise<infer U> ? U : T;
7
- export type Rules = RuleOptions;
8
- export type LanguageOptions = Linter.Config["languageOptions"];
9
- export type TypedFlatConfigItem = Omit<Linter.Config<Linter.RulesRecord & Rules>, "plugins"> & {
10
- /**
11
- * Custom name of each config item
12
- */
13
- name?: string;
4
+ import type { RuleOptionsUnion as Rules } from "./generated/rule-options.js";
5
+ export type Config = Omit<Linter.Config<Linter.RulesRecord & Rules>, "plugins"> & {
14
6
  /**
15
7
  * An object containing a name-value mapping of plugin names to plugin objects. When `files` is specified, these plugins are only available to the matching files.
16
8
  *
@@ -18,8 +10,11 @@ export type TypedFlatConfigItem = Omit<Linter.Config<Linter.RulesRecord & Rules>
18
10
  */
19
11
  plugins?: Record<string, any>;
20
12
  };
13
+ export type Awaitable<T> = T | Promise<T>;
14
+ export type UnPromise<T> = T extends Promise<infer U> ? U : T;
15
+ export type LanguageOptions = Linter.Config["languageOptions"];
21
16
  export type RuleName = keyof Rules;
22
- export type TypedFlatConfigItemWithId = TypedFlatConfigItem & {
17
+ export type TypedFlatConfigItemWithId = Config & {
23
18
  name: string;
24
19
  };
25
20
  export type OptionsCommon = {
@@ -46,8 +41,7 @@ export type OptionsComponentExts = {
46
41
  */
47
42
  componentExts?: string[];
48
43
  };
49
- export type PromiseFlatConfigItem = Promise<TypedFlatConfigItemWithId[]>;
50
- export type EslintConfigFn<T = undefined> = (options?: T) => PromiseFlatConfigItem;
44
+ export type EslintConfigFn<T = undefined> = (options?: T) => Promise<Config[]>;
51
45
  export type OptionsFiles = {
52
46
  /**
53
47
  * Override the `files` option to provide custom globs.
@@ -83,6 +77,18 @@ export type OptionsTypeScriptWithTypes = {
83
77
  * @see https://typescript-eslint.io/linting/typed-linting/
84
78
  */
85
79
  tsconfig?: string | string[];
80
+ /**
81
+ * Override type aware rules.
82
+ */
83
+ overridesTypeAware?: Config["rules"];
84
+ /**
85
+ * strict vs recommended configs
86
+ * @default false
87
+ */
88
+ strict?: boolean;
89
+ /**
90
+ * typeAware
91
+ */
86
92
  typeAware?: boolean;
87
93
  };
88
94
  export type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
@@ -104,7 +110,7 @@ export type OptionsPrefix = {
104
110
  };
105
111
  };
106
112
  export type OptionsOverrides = {
107
- overrides?: TypedFlatConfigItem["rules"];
113
+ overrides?: Config["rules"];
108
114
  };
109
115
  export type OptionsIsInEditor = {
110
116
  isInEditor?: boolean;
@@ -167,6 +173,19 @@ export type OptionsConfig = {
167
173
  * PLUGIN!.
168
174
  */
169
175
  prettier?: boolean;
176
+ /**
177
+ * Enable eslint-plugin-pnpm.
178
+ *
179
+ * @default false
180
+ */
181
+ pnpm?: boolean;
182
+ /**
183
+ * Enable Tailwind CSS support.
184
+ *
185
+ * Passing an object to configure the options.
186
+ *
187
+ * @default true
188
+ */
170
189
  tailwind?: TailwindOptions;
171
190
  /**
172
191
  * The prefix for the name of the config item.
@@ -176,7 +195,7 @@ export type OptionsConfig = {
176
195
  /**
177
196
  * Optional function to run before the final config is returned.
178
197
  */
179
- preReturn?: (configs: TypedFlatConfigItem[]) => TypedFlatConfigItem[] | Awaitable<TypedFlatConfigItem[]>;
198
+ preReturn?: (configs: Config[]) => Config[] | Awaitable<Config[]>;
180
199
  /**
181
200
  * Enable gitignore support.
182
201
  *
@@ -189,9 +208,11 @@ export type OptionsConfig = {
189
208
  tsPrefix?: string;
190
209
  /**
191
210
  * Glob patterns for ADDITIONAL tsconfig files to lint (aka sort)
211
+ *
212
+ * Has nothing to do with `@typescript-eslint/parser` or `typescript-eslint/eslint-plugin`
213
+ * @default ['tsconfig.json', 'tsconfig.*.json']
192
214
  */
193
215
  extendTsconfigLintGlobs?: string[];
194
- typeAware?: boolean;
195
216
  /**
196
217
  * Enable TypeScript support.
197
218
  *
@@ -200,6 +221,10 @@ export type OptionsConfig = {
200
221
  * @default auto-detect based on the dependencies
201
222
  */
202
223
  typescript?: boolean | OptionsTypeScriptWithTypes;
224
+ /**
225
+ * Forcibly disable type aware rules
226
+ */
227
+ typeAware?: boolean;
203
228
  react?: boolean;
204
229
  reactRefresh?: boolean;
205
230
  /**
@@ -249,12 +274,12 @@ export type OptionsConfig = {
249
274
  * Provide overrides for rules for each integration.
250
275
  */
251
276
  overrides?: {
252
- javascript?: TypedFlatConfigItem["rules"];
253
- typescript?: TypedFlatConfigItem["rules"];
254
- test?: TypedFlatConfigItem["rules"];
255
- jsonc?: TypedFlatConfigItem["rules"];
256
- markdown?: TypedFlatConfigItem["rules"];
257
- yaml?: TypedFlatConfigItem["rules"];
277
+ javascript?: Config["rules"];
278
+ typescript?: Config["rules"];
279
+ test?: Config["rules"];
280
+ jsonc?: Config["rules"];
281
+ markdown?: Config["rules"];
282
+ yaml?: Config["rules"];
258
283
  };
259
284
  } & OptionsComponentExts & OptionsTypeScriptParserOptions;
260
285
  export type RenamePefix<T extends Record<string, unknown>, FromPref extends string, ToPref extends string> = {
@@ -1,9 +1,9 @@
1
1
  import type { Linter } from "eslint";
2
- import type { Awaitable, TypedFlatConfigItem } from "./types.js";
2
+ import type { Awaitable, Config } from "./types.js";
3
3
  /**
4
4
  * Combine array and non-array configs into a single array.
5
5
  */
6
- export declare function combine(...configs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]): Promise<TypedFlatConfigItem[]>;
6
+ export declare function combine(...configs: Awaitable<Config | Config[]>[]): Promise<Config[]>;
7
7
  /**
8
8
  * Combine array and non-array configs into a single array.
9
9
  */
@@ -45,7 +45,7 @@ export declare const parserPlain: {
45
45
  };
46
46
  };
47
47
  };
48
- export declare function turnOffRules(configs: TypedFlatConfigItem[], off: string[]): TypedFlatConfigItem[];
48
+ export declare function turnOffRules(configs: Config[], off: string[]): Config[];
49
49
  export declare function changeRuleEntrySeverity(ruleConfig: Linter.RuleEntry<any>, level: Linter.RuleSeverity): Linter.RuleEntry<any>;
50
- export declare function error2warn<T extends TypedFlatConfigItem>(configs: T[]): T[];
51
- export declare function warn2error<T extends TypedFlatConfigItem>(configs: T[]): T[];
50
+ export declare function error2warn<T extends Config>(configs: T[]): T[];
51
+ export declare function warn2error<T extends Config>(configs: T[]): T[];
package/dist/esm/utils.js CHANGED
@@ -76,7 +76,7 @@ export const parserPlain = {
76
76
  }),
77
77
  };
78
78
  export function turnOffRules(configs, off) {
79
- if (off && off.length > 0) {
79
+ if (off.length > 0) {
80
80
  // turrning off rules
81
81
  // duplicate off rules
82
82
  for (const rule of off) {