Skip to content

Commit ccfdced

Browse files
committed
chore(ui): harden ui eslint rules, fix hook basePath globs, and enable tsc typechecking
- Fix ESLint root-cwd glob matching in `cmd/ui/eslint.config.js` (`**/app/testing/**`, `**/index.html`, `**/dist/**`, `**/coverage/**`, `**/out-tsc/**`, `**/node_modules/**`), enforce `max-lines` and Angular template rules, and keep strict `no-explicit-any`/`no-unused-vars`/`unused-imports` checks enabled on tests and mocks. - Update `.githooks/pre-commit` (`check_ui`) to use safe shell arrays, run ESLint from `cmd/ui`, delegate `npm run --silent typecheck`, and cover deletes, `eslint.config.js`, `tsconfig*.json`, and `package*.json`. - Add `cmd/ui/tsconfig.e2e.json`, `npm run typecheck`, `.github/workflows/lint.yml` typecheck step, and `.vscode/settings.json` ESLint validators. TAG=agy CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
1 parent 3c236a4 commit ccfdced

6 files changed

Lines changed: 122 additions & 31 deletions

File tree

‎.githooks/pre-commit‎

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -202,50 +202,99 @@ check_ui_selector_contract() {
202202

203203

204204
check_ui() {
205-
local ui_files
206-
if [ "$MODE" = "check" ]; then
207-
ui_files=$(find cmd/ui -type f \( -name "*.ts" -o -name "*.html" -o -name "*.scss" \) -not -path "*/node_modules/*" -not -path "*/.angular/*" || true)
205+
local ui_files=()
206+
local file
207+
if [ "${MODE}" = "check" ]; then
208+
while IFS= read -r file; do
209+
if [ -n "${file}" ]; then ui_files+=("${file}"); fi
210+
done < <(find cmd/ui -type f \( -name "*.ts" -o -name "*.html" -o -name "*.scss" \) -not -path "*/node_modules/*" -not -path "*/.angular/*" -not -path "*/dist/*" -not -path "*/coverage/*" -not -path "*/out-tsc/*" | sort || true)
208211
else
209-
ui_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^cmd/ui/.*\.(ts|html|scss)$' || true)
212+
while IFS= read -r file; do
213+
if [ -n "${file}" ]; then ui_files+=("${file}"); fi
214+
done < <(git -c core.quotePath=false diff --cached --name-only --diff-filter=ACMR | grep -E '^cmd/ui/.*\.(ts|html|scss)$' || true)
215+
fi
216+
217+
local run_all_eslint=0
218+
if [ "${MODE}" = "check" ] || staged_paths_match AM '^cmd/ui/eslint\.config\.js$'; then
219+
run_all_eslint=1
210220
fi
211221

212-
if [ -z "$ui_files" ]; then
222+
local run_typecheck=0
223+
if [ "${MODE}" = "check" ] || staged_paths_match AMD '^cmd/ui/(.*\.ts|([^/]+/)*tsconfig[^/]*\.json|([^/]+/)*package(-lock)?\.json)$'; then
224+
run_typecheck=1
225+
fi
226+
227+
if [ "${#ui_files[@]}" -eq 0 ] && [ "${run_all_eslint}" -eq 0 ] && [ "${run_typecheck}" -eq 0 ]; then
213228
return
214229
fi
215230

216231
local prettier_bin="cmd/ui/node_modules/.bin/prettier"
217232
local eslint_bin="cmd/ui/node_modules/.bin/eslint"
233+
local tsc_bin="cmd/ui/node_modules/.bin/tsc"
234+
235+
if [ "${#ui_files[@]}" -gt 0 ]; then
236+
if [ -x "${prettier_bin}" ]; then
237+
echo "--> Running UI Formatter (Prettier)..."
238+
if [ "${MODE}" = "check" ]; then
239+
if ! "${prettier_bin}" --config cmd/ui/.prettierrc --check "${ui_files[@]}"; then
240+
echo "❌ Prettier check failed."
241+
FAILED=1
242+
fi
243+
else
244+
"${prettier_bin}" --config cmd/ui/.prettierrc --write "${ui_files[@]}"
245+
fi
246+
else
247+
echo "❌ ERROR: Local Prettier not found at ${prettier_bin}."
248+
echo " Please install dependencies: cd cmd/ui && npm ci --legacy-peer-deps"
249+
if [ "${MODE}" = "check" ]; then FAILED=1; fi
250+
fi
251+
fi
218252

219-
if [ -f "$prettier_bin" ]; then
220-
echo "--> Running UI Formatter (Prettier)..."
221-
if [ "$MODE" = "check" ]; then
222-
if ! $prettier_bin --config cmd/ui/.prettierrc --check $ui_files; then
223-
echo "❌ Prettier check failed."
253+
local ui_lint_files=()
254+
if [ "${#ui_files[@]}" -gt 0 ]; then
255+
for file in "${ui_files[@]}"; do
256+
case "${file}" in
257+
cmd/ui/index.html) ;;
258+
*.ts|*.html) ui_lint_files+=("${file#cmd/ui/}") ;;
259+
esac
260+
done
261+
fi
262+
263+
if [ "${run_all_eslint}" -eq 1 ] || [ "${#ui_lint_files[@]}" -gt 0 ]; then
264+
if [ -x "${eslint_bin}" ]; then
265+
echo "--> Running UI Linter (ESLint)..."
266+
local eslint_args=()
267+
if [ "${MODE}" != "check" ]; then
268+
eslint_args+=(--fix)
269+
fi
270+
if [ "${run_all_eslint}" -eq 1 ]; then
271+
eslint_args+=(.)
272+
else
273+
eslint_args+=("${ui_lint_files[@]}")
274+
fi
275+
if ! (cd cmd/ui && ./node_modules/.bin/eslint "${eslint_args[@]}"); then
276+
echo "❌ ESLint check failed."
224277
FAILED=1
225278
fi
226279
else
227-
$prettier_bin --config cmd/ui/.prettierrc --write $ui_files
280+
echo "❌ ERROR: Local ESLint not found at ${eslint_bin}."
281+
echo " Please install dependencies: cd cmd/ui && npm ci --legacy-peer-deps"
282+
if [ "${MODE}" = "check" ]; then FAILED=1; fi
228283
fi
229-
else
230-
echo "❌ ERROR: Local Prettier not found at $prettier_bin."
231-
echo " Please install dependencies: cd cmd/ui && npm ci --legacy-peer-deps"
232-
if [ "$MODE" = "check" ]; then FAILED=1; fi
233284
fi
234285

