Skip to content

Commit e99e76b

Browse files
committed
fix: fix all lint error
1 parent cc63e57 commit e99e76b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+387
-497
lines changed

.commitlintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: ['@commitlint/config-conventional'],
2+
extends: ['@commitlint/config-conventional']
33
}

.eslintrc.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ module.exports = {
22
env: {
33
browser: true,
44
commonjs: true,
5-
es2021: true,
5+
es2021: true
66
},
77
extends: '@antfu',
88
overrides: [
99
{
1010
env: {
11-
node: true,
11+
node: true
1212
},
1313
files: ['.eslintrc.{js,cjs}'],
1414
parserOptions: {
15-
sourceType: 'script',
16-
},
17-
},
15+
sourceType: 'script'
16+
}
17+
}
1818
],
1919
parserOptions: {
20-
ecmaVersion: 'latest',
20+
ecmaVersion: 'latest'
2121
},
22-
rules: {},
22+
rules: {}
2323
}

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# CHANGELOG
2-
## 1.0.5 release [2024-3-]
2+
3+
## 1.0.5 release [2024-3-]
34

45
### Features
56

67
- Added eslint, prettier, and commit-lint to development dependencies.
78
- Implemented a hot 100 list feature and added keyword search functionality.
89

9-
## 1.0.4 release [2024-3-5 22:10]
10+
## 1.0.4 release [2024-3-5 22:10]
1011

1112
### Fixes
1213

bin/lc.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { easyLanguageView } from '#common/view/language.view.js'
1919
import { DefaultVer } from '#common/constants/question.const.js'
2020
import {
2121
create,
22-
createQuestionById,
22+
createQuestionById
2323
} from '#common/utils/create-check/createUtil.js'
2424

2525
const version = process.env.VERSION ?? DefaultVer
@@ -36,7 +36,7 @@ program
3636
.option('-l, --language [language]', 'Set/Get the code language of question.')
3737
.option(
3838
'-u, --update',
39-
'Check the version to determine whether to update to the latest one.',
39+
'Check the version to determine whether to update to the latest one.'
4040
)
4141
.parse(process.argv)
4242

@@ -56,8 +56,7 @@ const cmdOpts = program.opts()
5656
if (cmdOpts.language) {
5757
if (cmdOpts.language !== true) {
5858
await easyLanguageView(cmdOpts.language)
59-
}
60-
else {
59+
} else {
6160
const lang = await getQuestionLanguage()
6261
console.log(`当前CLI语言环境为:${lang}`)
6362
}
@@ -97,7 +96,7 @@ export const callModeAction = {
9796
identity: async (id) => {
9897
await createQuestionById(id, baseDir)
9998
process.exit(0)
100-
},
99+
}
101100
}
102101
// 获取模式和参数
103102
const mode = referMode(cmdArgs, cmdOpts)

bin/lf.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ program
1919
.option('-l, --language [language]', 'Set/Get the code language of question.')
2020
.option(
2121
'-u, --update',
22-
'Check the version to determine whether to update to the latest one.',
22+
'Check the version to determine whether to update to the latest one.'
2323
)
2424
.parse(process.argv)
2525

