From aec4a3587e50b73f70bf561345d15a4175b6c15e Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Wed, 12 Nov 2025 00:04:08 +0800 Subject: [PATCH 1/3] chore: bump eslint --- .eslintignore | 5 ----- .eslintrc.json | 11 ----------- assets | 2 +- eslint.config.js | 29 +++++++++++++++++++++++++++++ lib/console/init.ts | 4 ++-- lib/hexo.ts | 4 ++-- package.json | 6 +++--- test/.eslintrc.json | 7 ------- test/scripts/console.ts | 6 +++--- test/scripts/context.ts | 6 +++--- test/scripts/help.ts | 4 ++-- test/scripts/hexo.ts | 23 ++++++++++++----------- test/scripts/init.ts | 10 +++++----- test/scripts/version.ts | 2 +- 14 files changed, 63 insertions(+), 56 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.js delete mode 100644 test/.eslintrc.json diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 383d0858..00000000 --- a/.eslintignore +++ /dev/null @@ -1,5 +0,0 @@ -node_modules/ -coverage/ -tmp/ -assets/ -dist/ \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 7f9c5fa5..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "root": true, - "extends": "hexo/ts.js", - "parserOptions": { - "sourceType": "module", - "ecmaVersion": 2020 - }, - "rules": { - "@typescript-eslint/no-var-requires": 0 - } -} \ No newline at end of file diff --git a/assets b/assets index 8d82c48e..c92a4154 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 8d82c48e0f2294fe88e7166f6dae383e3da406e6 +Subproject commit c92a4154cd5a30e5d33b09f7e5fb629ced6100d5 diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..54dc5fab --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,29 @@ +const config = require('eslint-config-hexo/ts'); +const testConfig = require('eslint-config-hexo/test'); + +module.exports = [ + // Configurations applied globally + ...config, + { + rules: { + '@typescript-eslint/no-explicit-any': 0, + '@typescript-eslint/no-var-requires': 0, + '@typescript-eslint/no-require-imports': 0 + } + }, + // Configurations applied only to test files + { + files: [ + 'test/**/*.ts' + ], + languageOptions: { + ...testConfig.languageOptions + }, + rules: { + ...testConfig.rules, + '@typescript-eslint/no-var-requires': 0, + '@typescript-eslint/ban-ts-comment': 0, + '@typescript-eslint/no-unused-expressions': 0 + } + } +]; diff --git a/lib/console/init.ts b/lib/console/init.ts index 4e15a4ae..09abe21a 100644 --- a/lib/console/init.ts +++ b/lib/console/init.ts @@ -35,7 +35,7 @@ async function initConsole(this: Context, args: InitArgs) { await spawn('git', ['clone', '--recurse-submodules', '--depth=1', '--quiet', GIT_REPO_URL, target], { stdio: 'inherit' }); - } catch (err) { + } catch { log.warn('git clone failed. Copying data instead'); await copyAsset(target); } @@ -85,7 +85,7 @@ async function initConsole(this: Context, args: InitArgs) { }); } log.info('Start blogging with Hexo!'); - } catch (err) { + } catch { log.warn(`Failed to install dependencies. Please run 'npm install' in "${target}" folder.`); } } diff --git a/lib/hexo.ts b/lib/hexo.ts index 26915c95..2d4439b9 100644 --- a/lib/hexo.ts +++ b/lib/hexo.ts @@ -7,7 +7,7 @@ import goodbye from './goodbye'; import minimist from 'minimist'; import resolve from 'resolve'; import { camelCaseKeys } from 'hexo-util'; -import registerConsole from './console'; +import registerConsole from './console/index'; import helpConsole from './console/help'; import initConsole from './console/init'; import versionConsole from './console/version'; @@ -89,7 +89,7 @@ function watchSignal(hexo: Context) { hexo.unwatch(); hexo.exit().then(() => { - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line n/no-process-exit process.exit(); }); }); diff --git a/package.json b/package.json index 2602aa95..48441f78 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "prepublishOnly": "npm install && npm run clean && npm run build", "build": "tsc -b", "clean": "tsc -b --clean", - "eslint": "eslint .", + "eslint": "eslint lib test", "pretest": "npm run clean && npm run build", "test": "mocha test/**/*.ts --require ts-node/register", "test-cov": "nyc --reporter=lcovonly npm test", @@ -64,8 +64,8 @@ "@types/rewire": "^2.5.30", "@types/sinon": "^17.0.3", "chai": "^4.3.4", - "eslint": "^8.2.0", - "eslint-config-hexo": "^5.0.0", + "eslint": "^9.39.1", + "eslint-config-hexo": "^6.0.0", "hexo-renderer-marked": "^6.0.0", "mocha": "^11.7.5", "nyc": "^15.1.0", diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index 44ee061d..00000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "hexo/ts-test", - "rules": { - "@typescript-eslint/no-var-requires": 0, - "@typescript-eslint/ban-ts-comment": 0 - } -} diff --git a/test/scripts/console.ts b/test/scripts/console.ts index fa5b9bd7..ddfa9792 100644 --- a/test/scripts/console.ts +++ b/test/scripts/console.ts @@ -9,7 +9,7 @@ describe('console', () => { try { // @ts-expect-error consoleExtend.register(); - } catch (err) { + } catch (err: any) { err.should.have.property('message', 'name is required'); } }); @@ -19,7 +19,7 @@ describe('console', () => { try { // @ts-expect-error consoleExtend.register('test', 'fn'); - } catch (err) { + } catch (err: any) { err.should.have.property('message', 'fn must be a function'); } }); @@ -29,7 +29,7 @@ describe('console', () => { try { // @ts-expect-error consoleExtend.register('test', 'desc', 'fn'); - } catch (err) { + } catch (err: any) { err.should.have.property('message', 'fn must be a function'); } }); diff --git a/test/scripts/context.ts b/test/scripts/context.ts index 2540062d..16266e56 100644 --- a/test/scripts/context.ts +++ b/test/scripts/context.ts @@ -26,7 +26,7 @@ describe('context', () => { try { await hexo.call('wtf'); should.fail(); - } catch (err) { + } catch (err: any) { err.should.have.property('message', 'Console `wtf` has not been registered yet!'); } }); @@ -46,7 +46,7 @@ describe('context', () => { }); it('with callback but no args', done => { - hexo.call('test', err => { + hexo.call('test', (err: any) => { if (err) return done(err); spy.calledOnce.should.be.true; @@ -57,7 +57,7 @@ describe('context', () => { }); describe('exit', () => { - let hexo, fatal; + let hexo: Context, fatal: any; beforeEach(() => { hexo = new Context(); diff --git a/test/scripts/help.ts b/test/scripts/help.ts index 251a730c..2f3a1df1 100644 --- a/test/scripts/help.ts +++ b/test/scripts/help.ts @@ -5,10 +5,10 @@ import { join } from 'path'; import { format } from 'util'; import rewire from 'rewire'; import Context from '../../lib/context'; -import console from '../../lib/console'; +import console from '../../lib/console/index'; chai.should(); -function getConsoleLog({ args }) { +function getConsoleLog({ args }: { args: any[] }) { return args.map(arr => format(...arr)).join('\n'); } diff --git a/test/scripts/hexo.ts b/test/scripts/hexo.ts index 11e5ceae..2a910109 100644 --- a/test/scripts/hexo.ts +++ b/test/scripts/hexo.ts @@ -2,6 +2,7 @@ import chai from 'chai'; import sinon from 'sinon'; import rewire from 'rewire'; import ConsoleExtend from '../../lib/extend/console'; +import type Context from '../../lib/context'; chai.should(); require('chai').should(); @@ -14,7 +15,7 @@ describe('hexo', () => { const hexo = rewire('../../dist/hexo'); return hexo.__with__({ console_1: { - default: ctx => { + default: (ctx: Context) => { ctx.extend.console.register('help', spy); } } @@ -30,7 +31,7 @@ describe('hexo', () => { const hexo = rewire('../../dist/hexo'); return hexo.__with__({ console_1: { - default: ctx => { + default: (ctx: Context) => { ctx.extend.console.register('test', spy); } } @@ -46,7 +47,7 @@ describe('hexo', () => { const hexo = rewire('../../dist/hexo'); return hexo.__with__({ console_1: { - default: ctx => { + default: (ctx: Context) => { ctx.extend.console.register('help', spy); } } @@ -58,11 +59,11 @@ describe('hexo', () => { }); it('path - number (issue hexo#4334)', async () => { - let args; + let args: Record; const hexo = rewire('../../dist/hexo'); return hexo.__with__({ find_pkg_1: { - default: (_cwd, _args) => { + default: (_cwd: string, _args: { cwd?: string }) => { args = _args; return Promise.resolve(); } @@ -77,11 +78,11 @@ describe('hexo', () => { }); it('p - number (issue hexo#4334)', async () => { - let args; + let args: Record; const hexo = rewire('../../dist/hexo'); return hexo.__with__({ find_pkg_1: { - default: (_cwd, _args) => { + default: (_cwd: string, _args: { cwd?: string }) => { args = _args; return Promise.resolve(); } @@ -96,11 +97,11 @@ describe('hexo', () => { }); it('slug - number (issue hexo#4334)', async () => { - let args; + let args: Record; const hexo = rewire('../../dist/hexo'); return hexo.__with__({ find_pkg_1: { - default: (_cwd, _args) => { + default: (_cwd: string, _args: { cwd?: string }) => { args = _args; return Promise.resolve(); } @@ -115,11 +116,11 @@ describe('hexo', () => { }); it('s - number (issue hexo#4334)', async () => { - let args; + let args: Record; const hexo = rewire('../../dist/hexo'); return hexo.__with__({ find_pkg_1: { - default: (_cwd, _args) => { + default: (_cwd: string, _args: { cwd?: string }) => { args = _args; return Promise.resolve(); } diff --git a/test/scripts/init.ts b/test/scripts/init.ts index 8886715b..fdcee2eb 100644 --- a/test/scripts/init.ts +++ b/test/scripts/init.ts @@ -18,13 +18,13 @@ describe('init', () => { async function rmDir(path: string) { try { await rmdir(path); - } catch (err) { + } catch (err: any) { if (err && err.code === 'ENOENT') return; throw err; } } - function pipeStream(rs, ws) { + function pipeStream(rs: ReturnType, ws: ReturnType) { return new Promise((resolve, reject) => { rs.pipe(ws) .on('error', reject) @@ -32,7 +32,7 @@ describe('init', () => { }); } - async function compareFile(a, b) { + async function compareFile(a: string, b: string) { const streamA = createSha1Hash(); const streamB = createSha1Hash(); @@ -44,7 +44,7 @@ describe('init', () => { return streamA.read().equals(streamB.read()); } - async function check(path) { + async function check(path: string) { for (const item of assets) { const result = await compareFile( join(assetDir, item), @@ -56,7 +56,7 @@ describe('init', () => { } - function withoutSpawn(fn) { + function withoutSpawn(fn: () => Promise) { return initModule.__with__({ 'spawn_1': () => Promise.reject(new Error('spawn is not available')) })(fn); diff --git a/test/scripts/version.ts b/test/scripts/version.ts index 44ceaa5b..11b65c58 100644 --- a/test/scripts/version.ts +++ b/test/scripts/version.ts @@ -8,7 +8,7 @@ import rewire from 'rewire'; import { spawn } from 'hexo-util'; chai.should(); -function getConsoleLog({ args }) { +function getConsoleLog({ args }: { args: any[] }) { return args.map(arr => format(...arr)).join('\n'); } From cf4dccab76f3ae0d83e22b77c98686fe3cfc99ee Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Wed, 12 Nov 2025 00:10:11 +0800 Subject: [PATCH 2/3] fix: test --- lib/hexo.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/hexo.ts b/lib/hexo.ts index 2d4439b9..810f840c 100644 --- a/lib/hexo.ts +++ b/lib/hexo.ts @@ -7,7 +7,8 @@ import goodbye from './goodbye'; import minimist from 'minimist'; import resolve from 'resolve'; import { camelCaseKeys } from 'hexo-util'; -import registerConsole from './console/index'; +// eslint-disable-next-line n/no-missing-import +import registerConsole from './console'; import helpConsole from './console/help'; import initConsole from './console/init'; import versionConsole from './console/version'; From b3cac4bdddc6032e54139d6752dbd749a3ca8851 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Wed, 12 Nov 2025 00:13:14 +0800 Subject: [PATCH 3/3] chore: update dependencies to latest versions --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 48441f78..36f43d50 100644 --- a/package.json +++ b/package.json @@ -45,9 +45,9 @@ "abbrev": "^2.0.0", "bluebird": "^3.7.2", "command-exists": "^1.2.9", - "hexo-fs": "^4.1.1", + "hexo-fs": "^5.0.1", "hexo-log": "^4.0.1", - "hexo-util": "^3.3.0", + "hexo-util": "^4.0.0", "minimist": "^1.2.5", "picocolors": "^1.0.0", "resolve": "^1.20.0", @@ -66,7 +66,7 @@ "chai": "^4.3.4", "eslint": "^9.39.1", "eslint-config-hexo": "^6.0.0", - "hexo-renderer-marked": "^6.0.0", + "hexo-renderer-marked": "^7.0.1", "mocha": "^11.7.5", "nyc": "^15.1.0", "rewire": "^9.0.1",