235-
if [ -f "$eslint_bin" ]; then
236-
echo "--> Running UI Linter (ESLint)..."
237-
if [ "$MODE" = "check" ]; then
238-
if ! $eslint_bin --config cmd/ui/eslint.config.js $ui_files; then
239-
echo "❌ ESLint check failed."
286+
if [ "${run_typecheck}" -eq 1 ]; then
287+
if [ -x "${tsc_bin}" ]; then
288+
echo "--> Running UI Typechecker (tsc)..."
289+
if ! (cd cmd/ui && npm run --silent typecheck); then
290+
echo "❌ UI TypeScript typecheck failed."
240291
FAILED=1
241292
fi
242293
else
243-
$eslint_bin --config cmd/ui/eslint.config.js --fix $ui_files
294+
echo "❌ ERROR: Local tsc not found at ${tsc_bin}."
295+
echo " Please install dependencies: cd cmd/ui && npm ci --legacy-peer-deps"
296+
if [ "${MODE}" = "check" ]; then FAILED=1; fi
244297
fi
245-
else
246-
echo "❌ ERROR: Local ESLint not found at $eslint_bin."
247-
echo " Please install dependencies: cd cmd/ui && npm ci --legacy-peer-deps"
248-
if [ "$MODE" = "check" ]; then FAILED=1; fi
249298
fi
250299
}
251300

‎.github/workflows/lint.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ jobs:
272272
run: npm run lint
273273
working-directory: 'cmd/ui'
274274

275+
- name: 'Run TypeScript Typecheck'
276+
if: steps.changes.outputs.ui == 'true'
277+
run: npm run typecheck
278+
working-directory: 'cmd/ui'
279+
275280
- name: 'Run ESLint on Non-UI JS Scripts'
276281
if: steps.changes.outputs.nonui_js == 'true'
277282
run: |