@@ -34,8 +34,7 @@ const cmdOpts = program.opts()
3434
if (cmdOpts.language) {
3535
if (cmdOpts.language !== true) {
3636
await easyLanguageView(cmdOpts.language)
37-
}
38-
else {
37+
} else {
3938
const lang = await getQuestionLanguage()
4039
console.log(`当前CLI语言环境为:${lang}`)
4140
}

bin/lk.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,25 @@ program
2828
.option('-t, --today', 'Check the question today.')
2929
.option(
3030
'-i, --identity <identity>',
31-
'Check the specified question by identity.',
31+
'Check the specified question by identity.'
3232
)
3333
.option('-r, --random', 'Check the last random question.')
3434
.option('-e, --easy', 'Use easy mode.')
3535
.option('-d, --directory <directory>', 'Set the question directory.')
3636
.option('-l, --language [language]', 'Set/Get the code language of question.')
3737
.option(
3838
'-u, --update',
39-
'Check the version to determine whether to update to the latest one.',
39+
'Check the version to determine whether to update to the latest one.'
4040
)
4141
.parse(process.argv)
4242

4343
const cmdArgs = program.args
4444
const cmdOpts = program.opts()
45+
// 获取模式和参数
46+
47+
const mode = referMode(cmdArgs, cmdOpts)
48+
const args = getArgs(mode, cmdArgs, cmdOpts)
49+
4550
/**
4651
* 执行逻辑:
4752
* 目录检测 - 设置基础目录
@@ -56,8 +61,7 @@ const cmdOpts = program.opts()
5661
if (cmdOpts.language) {
5762
if (cmdOpts.language !== true) {
5863
await easyLanguageView(cmdOpts.language)
59-
}
60-
else {
64+
} else {
6165
const lang = await getQuestionLanguage()
6266
console.log(`当前CLI语言环境为:${lang}`)
6367
}
@@ -85,14 +89,13 @@ async function check(mode, question) {
8589
const filePath = path.join(
8690
baseDir,
8791
getQuestionFileName(question),
88-
`question${getQuestionFileExtension(question?.lang)}`,
92+
`question${getQuestionFileExtension(question?.lang)}`
8993
)
9094
if (!fs.existsSync(filePath)) {
9195
console.log(`文件[${filePath}]不存在,请确保已经创建!`)
92-
}
93-
else {
96+
} else {
9497
console.log(
95-
`MODE: ${mode}\n题目[${getQuestionChineseName(question)}]检测结果:`,
98+
`MODE: ${mode}\n题目[${getQuestionChineseName(question)}]检测结果:`
9699
)
97100
await checkQuestion(filePath)
98101
}
@@ -116,10 +119,8 @@ const callModeAction = {
116119
: await getQuestionById(id)
117120
await check('identity', question)
118121
process.exit(0)
119-
},
122+
}
120123
}
121-
// 获取模式和参数
122-
const mode = referMode(cmdArgs, cmdOpts)
123-
const args = getArgs(mode, cmdArgs, cmdOpts)
124+
124125
// 执行指令分发
125126
callModeAction[mode](args)

common/structures/ListNode.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export class ListNode {
1212
}
1313

1414
static parse(arr) {
15-
if (arr.length === 0)
16-
return null // Return null for an empty array
15+
if (arr.length === 0) return null // Return null for an empty array
1716

1817
const head = new ListNode(arr.shift(), null)
1918
let current = head
@@ -25,8 +24,7 @@ export class ListNode {
2524
}
2625

2726
static toArray(listNodes, arr = []) {
28-
if (listNodes === undefined || listNodes === null)
29-
return arr
27+
if (listNodes === undefined || listNodes === null) return arr
3028

3129
arr.push(listNodes.val)
3230
return ListNode.toArray(listNodes.next, arr)

common/structures/Node.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ export class Node {
3030
}
3131

3232
static toArray(node) {
33-
if (!node)
34-
return []
33+
if (!node) return []
3534

3635
const visited = new Set()
3736
const result = []
3837

3938
const dfs = (currentNode) => {
40-
if (visited.has(currentNode.val))
41-
return
39+
if (visited.has(currentNode.val)) return
4240

4341
const { neighbors, val } = currentNode
4442
visited.add(val)

common/structures/TreeNode.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export class TreeNode {
77
}
88

99
static parse(arr) {
10-
if (arr.length === 0)
11-
return null
10+
if (arr.length === 0) return null
1211
const root = new TreeNode(arr[0])
1312
const queue = [root]
1413
for (let i = 1; i < arr.length; i += 2) {
@@ -27,8 +26,7 @@ export class TreeNode {
2726

2827
static toArray(treeNode) {
2928
const result = []
30-
if (!treeNode)
31-
return result
29+
if (!treeNode) return result
3230

3331
const queue = [treeNode]
3432

@@ -38,8 +36,7 @@ export class TreeNode {
3836
result.push(node.val)
3937
queue.push(node.left)
4038
queue.push(node.right)
41-
}
42-
else {
39+
} else {
4340
result.push(null)
4441
}
4542
}

common/utils/create-check/createUtil.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ export function create(mode, question, baseDir) {
1313
setQuestion(mode, question)
1414
const questionDir = path.join(baseDir, getQuestionFileName(question))
1515
createQuestion(question, questionDir).then(async (path) => {
16-
if (!path)
17-
path = await createQuestionCopy(question, questionDir)
16+
if (!path) path = await createQuestionCopy(question, questionDir)
1817
console.log(
19-
`题目[${getQuestionChineseName(question)}]获取成功!\n题目文件地址为:${path}`,
18+
`题目[${getQuestionChineseName(question)}]获取成功!\n题目文件地址为:${path}`
2019
)
2120
resolve(true)
2221
})
@@ -25,16 +24,15 @@ export function create(mode, question, baseDir) {
2524

2625
export async function createQuestionByTitleSlug(
2726
titleSlug,
28-
baseDir = process.cwd(),
27+
baseDir = process.cwd()
2928
) {
3029
const { question } = await getQuestionIdBySlug(titleSlug)
3130

3231
await createQuestionById(question.questionId, baseDir)
3332
}
3433
export async function createQuestionById(id, baseDir) {
3534
const question = await getQuestionById(id)
36-
if (!question?.id)
37-
console.log(`指定编号: [ ${id} ] 题目不存在.`)
35+
if (!question?.id) console.log(`指定编号: [ ${id} ] 题目不存在.`)
3836

3937
await create('identity', question, baseDir)
4038
}
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// 推测模式
22
export function referMode(args, opts) {
3-
if (args.length > 0 || opts.identity)
4-
return 'identity'
3+
if (args.length > 0 || opts.identity) return 'identity'
54

6-
if (opts.random)
7-
return 'random'
5+
if (opts.random) return 'random'
86

97
return 'today'
108
}

common/utils/etc/createColorFont.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export function createColorFont(font) {
77
const code = gradient_string([
88
{ color: '#ff0000', pos: 0 },
99
{ color: '#ffc600', pos: 0.5 },
10-
{ color: '#003dff', pos: 1 },
10+
{ color: '#003dff', pos: 1 }
1111
])(font)
1212
writeFileSync(path.resolve(process.cwd(), 'colorFont.js'), code)
1313
console.log(
14-
`[ColorFont]Create color font: ${font}\ncode location:${path.resolve(process.cwd(), 'colorFont.js')}`,
14+
`[ColorFont]Create color font: ${font}\ncode location:${path.resolve(process.cwd(), 'colorFont.js')}`
1515
)
1616
console.log(code)
1717
}

common/utils/etc/typeof_.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* @private
66
*/
77
export function typeof_(data) {
8-
if (data === null)
9-
return 'null'
10-
else
11-
return typeof data
8+
if (data === null) return 'null'
9+
else return typeof data
1210
}

common/utils/file/getCountBySameName.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import { readdirSync } from 'node:fs'
77
* @returns {number}
88
*/
99
export function getCountBySameName(dir, name) {
10-
return readdirSync(dir).filter(filename => filename.includes(name)).length
10+
return readdirSync(dir).filter((filename) => filename.includes(name)).length
1111
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readdirSync } from 'node:fs'
22

33
export function getFileListBySameName(dir, name) {
4-
return readdirSync(dir).filter(filename => filename.includes(name))
4+
return readdirSync(dir).filter((filename) => filename.includes(name))
55
}

common/utils/functions/isSameData.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
export function isSameData(a, b) {
88
const typeA = typeof a
99
const typeB = typeof b
10-
if (typeA !== typeB)
11-
return false
10+
if (typeA !== typeB) return false
1211
switch (typeA) {
1312
case 'bigint':
1413
case 'boolean':
@@ -19,14 +18,13 @@ export function isSameData(a, b) {
1918
return a === b
2019
case 'function':
2120
return a.toString() === b.toString()
22-
case 'object':
23-
if (a === null || a === undefined)
24-
return a === b
21+
case 'object': {
22+
if (a === null || a === undefined) return a === b
2523

2624
const keysA = Object.keys(a)
2725
const keysB = Object.keys(b)
28-
if (keysA.length !== keysB.length)
29-
return false
30-
return keysA.every(key => isSameData(a[key], b[key]))
26+
if (keysA.length !== keysB.length) return false
27+
return keysA.every((key) => isSameData(a[key], b[key]))
28+
}
3129
}
3230
}

common/utils/functions/sizeUtil.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ export const PB = 1024 * GB
1515
* @return {size: number, label: string}
1616
*/
1717
export function getFileSizeUnit(size) {
18-
if (size < KB)
19-
return { size: 1, label: 'B' }
20-
if (size < MB)
21-
return { size: KB, label: 'KB' }
22-
if (size < GB)
23-
return { size: MB, label: 'MB' }
24-
if (size < TB)
25-
return { size: GB, label: 'GB' }
26-
if (size < PB)
27-
return { size: TB, label: 'TB' }
18+
if (size < KB) return { size: 1, label: 'B' }
19+
if (size < MB) return { size: KB, label: 'KB' }
20+
if (size < GB) return { size: MB, label: 'MB' }
21+
if (size < TB) return { size: GB, label: 'GB' }
22+
if (size < PB) return { size: TB, label: 'TB' }
2823

2924
return { size: PB, label: 'PB' }
3025
}

common/utils/http/fetch_.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* @private
77
*/
88
export async function fetch_(url, options) {
9-
return await fetch(url, options).then(res => res.json())
9+
return await fetch(url, options).then((res) => res.json())
1010
}

0 commit comments

Comments
 (0)