Skip to content

Commit b237c06

Browse files
committed
fix:lint
1 parent 2f4eb5d commit b237c06

Some content is hidden

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

63 files changed

+382
-346
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: 'airbnb-base',
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
}

.husky/commit-msg

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
4-
npx --no-install commitlint --edit
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit

.husky/pre-commit

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
echo "lint and format before commit"
4-
npm run lint && npm run format
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
echo "lint and format before commit"
4+
npm run lint && npm run format

bin/lc.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#! /usr/bin/env node
2+
import path from 'node:path'
23
import { program } from 'commander'
34
import { artFontLogo } from '#resources/text/art-font-logo.js'
45
import { lcExamples } from '#resources/text/examples.js'
@@ -7,7 +8,6 @@ import { aim } from '#resources/text/aim.js'
78
import { referMode } from '#common/utils/create-check/refer-mode.js'
89
import { getArgs } from '#common/utils/create-check/get-args.js'
910
import { getQuestionToday } from '#common/utils/question-getter/getQuestionToday.js'
10-
import path from 'path'
1111

1212
import { getQuestionRandom } from '#common/utils/question-getter/getQuestionRandom.js'
1313

@@ -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,9 +56,10 @@ const cmdOpts = program.opts()
5656
if (cmdOpts.language) {
5757
if (cmdOpts.language !== true) {
5858
await easyLanguageView(cmdOpts.language)
59-
} else {
59+
}
60+
else {
6061
const lang = await getQuestionLanguage()
61-
console.log('当前CLI语言环境为:' + lang)
62+
console.log(`当前CLI语言环境为:${lang}`)
6263
}
6364
process.exit(0)
6465
}
@@ -96,7 +97,7 @@ export const callModeAction = {
9697
identity: async (id) => {
9798
await createQuestionById(id, baseDir)
9899
process.exit(0)
99-
}
100+
},
100101
}
101102
// 获取模式和参数
102103
const mode = referMode(cmdArgs, cmdOpts)

bin/lf.js

