Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ jobs:
run: npm run lint
working-directory: 'cmd/ui'

- name: 'Run TypeScript Typecheck'
if: steps.changes.outputs.ui == 'true'
run: npm run typecheck
working-directory: 'cmd/ui'

- name: 'Run ESLint on Non-UI JS Scripts'
if: github.event_name == 'workflow_dispatch' || steps.changes.outputs.nonui_js == 'true'
run: |
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"typescript"
"javascript",
"typescript",
"html"
]
}
28 changes: 24 additions & 4 deletions cmd/ui/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ import eslintConfigPrettier from 'eslint-config-prettier';

export default tseslint.config(
{
ignores: ['dist/**', 'node_modules/**', 'coverage/**', '**/*.scss', '**/*.css'],
ignores: [
'**/dist/**',
'**/node_modules/**',
'**/coverage/**',
'**/out-tsc/**',
'**/*.scss',
'**/*.css',
],
},
{
files: ['**/*.ts'],
Expand Down Expand Up @@ -102,6 +109,7 @@ export default tseslint.config(
],
},
],
'max-lines': ['error', { max: 300, skipBlankLines: true, skipComments: true }],
'max-lines-per-function': ['error', { max: 35, skipComments: true }],
complexity: ['error', { max: 10, variant: 'modified' }],
'max-depth': ['error', 3],
Expand Down Expand Up @@ -151,9 +159,8 @@ export default tseslint.config(
'**/screenshot_tests/**',
],
rules: {
'unused-imports/no-unused-imports': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@angular-eslint/prefer-standalone': 'off',
'max-lines': ['error', { max: 600, skipBlankLines: true, skipComments: true }],
'max-lines-per-function': 'off',
complexity: 'off',
},
Expand All @@ -164,6 +171,12 @@ export default tseslint.config(
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['**/*.ts'],
ignores: [
Expand Down Expand Up @@ -203,7 +216,7 @@ export default tseslint.config(
},
{
files: ['**/*.html'],
ignores: ['index.html'],
ignores: ['**/index.html'],
languageOptions: {
parser: angularTemplateParser,
},
Expand All @@ -225,6 +238,13 @@ export default tseslint.config(
'@angular-eslint/template/valid-aria': 'error',
'@angular-eslint/template/elements-content': 'error',
'@angular-eslint/template/no-positive-tabindex': 'error',
'max-lines': ['error', { max: 300, skipBlankLines: true, skipComments: true }],
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
'@angular-eslint/template/cyclomatic-complexity': ['error', { maxComplexity: 10 }],
'@angular-eslint/template/conditional-complexity': ['error', { maxComplexity: 4 }],
'@angular-eslint/template/no-inline-styles': ['error', { allowBindToStyle: true }],
'@angular-eslint/template/no-any': 'error',
'@angular-eslint/template/prefer-at-else': 'error',
'@angular-eslint/template/no-interpolation-in-attributes': 'error',
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
},
},
eslintConfigPrettier,
Expand Down
1 change: 1 addition & 0 deletions cmd/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test:screenshot": "playwright test",
"test:screenshot:update": "playwright test --update-snapshots",
"lint": "eslint .",
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.spec.json && tsc --noEmit -p tsconfig.e2e.json",
"format": "prettier --write --ignore-path ../../.gitignore .",
"format:check": "prettier --check --ignore-path ../../.gitignore ."
},
Expand Down
9 changes: 9 additions & 0 deletions cmd/ui/tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"types": ["node"]
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
},
"include": ["screenshot_tests/**/*.ts", "playwright.config.ts"],
"exclude": ["node_modules", "dist"]
}
86 changes: 64 additions & 22 deletions tools/lint/precommit_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,73 @@ def check_go(ctx: gates.RunContext) -> None:
)


_UI_EXCLUDES = gates.COMMON_EXCLUDES | frozenset({"dist", "coverage", "out-tsc"})
_UI_TYPECHECK_PATTERN = (
r"^cmd/ui/(.*\.ts|([^/]+/)*tsconfig[^/]*\.json|([^/]+/)*package(-lock)?\.json)$"
)


