@mouse_484/eslint-config 5.4.4 → 5.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.
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.4",
4
+ "version": "5.5.0",
5
5
  "author": "mouse_484",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/mouse484/config/tree/main/packages/eslint",
@@ -18,7 +18,7 @@
18
18
  "main": "src/index.js",
19
19
  "types": "src/index.d.ts",
20
20
  "bin": {
21
- "setup": "./bin/cli.js"
21
+ "setup-eslint-mouse-config": "bin/cli.js"
22
22
  },
23
23
  "scripts": {
24
24
  "typegen": "node scripts/typegen.js"
@@ -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
@@ -19,6 +19,9 @@ type Config = Awaitable<
19
19
  >
20
20
  export interface Options extends OptionsConfig, Omit<TypedFlatConfigItem, 'files'> {
21
21
  tailwind?: false | { entryPoint: string }
22
+ typescript?: OptionsConfig['typescript'] & {
23
+ allowJS?: boolean
24
+ }
22
25
  }
23
26
 
24
27
  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,27 @@ async function mouse(options, ...userConfigs) {
37
37
  ignores: typeof options?.ignores === 'function' ? options.ignores([]) : options?.ignores,
38
38
  }
39
39
 
40
+ /**
41
+ *
42
+ * @param {import("eslint").Linter.Config} config
43
+ */
44
+ const overrideTypeScriptAllowJS = (config) => {
45
+ if (!options?.typescript?.allowJS) {
46
+ return config
47
+ }
48
+ return {
49
+ ...config,
50
+ files: [...(config.files ?? []), GLOB_JS, GLOB_JSX],
51
+ }
52
+ }
53
+
40
54
  return antfu(normalizedOptions, ...configs, ...userConfigs)
55
+ .overrides({
56
+ 'antfu/typescript/parser': overrideTypeScriptAllowJS,
57
+ 'antfu/typescript/type-aware-parser': overrideTypeScriptAllowJS,
58
+ 'antfu/typescript/rules': overrideTypeScriptAllowJS,
59
+ 'antfu/typescript/rules-type-aware': overrideTypeScriptAllowJS,
60
+ })
41
61
  }
42
62
 
43
63
  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