Skip to content

Commit fa77b60

Browse files
committed
chore: format
1 parent eb885c9 commit fa77b60

File tree

16 files changed

+63
-250
lines changed

16 files changed

+63
-250
lines changed

example/html.html

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
ga('create', 'UA-XXXXX-Y', 'auto')
2121
ga('send', 'pageview')
2222
</script>
23-
<script
24-
src="https://www.google-analytics.com/analytics.js"
25-
async
26-
defer
27-
></script>
23+
<script src="https://www.google-analytics.com/analytics.js" async defer></script>
2824
</body>
2925
</html>

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"build": "tsup",
4141
"dev": "tsup --format esm,cjs --watch & eslint-flat-config-viewer",
4242
"lint": "eslint .",
43+
"lint:fix": "eslint . --fix",
4344
"prepack": "nr build",
4445
"release": "bumpp && pnpm publish",
4546
"typecheck": "tsc --noEmit",

src/cli/run.ts

+10-35
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ import c from 'picocolors'
88

99
// @ts-expect-error missing types
1010
import parse from 'parse-gitignore'
11-
import {
12-
ARROW,
13-
CHECK,
14-
WARN,
15-
eslintVersion,
16-
version,
17-
vscodeSettingsString,
18-
} from './constants'
11+
import { ARROW, CHECK, WARN, eslintVersion, version, vscodeSettingsString } from './constants'
1912
import { isGitClean } from './utils'
2013