+3-2
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,7 +34,8 @@ const cmdOpts = program.opts()
3434
if (cmdOpts.language) {
3535
if (cmdOpts.language !== true) {
3636
await easyLanguageView(cmdOpts.language)
37-
} else {
37+
}
38+
else {
3839
const lang = await getQuestionLanguage()
3940
console.log(`当前CLI语言环境为:${lang}`)
4041
}

bin/lk.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ 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

@@ -56,7 +56,8 @@ const cmdOpts = program.opts()
5656
if (cmdOpts.language) {
5757
if (cmdOpts.language !== true) {
5858
await easyLanguageView(cmdOpts.language)
59-
} else {
59+
}
60+
else {
6061
const lang = await getQuestionLanguage()
6162
console.log(`当前CLI语言环境为:${lang}`)
6263
}
@@ -84,13 +85,14 @@ async function check(mode, question) {
8485
const filePath = path.join(
8586
baseDir,
8687
getQuestionFileName(question),
87-
`question${getQuestionFileExtension(question?.lang)}`
88+
`question${getQuestionFileExtension(question?.lang)}`,
8889
)
8990
if (!fs.existsSync(filePath)) {
9091
console.log(`文件[${filePath}]不存在,请确保已经创建!`)
91-
} else {
92+
}
93+
else {
9294
console.log(
93-
`MODE: ${mode}\n题目[${getQuestionChineseName(question)}]检测结果:`
95+
`MODE: ${mode}\n题目[${getQuestionChineseName(question)}]检测结果:`,
9496
)
9597
await checkQuestion(filePath)
9698
}
@@ -114,7 +116,7 @@ const callModeAction = {
114116
: await getQuestionById(id)
115117
await check('identity', question)
116118
process.exit(0)
117-
}
119+
},
118120
}
119121
// 获取模式和参数
120122
const mode = referMode(cmdArgs, cmdOpts)

common/structures/ListNode.js

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

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

1718
const head = new ListNode(arr.shift(), null)
1819
let current = head
@@ -24,7 +25,8 @@ export class ListNode {
2425
}
2526

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

2931
arr.push(listNodes.val)
3032
return ListNode.toArray(listNodes.next, arr)

common/structures/Node.js

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

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

3536
const visited = new Set()
3637
const result = []
3738

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

4143
const { neighbors, val } = currentNode
4244
visited.add(val)

common/structures/TreeNode.js

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

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

2728
static toArray(treeNode) {
2829
const result = []
29-
if (!treeNode) return result
30+
if (!treeNode)
31+
return result
3032

3133
const queue = [treeNode]
3234

@@ -36,7 +38,8 @@ export class TreeNode {
3638
result.push(node.val)
3739
queue.push(node.left)
3840
queue.push(node.right)
39-
} else {
41+
}
42+
else {
4043
result.push(null)
4144
}
4245
}

common/utils/create-check/createUtil.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1+
import path from 'node:path'
12
import { createQuestion } from '#common/utils/question-handler/createQuestion.js'
23
import { getQuestionFileName } from '#common/utils/question-handler/getQuestionFileName.js'
34
import { createQuestionCopy } from '#common/utils/question-handler/createQuestionCopy.js'
45
import { setQuestion } from '#common/utils/store/controller/question.js'
56
import { getQuestionChineseName } from '#common/utils/question-handler/getQuestionChineseName.js'
67
import { getQuestionById } from '#common/utils/question-getter/getQuestionById.js'
78
import { getQuestionIdBySlug } from '#common/utils/question-handler/getQuestionIdBySlug.js'
8-
import path from 'path'
99

10-
export const create = (mode, question, baseDir) => {
10+
export function create(mode, question, baseDir) {
1111
console.log(`MODE: ${mode}`)
1212
return new Promise((resolve) => {
1313
setQuestion(mode, question)
1414
const questionDir = path.join(baseDir, getQuestionFileName(question))
1515
createQuestion(question, questionDir).then(async (path) => {
16-
if (!path) path = await createQuestionCopy(question, questionDir)
16+
if (!path)
17+
path = await createQuestionCopy(question, questionDir)
1718
console.log(
18-
`题目[${getQuestionChineseName(question)}]获取成功!\n题目文件地址为:${path}`
19+
`题目[${getQuestionChineseName(question)}]获取成功!\n题目文件地址为:${path}`,
1920
)
2021
resolve(true)
2122
})
2223
})
2324
}
2425

25-
export const createQuestionByTitleSlug = async (
26-
titleSlug,
27-
baseDir = process.cwd()
28-
) => {
26+
export async function createQuestionByTitleSlug(titleSlug, baseDir = process.cwd()) {
2927
const { question } = await getQuestionIdBySlug(titleSlug)
3028

3129
await createQuestionById(question.questionId, baseDir)
3230
}
33-
export const createQuestionById = async (id, baseDir) => {
31+
export async function createQuestionById(id, baseDir) {
3432
const question = await getQuestionById(id)
3533
if (!question?.id) {
3634
console.log(`指定编号: [ ${id} ] 题目不存在.`)
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// 推测模式
22
export function referMode(args, opts) {
3-
if (args.length > 0 || opts.identity) return 'identity'
3+
if (args.length > 0 || opts.identity)
4+
return 'identity'
45

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

79
return 'today'
810
}

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/temExe.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export function temExe(temCommand, ...args) {
1515
return args[argIndex]
1616
})
1717
exec(command, (error, stdout, stderr) => {
18-
if (error) reject(error.message)
19-
else if (stderr) reject(stderr)
18+
if (error)
19+
reject(error.message)
20+
else if (stderr)
21+
reject(stderr)
2022
else resolve(stdout)
2123
})
2224
})

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
export function isSameData(a, b) {
88
const typeA = typeof a
99
const typeB = typeof b
10-
if (typeA !== typeB) return false
10+
if (typeA !== typeB)
11+
return false
1112
switch (typeA) {
1213
case 'bigint':
1314
case 'boolean':
@@ -19,11 +20,13 @@ export function isSameData(a, b) {
1920
case 'function':
2021
return a.toString() === b.toString()
2122
case 'object':
22-
if (a === null || a === undefined) return a === b
23+
if (a === null || a === undefined)
24+
return a === b
2325

2426
const keysA = Object.keys(a)
2527
const keysB = Object.keys(b)
26-
if (keysA.length !== keysB.length) return false
27-
return keysA.every((key) => isSameData(a[key], b[key]))
28+
if (keysA.length !== keysB.length)
29+
return false
30+
return keysA.every(key => isSameData(a[key], b[key]))
2831
}
2932
}

common/utils/functions/sizeUtil.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ export const PB = 1024 * GB
1515
* @return {size: number, label: string}
1616
*/
1717
export function getFileSizeUnit(size) {
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' }
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' }
2328

2429
return { size: PB, label: 'PB' }
2530
}

0 commit comments

Comments
 (0)