Repository navigation
chore: harden ui eslint rules and enable tsc typechecking #1672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| "source.fixAll.eslint": "explicit" | ||
| }, | ||
| "eslint.validate": [ | ||
| "typescript" | ||
| "javascript", | ||
| "typescript", | ||
| "html" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": true, | ||
| "types": ["node"] | ||
|
VLukiantsev marked this conversation as resolved.
Resolved
|
||
| }, | ||
| "include": ["screenshot_tests/**/*.ts", "playwright.config.ts"], | ||
| "exclude": ["node_modules", "dist"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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")) | ||
| ] | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of invoking 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.")
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Push Back: Intentionally keeping |
||
|
|
||
|
|
||
| def check_license(ctx: gates.RunContext) -> None: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.