2114
export interface RuleOptions {
@@ -36,19 +29,14 @@ export async function run(options: RuleOptions = {}) {
3629
const pathESLintIngore = path.join(cwd, '.eslintignore')
3730

3831
if (fs.existsSync(pathFlatConfig)) {
39-
console.log(
40-
c.yellow(
41-
`${WARN} eslint.config.js already exists, migration wizard exited.`,
42-
),
43-
)
32+
console.log(c.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`))
4433
return process.exit(1)
4534
}
4635

4736
if (!SKIP_GIT_CHECK && !isGitClean()) {
4837
const { confirmed } = await prompts({
4938
initial: false,
50-
message:
51-
'There are uncommitted changes in the current repository, are you sure to continue?',
39+
message: 'There are uncommitted changes in the current repository, are you sure to continue?',
5240
name: 'confirmed',
5341
type: 'confirm',
5442
})
@@ -79,18 +67,13 @@ export async function run(options: RuleOptions = {}) {
7967

8068
for (const glob of globs) {
8169
if (glob.type === 'ignore') eslintIgnores.push(...glob.patterns)
82-
else if (glob.type === 'unignore')
83-
eslintIgnores.push(
84-
...glob.patterns.map((pattern: string) => `!${pattern}`),
85-
)
70+
else if (glob.type === 'unignore') eslintIgnores.push(...glob.patterns.map((pattern: string) => `!${pattern}`))
8671
}
8772
}
8873

8974
let eslintConfigContent: string = ''
9075

91-
const coderwydConfig = `${
92-
eslintIgnores.length ? `ignores: ${JSON.stringify(eslintIgnores)}` : ''
93-
}`
76+
const coderwydConfig = `${eslintIgnores.length ? `ignores: ${JSON.stringify(eslintIgnores)}` : ''}`
9477
if (pkg.type === 'module') {
9578
eslintConfigContent = `
9679
import { defineConfig } from '@coderwyd/eslint-config'
@@ -111,8 +94,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
11194
const files = fs.readdirSync(cwd)
11295
const legacyConfig: string[] = []
11396
files.forEach(file => {
114-
if (file.includes('eslint') || file.includes('prettier'))
115-
legacyConfig.push(file)
97+
if (file.includes('eslint') || file.includes('prettier')) legacyConfig.push(file)
11698
})
11799
if (legacyConfig.length) {
118100
console.log(`${WARN} you can now remove those files manually:`)
@@ -130,8 +112,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
130112
promptResult = await prompts(
131113
{
132114
initial: true,
133-
message:
134-
'Update .vscode/settings.json for better VS Code experience?',
115+
message: 'Update .vscode/settings.json for better VS Code experience?',
135116
name: 'updateVscodeSettings',
136117
type: 'confirm',
137118
},
@@ -151,8 +132,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
151132
const dotVscodePath: string = path.join(cwd, '.vscode')
152133
const settingsPath: string = path.join(dotVscodePath, 'settings.json')
153134

154-
if (!fs.existsSync(dotVscodePath))
155-
await fsp.mkdir(dotVscodePath, { recursive: true })
135+
if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true })
156136

157137
if (!fs.existsSync(settingsPath)) {
158138
await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, 'utf-8')
@@ -161,10 +141,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
161141
let settingsContent = await fsp.readFile(settingsPath, 'utf8')
162142

163143
settingsContent = settingsContent.trim().replace(/\s*}$/, '')
164-
settingsContent +=
165-
settingsContent.endsWith(',') || settingsContent.endsWith('{')
166-
? ''
167-
: ','
144+
settingsContent += settingsContent.endsWith(',') || settingsContent.endsWith('{') ? '' : ','
168145
settingsContent += `${vscodeSettingsString}}\n`
169146

170147
await fsp.writeFile(settingsPath, settingsContent, 'utf-8')
@@ -174,7 +151,5 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
174151

175152
// End update .vscode/settings.json
176153
console.log(c.green(`${CHECK} migration completed`))
177-
console.log(
178-
`Now you can update the dependencies and run ${c.blue('eslint . --fix')}\n`,
179-
)
154+
console.log(`Now you can update the dependencies and run ${c.blue('eslint . --fix')}\n`)
180155
}

src/configs/formatter.ts

+4-22
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,19 @@ import {
1111
} from '../constants/glob'
1212

1313
import { ensurePackages, interopDefault, parserPlain } from '../shared'
14-
import type {
15-
FlatConfigItem,
16-
OptionsFormatters,
17-
PartialPrettierExtendedOptions,
18-
PrettierParser,
19-
} from '../types'
14+
import type { FlatConfigItem, OptionsFormatters, PartialPrettierExtendedOptions, PrettierParser } from '../types'
2015

2116
export async function formatter(
2217
options: OptionsFormatters = {},
2318
prettierRules: PartialPrettierExtendedOptions = {},
2419
): Promise<FlatConfigItem[]> {
2520
await ensurePackages(['eslint-plugin-prettier'])
2621

27-
const {
28-
css = true,
29-
graphql,
30-
html = true,
31-
markdown,
32-
toml,
33-
yaml,
34-
} = options || {}
22+
const { css = true, graphql, html = true, markdown, toml, yaml } = options || {}
3523

3624
const pluginPrettier = await interopDefault(import('eslint-plugin-prettier'))
3725

38-
function createPrettierFormatter(
39-
files: string[],
40-
parser: PrettierParser,
41-
plugins?: string[],
42-
) {
26+
function createPrettierFormatter(files: string[], parser: PrettierParser, plugins?: string[]) {
4327
const rules = {
4428
...prettierRules,
4529
parser,
@@ -106,9 +90,7 @@ export async function formatter(
10690
if (toml) {
10791
await ensurePackages(['@toml-tools/parser', 'prettier-plugin-toml'])
10892

109-
const tomlConfig = createPrettierFormatter([GLOB_TOML], 'toml', [
110-
'prettier-plugin-toml',
111-
])
93+
const tomlConfig = createPrettierFormatter([GLOB_TOML], 'toml', ['prettier-plugin-toml'])
11294

11395
configs.push(tomlConfig)
11496
}

src/configs/imports.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ export async function imports(): Promise<FlatConfigItem[]> {
1616
'antfu/no-import-node-modules-by-path': 'error',
1717

1818
'import/first': 'error',
19-
'import/newline-after-import': [
20-
'error',
21-
{ considerComments: true, count: 1 },
22-
],
19+
'import/newline-after-import': ['error', { considerComments: true, count: 1 }],
2320
'import/no-duplicates': 'error',
2421
'import/no-mutable-exports': 'error',
2522
'import/no-named-default': 'error',
@@ -28,16 +25,7 @@ export async function imports(): Promise<FlatConfigItem[]> {
2825
'import/order': [
2926
'error',
3027
{
31-
groups: [
32-
'builtin',
33-
'external',
34-
'internal',
35-
'parent',
36-
'sibling',
37-
'index',
38-
'object',
39-
'type',
40-
],
28+
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
4129
pathGroups: [{ group: 'internal', pattern: '{{@,~}/,#}**' }],
4230
pathGroupsExcludedImportTypes: ['type'],
4331
},

src/configs/javascript.ts

+7-26
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import globals from 'globals'
22
import { pluginUnusedImports } from '../plugins'
33
import { GLOB_SRC, GLOB_SRC_EXT } from '../constants/glob'
4-
import type {
5-
FlatConfigItem,
6-
OptionsIsInEditor,
7-
OptionsOverrides,
8-
} from '../types'
4+
import type { FlatConfigItem, OptionsIsInEditor, OptionsOverrides } from '../types'
95

10-
export async function javascript(
11-
options: OptionsIsInEditor & OptionsOverrides = {},
12-
): Promise<FlatConfigItem[]> {
6+
export async function javascript(options: OptionsIsInEditor & OptionsOverrides = {}): Promise<FlatConfigItem[]> {
137
const { isInEditor = false, overrides = {} } = options
148

159
return [
@@ -41,21 +35,15 @@ export async function javascript(
4135
'unused-imports': pluginUnusedImports,
4236
},
4337
rules: {
44-
'accessor-pairs': [
45-
'error',
46-
{ enforceForClassMembers: true, setWithoutGet: true },
47-
],
38+
'accessor-pairs': ['error', { enforceForClassMembers: true, setWithoutGet: true }],
4839

4940
'array-callback-return': 'error',
5041
'block-scoped-var': 'error',
5142
'constructor-super': 'error',
5243
'default-case-last': 'error',
5344
'dot-notation': ['error', { allowKeywords: true }],
5445
eqeqeq: ['error', 'smart'],
55-
'new-cap': [
56-
'error',
57-
{ capIsNew: false, newIsCap: true, properties: true },
58-
],
46+
'new-cap': ['error', { capIsNew: false, newIsCap: true, properties: true }],
5947
'no-alert': 'error',
6048
'no-array-constructor': 'error',
6149
'no-async-promise-executor': 'error',
@@ -114,8 +102,7 @@ export async function javascript(
114102
'no-restricted-properties': [
115103
'error',
116104
{
117-
message:
118-
'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.',
105+
message: 'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.',
119106
property: '__proto__',
120107
},
121108
{
@@ -177,10 +164,7 @@ export async function javascript(
177164
vars: 'all',
178165
},
179166
],
180-
'no-use-before-define': [
181-
'error',
182-
{ classes: false, functions: false, variables: true },
183-
],
167+
'no-use-before-define': ['error', { classes: false, functions: false, variables: true }],
184168
'no-useless-backreference': 'error',
185169
'no-useless-call': 'error',
186170
'no-useless-catch': 'error',
@@ -243,10 +227,7 @@ export async function javascript(
243227
varsIgnorePattern: '^_',
244228
},
245229
],
246-
'use-isnan': [
247-
'error',
248-
{ enforceForIndexOf: true, enforceForSwitchCase: true },
249-
],
230+
'use-isnan': ['error', { enforceForIndexOf: true, enforceForSwitchCase: true }],
250231
'valid-typeof': ['error', { requireStringLiterals: true }],
251232
'vars-on-top': 'error',
252233
yoda: ['error', 'never'],

src/configs/jsonc.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import { GLOB_JSON, GLOB_JSON5, GLOB_JSONC } from '../constants/glob'
22
import { interopDefault } from '../shared'
33
import type { FlatConfigItem, OptionsFiles, OptionsOverrides } from '../types'
44

5-
export async function jsonc(
6-
options: OptionsFiles & OptionsOverrides = {},
7-
): Promise<FlatConfigItem[]> {
8-
const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } =
9-
options || {}
5+
export async function jsonc(options: OptionsFiles & OptionsOverrides = {}): Promise<FlatConfigItem[]> {
6+
const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } = options || {}
107

118
const [pluginJsonc, parserJsonc] = await Promise.all([
129
interopDefault(import('eslint-plugin-jsonc')),

src/configs/react.ts

+10-30
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
11
import { isPackageExists } from 'local-pkg'
22
import { ensurePackages, interopDefault } from '../shared'
33
import { GLOB_JSX, GLOB_TSX } from '../constants/glob'
4-
import type {
5-
FlatConfigItem,
6-
OptionsFiles,
7-
OptionsHasTypeScript,
8-
OptionsOverrides,
9-
} from '../types'
4+
import type { FlatConfigItem, OptionsFiles, OptionsHasTypeScript, OptionsOverrides } from '../types'
105

116
// react refresh
127
const ReactRefreshAllowConstantExportPackages = ['vite']
138

149
export async function react(
1510
options: OptionsHasTypeScript & OptionsOverrides & OptionsFiles = {},
1611
): Promise<FlatConfigItem[]> {
17-
const {
18-
files = [GLOB_JSX, GLOB_TSX],
19-
overrides = {},
20-
typescript = true,
21-
} = options
12+
const { files = [GLOB_JSX, GLOB_TSX], overrides = {}, typescript = true } = options
2213

23-
await ensurePackages([
24-
'eslint-plugin-react',
25-
'eslint-plugin-react-hooks',
26-
'eslint-plugin-react-refresh',
27-
])
14+
await ensurePackages(['eslint-plugin-react', 'eslint-plugin-react-hooks', 'eslint-plugin-react-refresh'])
2815

29-
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
30-
[
31-
interopDefault(import('eslint-plugin-react')),
32-
interopDefault(import('eslint-plugin-react-hooks')),
33-
interopDefault(import('eslint-plugin-react-refresh')),
34-
] as const,
35-
)
16+
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
17+
interopDefault(import('eslint-plugin-react')),
18+
interopDefault(import('eslint-plugin-react-hooks')),
19+
interopDefault(import('eslint-plugin-react-refresh')),
20+
] as const)
3621

37-
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
38-
i => isPackageExists(i),
39-
)
22+
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(i => isPackageExists(i))
4023

4124
return [
4225
{
@@ -68,10 +51,7 @@ export async function react(
6851
'react-hooks/rules-of-hooks': 'error',
6952

7053
// react refresh
71-
'react-refresh/only-export-components': [
72-
'warn',
73-
{ allowConstantExport: isAllowConstantExport },
74-
],
54+
'react-refresh/only-export-components': ['warn', { allowConstantExport: isAllowConstantExport }],
7555

7656
// recommended rules react
7757
'react/display-name': 'error',

src/configs/sort.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export async function sortPackageJson(): Promise<FlatConfigItem[]> {
7070
},
7171
{
7272
order: { type: 'asc' },
73-
pathPattern:
74-
'^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$',
73+
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$',
7574
},
7675
{
7776
order: { type: 'asc' },
@@ -101,14 +100,7 @@ export function sortTsconfig(): FlatConfigItem[] {
101100
'jsonc/sort-keys': [
102101
'error',
103102
{
104-
order: [
105-
'extends',
106-
'compilerOptions',
107-
'references',
108-
'files',
109-
'include',
110-
'exclude',
111-
],
103+
order: ['extends', 'compilerOptions', 'references', 'files', 'include', 'exclude'],
112104
pathPattern: '^$',
113105
},
114106
{

0 commit comments

Comments
 (0)