Skip to content

Commit 5ccdca5

Browse files
authored
Merge pull request #749 from SlideRuleEarth/carlos-dev4
Carlos dev4 Major update for log refactor, auto ESLinter
2 parents 48bc56b + cc2a684 commit 5ccdca5

File tree

182 files changed

+24438
-21493
lines changed

Some content is hidden

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

182 files changed

+24438
-21493
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ lint-fix: ## Run ESLint with auto-fix
172172
lint-staged: ## Run lint-staged on staged files (used by pre-commit hook)
173173
cd web-client && npx lint-staged
174174

175-
pre-commit-check: lint-staged ## Manually run pre-commit checks without committing
175+
pre-commit-check: ## Manually run pre-commit checks without committing
176+
cd web-client && npx lint-staged && npm run typecheck && npm run test:unit
176177
@echo "✅ Pre-commit checks passed!"
177178

178179
test-unit: ## Run Vitest unit tests (CI-friendly)

web-client/.eslintrc.cjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,25 @@ module.exports = {
2424
// Warn about async functions that don't use await
2525
'require-await': 'warn',
2626
// Require functions that return promises to be marked async
27-
'@typescript-eslint/promise-function-async': 'warn'
27+
'@typescript-eslint/promise-function-async': 'warn',
28+
// Allow unused vars that start with _
29+
'no-unused-vars': ['error', {
30+
argsIgnorePattern: '^_',
31+
varsIgnorePattern: '^_'
32+
}],
33+
'@typescript-eslint/no-unused-vars': ['error', {
34+
argsIgnorePattern: '^_',
35+
varsIgnorePattern: '^_'
36+
}]
2837
},
2938
overrides: [
3039
{
3140
files: ['tests/**/*.{ts,tsx,js,jsx}'],
3241
env: {
3342
node: true
43+
},
44+
globals: {
45+
globalThis: 'readonly'
3446
}
3547
}
3648
]

web-client/.husky/pre-commit

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
npm test
1+
#!/bin/sh
2+
npx lint-staged && npm run typecheck && npm run test:unit

web-client/fix-unused-vars.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env node
2+
const { exec } = require('child_process');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
// Get ESLint errors
7+
exec('ESLINT_USE_FLAT_CONFIG=false npx eslint src/ --ext .vue,.js,.jsx,.ts,.tsx --format=json', (error, stdout) => {
8+
const results = JSON.parse(stdout);
9+
const fixes = new Map();
10+
11+
results.forEach(result => {
12+
const filePath = result.filePath;
13+
const messages = result.messages.filter(m =>
14+
m.ruleId === 'no-unused-vars' || m.ruleId === '@typescript-eslint/no-unused-vars'
15+
);
16+
17+
messages.forEach(msg => {
18+
const match = msg.message.match(/'([^']+)' is (defined|assigned)/);
19+
if (match) {
20+
const varName = match[1];
21+
// Skip if already starts with underscore
22+
if (!varName.startsWith('_')) {
23+
if (!fixes.has(filePath)) {
24+
fixes.set(filePath, []);
25+
}
26+
fixes.set(filePath, [...fixes.get(filePath), { line: msg.line, varName }]);
27+
}
28+
}
29+
});
30+
});
31+
32+
console.log(`Found ${fixes.size} files with unused variables to fix`);
33+
34+
// Apply fixes
35+
let totalFixed = 0;
36+
fixes.forEach((varList, filePath) => {
37+
let content = fs.readFileSync(filePath, 'utf8');
38+
const lines = content.split('\n');
39+
40+
// Group by unique var names
41+
const uniqueVars = [...new Set(varList.map(v => v.varName))];
42+
43+
uniqueVars.forEach(varName => {
44+
// Use regex to replace variable declarations/parameters
45+
// Match various patterns: const varName, let varName, varName:, (varName), {varName}
46+
const patterns = [
47+
// Function parameters
48+
new RegExp(`\\(([^)]*)\\b${varName}\\b([^)]*)\\)`, 'g'),
49+
// Destructuring
50+
new RegExp(`\\{([^}]*)\\b${varName}\\b([^}]*)\\}`, 'g'),
51+
// Array destructuring
52+
new RegExp(`\\[([^\\]]*)\\b${varName}\\b([^\\]]*)\\]`, 'g'),
53+
// Variable declarations
54+
new RegExp(`\\b(const|let|var)\\s+${varName}\\b`, 'g'),
55+
// Type annotations
56+
new RegExp(`\\b${varName}\\s*:`, 'g'),
57+
];
58+
59+
patterns.forEach(pattern => {
60+
content = content.replace(pattern, (match) => {
61+
return match.replace(new RegExp(`\\b${varName}\\b`), `_${varName}`);
62+
});
63+
});
64+
});
65+
66+
fs.writeFileSync(filePath, content);
67+
totalFixed += uniqueVars.length;
68+
console.log(`Fixed ${uniqueVars.length} variables in ${path.basename(filePath)}`);
69+
});
70+
71+
console.log(`\nTotal: Fixed ${totalFixed} unused variables in ${fixes.size} files`);
72+
});

web-client/package-lock.json

Lines changed: 63 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-client/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"dev": "vite",
1515
"build-only": "vite build",
1616
"typecheck": "vue-tsc --noEmit -p tsconfig.app.json",
17-
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
18-
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
17+
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint src tests --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
18+
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint src tests --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
1919
"preview": "vite preview",
2020
"build": "run-p \"build-only {@}\" --",
2121
"build_with_maps": "VITE_BUILD_SOURCEMAP=true run-p \"build-only {@}\" --",
@@ -45,9 +45,10 @@
4545
"echarts-gl": "^2.0.9",
4646
"events": "^3.3.0",
4747
"highlight.js": "^11.11.1",
48-
"intro.js": "^8.3.1",
48+
"intro.js": "^8.3.2",
4949
"jszip": "^3.10.1",
5050
"lodash-es": "^4.17.21",
51+
"loglevel": "^1.9.2",
5152
"mitt": "^3.0.1",
5253
"ol": "^10.6.0",
5354
"ol-contextmenu": "^5.5.0",
@@ -57,7 +58,7 @@
5758
"pinia-plugin-persistedstate": "^4.0.1",
5859
"primeflex": "^3.3.1",
5960
"primeicons": "^7.0.0",
60-
"primevue": "^4.3.2",
61+
"primevue": "^4.4.1",
6162
"sharp": "^0.34.3",
6263
"shpjs": "^6.1.0",
6364
"vue": "^3.5.6",

0 commit comments

Comments
 (0)