@mouse_484/eslint-config 5.4.5 → 5.5.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.
package/bin/cli.js CHANGED
@@ -22,8 +22,12 @@ function logger(message) {
22
22
  /**
23
23
  * @type {(...args: Parameters<typeof import("package-manager-detector/commands").resolveCommand>) => Promise<void>}
24
24
  */
25
- function runAgentCommand(agent, command_, args_) {
26
- const { command, args } = resolveCommand(agent, command_, args_)
25
+ async function runAgentCommand(agent, command_, args_) {
26
+ const result = resolveCommand(agent, command_, args_)
27
+ if (!result) {
28
+ throw new Error(`Unsupported package manager or command: ${agent} ${command_}`)
29
+ }
30
+ const { command, args } = result
27
31
  console.info(`Running command: ${command} ${args.join(' ')}`)
28
32
  return new Promise((resolve, reject) => {
29
33
  const child = spawn(
@@ -82,10 +86,14 @@ async function main() {
82
86
 
83
87
  logger('Updating package.json scripts')
84
88
  const packageJsonPath = path.join(cwd, 'package.json')
89
+
90
+ const packageJsonRaw = await readFile(packageJsonPath, 'utf8')
85
91
  /**
86
- * @type {{ scripts: Record<string, string>, type?: "module" }}
92
+ * @type {{ scripts?: Record<string, string>, type?: "module" }}
87
93
  */
88
- const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))
94
+ // eslint-disable-next-line ts/no-unsafe-assignment
95
+ const packageJson = JSON.parse(packageJsonRaw) ?? {}
96
+
89
97
  packageJson.scripts = {
90
98
  ...packageJson.scripts,
91
99
  'lint': 'eslint .',
@@ -113,10 +121,11 @@ async function main() {
113
121
  'run',
114
122
  ['lint:fix'],
115
123
  ).catch((error) => {
116
- logger(`Linting failed: ${error.message}`)
124
+ if (error instanceof Error) {
125
+ logger(`Linting failed: ${error.message}`)
126
+ }
117
127
  })
118
128
  }
119
129
 
120
- console.info('---------------- Setting up @mouse_484/eslint-config ----------------')
121
130
  await main()
122
131
  console.info('---------------- Setup Complete ----------------')
package/jsconfig.json CHANGED
@@ -1,10 +1,6 @@
1
1
  {
2
+ "extends": "../../jsconfig.json",
2
3
  "compilerOptions": {
3
- "target": "ES2020",
4
- "moduleResolution": "node",
5
- "checkJs": true,
6
- "strict": true,
7
- "noEmit": true
8
- },
9
- "include": ["src"]
4
+ "module": "es2022"
5
+ }
10
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mouse_484/eslint-config",
3
3
  "type": "module",
4
- "version": "5.4.5",
4
+ "version": "5.5.1",
5
5
  "author": "mouse_484",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/mouse484/config/tree/main/packages/eslint",
@@ -1,4 +1,4 @@
1
- import fs from 'node:fs/promises'
1
+ import { writeFile } from 'node:fs/promises'
2
2
  import eslintPluginBetterTailwindcss from 'eslint-plugin-better-tailwindcss'
3
3
  import { pluginsToRulesDTS } from 'eslint-typegen/core'
4
4
 
@@ -6,4 +6,4 @@ const dts = await pluginsToRulesDTS({
6
6
  tailwind: eslintPluginBetterTailwindcss,
7
7
  })
8
8
 
9
- await fs.writeFile('./src/lib/rules.gen.d.ts', dts)
9
+ await writeFile('./src/lib/rules.gen.d.ts', dts)
@@ -6,7 +6,7 @@ export default createConfigs({
6
6
  baseWithOption: 'tailwind',
7
7
  configs: [
8
8
  (meta) => {
9
- if (!meta?.entryPoint) return
9
+ if (meta?.entryPoint === undefined) return
10
10
 
11
11
  return {
12
12
  name: 'tailwind',
@@ -6,7 +6,7 @@ export default createConfigs({
6
6
  baseWithOption: 'typescript',
7
7
  configs: [
8
8
  (meta) => {
9
- if (meta && 'tsconfigPath' in meta && meta.tsconfigPath) {
9
+ if (meta && 'tsconfigPath' in meta && meta.tsconfigPath !== undefined) {
10
10
  return {
11
11
  name: 'type-aware',
12
12
  files: [GLOB_TS],
package/src/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type {
2
2
  TypedFlatConfigItem as AntfuTypedFlatConfigItem,
3
3
  OptionsConfig,
4
+ OptionsOverrides,
5
+ OptionsTypescript,
6
+ OptionsTypeScriptErasableOnly,
7
+ OptionsTypeScriptWithTypes,
4
8
  Rules,
5
9
  } from '@antfu/eslint-config'
6
10
  import type { Linter } from 'eslint'
@@ -19,6 +23,11 @@ type Config = Awaitable<
19
23
  >
20
24
  export interface Options extends OptionsConfig, Omit<TypedFlatConfigItem, 'files'> {
21
25
  tailwind?: false | { entryPoint: string }
26
+ typescript?: boolean
27
+ | OptionsTypescript
28
+ | (OptionsTypeScriptWithTypes & { allowJS?: boolean })
29
+ & OptionsOverrides
30
+ & OptionsTypeScriptErasableOnly
22
31
  }
23
32
 
24
33
  export declare function mouse(
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import antfu from '@antfu/eslint-config'
1
+ import antfu, { GLOB_JS, GLOB_JSX } from '@antfu/eslint-config'
2
2
  import astro from './configs/astro.js'
3
3
  import base from './configs/base.js'
4
4
  import perfectionist from './configs/perfectionist.js'
@@ -37,7 +37,29 @@ async function mouse(options, ...userConfigs) {
37
37
  ignores: typeof options?.ignores === 'function' ? options.ignores([]) : options?.ignores,
38
38
  }
39
39
 
40
- return antfu(normalizedOptions, ...configs, ...userConfigs)
40
+ const composer = antfu(normalizedOptions, ...configs, ...userConfigs)
41
+
42
+ /**
43
+ * Override TypeScript configs for JS/JSX files if `allowJS` is enabled.
44
+ */
45
+ if (
46
+ typeof options.typescript === 'object'
47
+ && 'allowJS' in options.typescript
48
+ && options.typescript.allowJS
49
+ ) {
50
+ /** @type {import("eslint").Linter.Config} */
51
+ const overrideTypeScriptAllowJS = { files: [GLOB_JS, GLOB_JSX] }
52
+
53
+ await composer.override('antfu/typescript/parser', overrideTypeScriptAllowJS)
54
+ await composer.override('antfu/typescript/rules', overrideTypeScriptAllowJS)
55
+
56
+ if (options.typescript.tsconfigPath !== undefined) {
57
+ await composer.override('antfu/typescript/type-aware-parser', overrideTypeScriptAllowJS)
58
+ await composer.override('antfu/typescript/rules-type-aware', overrideTypeScriptAllowJS)
59
+ }
60
+ }
61
+
62
+ return composer
41
63
  }
42
64
 
43
65
  export default mouse
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  *
3
3
  * @param {string} name
4
- * @param {(keyof import('..').Options)[]} withOptions
4
+ * @param {(keyof import('..').Options)[]?} withOptions
5
5
  * @param {Omit<import('@antfu/eslint-config').TypedFlatConfigItem,'name'>} config
6
6
  * @returns {(options: import('..').Options) => import('@antfu/eslint-config').TypedFlatConfigItem|[]} _
7
7
  */
@@ -29,10 +29,10 @@ export function createConfigs({ name, baseWithOption, configs }) {
29
29
  throw new Error('baseWithOption is required when configItem is a function')
30
30
  }
31
31
  const meta = options[baseWithOption]
32
- // @ts-ignore
33
- configItem = configItem(typeof meta === 'object' ? meta : undefined) ?? {}
32
+ // @ts-expect-error: may be undefined
33
+ configItem = configItem(typeof meta === 'object' ? meta : undefined)
34
34
  }
35
- if (!configItem) {
35
+ if (configItem === undefined) {
36
36
  return []
37
37
  }
38
38
  const { name: configName, withOptions = [], ...restConfig } = configItem