‎.vscode/settings.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"source.fixAll.eslint": "explicit"
77
},
88
"eslint.validate": [
9-
"typescript"
9+
"javascript",
10+
"typescript",
11+
"html"
1012
]
1113
}

‎cmd/ui/eslint.config.js‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ import eslintConfigPrettier from 'eslint-config-prettier';
2525

2626
export default tseslint.config(
2727
{
28-
ignores: ['dist/**', 'node_modules/**', 'coverage/**', '**/*.scss', '**/*.css'],
28+
ignores: [
29+
'**/dist/**',
30+
'**/node_modules/**',
31+
'**/coverage/**',
32+
'**/out-tsc/**',
33+
'**/*.scss',
34+
'**/*.css',
35+
],
2936
},
3037
{
3138
files: ['**/*.ts'],
@@ -102,6 +109,7 @@ export default tseslint.config(
102109
],
103110
},
104111
],
112+
'max-lines': ['error', { max: 300, skipBlankLines: true, skipComments: true }],
105113
'max-lines-per-function': ['error', { max: 35, skipComments: true }],
106114
complexity: ['error', { max: 10, variant: 'modified' }],
107115
'max-depth': ['error', 3],
@@ -151,14 +159,24 @@ export default tseslint.config(
151159
'**/screenshot_tests/**',
152160
],
153161
rules: {
154-
'unused-imports/no-unused-imports': 'off',
155-
'@typescript-eslint/no-explicit-any': 'off',
156-
'@typescript-eslint/no-unused-vars': 'off',
157162
'@angular-eslint/prefer-standalone': 'off',
163+
'max-lines': ['error', { max: 600, skipBlankLines: true, skipComments: true }],
158164
'max-lines-per-function': 'off',
159165
complexity: 'off',
160166
},
161167
},
168+
{
169+
files: ['**/app/testing/**', '**/*.d.ts'],
170+
rules: {
171+
'@typescript-eslint/no-explicit-any': 'off',
172+
},
173+
},
174+
{
175+
files: ['**/*.d.ts'],
176+
rules: {
177+
'@typescript-eslint/no-unused-vars': 'off',
178+
},
179+
},
162180
{
163181
files: ['**/*.ts'],
164182
ignores: [
@@ -198,7 +216,7 @@ export default tseslint.config(
198216
},
199217
{
200218
files: ['**/*.html'],
201-
ignores: ['index.html'],
219+
ignores: ['**/index.html'],
202220
languageOptions: {
203221
parser: angularTemplateParser,
204222
},
@@ -220,6 +238,13 @@ export default tseslint.config(
220238
'@angular-eslint/template/valid-aria': 'error',
221239
'@angular-eslint/template/elements-content': 'error',
222240
'@angular-eslint/template/no-positive-tabindex': 'error',
241+
'max-lines': ['error', { max: 300, skipBlankLines: true, skipComments: true }],
242+
'@angular-eslint/template/cyclomatic-complexity': ['error', { maxComplexity: 10 }],
243+
'@angular-eslint/template/conditional-complexity': ['error', { maxComplexity: 4 }],
244+
'@angular-eslint/template/no-inline-styles': ['error', { allowBindToStyle: true }],
245+
'@angular-eslint/template/no-any': 'error',
246+
'@angular-eslint/template/prefer-at-else': 'error',
247+
'@angular-eslint/template/no-interpolation-in-attributes': 'error',
223248
},
224249
},
225250
eslintConfigPrettier,

‎cmd/ui/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"test:screenshot": "playwright test",
1212
"test:screenshot:update": "playwright test --update-snapshots",
1313
"lint": "eslint .",
14+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.spec.json && tsc --noEmit -p tsconfig.e2e.json",
1415
"format": "prettier --write --ignore-path ../../.gitignore .",
1516
"format:check": "prettier --check --ignore-path ../../.gitignore ."
1617
},

‎cmd/ui/tsconfig.e2e.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"types": ["node"]
6+
},
7+
"include": ["screenshot_tests/**/*.ts", "playwright.config.ts"],
8+
"exclude": ["node_modules", "dist"]
9+
}

0 commit comments

Comments
 (0)