@w5s/eslint-config 3.36.0 → 4.0.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.
package/src/config/yml.ts CHANGED
@@ -3,19 +3,20 @@ import { interopDefault } from '@w5s/dev';
3
3
  import type { RuleOptions } from '../typegen/yml.js';
4
4
 
5
5
  import { ymlSourceGlob } from '../glob.js';
6
+ import { defaultPluginOptions } from '../internal/defaultOptions.js';
6
7
  import { withDefaultFiles } from '../internal/withDefaultFiles.js';
7
- import { type Config, type PluginOptionsBase, StylisticConfig } from '../type.js';
8
+ import { type Config, type PluginOptionsBase } from '../type.js';
8
9
 
9
10
  const defaultFiles = [ymlSourceGlob];
10
11
 
11
12
  export async function yml(options: yml.Options = {}) {
12
13
  const [ymlPlugin] = await Promise.all([interopDefault(import('eslint-plugin-yml'))] as const);
13
- const { files, recommended = true, rules = {}, stylistic = true } = options;
14
- const { enabled: stylisticEnabled, indent, quotes } = StylisticConfig.from(stylistic);
14
+ const { files, namespace, recommended, rules = {}, stylistic } = defaultPluginOptions(options);
15
+ const { enabled: stylisticEnabled, indent, quotes } = stylistic;
15
16
 
16
17
  return [
17
18
  {
18
- name: 'w5s/yml/setup',
19
+ name: `${namespace}/yml/setup`,
19
20
  plugins: {
20
21
  yml: ymlPlugin,
21
22
  },
@@ -23,7 +24,7 @@ export async function yml(options: yml.Options = {}) {
23
24
  {
24
25
  files: withDefaultFiles(files, defaultFiles),
25
26
  language: 'yml/yaml',
26
- name: 'w5s/yml/rules',
27
+ name: `${namespace}/yml/rules`,
27
28
  rules: {
28
29
  ...(recommended
29
30
  ? ymlPlugin.configs.recommended.reduce(
@@ -7,10 +7,18 @@ import type { Config } from './type.js';
7
7
  import * as config from './config.js';
8
8
 
9
9
  export interface DefineConfigOptions extends config.ignores.Options {
10
+ /**
11
+ * Additional override config entries appended last.
12
+ *
13
+ * Overrides are always applied at the end of the final config array so they
14
+ * win over the base preset and any todo layers.
15
+ */
16
+ overrides?: Array<Config> | undefined;
17
+
10
18
  /**
11
19
  * Plugins configuration
12
20
  */
13
- plugins?: {
21
+ plugins?: undefined | {
14
22
  'e18e'?: boolean | config.e18e.Options | undefined;
15
23
  'es'?: boolean | config.es.Options | undefined;
16
24
  'import'?: boolean | config.imports.Options | undefined;
@@ -33,11 +41,18 @@ export interface DefineConfigOptions extends config.ignores.Options {
33
41
  /**
34
42
  * Override rules
35
43
  */
36
- rules?: eslint.Linter.RulesRecord;
44
+ rules?: eslint.Linter.RulesRecord | undefined;
45
+
46
+ /**
47
+ * Additional config entries appended after the base configuration.
48
+ *
49
+ * They are meant to be temporary rules overrides that need a fix
50
+ */
51
+ todo?: Array<Config> | undefined;
37
52
  }
38
53
 
39
54
  export async function defineConfig(options: DefineConfigOptions = {}): Promise<Array<Config>> {
40
- const { plugins = {}, rules } = options;
55
+ const { overrides = [], plugins = {}, rules, todo = [] } = options;
41
56
  const stylisticOptions =
42
57
  typeof plugins.stylistic === 'boolean' ? { enabled: plugins.stylistic } : { enabled: true, ...plugins.stylistic };
43
58
  const withDefaultStylistic = <T>(_options: T) => ({ stylistic: stylisticOptions, ..._options });
@@ -66,6 +81,7 @@ export async function defineConfig(options: DefineConfigOptions = {}): Promise<A
66
81
  ...includeEnabled(config.e18e, toOption(plugins.e18e)),
67
82
  ...includeEnabled(config.jsx, toOption(plugins.jsx)),
68
83
  ...includeEnabled(config.unusedImports, toOption(plugins['unused-imports'])),
84
+ ...includeEnabled(config.jsdoc, toOption(plugins.jsdoc)),
69
85
  ...includeEnabled(config.imports, toOption(plugins.import)),
70
86
  ...includeEnabled(config.perfectionist, toOption(plugins.perfectionist)),
71
87
  ...includeEnabled(config.node, toOption(plugins.node)),
@@ -78,9 +94,10 @@ export async function defineConfig(options: DefineConfigOptions = {}): Promise<A
78
94
 
79
95
  // other languages
80
96
  ...includeEnabled(config.jsonc, toOption(plugins.jsonc)),
81
- ...includeEnabled(config.jsdoc, toOption(plugins.jsdoc)),
82
97
  ...includeEnabled(config.markdown, toOption(plugins.markdown)),
83
98
  ...includeEnabled(config.yml, toOption(plugins.yml)),
84
99
  ...(rules ? [{ rules }] : []),
100
+ ...todo,
101
+ ...overrides,
85
102
  );
86
103
  }
package/src/glob.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Project } from '@w5s/dev';
2
2
 
3
- export const sourceGlob = `**/${Project.extensionsToGlob(Project.sourceExtensions())}`;
3
+ export const sourceGlob = Project.glob({ fileExtensions: [Project.sourceExtensions()], nested: true });
4
4
 
5
- export const esSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['javascript', 'javascriptreact']))}`;
5
+ export const esSourceGlob = Project.glob({ fileExtensions: [Project.queryExtensions(['javascript', 'javascriptreact'])], nested: true });
6
6
 
7
- export const jsxSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['javascriptreact', 'typescriptreact']))}`;
7
+ export const jsxSourceGlob = Project.glob({ fileExtensions: [Project.queryExtensions(['javascriptreact', 'typescriptreact'])], nested: true });
8
8
 
9
- export const jsonSourceGlob = `**/${Project.extensionsToGlob(['.json', '.json5', '.jsonc'])}`;
9
+ export const jsonSourceGlob = Project.glob({ fileExtensions: [['.json', '.json5', '.jsonc']], nested: true });
10
10
 
11
- export const tsSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['typescript', 'typescriptreact']))}`;
11
+ export const tsSourceGlob = Project.glob({ fileExtensions: [Project.queryExtensions(['typescript', 'typescriptreact'])], nested: true });
12
12
 
13
- export const ymlSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['yaml']))}`;
13
+ export const ymlSourceGlob = Project.glob({ fileExtensions: [Project.queryExtensions(['yaml'])], nested: true });
@@ -0,0 +1,19 @@
1
+ import { type PluginOptionsBase, StylisticConfig } from '../type.js';
2
+
3
+ /**
4
+ * Return a new plugin option object with default values
5
+ *
6
+ * @param options
7
+ */
8
+ export function defaultPluginOptions<T extends PluginOptionsBase<any>>(options: T): Omit<T, 'namespace' | 'recommended' | 'stylistic'> & {
9
+ namespace: Exclude<PluginOptionsBase<any>['namespace'], undefined>;
10
+ recommended: Exclude<PluginOptionsBase<any>['recommended'], undefined>;
11
+ stylistic: StylisticConfig;
12
+ } {
13
+ return {
14
+ ...options,
15
+ namespace: options.namespace ?? 'w5s',
16
+ recommended: options.recommended ?? true,
17
+ stylistic: StylisticConfig.from(options.stylistic ?? true),
18
+ };
19
+ }
@@ -8,6 +8,14 @@ export interface PluginOptionsBase<Rules> {
8
8
  */
9
9
  files?: ((currentFiles: Array<string>) => Array<string>) | Linter.Config['files'];
10
10
 
11
+ /**
12
+ * Namespace of configurations.
13
+ * Useful for tier configuration and rebranding
14
+ *
15
+ * @default 'w5s'
16
+ */
17
+ namespace?: string | undefined;
18
+
11
19
  /**
12
20
  * Include recommended settings
13
21
  */
@@ -363,6 +363,11 @@ export interface RuleOptions {
363
363
  * @see https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/text-escaping.md#repos-sticky-header
364
364
  */
365
365
  'jsdoc/text-escaping'?: Linter.RuleEntry<JsdocTextEscaping>
366
+ /**
367
+ * Disallows (or requires descriptions for) `@ts-<directive>` comments, mirroring `@typescript-eslint/ban-ts-comment`.
368
+ * @see https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/ts-ban-ts-comment.md#repos-sticky-header
369
+ */
370
+ 'jsdoc/ts-ban-ts-comment'?: Linter.RuleEntry<JsdocTsBanTsComment>
366
371
  /**
367
372
  * Prefers either function properties or method signatures
368
373
  * @see https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/ts-method-signature-style.md#repos-sticky-header
@@ -739,6 +744,8 @@ type JsdocNoUnnecessaryTypeAssertion = []|[{
739
744
 
740
745
  enableFixer?: boolean
741
746
 
747
+ preferConstToLiteralTuples?: boolean
748
+
742
749
  treatAnyAsRedundant?: boolean
743
750
 
744
751
  typesToIgnore?: string[]
@@ -1135,6 +1142,31 @@ type JsdocTextEscaping = []|[{
1135
1142
 
1136
1143
  escapeMarkdown?: boolean
1137
1144
  }]
1145
+ // ----- jsdoc/ts-ban-ts-comment -----
1146
+ type JsdocTsBanTsComment = []|[{
1147
+
1148
+ minimumDescriptionLength?: number
1149
+
1150
+ "ts-check"?: (boolean | "allow-with-description" | {
1151
+
1152
+ descriptionFormat?: string
1153
+ })
1154
+
1155
+ "ts-expect-error"?: (boolean | "allow-with-description" | {
1156
+
1157
+ descriptionFormat?: string
1158
+ })
1159
+
1160
+ "ts-ignore"?: (boolean | "allow-with-description" | {
1161
+
1162
+ descriptionFormat?: string
1163
+ })
1164
+
1165
+ "ts-nocheck"?: (boolean | "allow-with-description" | {
1166
+
1167
+ descriptionFormat?: string
1168
+ })
1169
+ }]
1138
1170
  // ----- jsdoc/ts-method-signature-style -----
1139
1171
  type JsdocTsMethodSignatureStyle = []|[("method" | "property")]|[("method" | "property"), {
1140
1172
 
@@ -79,6 +79,11 @@ export interface RuleOptions {
79
79
  * @see https://nextjs.org/docs/messages/no-img-element
80
80
  */
81
81
  'next/no-img-element'?: Linter.RuleEntry<[]>
82
+ /**
83
+ * Prevent usage of `location.assign` or `location.href` assignment to navigate to internal Next.js pages.
84
+ * @see https://nextjs.org/docs/messages/no-location-assign-relative-destination
85
+ */
86
+ 'next/no-location-assign-relative-destination'?: Linter.RuleEntry<[]>
82
87
  /**
83
88
  * Prevent page-only custom fonts.
84
89
  * @see https://nextjs.org/docs/messages/no-page-custom-font
@@ -105,7 +105,7 @@ export interface RuleOptions {
105
105
  */
106
106
  'react/globals'?: Linter.RuleEntry<[]>
107
107
  /**
108
- * Validates against passing functions that mutate captured local variables into frozen contexts such as JSX props, hook arguments, and hook return values.
108
+ * Validates against mutating props, state, and other immutable values, including through functions passed into frozen contexts such as JSX props, hook arguments, and hook return values.
109
109
  * @see https://eslint-react.xyz/docs/rules/immutability
110
110
  */
111
111
  'react/immutability'?: Linter.RuleEntry<[]>
@@ -460,7 +460,7 @@ export interface RuleOptions {
460
460
  */
461
461
  'react/x-globals'?: Linter.RuleEntry<[]>
462
462
  /**
463
- * Validates against passing functions that mutate captured local variables into frozen contexts such as JSX props, hook arguments, and hook return values.
463
+ * Validates against mutating props, state, and other immutable values, including through functions passed into frozen contexts such as JSX props, hook arguments, and hook return values.
464
464
  * @see https://eslint-react.xyz/docs/rules/immutability
465
465
  */
466
466
  'react/x-immutability'?: Linter.RuleEntry<[]>
@@ -220,6 +220,11 @@ export interface RuleOptions {
220
220
  * @see https://typescript-eslint.io/rules/no-for-in-array
221
221
  */
222
222
  'ts/no-for-in-array'?: Linter.RuleEntry<[]>
223
+ /**
224
+ * Disallow type operations that resolve to the "empty object" type
225
+ * @see https://typescript-eslint.io/rules/no-generated-empty-object-type
226
+ */
227
+ 'ts/no-generated-empty-object-type'?: Linter.RuleEntry<[]>
223
228
  /**
224
229
  * Disallow the use of `eval()`-like functions
225
230
  * @see https://typescript-eslint.io/rules/no-implied-eval
@@ -1356,7 +1361,10 @@ type TsNoMeaninglessVoidOperator = []|[{
1356
1361
  // ----- ts/no-misused-promises -----
1357
1362
  type TsNoMisusedPromises = []|[{
1358
1363
 
1359
- checksConditionals?: boolean
1364
+ checksConditionals?: (boolean | {
1365
+
1366
+ flagUnions?: ("all" | "strict" | "none")
1367
+ })
1360
1368
 
1361
1369
  checksSpreads?: boolean
1362
1370