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
5 files changed
+1949 -1925

No files matched your search

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