Refactor ESLint config for improved readability

Reformatted the ESLint configuration file to use consistent array/object formatting and removed unnecessary quotes from rule names. No functional changes were made; this improves maintainability and clarity. Other config files had only minor formatting updates.
This commit is contained in:
xixu-me committed 2025-07-25 12:01:29 +08:00
1 parent 782fb3492d
commit 78ebc49a4b
6 files changed
+5024 -5000

No files matched your search

+120 -68
View File
@@ -33,19 +33,25 @@ export default [
}, },
rules: { rules: {
// Code quality rules // Code quality rules
'no-unused-vars': ['error', { 'no-unused-vars': [
argsIgnorePattern: '^_', 'error',
varsIgnorePattern: '^_' {
}], argsIgnorePattern: '^_',
'no-console': ['warn', { varsIgnorePattern: '^_'
allow: ['warn', 'error'] }
}], ],
'no-console': [
'warn',
{
allow: ['warn', 'error']
}
],
'no-debugger': 'error', 'no-debugger': 'error',
'no-alert': 'error', 'no-alert': 'error',
// Best practices // Best practices
'eqeqeq': ['error', 'always'], eqeqeq: ['error', 'always'],
'curly': ['error', 'all'], curly: ['error', 'all'],
'no-eval': 'error', 'no-eval': 'error',
'no-implied-eval': 'error', 'no-implied-eval': 'error',
'no-new-func': 'error', 'no-new-func': 'error',
@@ -59,8 +65,8 @@ export default [
'no-useless-concat': 'error', 'no-useless-concat': 'error',
'no-useless-return': 'error', 'no-useless-return': 'error',
'prefer-promise-reject-errors': 'error', 'prefer-promise-reject-errors': 'error',
'radix': 'error', radix: 'error',
'yoda': 'error', yoda: 'error',
// Variables // Variables
'no-delete-var': 'error', 'no-delete-var': 'error',
@@ -70,74 +76,116 @@ export default [
'no-shadow-restricted-names': 'error', 'no-shadow-restricted-names': 'error',
'no-undef': 'error', 'no-undef': 'error',
'no-undef-init': 'error', 'no-undef-init': 'error',
'no-use-before-define': ['error', { 'no-use-before-define': [
functions: false, 'error',
classes: true, {
variables: true functions: false,
}], classes: true,
variables: true
}
],
// Stylistic issues // Stylistic issues
'array-bracket-spacing': ['error', 'never'], 'array-bracket-spacing': ['error', 'never'],
'block-spacing': ['error', 'always'], 'block-spacing': ['error', 'always'],
'brace-style': ['error', '1tbs', { 'brace-style': [
allowSingleLine: true 'error',
}], '1tbs',
'camelcase': ['error', { {
properties: 'never' allowSingleLine: true
}], }
],
camelcase: [
'error',
{
properties: 'never'
}
],
'comma-dangle': ['error', 'never'], 'comma-dangle': ['error', 'never'],
'comma-spacing': ['error', { 'comma-spacing': [
before: false, 'error',
after: true {
}], before: false,
after: true
}
],
'comma-style': ['error', 'last'], 'comma-style': ['error', 'last'],
'computed-property-spacing': ['error', 'never'], 'computed-property-spacing': ['error', 'never'],
'eol-last': ['error', 'always'], 'eol-last': ['error', 'always'],
'func-call-spacing': ['error', 'never'], 'func-call-spacing': ['error', 'never'],
'indent': ['error', 2, { indent: [
SwitchCase: 1 'error',
}], 2,
'key-spacing': ['error', { {
beforeColon: false, SwitchCase: 1
afterColon: true }
}], ],
'keyword-spacing': ['error', { 'key-spacing': [
before: true, 'error',
after: true {
}], beforeColon: false,
afterColon: true
}
],
'keyword-spacing': [
'error',
{
before: true,
after: true
}
],
'linebreak-style': ['error', 'unix'], 'linebreak-style': ['error', 'unix'],
'no-multiple-empty-lines': ['error', { 'no-multiple-empty-lines': [
max: 2, 'error',
maxEOF: 1 {
}], max: 2,
maxEOF: 1
}
],
'no-trailing-spaces': 'error', 'no-trailing-spaces': 'error',
'object-curly-spacing': ['error', 'always'], 'object-curly-spacing': ['error', 'always'],
'quotes': ['error', 'single', { quotes: [
avoidEscape: true 'error',
}], 'single',
'semi': ['error', 'always'], {
'semi-spacing': ['error', { avoidEscape: true
before: false, }
after: true ],
}], semi: ['error', 'always'],
'semi-spacing': [
'error',
{
before: false,
after: true
}
],
'space-before-blocks': ['error', 'always'], 'space-before-blocks': ['error', 'always'],
'space-before-function-paren': ['error', { 'space-before-function-paren': [
anonymous: 'always', 'error',
named: 'never', {
asyncArrow: 'always' anonymous: 'always',
}], named: 'never',
asyncArrow: 'always'
}
],
'space-in-parens': ['error', 'never'], 'space-in-parens': ['error', 'never'],
'space-infix-ops': 'error', 'space-infix-ops': 'error',
'space-unary-ops': ['error', { 'space-unary-ops': [
words: true, 'error',
nonwords: false {
}], words: true,
nonwords: false
}
],
// ES6+ rules // ES6+ rules
'arrow-spacing': ['error', { 'arrow-spacing': [
before: true, 'error',
after: true {
}], before: true,
after: true
}
],
'constructor-super': 'error', 'constructor-super': 'error',
'no-class-assign': 'error', 'no-class-assign': 'error',
'no-const-assign': 'error', 'no-const-assign': 'error',
@@ -152,12 +200,16 @@ export default [
'object-shorthand': ['error', 'always'], 'object-shorthand': ['error', 'always'],
'prefer-arrow-callback': 'error', 'prefer-arrow-callback': 'error',
'prefer-const': 'error', 'prefer-const': 'error',
'prefer-destructuring': ['error', { 'prefer-destructuring': [
array: true, 'error',
object: true {
}, { array: true,
enforceForRenamedProperties: false object: true
}], },
{
enforceForRenamedProperties: false
}
],
'prefer-rest-params': 'error', 'prefer-rest-params': 'error',
'prefer-spread': 'error', 'prefer-spread': 'error',
'prefer-template': 'error', 'prefer-template': 'error',
+4828 -4828
View File
File diff suppressed because it is too large. Load diff
+29 -29
View File
@@ -1,31 +1,31 @@
{ {
"dependencies": { "dependencies": {
"xget": "file:" "xget": "file:"
}, },
"devDependencies": { "devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.8.36", "@cloudflare/vitest-pool-workers": "^0.8.36",
"@cloudflare/workers-types": "^4.20250724.0", "@cloudflare/workers-types": "^4.20250724.0",
"eslint": "^9.31.0", "eslint": "^9.31.0",
"prettier": "^3.6.2", "prettier": "^3.6.2",
"vitest": "^3.1.4", "vitest": "^3.1.4",
"wrangler": "^4.26.0" "wrangler": "^4.26.0"
}, },
"name": "xget", "name": "xget",
"private": true, "private": true,
"scripts": { "scripts": {
"deploy": "wrangler deploy", "deploy": "wrangler deploy",
"dev": "wrangler dev", "dev": "wrangler dev",
"format": "prettier --write src/ test/ *.js *.json *.md", "format": "prettier --write src/ test/ *.js *.json *.md",
"format:check": "prettier --check src/ test/ *.js *.json *.md", "format:check": "prettier --check src/ test/ *.js *.json *.md",
"lint": "eslint src/ test/", "lint": "eslint src/ test/",
"lint:fix": "eslint src/ test/ --fix", "lint:fix": "eslint src/ test/ --fix",
"start": "wrangler dev", "start": "wrangler dev",
"test": "vitest", "test": "vitest",
"test:coverage": "vitest run --coverage", "test:coverage": "vitest run --coverage",
"test:run": "vitest run", "test:run": "vitest run",
"test:ui": "vitest --ui", "test:ui": "vitest --ui",
"test:watch": "vitest --watch", "test:watch": "vitest --watch",
"type-check": "tsc --noEmit" "type-check": "tsc --noEmit"
}, },
"version": "1.0.0" "version": "1.0.0"
} }
+16 -31
View File
@@ -78,11 +78,7 @@ async function main() {
async function runTests(args = []) { async function runTests(args = []) {
console.log('🏃 Running tests...'); console.log('🏃 Running tests...');
const vitestArgs = [ const vitestArgs = ['run', '--config', 'vitest.config.js', ...args];
'run',
'--config', 'vitest.config.js',
...args
];
await runCommand('npx', ['vitest', ...vitestArgs]); await runCommand('npx', ['vitest', ...vitestArgs]);
} }
@@ -93,11 +89,7 @@ async function runTests(args = []) {
async function watchTests(args = []) { async function watchTests(args = []) {
console.log('👀 Watching tests...'); console.log('👀 Watching tests...');
const vitestArgs = [ const vitestArgs = ['--config', 'vitest.config.js', '--watch', ...args];
'--config', 'vitest.config.js',
'--watch',
...args
];
await runCommand('npx', ['vitest', ...vitestArgs]); await runCommand('npx', ['vitest', ...vitestArgs]);
} }
@@ -108,12 +100,7 @@ async function watchTests(args = []) {
async function runCoverage(args = []) { async function runCoverage(args = []) {
console.log('📊 Generating coverage report...'); console.log('📊 Generating coverage report...');
const vitestArgs = [ const vitestArgs = ['run', '--config', 'vitest.config.js', '--coverage', ...args];
'run',
'--config', 'vitest.config.js',
'--coverage',
...args
];
await runCommand('npx', ['vitest', ...vitestArgs]); await runCommand('npx', ['vitest', ...vitestArgs]);
@@ -129,11 +116,7 @@ async function runCoverage(args = []) {
async function runBenchmarks(args = []) { async function runBenchmarks(args = []) {
console.log('⚡ Running performance benchmarks...'); console.log('⚡ Running performance benchmarks...');
const vitestArgs = [ const vitestArgs = ['bench', '--config', 'vitest.config.js', ...args];
'bench',
'--config', 'vitest.config.js',
...args
];
await runCommand('npx', ['vitest', ...vitestArgs]); await runCommand('npx', ['vitest', ...vitestArgs]);
} }
@@ -205,10 +188,7 @@ async function setupTestEnvironment() {
version: process.env.npm_package_version || '1.0.0' version: process.env.npm_package_version || '1.0.0'
}; };
writeFileSync( writeFileSync(join(rootDir, 'test/config.json'), JSON.stringify(testConfig, null, 2));
join(rootDir, 'test/config.json'),
JSON.stringify(testConfig, null, 2)
);
console.log('✅ Test environment setup completed'); console.log('✅ Test environment setup completed');
} }
@@ -248,9 +228,15 @@ async function generateCoverageSummary() {
const total = coverage.total; const total = coverage.total;
console.log(`Lines: ${total.lines.pct}% (${total.lines.covered}/${total.lines.total})`); console.log(`Lines: ${total.lines.pct}% (${total.lines.covered}/${total.lines.total})`);
console.log(`Functions: ${total.functions.pct}% (${total.functions.covered}/${total.functions.total})`); console.log(
console.log(`Branches: ${total.branches.pct}% (${total.branches.covered}/${total.branches.total})`); `Functions: ${total.functions.pct}% (${total.functions.covered}/${total.functions.total})`
console.log(`Statements: ${total.statements.pct}% (${total.statements.covered}/${total.statements.total})`); );
console.log(
`Branches: ${total.branches.pct}% (${total.branches.covered}/${total.branches.total})`
);
console.log(
`Statements: ${total.statements.pct}% (${total.statements.covered}/${total.statements.total})`
);
// Check if coverage meets threshold // Check if coverage meets threshold
const threshold = TEST_CONFIG.coverage.threshold; const threshold = TEST_CONFIG.coverage.threshold;
@@ -280,7 +266,7 @@ function runCommand(command, args = [], options = {}) {
...options ...options
}); });
child.on('close', (code) => { child.on('close', code => {
if (code === 0) { if (code === 0) {
resolve(); resolve();
} else { } else {
@@ -288,7 +274,7 @@ function runCommand(command, args = [], options = {}) {
} }
}); });
child.on('error', (error) => { child.on('error', error => {
reject(error); reject(error);
}); });
}); });
@@ -332,4 +318,3 @@ if (import.meta.url === `file://${process.argv[1]}`) {
} }
export { main, runBenchmarks, runCoverage, runTests }; export { main, runBenchmarks, runCoverage, runTests };
+15 -25
View File
@@ -1,27 +1,17 @@
{ {
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"esModuleInterop": true, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"module": "ESNext", "module": "ESNext",
"moduleResolution": "node", "moduleResolution": "node",
"noEmit": true, "noEmit": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": true, "strict": true,
"target": "ES2022", "target": "ES2022",
"types": [ "types": ["@cloudflare/workers-types", "vitest/globals"]
"@cloudflare/workers-types", },
"vitest/globals" "exclude": ["node_modules", "dist", "coverage"],
] "include": ["src/**/*", "test/**/*"]
},
"exclude": [
"node_modules",
"dist",
"coverage"
],
"include": [
"src/**/*",
"test/**/*"
]
} }
+16 -19
View File
@@ -1,36 +1,33 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'; import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersConfig({ export default defineWorkersConfig({
test: { test: {
poolOptions: { poolOptions: {
workers: { workers: {
wrangler: { configPath: './wrangler.toml' }, wrangler: { configPath: "./wrangler.toml" },
}, },
}, },
coverage: { coverage: {
provider: 'v8', provider: "v8",
reporter: ['text', 'json', 'html', 'lcov'], reporter: ["text", "json", "html", "lcov"],
reportsDirectory: './coverage', reportsDirectory: "./coverage",
exclude: [ exclude: [
'node_modules/**', "node_modules/**",
'test/**', "test/**",
'coverage/**', "coverage/**",
'dist/**', "dist/**",
'*.config.js', "*.config.js",
'*.config.ts' "*.config.ts",
],
include: [
'src/**/*.js',
'src/**/*.ts'
], ],
include: ["src/**/*.js", "src/**/*.ts"],
thresholds: { thresholds: {
global: { global: {
branches: 80, branches: 80,
functions: 80, functions: 80,
lines: 80, lines: 80,
statements: 80 statements: 80,
} },
} },
} },
}, },
}); });