def _run_ui_eslint(ctx: gates.RunContext, ui_files: Sequence[str], *, run_all_eslint: bool) -> None:
ui_lint_files = [
f.removeprefix("cmd/ui/")
for f in ui_files
if f != "cmd/ui/index.html" and f.endswith((".ts", ".html"))
]
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
if not run_all_eslint and not ui_lint_files:
return
eslint = gates.resolve_ui_binary(ctx, "eslint")
if not eslint:
return
print("--> Running UI Linter (ESLint)...")
targets = ["."] if run_all_eslint else ui_lint_files
gates.run_mode_command(
ctx,
[eslint],
check_args=[],
fix_args=["--fix"],
failure_msg="ESLint check failed.",
cwd=gates.REPO_ROOT / "cmd/ui",
files=targets,
chunk_size=200,
)


def check_ui(ctx: gates.RunContext) -> None:
"""Runs Prettier and ESLint on Angular UI sources."""
files = gates.collect_target_files(
ctx.mode,
staged_regex=r"^cmd/ui/.*\.(ts|html|scss)$",
roots=("cmd/ui",),
suffixes=(".ts", ".html", ".scss"),
"""Runs Prettier, ESLint (cwd=`cmd/ui`), and `tsc` typecheck on Angular UI sources."""
if ctx.mode == "check":
ui_files = gates.walk_repo_files(
("cmd/ui",), suffixes=(".ts", ".html", ".scss"), excluded_dirs=_UI_EXCLUDES
)
else:
regex = re.compile(r"^cmd/ui/.*\.(ts|html|scss)$")
ui_files = [p for p in gates.git_staged_paths("ACMR") if regex.search(p)]
run_all_eslint = ctx.mode == "check" or gates.staged_paths_match(
"AM", r"^cmd/ui/eslint\.config\.js$"
)
if not files:
run_typecheck = ctx.mode == "check" or gates.staged_paths_match("AMD", _UI_TYPECHECK_PATTERN)
if not ui_files and not run_all_eslint and not run_typecheck:
return
for tool, cfg, chk, fx, title in (
("prettier", "cmd/ui/.prettierrc", ["--check"], ["--write"], "Formatter (Prettier)"),
("eslint", "cmd/ui/eslint.config.js", [], ["--fix"], "Linter (ESLint)"),
):
if binary := gates.resolve_ui_binary(ctx, tool):
print(f"--> Running UI {title}...")
gates.run_mode_command(
ctx,
[binary, "--config", cfg],
check_args=chk,
fix_args=fx,
failure_msg=f"{tool.capitalize()} check failed.",
files=files,
chunk_size=200,
)
if ui_files and (prettier := gates.resolve_ui_binary(ctx, "prettier")):
print("--> Running UI Formatter (Prettier)...")
gates.run_mode_command(
ctx,
[prettier, "--config", "cmd/ui/.prettierrc"],
check_args=["--check"],
fix_args=["--write"],
failure_msg="Prettier check failed.",
files=ui_files,
chunk_size=200,
)
_run_ui_eslint(ctx, ui_files, run_all_eslint=run_all_eslint)
if run_typecheck and gates.resolve_ui_binary(ctx, "tsc"):
print("--> Running UI Typechecker (tsc)...")
if (
gates.exec_cmd(
["npm", "run", "--silent", "typecheck"], cwd=gates.REPO_ROOT / "cmd/ui"
).returncode
!= 0
):
ctx.fail("UI TypeScript typecheck failed.")
Comment on lines +180 to +188

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of invoking npm run --silent typecheck which introduces significant startup overhead from npm (often 0.5 to 1.5 seconds), we can run the resolved tsc binary directly on each configuration file. This is much faster, avoids the extra process overhead, and aligns with how eslint and prettier are executed.

    if run_typecheck and (tsc := gates.resolve_ui_binary(ctx, "tsc")):
        print("--> Running UI Typechecker (tsc)...")
        failed = False
        for config in ("tsconfig.json", "tsconfig.spec.json", "tsconfig.e2e.json"):
            if (
                gates.exec_cmd(
                    [tsc, "--noEmit", "-p", config], cwd=gates.REPO_ROOT / "cmd/ui"
                ).returncode
                != 0
            ):
                failed = True
                break
        if failed:
            ctx.fail("UI TypeScript typecheck failed.")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push Back: Intentionally keeping npm run --silent typecheck so the list of TypeScript project configs (tsconfig.json, tsconfig.spec.json, tsconfig.e2e.json) stays in a single source of truth inside cmd/ui/package.json shared with .github/workflows/lint.yml (Run TypeScript Typecheck), rather than duplicating the project list in tools/lint/precommit_runner.py where future configs could drift. This trade-off is documented in PR #1672 ## Assumptions.



def check_license(ctx: gates.RunContext) -> None:
Expand Down
39 changes: 35 additions & 4 deletions tools/lint/precommit_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,48 @@ def test_check_go_fails_on_gofmt_and_go_mod_tidy_errors_in_fix_mode(self):

def test_check_ui_chunks_and_license(self):
ctx = gates.RunContext(mode="fix")
many_ui = [f"cmd/ui/src/f{i}.ts" for i in range(201)]
with (
mock.patch.object(gates, "collect_target_files", return_value=many_ui),
mock.patch.object(gates, "resolve_ui_binary", side_effect=["/p/prettier", "/p/eslint"]),
mock.patch.object(
gates,
"git_staged_paths",
return_value=["cmd/ui/app.ts", "cmd/ui/index.html", "cmd/ui/s.scss"],
),
mock.patch.object(gates, "staged_paths_match", side_effect=[False, True]),
mock.patch.object(
gates, "resolve_ui_binary", side_effect=["/p/prettier", "/p/eslint", "/p/tsc"]
),
mock.patch.object(gates, "run_mode_command") as run_mode,
mock.patch.object(
gates, "exec_cmd", return_value=subprocess.CompletedProcess([], 0, "", "")
) as exec_mock,
mock.patch("sys.stdout", new_callable=io.StringIO),
):
runner.check_ui(ctx)
self.assertFalse(ctx.failed)
self.assertEqual(run_mode.call_count, 2)
self.assertEqual(run_mode.call_args_list[0].kwargs["chunk_size"], 200)
self.assertEqual(run_mode.call_args_list[0].kwargs["files"], many_ui)
self.assertEqual(
run_mode.call_args_list[0].kwargs["files"],
["cmd/ui/app.ts", "cmd/ui/index.html", "cmd/ui/s.scss"],
)
self.assertEqual(run_mode.call_args_list[1].args[1], ["/p/eslint"])
self.assertEqual(run_mode.call_args_list[1].kwargs["cwd"], gates.REPO_ROOT / "cmd/ui")
self.assertEqual(run_mode.call_args_list[1].kwargs["fix_args"], ["--fix"])
self.assertEqual(run_mode.call_args_list[1].kwargs["files"], ["app.ts"])
exec_mock.assert_called_once_with(
["npm", "run", "--silent", "typecheck"], cwd=gates.REPO_ROOT / "cmd/ui"
)

ctx_cfg = gates.RunContext(mode="fix")
with (
mock.patch.object(gates, "git_staged_paths", return_value=["cmd/ui/eslint.config.js"]),
mock.patch.object(gates, "staged_paths_match", side_effect=[True, False]),
mock.patch.object(gates, "resolve_ui_binary", return_value="/p/eslint"),
mock.patch.object(gates, "run_mode_command") as run_mode_cfg,
mock.patch("sys.stdout", new_callable=io.StringIO),
):
runner.check_ui(ctx_cfg)
self.assertEqual(run_mode_cfg.call_args.kwargs["files"], ["."])

ctx_check = gates.RunContext(mode="check")
with (
Expand Down
Loading