Repository navigation
feat(lint): add the first ten ast-grep rules and drop the prose they replace - #117
Conversation
|
@codex review |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| severity: warning | ||
| message: "Add `strict=True` so the run fails when the test unexpectedly passes." | ||
| rule: | ||
| pattern: pytest.mark.xfail($$$ARGS) |
There was a problem hiding this comment.
P2: pattern: pytest.mark.xfail($$$ARGS) only matches the call form. The bare decorator @pytest.mark.xfail (no parentheses) is an attribute node, not a call, so it is never reported, even though it is the most common non-strict usage. Module-level pytestmark = pytest.mark.xfail is missed for the same reason. Consider adding an any: branch for a decorator whose child is exactly pytest.mark.xfail, and adding a bare-decorator case to tests/ast-grep/py_xfail_requires_strict.yml under invalid.
| rule: | ||
| any: | ||
| - pattern: mocker.patch($$$ARGS) | ||
| - pattern: mocker.patch.object($$$ARGS) |
There was a problem hiding this comment.
P2: The exemption only checks keyword arguments, but new is often passed positionally: mocker.patch("mod.X", fake) or mocker.patch.object(Tool, "run", fake). autospec=True cannot be combined with new, so the rule flags these calls even though they cannot comply. Following the message would raise at runtime. Consider also exempting calls with more than one positional argument for patch (more than two for patch.object), and adding a valid test case for this.
There was a problem hiding this comment.
修正しました(7e56964).位置引数の new(patch は 2 番目,patch.object は 3 番目)を nthChild で除外し,valid に 2 件追加.agent-config の hit は 2 件減った.
| rule: | ||
| any: | ||
| - pattern: import unittest | ||
| - pattern: from unittest import TestCase |
There was a problem hiding this comment.
P3: from unittest import TestCase is matched literally, so from unittest import IsolatedAsyncioTestCase, from unittest import TestCase, main, and import unittest as ut are not reported. Matching any import_from_statement whose module is unittest, except a bare mock import (that one is left to py_no_unittest_mock), would close the gap.
There was a problem hiding this comment.
修正しました(7e56964).module が unittest の from-import をすべて判定し(from unittest import mock は py_no_unittest_mock に任せて除外),import unittest as ut も追加.invalid に 3 件,valid に 1 件追加.
|
|
||
| assert sorted(path.name for path in CASE_DIRECTORY.glob("*.yml") if path.name not in rule_names) == [] | ||
|
|
||
|
|
There was a problem hiding this comment.
P3: Nothing runs the registry examples.conforming / examples.violating entries in the rule files through ast-grep. Only tests/ast-grep/*.yml is exercised, so the registry examples can drift from the rule without any test failing. Consider a test that checks each registry example appears in the matching valid/invalid list, or scans it directly.
There was a problem hiding this comment.
修正しました(7e56964).test_registry_examples_agree_with_the_rule が各規則の examples を ast-grep scan --stdin に流し,conforming は 0 件,violating は 1 件以上であることを確かめる.
Review summaryNo blocking findings (0 × P0/P1). The rules and the test harness are well shaped. Four non-blocking findings are posted inline:
Note: I couldn't run |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| severity: warning | ||
| message: "Add `strict=True` so the run fails when the test unexpectedly passes." | ||
| rule: | ||
| pattern: pytest.mark.xfail($$$ARGS) |
There was a problem hiding this comment.
P2: The pattern pytest.mark.xfail($$$ARGS) only matches the call form, so the bare decorator @pytest.mark.xfail (no parentheses) never matches. That's the most common non-strict form, and pyproject.toml doesn't set xfail_strict = true, so such a test silently XPASSes and the rule doesn't report it. pytestmark = pytest.mark.xfail is also missed.
Consider adding an alternative such as kind: decorator + pattern: "@pytest.mark.xfail" (or matching the bare attribute when its parent is not a call), plus an invalid case for the bare decorator in tests/ast-grep/py_xfail_requires_strict.yml.
There was a problem hiding this comment.
修正しました(7e56964).裸の @pytest.mark.xfail と pytestmark = pytest.mark.xfail を any の枝で判定し,invalid に 2 件追加.
Review summaryI checked all 10 rules, their test cases, Findings
Checked and found correct
No blocking (P0 or P1) findings. 🤖 Generated with Claude Code |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| rule: | ||
| any: | ||
| - all: | ||
| - kind: variable_assignment | ||
| - regex: ^[^_] | ||
| - all: | ||
| - kind: variable_name |
There was a problem hiding this comment.
P2: This rule flags any local name that doesn't start with _. That includes the standard idioms that localize special shell variables, such as local IFS=$'\n', local OPTIND OPTARG (the usual way to run getopts inside a function), local LC_ALL=C, and local - (bash ≥4.4). Those names can't take a _ prefix because the whole point is to shadow the special variable, so every hit on them is a false positive with no conforming fix.
Suggestion: exclude the special/environment names, for example by adding not: { regex: '^(IFS|OPTIND|OPTARG|OPTERR|LC_[A-Z]+|LANG|PATH|TMPDIR)\b' } to both branches (or more generally ^[A-Z][A-Z0-9_]*\b). Add a valid case such as local OPTIND / local IFS=, to tests/ast-grep/bash_local_underscore_prefix.yml.
There was a problem hiding this comment.
修正しました(8a1435a).大文字で始まる名前(IFS,OPTIND,LC_ALL など特殊変数)を除外し,valid に追加.
| any: | ||
| - pattern: from unittest.mock import $$$NAMES | ||
| - pattern: from unittest import mock | ||
| - pattern: import unittest.mock | ||
| - pattern: import unittest.mock as $ALIAS |
There was a problem hiding this comment.
P3: pattern: from unittest import mock only matches that exact statement. Two variants get through:
from unittest import mock as mis missed here.py_no_unittestreports it instead, because itsnot: pattern: from unittest import mockexclusion doesn't match the aliased form, so the user sees the wrong message.from unittest import TestCase, mockis also missed here and only reported as a generic unittest import.
Matching on structure would cover both: an import_from_statement whose module_name is unittest and that has (stopBy: end) a dotted_name with regex ^mock$. Use the same matcher as the exclusion in py_no_unittest.
There was a problem hiding this comment.
修正しました(8a1435a).from unittest import mock as m と from unittest import TestCase, mock も判定し,py_no_unittest 側は別名 mock だけの import を除外.rule-tests に追加.
| kind: argument_list | ||
| has: | ||
| kind: keyword_argument | ||
| regex: ^(autospec|new|new_callable|spec|spec_set|wraps)\s*= |
There was a problem hiding this comment.
P3: The exclusion regex ^(autospec|new|...)\s*= treats autospec=False (and autospec=None) as compliant, so mocker.patch("tool.run", autospec=False) passes even though it explicitly turns off what the rule requires. Consider requiring autospec\s*=\s*True (like py_xfail_requires_strict does for strict), and add an invalid case for it.
There was a problem hiding this comment.
修正しました(8a1435a).autospec は False で始まる値を除外から外し,autospec=False を invalid に追加.
Review summaryI found no blocking issues (0 × P0/P1). The rules are warning-only and not yet wired into any hook, and the contract tests ( Inline findings:
Note: ast-grep isn't installed in the review environment, so I checked the rules by reading them, not by running them. 🤖 Generated with Claude Code |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| - **Helper function**: prefer over fixture when arguments need to be passed or setup is lightweight | ||
| - **`@pytest.mark.parametrize`**: same logic with different inputs | ||
| - **Fixture scope**: default `function`; use `module`/`session` only when setup is expensive | ||
| - **Mocking**: use `mocker.patch("mod.func", autospec=True)` — enforces real signature, catches wrong-argument bugs silently missed by plain mocks |
There was a problem hiding this comment.
P1 — This deletes the prose, but nothing ever runs the rules that are supposed to replace it. The only reference to agents/lint/sgconfig.yml in the repo is tests/test_ast_grep_rules.py, and that only runs ast-grep test on the rules' own fixtures. No hook, CI job or lint script scans real code with these rules, and the PR description says they stay warnings for now.
So for an agent writing Python or Go in a consuming repo, the guidance just disappears. Nothing tells it to use autospec=True, to avoid @staticmethod, unittest or unittest.mock, or to avoid string-matching errors (go-style/references/errors.md), or to avoid namespace imports (typescript-style/references/code_style.md). Nothing enforces those rules either.
Suggest keeping these prose lines until the ast-grep scan is wired into a hook or CI that actually runs on code. Alternatively, wire it in this PR.
There was a problem hiding this comment.
設計上の決定として反論します.ユーザーの設計変更(2026-11-10)で「規則に置き換えた文章は同じ PR で削除し,registry は置かない.各ツールの設定を正とする」と決まっている.規則を実コードに走らせる配線(編集後 hook で結果を返す)は段階 2D(agent-harness,別 PR)で入れる.この PR は ast-grep test で規則自体を検証し,agent-config / dotfiles への実行結果(25 件・10 件)を PR 本文に載せている.2D が入るまでの間,削除した行のガイダンスが一時的に強制されない点は認識しており,PR 本文の対応表に削除と残した行を明記している.
| - regex: ^[^_] | ||
| inside: | ||
| kind: declaration_command | ||
| regex: ^local\b |
There was a problem hiding this comment.
P2 — This rule flags standard idioms where the name of the local variable is what makes it work: local IFS=$'\n', local OPTIND (needed so getopts works again inside a function), local LC_ALL=C, and local PATH=.... Following the warning and renaming them to _IFS or _OPTIND quietly breaks the script, because the special variable is no longer made local.
Suggest excluding special or uppercase shell variables, e.g. regex: ^[a-z] (or an explicit not list for IFS|OPTIND|OPTARG|LC_.*|PATH), and adding a valid case for local IFS=....
There was a problem hiding this comment.
修正しました(8a1435a).同上.local IFS / OPTIND / OPTARG / LC_ALL は除外し,rule-tests の valid に追加.
| - pattern: $ERR.Error() != $TEXT | ||
| - pattern: strings.Contains($ERR.Error(), $TEXT) | ||
| - pattern: strings.HasPrefix($ERR.Error(), $TEXT) | ||
| - pattern: strings.HasSuffix($ERR.Error(), $TEXT) |
There was a problem hiding this comment.
P3 — The PR says the deleted prose ("never == or string matching") is fully replaced, but this rule misses some common forms:
- reversed comparisons:
"not found" == err.Error() switch err.Error() { case "...": }strings.EqualFold(err.Error(), ...)
It also skips every _test.go file, while the prose had no such exception. Consider adding the reversed-operand patterns plus a switch case, or keeping part of the prose.
There was a problem hiding this comment.
一部修正しました(8a1435a).逆順の比較("x" == err.Error()),!=,strings.EqualFold を追加.switch err.Error() は未対応._test.go の除外は,テストが自分で作ったエラーの文言を検証する正当な用途があるための意図的な設計で,PR 表にも明記している.
Review summaryI reviewed this read-only. I could not install ast-grep in this environment, so I checked the rules by reading them, not by running them.
Blocking findings: 1 |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| @@ -0,0 +1,6 @@ | |||
| id: ts_no_namespace_import | |||
| language: typescript | |||
There was a problem hiding this comment.
P3 — language: typescript in ast-grep only applies to .ts/.mts/.cts. .tsx files are parsed as the separate tsx language, so import * as React from "react" in a .tsx file isn't reported. The PR also deletes the "Prefer explicit named imports" line from typescript-style/references/code_style.md and calls it fully replaced, so .tsx code now has neither the guidance nor the rule. Add a tsx twin rule (or restore the prose) if TSX is in scope.
There was a problem hiding this comment.
既知の限界として PR 本文に追記しました.template-typescript に .tsx は無く,.tsx が出た時点で language を tsx にした同規則を追加する.
There was a problem hiding this comment.
修正しました(b4ebb0f).tsx_no_namespace_import を追加しました(前の返信の「.tsx が出た時点で追加」は撤回します).
| - Run tests using `uv run --frozen pytest` | ||
| - Use `anyio` for async tests, do not use `asyncio` | ||
| - Use `pytest-mock` for mocking (`mocker` fixture), do not use `unittest.mock` directly | ||
| - Use `pytest-mock` for mocking (`mocker` fixture) |
There was a problem hiding this comment.
P2 — These deletions (along with @staticmethod in models.md, autospec=True below, and the TS namespace-import line) remove guidance that agents read today. The rules that replace it won't run on edited code until stage 2D. The PR description acknowledges this, but in the meantime nothing tells or makes agents avoid unittest.mock, plain mocker.patch, or @staticmethod. The repo already has 25 hits of exactly these patterns. Consider keeping the prose until the post-edit hook is wired, and deleting it in the 2D PR.
There was a problem hiding this comment.
設計判断として維持します(P1 への返信と同じ).規則に置き換えた文章は同じ PR で削除し,hook の配線は段階 2D で入る,というユーザーの決定による.一時的に強制が無い点は PR 本文の既知の限界に明記した.
Review summaryI reviewed the 10 rule YAMLs, their test cases, No blocking findings. The rule logic looks right for the cases it targets, including the Non-blocking:
🤖 Generated with Claude Code |
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…or rules Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…= guidance Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The hook bundle ships agents/hooks/lint as the shared rule config, so the rules live beside the hooks that scan with them. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
d72fd67 to
4998b96
Compare
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Review summary (read-only) No blocking findings, and no inline comments. What I checked:
Not verified: ast-grep isn't installed in the review environment, so I couldn't run Blocking findings (P0/P1): 0 |
🤖 I have created a release *beep* *boop* --- ## 0.1.0 (2026-11-10) ### Features * add devin provider to hooks.json with hook adapter (furedea/dotfiles[#136](#136)) ([5bc5550](5bc5550)) * add git-commit-split skill ([35f4e16](35f4e16)) * add Hermes Agent and pi hook providers (furedea/dotfiles[#138](#138)) ([ed3a774](ed3a774)) * add lock-settings, report-doc-conflict, and report-hook-block skills ([35b8585](35b8585)) * **agents:** add Rust style skill ([a82df41](a82df41)) * **agents:** allow cd, sed, awk, xargs, cp, and mv under the sandbox (furedea/dotfiles[#165](#165)) ([5783f87](5783f87)) * **agents:** bootstrap the harness on servers without Nix ([80a0f9b](80a0f9b)) * **agents:** chain git add, status, commit, and push outside the sandbox (furedea/dotfiles[#169](#169)) ([dd5a05c](dd5a05c)) * **agents:** Codex implements, Claude reviews, and lanes clean up opened workspaces (furedea/dotfiles[#266](#266)) ([c9a3fd9](c9a3fd9)) * **agents:** generate hook settings from nix ([b20d592](b20d592)) * **agents:** hand approved lanes to Herdr task worktree sessions (furedea/dotfiles[#184](#184)) ([58a591f](58a591f)) * **agents:** own personal agent source (furedea/dotfiles[#52](#52)) ([51060b1](51060b1)) * **agents:** permit commands by reversibility (furedea/dotfiles[#124](#124)) ([bb96256](bb96256)) * **agents:** run agent git inside the sandbox with unsigned commits (furedea/dotfiles[#172](#172)) ([1492f3e](1492f3e)) * **agents:** start Herdr Claude lanes on Sonnet at medium effort (furedea/dotfiles[#257](#257)) ([3caf8d5](3caf8d5)) * **agents:** write PR bodies inline and close lanes' parent workspaces (furedea/dotfiles[#211](#211)) ([8c6df4e](8c6df4e)) * **claude:** close the sandbox escape and reach the Nix daemon inside (furedea/dotfiles[#191](#191)) ([b61f2ac](b61f2ac)) * **claude:** let Go CLIs verify TLS inside the sandbox (furedea/dotfiles[#167](#167)) ([282b3d2](282b3d2)) * **claude:** let sandboxed commands listen on local ports (furedea/dotfiles[#206](#206)) ([36c09d2](36c09d2)) * **claude:** run the Codex plugin companion outside the sandbox (furedea/dotfiles[#232](#232)) ([0255159](0255159)) * **codex:** let Codex write, test, and deliver inside the sandbox (furedea/dotfiles[#200](#200)) ([33a0a82](33a0a82)) * compose Herdr and Moshi agent hooks (furedea/dotfiles[#33](#33)) ([4951ee8](4951ee8)) * **dsh:** add the dsh hook adapter ([#101](#101)) ([db86f57](db86f57)) * **git-commit-split:** accept mode from slash-command argument ([10c3ef7](10c3ef7)) * **git-commit-split:** modularize commit splitting workflow with branch ([bab6f19](bab6f19)) * **github:** add repository creation script ([1a7910b](1a7910b)) * **hermes:** use Apple Mail for mail access (furedea/dotfiles[#69](#69)) ([94268fa](94268fa)) * **hooks:** add related test selection rules ([2aca101](2aca101)) * **hooks:** add shared audit and command guard hooks ([6ab33b5](6ab33b5)) * **hooks:** allow read-only local curl diagnostics and log syntax ask kinds (furedea/dotfiles[#287](#287)) ([83cd643](83cd643)) * **hooks:** ask before an agent adds a lint suppression (furedea/dotfiles[#214](#214)) ([b767665](b767665)) * **hooks:** ask only for effects that escape the sandbox (furedea/dotfiles[#163](#163)) ([21409a5](21409a5)) * **hooks:** block destructive non-push git operations ([cc02cb4](cc02cb4)) * **hooks:** escalate unrecognized command forms to a prompt (furedea/dotfiles[#159](#159)) ([e30de17](e30de17)) * **hooks:** fast-forward main after cleaning up merged lanes (furedea/dotfiles[#210](#210)) ([f8a60af](f8a60af)) * **hooks:** honor project allow rules only from trusted owners ([#33](#33)) ([305d391](305d391)) * **hooks:** improve lint-format feedback across providers ([8a512f6](8a512f6)) * **hooks:** judge heredocs, substitutions, loops, and redirections structurally (furedea/dotfiles[#175](#175)) ([9276283](9276283)) * **hooks:** let sessions lock flake inputs and close their own lanes (furedea/dotfiles[#208](#208)) ([f109b49](f109b49)) * **hooks:** let the parent run cleanup_worktrees.py after merge (furedea/dotfiles[#300](#300)) ([fc44c74](fc44c74)) * **hooks:** remove merged task worktrees and branches at session start (furedea/dotfiles[#185](#185)) ([2701e0b](2701e0b)) * **hooks:** replay recent commands through the hooks (furedea/dotfiles[#199](#199)) ([2ed4984](2ed4984)) * **hooks:** report ast-grep rule findings after an edit ([#119](#119)) ([ff91d8c](ff91d8c)) * **hooks:** review only commands that reach past the sandbox (furedea/dotfiles[#178](#178)) ([40c97da](40c97da)) * **hooks:** run zizmor offline after workflow edits (furedea/dotfiles[#295](#295)) ([79b66a6](79b66a6)) * **hooks:** scan with the shared ast-grep rules shipped beside the hooks ([#121](#121)) ([35a9270](35a9270)) * **hooks:** support Go projects in formatting, verification, and permissions ([#57](#57)) ([5506f3c](5506f3c)) * **hooks:** verification selection, unified patch input, formatter/linter ordering (furedea/dotfiles[#144](#144)) ([99a825b](99a825b)) * **lint:** add the first ten ast-grep rules and drop the prose they replace ([#117](#117)) ([c235eb5](c235eb5)) * **nix:** expose the plain agents path as passthru.tree of agent-source ([#94](#94)) ([63632e4](63632e4)) * **security:** add a program_path option that pins a rule's program to one absolute path ([#61](#61)) ([d629ca9](d629ca9)) * **security:** allow agent-browser and agent-desktop except named risky forms ([#63](#63)) ([8dc8da5](8dc8da5)) * **security:** allow cargo caches, crates.io, and OSV in the sandbox ([#60](#60)) ([2f29423](2f29423)) * **security:** allow Go caches and module hosts in the sandbox ([#58](#58)) ([4b3a35c](4b3a35c)) * **security:** ask for every docker form the allowlist does not list ([#54](#54)) ([764374f](764374f)) * **security:** deny the 1Password CLI and keep the Codex login in the keyring ([#52](#52)) ([0580825](0580825)) * **skill-auditor:** support Codex audit workflow ([0d88c3f](0d88c3f)) * **skills:** add measurement-evidence and change-type evidence to tsdd ([#70](#70)) ([85714b5](85714b5)) * **skills:** clarify names and add Herdr delegation (furedea/dotfiles[#127](#127)) ([e6576ba](e6576ba)) * **skill:** skill-auditor by nyosegawa/skills/skill-auditor ([f191132](f191132)) * **skills:** render provider-specific SKILL.md frontmatter ([44325e5](44325e5)) * **statusline:** render the status on one line (furedea/dotfiles[#110](#110)) ([03ad85e](03ad85e)) * update bash-style skill instructions ([9ab1d65](9ab1d65)) * update github-ci-init skill templates ([d238f51](d238f51)) * verify agent changes through native hooks (furedea/dotfiles[#106](#106)) ([923b0ae](923b0ae)) ### Bug Fixes * **agents:** accept generated command permissions (furedea/dotfiles[#66](#66)) ([0af9650](0af9650)) * **agents:** allow gh api reads that pass --allow-escape-sequences (furedea/dotfiles[#265](#265)) ([e732939](e732939)) * **agents:** apply harness review findings (furedea/dotfiles[#149](#149)) ([c8a51d7](c8a51d7)) * **agents:** cap Codex session-end timeout ([2f29a7e](2f29a7e)) * **agents:** deny codex-companion calls the sandbox exclusion cannot match (furedea/dotfiles[#269](#269)) ([25518ab](25518ab)) * **agents:** harden hooks and separate workflow responsibilities (furedea/dotfiles[#128](#128)) ([7e508c4](7e508c4)) * **agents:** let pnpm fetch from the npm registry inside the sandbox (furedea/dotfiles[#222](#222)) ([ac114e8](ac114e8)) * **agents:** let the forbidden rule admit Sonnet lane arguments (furedea/dotfiles[#259](#259)) ([f1b29a9](f1b29a9)) * **agents:** make the bootstrap hint work for POSIX login shells ([c2667fa](c2667fa)) * **agents:** stop asking for commands the hooks can prove safe (furedea/dotfiles[#242](#242)) ([a93d241](a93d241)) * **agents:** wait for hook state locks instead of failing with EAGAIN (furedea/dotfiles[#285](#285)) ([673c108](673c108)) * allow secret scanner hook files ([bca4207](bca4207)) * **bootstrap:** give Codex the agent GitHub token settings and run the bootstrap in CI ([#21](#21)) ([25de080](25de080)) * **bootstrap:** keep Neovim's fallback nvim.log out of the working directory ([#43](#43)) ([3c9fc5c](3c9fc5c)) * **bootstrap:** make the server bootstrap behave like the Nix hosts ([#15](#15)) ([4554dec](4554dec)) * **bootstrap:** print actionable profile and legacy-file messages only when needed ([#49](#49)) ([1918254](1918254)) * **bootstrap:** target the login profile bash actually reads ([#50](#50)) ([0dae5bf](0dae5bf)) * **bootstrap:** verify downloaded tools against pinned checksums ([#111](#111)) ([1744df3](1744df3)) * **ci:** install the locked agent-harness instead of reading it from the flake ([bc2395b](bc2395b)) * **ci:** provide the shell format config and locked JavaScript tools ([dd59634](dd59634)) * **claude:** trust only the CA store bundled with Claude Code (furedea/dotfiles[#284](#284)) ([34be271](34be271)) * **codex:** fall back to auth.json when no keyring is available ([#62](#62)) ([79b6ceb](79b6ceb)) * correct agent tooling and Hister activation (furedea/dotfiles[#85](#85)) ([4bab065](4bab065)) * honor pytest testpaths and bootstrap bats on servers (furedea/dotfiles[#116](#116)) ([b17b59e](b17b59e)) * **hooks:** allow double quoted commit messages ([fc4afd4](fc4afd4)) * **hooks:** bound curl -o, -d and -H in the localhost rule (furedea/dotfiles[#291](#291)) ([7c9db8a](7c9db8a)) * **hooks:** close shell-syntax bypasses of the guard hooks ([#11](#11)) ([c6aacdf](c6aacdf)) * **hooks:** close the guard contract gaps from [#11](#11) review ([#31](#31)) ([db318db](db318db)) * **hooks:** deny codex-companion calls whose text holds a dollar sign or backtick (furedea/dotfiles[#290](#290)) ([f37c317](f37c317)) * **hooks:** find GNU grep on PATH instead of the first grep (furedea/dotfiles[#193](#193)) ([99ba317](99ba317)) * **hooks:** format without dotfiles-installed dprint and prettier configs ([#16](#16)) ([db21f55](db21f55)) * **hooks:** ignore git-ignored sources when judging a project removed ([#22](#22)) ([97c6b93](97c6b93)) * **hooks:** ignore prose arguments when matching forbidden patterns (furedea/dotfiles[#189](#189)) ([d2049d6](d2049d6)) * **hooks:** judge each command as one line with any grep (furedea/dotfiles[#196](#196)) ([202f937](202f937)) * **hooks:** keep merged worktrees holding non-regenerable ignored files ([#29](#29)) ([ac03cfa](ac03cfa)) * **hooks:** keep the first grep when no GNU grep is on PATH (furedea/dotfiles[#195](#195)) ([a0e6a2f](a0e6a2f)) * **hooks:** keep the verification snapshot from locking out symlinked or large worktrees ([#66](#66)) ([7d13f0e](7d13f0e)) * **hooks:** let cleanup_worktrees remove Claude Code session files ([#36](#36)) ([0a910bc](0a910bc)) * **hooks:** let cleanup_worktrees tests choose the untrusted locations (furedea/dotfiles[#306](#306)) ([e82980e](e82980e)) * **hooks:** let GitHub API reads take an unquoted jq filter (furedea/dotfiles[#198](#198)) ([5b6210a](5b6210a)) * **hooks:** make stop verification reliable (furedea/dotfiles[#81](#81)) ([04a33dd](04a33dd)) * **hooks:** preserve verification evidence (furedea/dotfiles[#87](#87)) ([4b5b9c2](4b5b9c2)) * **hooks:** redirect sandbox-failing Git forms and drop covered prompts (furedea/dotfiles[#180](#180)) ([34e39a7](34e39a7)) * **hooks:** resolve Rust integration test targets inside tests subdirectories (furedea/dotfiles[#304](#304)) ([2ccf547](2ccf547)) * **hooks:** respect project formatters and bound diagnostics (furedea/dotfiles[#131](#131)) ([30e83cf](30e83cf)) * **hooks:** scope generic secret regex to quoted values ([fc09292](fc09292)) * **hooks:** silence successful hook execution ([795d8f0](795d8f0)) * **hooks:** skip JavaScript triggers in projects without JavaScript tests (furedea/dotfiles[#161](#161)) ([dc80e28](dc80e28)) * **hooks:** skip verification for a language whose project was removed ([#6](#6)) ([4a9f325](4a9f325)) * **hooks:** support relocated harness assets (furedea/dotfiles[#82](#82)) ([59057bc](59057bc)) * **hooks:** treat any gh api call without write flags as a read (furedea/dotfiles[#201](#201)) ([3ecb215](3ecb215)) * **hooks:** treat glob characters inside double quotes as literal for literal_words rules ([#41](#41)) ([174a7f9](174a7f9)) * **hooks:** use agent-neutral guidance ([37153ce](37153ce)) * improve agent notifications and session setup (furedea/dotfiles[#92](#92)) ([9bf2349](9bf2349)) * load secret patterns from hook directory ([ca465ef](ca465ef)) * migrate dotfiles path to ghq convention ([faff774](faff774)) * **nix:** build CPython 3.15.2 for the ssl eMudhra denylist ([#113](#113)) ([faba045](faba045)) * **nix:** default editor to Neovim (furedea/dotfiles[#105](#105)) ([2a9a22a](2a9a22a)) * resolve hook directory from bash source ([c6ca454](c6ca454)) * restore SSH signing and reliable Bats verification (furedea/dotfiles[#91](#91)) ([891adce](891adce)) * **sandbox:** deny writes to every repository's git hooks and config (furedea/dotfiles[#298](#298)) ([1941513](1941513)) * **sandbox:** match the Codex plugin script under any numeric version (furedea/dotfiles[#302](#302)) ([a49ddc3](a49ddc3)) * **security:** allow the Go checksum tree head and vulnerability database in the sandbox ([#59](#59)) ([af6e158](af6e158)) * **security:** ask for every script a non-bash shell receives ([#99](#99)) ([f88f8fd](f88f8fd)) * **security:** close quoted-argument and wrapper bypasses in the command guard ([#76](#76)) ([5f72757](5f72757)) * **security:** close the remaining command guard bypasses ([#83](#83)) ([0387739](0387739)) * **security:** decide not-a-fork for project rules on hosts without gh ([#67](#67)) ([acaa758](acaa758)) * **security:** keep agent-browser and agent-desktop calls inside the sandbox ([#64](#64)) ([3f2d578](3f2d578)) * **security:** read more of the scripts handed to fish and PowerShell for deny rules ([#110](#110)) ([2c652bb](2c652bb)) * **skills:** audit Codex skill observations (furedea/dotfiles[#88](#88)) ([f429967](f429967)) * **skills:** refine routing triggers from audit ([cef3b9c](cef3b9c)) * **tests:** make git test wrappers exec the real git binary (furedea/dotfiles[#310](#310)) ([893c405](893c405)) * **tests:** stop shifting past the codex wrapper arguments ([eb0f6d7](eb0f6d7)) ### Performance Improvements * **hooks:** evaluate policy regexes with one grep and run pytest in parallel (furedea/dotfiles[#125](#125)) ([ce80ea3](ce80ea3)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
Refs #74,Refs #196([計画コメント](https://github.com/furedea/agent-config/issues/74#issuecomment-6860762203),go-style レーン) ## 概要 `agents/skills/go-style/` の規則文をすべて棚卸しし,最も安い判定手段へ移した. - ast-grep 規則 7 件(すべて `severity: error` で block.まれな正当な例外はレビュー済みの抑制コメントで通す)(`rules/go/`,`rule-tests/` 付き) - jev-lint model rule 5 件(`model-rules/go/`.ADR-0021 に従い文章は残す.fixture と baseline は未追加) - 既存 linter(golangci-lint,`template-go` で有効)が覆う文章は削除 - 規則で完全に置き換わる文章は同じ PR で削除し,一部だけ覆う文章は覆わない部分を残した 共有ファイル(`sgconfig.yml`,`tests/`,hook)は変更していない.`tests/test_model_rule_files.py` の eval suite の検査は fixture を持つ規則だけを数えるため,fixture 無しの新規 model rule は既存テストを壊さない. ## 文章と規則の対応表 パスは `agents/hooks/lint/` からの相対.`template-go` の golangci-lint は `default: standard`(errcheck,govet,ineffassign,staticcheck,unused)に errorlint,exhaustive,gochecksumtype,gocognit,gocyclo,gosec,nolintlint,paralleltest,revive(package-comments,exported,argument-limit,max-control-nesting,file-length-limit)と,formatter の gofumpt,goimports を有効にしている. | 規則 ID | 元の場所 | 元の規則 | 判定 | 実装 | 例のテスト | 元の文章の扱い | | ------------------------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | (formatter) | code_style.md Formatting | gofumpt と goimports に整形を任せる | 既存 linter(template-go の formatters gofumpt,goimports) | template-go の .golangci.yml | - | 削除(Formatting 節ごと.`tooling.md` の同内容の行も削除) | | go_package_name_lowercase | code_style.md Naming | パッケージ名は小文字,下線なし | 既存 linter(template-go の revive `var-naming`) | template-go の .golangci.yml | - | 「lowercase / without underscores」を削除.「短い,単語 1 つ」は残す.重複する ast-grep 規則は削除(rules と rule-tests) | | (stutter) | code_style.md Naming | `config.ConfigLoader` のような重複を避ける | 既存 linter(template-go の revive `exported`) | template-go の .golangci.yml | - | 削除 | | (initialism) | code_style.md Naming | `ID`,`URL`,`HTTP` の表記を揃える | 既存 linter(template-go の revive `var-naming`) | template-go の .golangci.yml | - | 削除 | | go_receiver_name_short | code_style.md Naming | レシーバ名は 1〜2 文字,メソッド間で同じ | 既存 linter(template-go の revive `receiver-naming`:`this` / `self` と一貫性) | template-go の .golangci.yml | - | 削除(ユーザー判断:ast-grep 規則は置かない.長さの文章も削除) | | - | code_style.md Naming | 名前の長さはスコープに合わせる | 文章のみ | - | - | 残す(スコープと名前の釣り合いは構文から判別できない) | | go_no_vague_name | code_style.md Naming | `manager` / `helper` / `util` / `common` を避ける | 文章のみ | - | - | 残す(「既存の命名なら許す」例外を hook は判別できず,既存の util パッケージを編集するたびに警告するため,ast-grep 規則は置かなかった) | | (doc comment) | code_style.md Comments | exported の doc comment は識別子名で始める | 既存 linter(template-go の revive `exported`) | template-go の .golangci.yml | - | 削除 | | - | code_style.md Comments | コメントは what でなく why を書く | 文章のみ | - | - | 残す(意図の質は文脈が要る.言語非依存の規則は agents レーンの領分) | | - | code_style.md Comments | 設計判断,依存の選定,外部ツール境界は ADR へ | 文章のみ | - | - | 残す(置き場所の方針.`source-of-truth` と ADR の領分) | | go_use_slog | code_style.md Logging | `log/slog` で記録する | ast-grep(severity: error) | rules/go/go_use_slog.yml | rule-tests/go_use_slog.yml | 削除(ユーザー判断:規則が覆うものとして削除) | | - | code_style.md Logging | 人間向け診断は stderr,機械可読な出力は stdout | 文章のみ | - | - | 残す(出力の性質は文脈で決まる.`fmt.Println` が診断か出力かは構文から判別できない) | | go_library_no_global_logger | code_style.md Logging | ライブラリはグローバル logger を設定しない | 文章のみ(ast-grep では正確に判定できない推奨事項.規則は置かない) | - | - | 残す(ユーザー判断:推奨事項として文章を残す.「ライブラリはグローバル logger を設定しない」を復元) | | go_context_param_named_ctx | concurrency.md | `context.Context` は `ctx` と名付ける | ast-grep(severity: error) | rules/go/go_context_param_named_ctx.yml | rule-tests/go_context_param_named_ctx.yml | 「named `ctx`」を削除 | | (ctx 位置) | concurrency.md | `context.Context` を第 1 引数にする | 既存 linter(template-go の revive `context-as-argument`) | template-go の .golangci.yml | - | 削除(第 1 引数・`ctx` の名前・struct への保存のすべてが規則で覆われる) | | go_no_context_in_struct | concurrency.md | `context.Context` を struct に保存しない | ast-grep(severity: error) | rules/go/go_no_context_in_struct.yml | rule-tests/go_no_context_in_struct.yml | 「never store it in a struct」を削除 | | goroutine-has-termination-path | concurrency.md | goroutine に所有者と終了経路を持たせる | jev-lint | model-rules/go/goroutine-has-termination-path/rule.yml | - | 残す(ADR-0021) | | - | concurrency.md | 並列でエラーを返す処理は `errgroup` | 文章のみ | - | - | 残す(`errgroup` が適するかは設計判断.構文から判別できない) | | channel-closed-by-sender | concurrency.md | channel は送信側が閉じる,複数の送信側から閉じない | jev-lint | model-rules/go/channel-closed-by-sender/rule.yml | - | 残す(ADR-0021) | | go_mutex_field_documented | concurrency.md | `sync.Mutex` は守るフィールドを文書化する | ast-grep(直前のコメントの有無だけ,severity: error) | rules/go/go_mutex_field_documented.yml | rule-tests/go_mutex_field_documented.yml | 残す(コメントの内容,直前フィールドの行末コメント,位置は規則が覆わない) | | - | concurrency.md | データを渡す設計を優先,共有時に mutex | 文章のみ | - | - | 残す(設計の好み) | | - | concurrency.md | テストを `-race` で実行する | 文章のみ | - | - | 残す(コマンドの運用.コードから判別できない.`tooling.md` の gate にも同じコマンドがある) | | (error 位置) | errors.md | `error` を最後の戻り値にする | 既存 linter(template-go の revive `error-return`) | template-go の .golangci.yml | - | 削除 | | go_error_no_failed_to_prefix | errors.md | "failed to" で始めない,大文字で始めない | ast-grep(#117 で追加済み,severity: error)+既存 linter(template-go の staticcheck `ST1005`:大文字始まり) | rules/go/go_error_no_failed_to_prefix.yml | rule-tests/go_error_no_failed_to_prefix.yml | 該当 2 文を削除.「操作と対象で包む」は残す(jev-lint `error-message-names-operation` が既にあり,ADR-0021 により文章は残す) | | (errors.Is) | errors.md | `errors.Is` / `As` で比較し `==` を使わない | 既存 linter+ast-grep(r(template-go の `errorlint`)) | golangci-lint `errorlint`(`==`),rules/go/go_error_no_string_matching.yml(文字列,#117) | - | 削除 | | - | errors.md | sentinel error や独自型は呼び出し側が分岐する時だけ | 文章のみ | - | - | 残す(呼び出し側の使われ方は同一ファイルから判別できない) | | error-handled-once | errors.md | 同じエラーを log して return しない | jev-lint | model-rules/go/error-handled-once/rule.yml | - | 残す(ADR-0021) | | (errcheck) | errors.md | `_` でエラーを無視しない | 既存 linter(template-go の errcheck `check-blank: true`) | template-go の .golangci.yml | - | 「`_` で無視しない」を削除.「無視してよい理由を説明する」は残す(linter が覆わない) | | panic-only-for-programmer-errors | errors.md | `panic` はプログラマ起因の誤りと初期化失敗だけ | jev-lint | model-rules/go/panic-only-for-programmer-errors/rule.yml | - | 残す(ADR-0021) | | go_no_other_assertion_library | testing.md | testify 以外の assertion library を足さない | ast-grep(既知の gomega,goconvey,is,gotest.tools,quicktest,go-testdeep,severity: error) | rules/go/go_no_other_assertion_library.yml | rule-tests/go_no_other_assertion_library.yml | 「do not add another assertion library」を削除.「testing と testify を使う」は残す | | - | testing.md | `go test -race -cover ./...` で実行する | 文章のみ | - | - | 残す(コマンドの運用) | | (testifylint) | testing.md | 前提は `require`,結果は `assert` | 既存 linter(template-go の `testifylint`) | template-go の .golangci.yml | - | 削除 | | (paralleltest) | testing.md | 共有状態が無ければ `t.Parallel()` | 既存 linter(template-go の `paralleltest`) | template-go の .golangci.yml | - | `t.Parallel()` の句を削除.「table-driven で `t.Run`」は残す | | - | testing.md | table-driven と `t.Run` | 文章のみ | - | - | 残す(構造の好み) | | (usetesting) | testing.md | `t.TempDir()`,`t.Setenv()`,実 HOME に触れない | 既存 linter(template-go の `usetesting`) | template-go の .golangci.yml | - | `t.TempDir()` / `t.Setenv()` を削除.「実 HOME に触れない」は残す(linter が覆わない) | | go_no_generated_mocks | testing.md | 生成 mock より手書き fake | ast-grep(gomock,testify/mock,mockery,counterfeiter の import,severity: error) | rules/go/go_no_generated_mocks.yml | rule-tests/go_no_generated_mocks.yml | 削除(fake の書き方は Test Structure の「Fake implementation」に残る) | | - | testing.md | golden file は `testdata/`,正確な出力が仕様の時だけ | 文章のみ | - | - | 残す(使うべきかの判断) | | - | testing.md | expected-failure の印が無いので stacked PR で欠陥を記録しない | 文章のみ | - | - | 残す(PR 運用の方針) | | - | testing.md Mutation Testing(各行) | `gremlins` の導入,範囲指定,フラグ確認,`LIVED` / `NOT COVERED`,report を管理外に置く | 文章のみ | - | - | 残す(ツール手順の参照情報) | | - | testing.md Test Structure | ブラックボックスは `foo_test`,ホワイトボックスは必要な時だけ | 文章のみ | - | - | 残す(内部が必要かの判断) | | (thelper) | testing.md Test Structure | helper は先頭で `t.Helper()` | 既存 linter(template-go の `thelper`) | template-go の .golangci.yml | - | 「先頭で `t.Helper()`」を削除.「共有する時だけ共通化する」は残す | | - | testing.md Test Structure | fake は消費側の小さい interface を実装する明示型 | 文章のみ | - | - | 残す(設計の好み) | | - | tooling.md Package Management | `go get`,`go mod tidy` で依存を整える | 文章のみ | - | - | 残す(コマンドの運用) | | - | tooling.md Package Management | `go get -tool` で固定し `go tool` で実行 | 文章のみ | - | - | 残す(コマンドの運用) | | - | tooling.md Package Management | `@latest` を文書やコミット済みコマンドに書かない | 文章のみ | - | - | 残す(Go の構文でなく文書と script の文字列.言語非依存で agents レーンの領分) | | - | tooling.md Package Management | `GOTOOLCHAIN=local` を前提にする | 文章のみ | - | - | 残す(環境の前提) | | - | tooling.md Package Management | `go.sum` を手で編集しない | 文章のみ | - | - | 残す(編集操作の規則.ソースの構文に現れない) | | - | tooling.md Package Management | 一般的だからという理由で依存を足さない | 文章のみ | - | - | 残す(判断) | | - | tooling.md Directory Structure | `main.go` から始め,複数 command なら `cmd/<name>/main.go` | 文章のみ | - | - | 残す(プロジェクト全体の構造の判断) | | - | tooling.md Directory Structure | 非公開パッケージは `internal/` | 文章のみ | - | - | 残す(公開すべきかの判断) | | (pkg / util / common) | tooling.md Directory Structure | `pkg/` `util/` `common/` を作らない | ast-grep(パッケージ名の `util` / `common` は go_no_vague_name)+既存 linter(波 2:ディレクトリ名) | go_no_vague_name,ls-lint の `.dir` 規則 | - | 残す(`pkg/` ディレクトリは規則が覆わない) | | main-is-thin | tooling.md Directory Structure | `main` を薄く保つ | jev-lint | model-rules/go/main-is-thin/rule.yml | - | 残す(ADR-0021) | | - | tooling.md Quality Gates | 検証結果を確認し,既定コマンドを実行する | 文章のみ | - | - | 残す(完了手順.`tsdd` の領分) | | - | tooling.md Quality Gates | linter 設定を緩めず,コードを直す | 文章のみ | - | - | 残す(変更方針.コードに現れない) | | (nolintlint) | tooling.md Quality Gates | `//nolint` は linter 名と理由を書く | 既存 linter(template-go の `nolintlint`) | template-go の .golangci.yml | - | 削除 | | - | types.md Structs | 不変条件があれば非公開フィールドと検証する `NewX` | 文章のみ | - | - | 残す(不変条件の有無は構文から判別できない) | | - | types.md Structs | 不変条件が無ければ有用なゼロ値 | 文章のみ | - | - | 残す(設計の好み) | | (flag-parameter) | types.md Structs | bool 引数を避ける | 既存 linter(template-go の revive `flag-parameter`) | template-go の .golangci.yml | - | 「bool 引数を避ける」を型付き定数への置き換え方(直し方)に言い換えて残す | | go_iota_enum_typed | types.md Enums | `iota` の列挙は型付き定数 | ast-grep(`X = iota` で型が無いもの,severity: error) | rules/go/go_iota_enum_typed.yml | rule-tests/go_iota_enum_typed.yml | 「typed」を削除.「`String()` を持たせる」は残す(同一ファイルに限らない) | | (exhaustive) | types.md Enums | `switch` で扱い,漏れは `exhaustive` が報告 | 既存 linter(template-go の `exhaustive`) | template-go の .golangci.yml | - | 削除 | | go_sealed_interface_sumtype_decl | types.md Sum Types | 非公開 marker メソッドの interface に `//sumtype:decl` | 文章のみ(ast-grep では正確に判定できない推奨事項.規則は置かない) | - | - | 残す(ユーザー判断:推奨事項として文章を残す.Sum Types 節を復元) | | - | types.md Interfaces | interface は小さく,消費側のパッケージで定義 | 文章のみ | - | - | 残す(別パッケージの使われ方の判断) | | (ireturn) | types.md Interfaces | interface を受け取り,具象型を返す | 既存 linter(template-go の `ireturn`) | template-go の .golangci.yml | - | 削除 | | - | types.md Interfaces | 実装が 2 つ目か fake が要るまで interface を作らない | 文章のみ | - | - | 残す(将来の実装は構文から判別できない) | | - | SKILL.md Scope,Task-Specific References | skill の適用範囲と参照の振り分け | 文章のみ | - | - | 残す(読む文書の案内) | ## 波 2: linter で有効化する規則 `template-go`(main)の `.golangci.yml` は revive の `var-naming`,`receiver-naming`,`context-as-argument`,`error-return`,`flag-parameter`,errcheck `check-blank`,`testifylint`,`usetesting`,`thelper`,`ireturn`,`paralleltest`,`nolintlint`,`errorlint`,`exhaustive`,formatter を有効にしており,上の表のとおりその文章を削除した.残る未対応は次の 1 件. | repo | 設定ファイル | 規則 ID | 置き換える文章 | | --- | --- | --- | --- | | furedea/template-go | .ls-lint.yml | `.dir` で `pkg` / `util` / `common` を禁止(現状は `internal` 配下の小文字だけを検査) | `pkg/` `util/` `common/` を作らない(文章は残す) | ## ユーザー判断(ast-grep 規則の扱い) 静的な規則は block し,まれな正当な例外はレビュー済みの抑制コメントで通す.`go_context_param_named_ctx`,`go_no_context_in_struct`,`go_iota_enum_typed`,`go_use_slog`,`go_mutex_field_documented`,`go_no_generated_mocks`,`go_no_other_assertion_library` を `severity: error` にした.既存の `go_error_no_failed_to_prefix` と `go_error_no_string_matching` も `severity: error` にした(ユーザー判断).`go_receiver_name_short`(revive `receiver-naming` が覆う),`go_library_no_global_logger`,`go_sealed_interface_sumtype_decl` は rule-tests を削除した(`go_library_no_global_logger` と `go_sealed_interface_sumtype_decl` の文章は,ユーザー判断で残す). ## 方針変更(#190 への適用) 新規プロジェクトは `furedea/template-*` からだけ作られるため,template の linter が完全に覆う文章は削除する(template-go #9 を main で確認).重複する ast-grep 規則 `go_package_name_lowercase`(revive `var-naming` が覆う)と `go_error_no_capitalized_message`(staticcheck `ST1005` が覆う)を,rule-tests ごと削除した.これにより,後者に出ていた未対応の指摘は不要になった. ## 現在の hit(修正はこの PR に含めない) `ast-grep scan --config agents/hooks/lint/sgconfig.yml <path>` を読み取りのみで実行した. | repo | Go 規則の hit | | -------------------------- | --------------------- | | agent-config | 0(`.go` 6 ファイル) | | agent-harness | 0 | | dotfiles | 0 | | rater,template-go(参考) | 0 | ## #196 で対応した指摘 - [x] `go_sealed_interface_sumtype_decl`: `//sumtype:decl`(空白なし)だけを受け入れる - [x] `go_context_param_named_ctx`,`go_no_context_in_struct`: 標準 `context` の無名 import を要求 - [x] `go_use_slog`,`go_library_no_global_logger`: `log` という引数を持つ関数を除外 - [x] `go_iota_enum_typed`: `iota + 1` など `<<` を含まない `iota` 式も対象にする - [x] `go_no_generated_mocks`: `//go:generate` の mockgen / mockery / counterfeiter / moq / minimock も検出 - [x] 方針:のちに「template の linter が覆う文章は削除する」へ変更(下の「方針変更」) ## 後続に回す指摘(#196 対応中のレビュー回数の上限) #196 の対応後,3 回目の再レビューで新たに出た指摘.修正せず "Deferred to a follow-up Issue (review limit)." と返信して解決済みにした. - `go_iota_enum_typed`: `_ = iota` の次が型なしの `KB = 1 << (10 * iota)` の場合,`_ = iota` を誤検出する - `go_library_no_global_logger`: `log` 引数による除外が `slog.SetDefault` の呼び出しにも効いて見逃す(除外は `log.*` の呼び出しだけに適用すべき) ## 後続に回す指摘(template linter 方針の対応中のレビュー回数の上限) - model rule `error-handled-once`: `slog.Default().Error(...)` や `log.Default().Printf(...)` のように `Default()` を挟む呼び出しを selector に含めていない ## 後続に回す指摘(レビュー回数の上限) - model rule `error-handled-once`: receiver 名が `log` / `logger` 以外(`l`,`audit` など)の logger 呼び出しを選ばない.receiver 側に `Output` も無い - `go_use_slog`: 標準 `log` を import するファイルで,関数内のローカル変数・receiver・名前付き戻り値が `log` をシャドーする呼び出しを除外していない(引数によるシャドーだけ除外) - 【要判断】`severity: error` を hook のブロック判定に結びつける(`static_rule_scan.py` は severity を読まず,`test_findings_are_never_blocking_whatever_the_scanner_exit_code` は常に非ブロックを要求している).この PR の範囲外で,ユーザーの判断が要る - model rule 5 件の fixture と baseline(ユーザーの指示で後回し) - model rule `error-handled-once`: 入れ子のクロージャがログを出すと,親関数も重複して選択される(ログ呼び出しに最も近い関数だけを選ぶべき) - `go_no_generated_mocks`: `// Code generated by ...` ヘッダーだけを持つ生成済み mock を検出しない - `go_no_context_in_struct`: `*context.Context`(ポインタ)のフィールドを検出しない なお `go_iota_enum_typed` は,オペランドの型を構文だけでは判別できないため,型なしの `X = iota` だけを判定する(`iota + Step` などの式は誤検出を避けるため判定しない). ## blocking 規則の message と note `severity: error` の ast-grep 規則 9 件すべてで,`message` に「なぜ誤りか(具体的な失敗)」,`note` に「そのまま適用できる修正(before/after)」を 1 文で書いた.従来の `note`(判定の限界)は規則 YAML の先頭コメント(`# Limits:`)へ移した. ## 既知の限界 - ast-grep の規則は import の別名や `.` import を追えない(`go_use_slog`,`go_library_no_global_logger`,`go_no_other_assertion_library`,`go_no_generated_mocks`). - `go_no_other_assertion_library` と `go_no_generated_mocks` は既知の library 名の一覧で判定する. - `go_error_no_capitalized_message` は大文字の後に小文字が続く先頭だけを対象にし,`HTTP 500` のような略語始まりは検出しない. - `go_mutex_field_documented` はコメントの有無だけを判定し,前のフィールドの行末コメントも直前のコメントとして数える. - `go_no_vague_name` は既存の命名を許す例外を判別しない(warning). - jev-lint の新規 5 規則は fixture,eval のしきい値の当てはめ,baseline を持たない(ユーザーの指示で後回し).しきい値 0.5 は初期値. ## 検証 - `ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests`: 24 規則すべて通過 - `jev-lint rules --no-config -R agents/hooks/lint/model-rules`: 17 規則,0 error - `nix develop --command uv run pytest -q`: 4882 passed,1 skipped(`tests/test_ast_grep_rules.py`,`tests/test_model_rule_files.py` を含む) - commit 時の lefthook(shfmt,ls-lint,shellcheck,commitlint): 通過 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
…checks (#195) Refs #74(TypeScript 担当) Refs #196 計画:#74 (comment) ## 概要 `agents/skills/typescript-style/` の規則を 1 文ずつ洗い出し,判定できる最も安い道具へ移した(ADR-0021). - **ast-grep(最終)**: この PR が残す TypeScript の ast-grep 規則は 0 件.不安定な 3 規則(`ts_no_unvalidated_json_cast`,`ts_catch_rethrow_requires_cause`,`ts_no_other_test_framework`)は review が収束しないため削除し,oxlint へ移す(下の「ast-grep から外した規則と理由」). - **ast-grep(削除)**: `ts_readonly_property`,`ts_readonly_array_property`,`ts_no_home_dir_in_tests`(文章は残す),`ts_no_namespace_import`(規則も文章も削除). - **jev-lint**: 8 規則を `model-rules/typescript/<id>/rule.yml` に追加(`threshold: 0.5`,`severity: warning`).prose は残す(ADR-0021).fixture・eval・baseline は未追加. - **既存 linter が覆う文章**は,template-typescript の `main` で有効な規則を確かめ,同じ PR で削除した.完全には覆われない部分は残した. - **共有ファイルの変更**: `tests/test_model_rule_files.py` の TypeScript 用の選択数テストだけ(jev 規則の追加に伴う期待値の更新). ## 最終の ast-grep 規則 なし(TypeScript の blocking な ast-grep 規則は残さない). ## ast-grep から外した規則と理由 blocking にする規則は安定していなければならない.次の規則は review のたびに新しい指摘が出て収束しなかった(11〜26 件)ため,既存の linter に任せることにした.判断の基準は ADR-0021 に記録する. | 規則 | 行き先 | review の指摘数 | 不安定の型 | 例 | | --- | --- | --- | --- | --- | | `ts_no_unvalidated_json_cast` / `tsx_` | oxlint `typescript/no-unsafe-type-assertion`,`no-unsafe-assignment`,`no-unsafe-return`(furedea/template-typescript#44) | 26 | 1(変数の宣言型や import 先を見られない),4(`as` / `<T>` / `!` / `satisfies` / 注釈 / 戻り値型の書き方が多い) | 誤検出:`const x: unknown \| null = JSON.parse(t)`.見逃し:`JSON.parse(t) as Record<string, unknown>` | | `ts_catch_rethrow_requires_cause` / `tsx_` | oxlint `preserve-caught-error`(furedea/template-typescript#44) | 11 | 2(捕捉した値が使われるかを追う),4(`new` なし,`cause` の渡し方,`.catch` など) | 誤検出:`new AppError({ message, cause: error })`.見逃し:`new Error(message)` | | `ts_no_other_test_framework` / `tsx_` | oxlint `no-restricted-globals`(スコープを見る)と `no-restricted-imports`(template-typescript の新しい PR.番号は作成後に追記) | 12 | 2(`jest` が局所変数・引数・分割代入・`catch` の引数などに隠されるかをスコープで追う) | 誤検出:`const { jest } = makeFormatters(); jest.format()`,`catch (jest) { jest.format() }` | 文章(typescript-style)は,template の PR がマージされるまで残す. ## 文章と規則の対応表(全規則) 場所は `agents/skills/typescript-style/` からの相対パス,実装は `agents/hooks/lint/` からの相対パス. | 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 | | ------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | (削除)ts_no_namespace_import | references/code_style.md(#117 で削除済み) | 名前空間 import を避ける | 規則を削除 | — | — | 文章は #117 で削除済み.ユーザーの判断で規則(`ts_` / `tsx_`)も削除した(Zod 4 が `import * as z from "zod"` を勧めるなど,名前空間 import は問題ない) | | (ls-lint) | references/code_style.md | Use snake_case file names (enforced by ls-lint) | 既存 linter(template-typescript の `.ls-lint.yml` の `.*:` regex) | — | — | 削除(新規プロジェクトは template から作る,というユーザーの方針) | | (wave 2) | references/code_style.md | Name files by the domain or action, not a role suffix | 既存 linter(ls-lint,有効化が必要) | — | — | 残す(波 2 に記載) | | `ts_no_vague_name` | references/code_style.md | Avoid `manager`, `helper`, `util`, and `common` unless the name is already established locally | 文章のまま | — | — | 残す.`Manager` / `Helper` / `Util` / `Common` を含む識別子は常に誤りとは限らず,静的規則だと編集を止めてしまうため,ユーザーの判断で規則を削除した(ts_no_vague_name / tsx_no_vague_name) | | (oxlint) | references/code_style.md | Use `import type` for type-only imports | 既存 linter(template-typescript の `typescript/consistent-type-imports`(tsc `verbatimModuleSyntax`)) | — | — | 削除 | | (oxlint) | references/code_style.md | Do not create import cycles | 既存 linter(template-typescript の `import/no-cycle`) | — | — | 削除 | | (oxfmt) | references/code_style.md | Let oxfmt define formatting. Do not hand-format around it | 既存 linter(template-typescript の `pnpm run format:check`(oxfmt)) | — | — | 削除 | | — | references/code_style.md | Keep user-facing wording separate from logic, in a dedicated module such as `src/copy/` | 文章のまま | — | — | 残す.文言かどうかとモジュール配置の判断はプロジェクト構成に依存し,構文からも関数単位でも yes/no にできない | | `comment-explains-why` | references/code_style.md | Comments explain why, not what | jev-lint | model-rules/typescript/comment-explains-why/rule.yml | なし(保留) | 残す(ADR-0021) | | `comment-explains-why` | references/code_style.md | Prefer clear types, function names, and module boundaries over explanatory comments | jev-lint(同上) | 同上 | なし | 残す(ADR-0021) | | — | references/code_style.md | Architectural choices, dependency decisions, and external-tool boundary rules belong in ADRs | 文章のまま | — | — | 残す.記録先の方針で,コードに現れない | | `expected-failure-returned-as-value` | references/errors.md | Return expected failures as values (`Result`) | jev-lint | model-rules/typescript/expected-failure-returned-as-value/rule.yml | なし | 残す | | — | references/errors.md | Define the `Result` type once and reuse it | 文章のまま | — | — | 残す.複数ファイルにまたがる重複で,1 関数・1 ファイルの判定にならない | | — | references/errors.md | Make `error` a union of tagged variants when callers branch on the failure category | 文章のまま | — | — | 残す.呼び出し側の分岐は他ファイルにあり,その場で見えない | | `expected-failure-returned-as-value` | references/errors.md | `throw` only for programmer errors and unrecoverable states | jev-lint(上と同じ規則) | 同上 | なし | 残す | | `ts_catch_rethrow_requires_cause` | references/errors.md | Add context when rethrowing or converting: `new Error(message, { cause })` | oxlint `preserve-caught-error`(ast-grep 規則は削除) | — | — | 残す(値への変換と「操作と対象を名指す」は規則が覆わない.後者は既存の `error-message-names-operation`) | | `error-message-names-operation`(既存) | references/errors.md | The message names the operation and subject | jev-lint(既存規則) | model-rules/typescript/error-message-names-operation | 既存 | 残す | | (波 2) | references/errors.md | Do not swallow errors with an empty `catch` | 既存 linter(template-typescript の `no-empty`(`allowEmptyCatch: false`)) | — | — | 一部削除(空ブロックは linter が覆う.コメントやログだけの `catch` も握りつぶしである,という点を残した) | | (oxlint) | references/errors.md | Await or explicitly handle every promise; do not disable `no-floating-promises` / `no-misused-promises` / `await-thenable` | 既存 linter(template-typescript の `typescript/no-floating-promises` / `no-misused-promises` / `await-thenable`) | — | — | 削除 | | `states-modeled-as-discriminated-union` | references/types.md | Model states and kinds as discriminated unions with a tag field, not optional fields or flags | jev-lint | model-rules/typescript/states-modeled-as-discriminated-union/rule.yml | なし | 残す | | (波 2) | references/types.md | Handle a union with an exhaustive `switch` whose `default` assigns `satisfies never` | 既存 linter(template-typescript の `typescript/switch-exhaustiveness-check`) | — | — | 一部削除(網羅性は linter が覆う.`default` で `satisfies never` を代入する形だけ残した) | | — | references/types.md | Represent values with validation or invariants as branded types created by a validating `parse` function | 文章のまま | — | — | 残す.値オブジェクト一般は `agents` 担当の AGENTS.md の規則.ブランドの作り方は 1 関数では判定できず,jev 規則にすると同規則と重複する | | `ts_readonly_property` | references/types.md | Declare properties `readonly` … by default | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).`typescript/prefer-readonly` は template-typescript で別途有効化する予定(この PR では未実施) | | `ts_readonly_array_property` | references/types.md | … and arrays `readonly T[]` by default | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).`typescript/prefer-readonly` は template-typescript で別途有効化する予定(この PR では未実施) | | `ts_readonly_array_property` | references/types.md | Do not expose a mutable raw collection from a domain type | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).`typescript/prefer-readonly` は template-typescript で別途有効化する予定(この PR では未実施) | | `ts_no_unvalidated_json_cast` | references/types.md | Accept external input as `unknown` and parse it once at the boundary | oxlint `typescript/no-unsafe-type-assertion` / `no-unsafe-assignment` / `no-unsafe-return`(ast-grep 規則は削除) | — | — | 残す(環境変数・storage など他の境界,「一度だけ検証」は覆わない) | | `type-assertion-follows-validation` | references/types.md | Do not use `as` casts except immediately after validation | jev-lint | model-rules/typescript/type-assertion-follows-validation/rule.yml | なし | 残す | | (oxlint) | references/types.md | Do not use `any`; use `unknown` and narrow | 既存 linter(template-typescript の `typescript/no-explicit-any`) | — | — | 削除 | | — | references/types.md | Group arguments into a type only when it names a real domain concept | 文章のまま | — | — | 残す.`agents` 担当の AGENTS.md に同じ規則があり,ここで別に判定しない | | `ts_no_other_test_framework` | references/testing.md | Use only `vitest` as test framework; do not add Jest | oxlint `no-restricted-globals` / `no-restricted-imports`(ast-grep 規則は削除) | — | — | 残す(`package.json` への依存追加と「globals を有効にする」設定は覆わない) | | — | references/testing.md | Run tests with `pnpm run test` | 文章のまま | — | — | 残す.実行手順 | | `repeated-cases-use-it-each` | references/testing.md | Use `it.each` for the same behavior across multiple inputs | jev-lint | model-rules/typescript/repeated-cases-use-it-each/rule.yml | なし | 残す | | `mock-only-external-boundaries` | references/testing.md | Prefer fake implementations over mocks. Use `vi.mock` only for external dependencies at module boundaries | jev-lint | model-rules/typescript/mock-only-external-boundaries/rule.yml | なし | 残す | | `inject-time-and-randomness` | references/testing.md | Inject time and randomness as arguments instead of reading `Date.now()` / `Math.random()` inside logic | jev-lint(エントリポイントでの読み取りは正当なので ast-grep にしない) | model-rules/typescript/inject-time-and-randomness/rule.yml | なし | 残す | | `ts_no_home_dir_in_tests` | references/testing.md | Do not touch the real home directory | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(`HOME` の退避と復元のための読み取りと区別できない) | | `known-defect-marker-names-removal`(既存) | references/testing.md | Record a reproduced defect with `test.fails` and a comment naming the removal condition; remove the marker in the fixing change | jev-lint(既存規則) | model-rules/typescript/known-defect-marker-names-removal | 既存 | 残す(マーカーを外す手順は規則が覆わない) | | — | references/testing.md | Mutation Testing: use StrykerJS 10.x with the Vitest runner; add dev dependencies only when needed | 文章のまま | — | — | 残す.道具の選択と導入時期の方針 | | — | references/testing.md | Set `"testRunner": "vitest"` in `stryker.config.json` | 文章のまま | — | — | 残す.設定を作る手順.JSON 設定は編集後 hook の走査対象外で,Stryker を使うときだけ関係する | | — | references/testing.md | Scope a run to the changed module (`pnpm exec stryker run --mutate ...`) | 文章のまま | — | — | 残す.実行手順 | | — | references/testing.md | Read survivors in the clear-text output or the HTML report | 文章のまま | — | — | 残す.作業手順 | | — | references/testing.md | Keep `.stryker-tmp/` and `reports/` out of version control | 文章のまま | — | — | 残す.`.gitignore` の内容で,編集後 hook の対象外 | | — | references/testing.md | Unit test: `*.test.ts` next to the module | 文章のまま | — | — | 残す.配置は vitest の `include` 設定で決まり,構文から判定できない | | — | references/testing.md | End-to-end test: under `tests/` | 文章のまま | — | — | 残す.同上 | | — | references/testing.md | Helper function: prefer local helpers when setup is lightweight | 文章のまま | — | — | 残す.好みの方針 | | `mock-only-external-boundaries` | references/testing.md | Fake implementation: prefer explicit fake objects over global mocks | jev-lint(上と同じ規則) | 同上 | なし | 残す | | — | references/tooling.md | Use pnpm only; do not mix in npm or yarn, no competing lock file | 文章のまま | — | — | 残す.`package.json` と lock ファイルの運用で,ソースの構文に現れない | | — | references/tooling.md | Install from the lock with `pnpm install --frozen-lockfile` | 文章のまま | — | — | 残す.実行手順 | | — | references/tooling.md | Add dependencies with `pnpm add` / `pnpm add -D` | 文章のまま | — | — | 残す.実行手順 | | — | references/tooling.md | Do not use `@latest`-style version shortcuts | 文章のまま | — | — | 残す.文書やコマンド履歴が対象で,ソースの構文に現れない | | — | references/tooling.md | Do not edit `pnpm-lock.yaml` manually | 文章のまま | — | — | 残す.編集経路の方針 | | — | references/tooling.md | Do not add a dependency only because it is common | 文章のまま | — | — | 残す.追加の動機の判断 | | — | references/tooling.md | Formatting is oxfmt, linting is oxlint, type checking is `oxlint --type-aware --type-check` | 文章のまま | — | — | 残す.道具の選択の記述 | | — | references/tooling.md | Do not add ESLint, Prettier, or another type checker | 文章のまま | — | — | 残す.道具の選択.`package.json` の依存は構文走査の対象外 | | — | references/tooling.md | Keep the strict `tsconfig.json` options and never loosen them | 文章のまま | — | — | 残す.JSON 設定は編集後 hook の走査対象外(ast-grep の JSON 規則を置いても走らない) | | (knip) | references/tooling.md | Detect unused files, exports, and dependencies with knip | 既存 linter(template-typescript の `pnpm run knip`(`check` にも含まれる)) | — | — | 削除 | | — | references/tooling.md | Store production code in `src/` | 文章のまま | — | — | 残す.配置の方針 | | — | references/tooling.md | Colocate unit tests as `*.test.ts`; e2e tests in `tests/` | 文章のまま | — | — | 残す(testing.md と同じ理由) | | — | references/tooling.md | Enforce layer boundaries with `no-restricted-imports` | 文章のまま | — | — | 残す.層の定義はプロジェクトごとの `.oxlintrc.json` で,共有の規則にできない | | (波 2) | references/tooling.md | Avoid `utils.ts` and `helpers.ts`; name modules by domain or action | 既存 linter(ls-lint,有効化が必要) | — | — | 残す(波 2 に記載) | | — | references/tooling.md | Confirm verification results; run through `package.json` scripts, not the underlying binaries | 文章のまま | — | — | 残す.実行手順(`tsdd` の検証方針) | | — | SKILL.md | Scope: routine edits do not authorize introducing Nix or changing GitHub settings | 文章のまま | — | — | 残す.作業範囲の方針 | | — | SKILL.md | Read only the references relevant to the current task | 文章のまま | — | — | 残す.案内.表の「code_style」行から imports と formatting を除いた | ## 波 2: linter で有効化する規則 テンプレートは変更していない.`no-empty` と `typescript/switch-exhaustiveness-check` は template-typescript で有効になったため表から外した.残る規則を有効化すれば,右端の文章を削除できる. | repo | 設定ファイル | 規則 ID | 置き換える文章 | | --------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | furedea/template-typescript | `.ls-lint.yml` | `.ts` / `.tsx` の名前に `utils` / `helpers` / `util` / `helper` / `manager` / `common` と役割接尾辞(`formatter` など)を禁じる regex | code_style.md「Name files by the domain or action…」,tooling.md「Avoid `utils.ts` and `helpers.ts`」,code_style.md の「Avoid `manager`…」のうちファイル名の部分 | - 再レビュー対応(この PR の最終): 受け手の名前に依存しない `json()` の型アサーション,`.catch` のコールバック(引数を束縛する場合),再エクスポートと動的 import,追加のフレームワーク名,ジェネレーターの境界を直した.以前の対応:`ts_no_unvalidated_json_cast` は `json()` の受け手を `res` / `response` 系の名前に限り,型付き引数の既定値も対象にした.`ts_catch_rethrow_requires_cause` は `.catch` のコールバックも見る.`ts_no_other_test_framework` は動的 `import()` / `require()` も見る.`repeated-cases-use-it-each` は `describe.each` の表の呼び出しを除く. - ブロックする 3 規則(`ts_` / `tsx_`)の `message` に失敗の理由,`note` に直し方(before / after の 1 行)を書いた(PR #203 の blocking hook が両方を表示する). ## 検証 - `ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests`: 15 件通過 - `REQUIRE_AST_GREP=1 nix develop --command uv run pytest`: 4864 passed,1 skipped ## 後続(再レビューの上限で保留した指摘) - `repeated-cases-use-it-each`: Vitest の `suite(...)` も `describe` と同じく選ぶ. - `inject-time-and-randomness`: `Date()`(`new` なし)と括弧なしの `new Date` も選ぶ. - `comment-explains-why`: アロー関数・関数式の親が `jsx_expression`,`export_statement`,`assignment_expression`,配列などの場合も subject にする. - `inject-time-and-randomness`: `crypto.getRandomValues(...)` も乱数の読み取りとして選ぶ. - `expected-failure-returned-as-value`,`comment-explains-why`,`inject-time-and-randomness`: オブジェクトプロパティ(`pair`)に束縛した関数も subject にする. - `type-assertion-follows-validation` と `angle-bracket-assertion-follows-validation`: `state` を `located` にする. - `comment-explains-why`: 関数外コメントの subject に隣接コードを渡すため `state` を `located` にする. - `expected-failure-returned-as-value`: `export default () => { throw ... }` のように `export_statement` に直接置かれた関数も subject にする. - `mock-only-external-boundaries`: `vi.spyOn(client, "send")` のように定義元が呼び出しから分からない場合のため,`state` を `located` にして周辺コードを渡す. - `inject-time-and-randomness`: bare な `randomInt(...)` などは import 元を確認せず over-match する(同名ヘルパーにも一致).`state` を `located` にするか criteria の false 側に加える. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
…ks (#194) Refs #74(段階 2C: bash-style / github-actions-style),Refs #196 計画: #74 (comment) ## 概要 `bash-style` と `github-actions-style`(SKILL.md と references)の規則を棚卸しし,判定できる最も安い道具へ移した(ADR-0021). - ast-grep 規則 6 件(Bash 3 件,GitHub Actions の YAML 3 件)を追加し,例のテストを付けた.すべて `severity: error`(ブロック).ユーザーの判断(監査の結果)で `bash_usage_function` は削除した.レビューが収束しなかった `bash_strict_mode_header`,`gha_workflow_default_shell`,`gha_workflow_concurrency` は,ast-grep では構文だけから判定できない(実行順,job と workflow の対応,trigger の多様な書き方)ため,ブロック規則から jev-lint のモデル規則(助言,`severity: warning`,しきい値 0.5,当てはめは後回し)に降格した.zizmor の `concurrency-limits` は pedantic persona でのみ同様の検査をするが,それでも降格した. - ブロックする ast-grep 規則 9 件すべてに `message`(なぜ誤りか)と `note`(そのまま適用できる直し方,1 行の前後例)を付けた.元の `note`(対象範囲の説明)は YAML のコメントに移した. - jev-lint 規則 7 件(Bash 5 件,YAML 2 件)を `model-rules/<language>/<id>/rule.yml` に追加した.jev-lint は `.sh` と,ast-grep が解析できる YAML を扱える(`jev-lint rules` で 19 規則・エラー 0 を確認).fixtures・eval・baseline は未追加(ユーザー指示で後回し).文章は ADR-0021 に従い残した. - 既存 linter(shellcheck,shfmt,ls-lint,zizmor)が覆う文章は削除し,規則 ID を表に書いた. - 規則で完全に置き換わる文章は同じ PR で削除した.一部だけ覆う文章は残した. 規則の置き場所は `agents/hooks/lint/rules/{bash,yaml}/`,テストは `agents/hooks/lint/rule-tests/`.YAML の規則は `files:` で `**/.github/workflows/**`(pin コメントのみ `**/action.yml` / `**/action.yaml` も)に絞った.hook は絶対パスで ast-grep を呼ぶため,先頭に `**/` が要る(レビュー指摘.`.github/workflows/**` だと絶対パスに一致せず規則が動かなかった).`sgconfig.yml` と hook のコードは変更していない. ## 共有ファイルの変更(1 件)と追加したテスト 新規 `tests/test_ast_grep_workflow_scope.py`: 絶対パスで渡した workflow に 5 つの workflow 規則が出ること,`.github/workflows` の外の YAML には出ないことを確かめる. `tests/hooks/test_lint_format_cli.py`: 実際の `shfmt` を通す 2 つの sh 例が `#!/bin/bash` と `set -eo pipefail` で,新しい Bash 規則(`bash_shebang_env_bash` ほか)の通知を出し「通知なし」の期待に反した.例を規約どおり(`#!/usr/bin/env bash`,`set -euo pipefail`)に直した. ## 文章と規則の対応表 「実装」の ast-grep は `agents/hooks/lint/rules/…`,例のテストは `agents/hooks/lint/rule-tests/…` の相対パス.jev-lint は `agents/hooks/lint/model-rules/…/rule.yml`(しきい値 0.5,fixtures なし). ### bash-style / SKILL.md | 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 | | --- | --- | --- | --- | --- | --- | --- | | `bash_shebang_env_bash` | `agents/skills/bash-style/SKILL.md` File Header | "`#!/usr/bin/env bash` — resolve Bash from `PATH` and run with it explicitly, not with `sh`" | 静的(ast-grep,error) | `rules/bash/bash_shebang_env_bash.yml` | 良 4 / 悪 2 | 削除(`sh` / `bash` を指す shebang だけを見る.ast-grep が Bash として読む `bats` と `zsh` は除く) | | `bash_strict_mode_header` | 同 File Header | "`set -euCo pipefail`"(`-e` `-u` `-C` `-o pipefail` の説明を含む) | モデル(jev-lint,助言) | `model-rules/bash/strict-mode-header/rule.yml` | fixtures は後回し | 降格(ast-grep の規則とテストは削除.prose は `-e` `-u` `-o pipefail` の見出しの説明として残した) | | `working-directory-by-responsibility` | 同 File Header | "Choose the working directory by responsibility. Hooks that operate on a project must use the target project's working directory…" | 動的(jev-lint,0.5) | `model-rules/bash/working-directory-by-responsibility/rule.yml` | なし(後回し) | 残す(ADR-0021: 昇格まで.規則は `cd` / `pushd` を選ぶため,自分のディレクトリへ移る場合だけを判定する.`cd` なしで相対パスの同梱ファイルを開く場合は選ぶ対象が無く,文章のまま) | | `tracing-not-left-on-for-secrets` | 同 File Header | "Enable tracing only when useful for debugging; keep it disabled by default for scripts handling secrets or user input" | 動的(jev-lint,0.5) | `model-rules/bash/tracing-not-left-on-for-secrets/rule.yml` | なし | 残す(書き換え: 既定でオフ,秘密とユーザー入力を扱うスクリプトでは付けない,スクリプトを編集せず `bash -x ./script.sh` で有効にする.よく調べるスクリプトには任意の `if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi`.この行を要求する規則は無い) | | `tracing-not-left-on-for-secrets` | 同 File Header | "suppress it around noisy or sensitive sections. Restore it only when subsequent commands are safe to trace" | 動的(jev-lint,0.5) | 上と同じ規則 | なし | 残す | | (なし)(`bash_usage_function` は削除) | 同 usage Function | "Every script must define a `usage` function that prints documentation" | 文章のまま(ユーザーの判断で規則を削除) | — | — | 残す(引数を取るスクリプトに限る形に書き換えた.引数の有無は構文から判定できず,数行の hook に要求すると手間が大きい) | | (なし) | 同 usage Function | "Use a heredoc inside the function body" | 文章のまま | — | — | 残す(形は構文で判別できるが,価値に対して誤検出の調整が大きい) | | `usage-help-and-error-exits` | 同 usage Function | "For requested help, call `usage` and `exit 0`. For missing or invalid arguments, call `usage >&2` and `exit 1`" | 動的(jev-lint,0.5) | `model-rules/bash/usage-help-and-error-exits/rule.yml` | なし | 残す | | `script-constants-readonly` | 同 Constants | "Declare constants with `readonly`" | 動的(jev-lint,0.5) | `model-rules/bash/script-constants-readonly/rule.yml` | なし | 残す | | `bash_readonly_constant_name` | 同 Constants / Naming | "Names use `SCREAMING_SNAKE_CASE`" | 静的(ast-grep,error) | `rules/bash/bash_readonly_constant_name.yml` | 良 5 / 悪 3 | 削除(`readonly -f`(関数名)は除外し,その valid 例を追加.規則は `readonly` で宣言した名前だけを見る.Naming 表は変数の `snake_case` の 1 文にした) | | shellcheck SC2086 / SC2046 | 同 Constants | "Always quote the right-hand side — values may contain spaces or special characters" | 既存 linter(shellcheck.hook が全リポジトリで `shellcheck -x` を実行,`lefthook.yml` でも有効) | — | — | 削除 | | shellcheck SC2086 | 同 Variables | "Quote all parameter expansions and string values to guard against word splitting and glob expansion" | 既存 linter(shellcheck SC2086) | — | — | 削除 | | (なし) | 同 Variables | "Use default values for variables that may be empty or undefined" | 文章のまま | — | — | 残す(どの変数が空になりうるかは設計の判断で,yes/no の基準にできない) | | `function-variables-local-near-use` | 同 Variables | "Define variables just before first use (minimize lifetime)" | 動的(jev-lint,0.5) | `model-rules/bash/function-variables-local-near-use/rule.yml` | なし | 残す | | (なし) | 同 Naming | "Variables: `snake_case`" | 文章のまま | — | — | 残す(定数 `NAME=…; readonly NAME` の 2 段書きと区別できず,構文から変数と定数を分けられない) | | `bash_function_name_snake_case` | 同 Naming | "Functions: `snake_case`" | 静的(ast-grep) | `rules/bash/bash_function_name_snake_case.yml` | 良 3 / 悪 4 | 削除(表の行) | | `bash_function_name_snake_case` | 同 Naming | "Do not start names with a digit" | 静的(ast-grep)+ Bash の構文エラー | 同上(関数名).変数名は Bash が受け付けない | 良 3 / 悪 4(`1st_step`) | 削除 | | `bash_local_underscore_prefix`(#117) | 同 Naming | "Local variables: `_snake_case` (leading underscore)" | 静的(ast-grep,既存) | `rules/bash/bash_local_underscore_prefix.yml` | 既存 | 表の行を削除.接頭辞の後の `snake_case` は規則が覆わず,Variables 行に残る | | `bash_local_underscore_prefix`(#117) | 同 Local Variables | "Declare function-local variables with `local` and prefix with `_`" | 静的(既存)+動的 | 上と `function-variables-local-near-use` | 既存 | 「`_` で始める」だけ削除.`local` で宣言する指示は残す | | `function-variables-local-near-use` | 同 Local Variables | "Declare function-local variables with `local`" | 動的(jev-lint,0.5) | 上 | なし | 残す | | shfmt(`.editorconfig`) | 同 Formatting | "Indent with 2 spaces … `shfmt` reads it automatically. Run `shfmt -d <file>`" | 文章のまま(#196 の方針) | — | — | 残す(template-* に shfmt の設定も `.editorconfig` も無い.hook の `shfmt -w` は `.editorconfig` が無いと tab にする) | | shellcheck | 同 Formatting | "Common quoting errors are caught by `shellcheck`" | 既存 linter(hook が `shellcheck -x` を全リポジトリで実行) | — | — | 削除(案内の文.規則ではない) | | (なし) | 同 Task-Specific References | 参照先の案内 | 文章のまま(案内) | — | — | 残す | ### bash-style / references | 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 | | --- | --- | --- | --- | --- | --- | --- | | ls-lint(template-minimal の `.*` の正規表現) | `references/bats_testing.md` Directory Layout | "Test files: `.bats` extension, `snake_case` naming" | 既存 linter(template-minimal の `.ls-lint.yml`.ハイフンを許さない) | — | — | `snake_case` だけ削除.拡張子の指示は ls-lint が覆わないため残す | | (なし) | 同 Directory Layout | `test-helper/` の名前,カテゴリごとに置く,`.bash` 拡張子,`load test-helper/setup` | 文章のまま | — | — | 残す(プロジェクト慣習.名前の形は ls-lint の `.dir` が見るが,この名前に固定する規則は無い) | | (なし) | 同 File Structure | `#!/usr/bin/env bats`,説明コメント 1 行,`setup()` に配線を置き assertion を置かない,`REPO_ROOT` を inline で求める | 文章のまま | — | — | 残す(ast-grep の Bash 文法は `@test "…" { }` を構文エラーとして読み,`.bats` は `sgconfig.yml` の言語対応にも無い.shellcheck も bats を扱わず,jev-lint の対象拡張子にも無い) | | (なし) | 同 Setup / Teardown Lifecycle | 最も狭いスコープを使う,`setup_file` の変数を `export` する | 文章のまま | — | — | 残す(同上.判断を含む) | | (なし) | 同 Test Naming / Section Separators | "descriptive lowercase sentence",コメントの区切り | 文章のまま | — | — | 残す(同上) | | (なし) | 同 Assertions / Loop-Based Assertions | 素の bats の組み込みを使う,`run` の後で `$status` を見る,`run` を省くのは副作用だけを見る時,ループでは失敗した要素を出す | 文章のまま | — | — | 残す(同上) | | (なし) | 同 Helper Functions / Temporary Directories | 共有 fixture は `test-helper/setup.bash`,JSON は `jq`,`gh` などの stub は `$BATS_TEST_TMPDIR/bin`,`mktemp` より `BATS_*_TMPDIR` | 文章のまま | — | — | 残す(同上) | | (なし) | 同 Making Scripts Testable | `BASH_SOURCE == $0` で main を守る | 文章のまま | — | — | 残す(テスト容易性の設計判断.`script_template.md` は守らない形で書かれており,構文だけで必須にできない) | | (なし) | 同 Running Tests | コマンド例 | 文章のまま(案内) | — | — | 残す | | (なし) | 同 Test Organization Rules | 1 スクリプト 1 `.bats`,正常系を先に,1 `@test` 1 振る舞い,本体を短く | 文章のまま | — | — | 残す(判断を含み,`.bats` を解析できる道具が無い) | | (なし) | `references/script_template.md` | スクリプトの雛形 | 文章のまま(雛形) | — | — | 残す | ### github-actions-style / SKILL.md | 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 | | --- | --- | --- | --- | --- | --- | --- | | `gha_workflow_permissions_deny_all` | `agents/skills/github-actions-style/SKILL.md` 1. Permissions | "Declare `permissions: {}` at the workflow level (deny-all)" | 静的(ast-grep)+ zizmor `excessive-permissions` | `rules/yaml/gha_workflow_permissions_deny_all.yml` | 良 1 / 悪 3 | 該当の文だけ削除(例の YAML は残す) | | `job-permissions-least-privilege` | 同 1. Permissions | "grant only what each job actually requires" | 動的(jev-lint,0.5)+ zizmor `excessive-permissions`(広すぎる書き込み権限) | `model-rules/yaml/job-permissions-least-privilege/rule.yml` | なし | 残す | | (なし) | 同 1. Permissions | "Common permission keys: …" | 文章のまま(参考の一覧) | — | — | 残す | | zizmor `unpinned-uses` | 同 2. Version Pinning | "Pin every action to a full commit SHA" | 既存 linter(zizmor.hook が `.github/workflows` の編集後に全リポジトリで `zizmor --offline` を実行.tag 参照で `error[unpinned-uses]` を確認) | — | — | 削除(節ごと) | | `gha_pinned_uses_version_comment` | 同 2. Version Pinning | "record the version in a comment for readability and update tooling" | 静的(ast-grep) | `rules/yaml/gha_pinned_uses_version_comment.yml` | 良 3 / 悪 5 | 削除(上と同じ節) | | zizmor `template-injection` | 同 3. Script Injection Prevention | "Always pass them through `env:` instead, and quote the variable in the script" | 既存 linter(zizmor.例の `run: echo "${{ github.event.pull_request.title }}"` で `error[template-injection]` を確認) | — | — | 削除(節ごと.危険な入力の一覧も含む) | | `gha_job_timeout_minutes` | 同 4. timeout-minutes | "Set an explicit timeout appropriate for the job" | 静的(ast-grep) | `rules/yaml/gha_job_timeout_minutes.yml` | 良 5 / 悪 4 | 「設定する」の文だけ削除 | | (なし) | 同 4. timeout-minutes | "typically 5–15 minutes for CI" | 文章のまま | — | — | 残す(値の選択は判断.規則は有無だけを見る) | | `gha_workflow_default_shell` | 同 5. Shell Settings | "Set it at the `defaults.run` level" | モデル(jev-lint,助言) | `model-rules/yaml/workflow-default-shell/rule.yml` | fixtures は後回し | 降格(ast-grep の規則とテストは削除.prose は `defaults.run.shell: bash` の説明として残した) | | (なし) | 同 5. Shell Settings | "For debugging, add `set -x` at the top of a `run:` block" | 文章のまま(デバッグの手引き) | — | — | 残す | | `gha_workflow_concurrency` | 同 6. Concurrency | "Use `concurrency` to cancel stale runs automatically" | モデル(jev-lint,助言) | `model-rules/yaml/workflow-concurrency/rule.yml` | fixtures は後回し | 降格(ast-grep の規則とテストは削除.prose は `concurrency` の説明として残した) | | (なし) | 同 6. Concurrency | "use false for deploy workflows that must run in order" | 文章のまま | — | — | 残す(デプロイ用かどうかは構文から判別できない) | | `cache-key-and-trust` | 同 7. Cache Design | "Include every compatibility boundary in the primary key… Always keep a correct cache-miss fallback" | 動的(jev-lint,0.5) | `model-rules/yaml/cache-key-and-trust/rule.yml` | なし | 残す | | `cache-key-and-trust` | 同 7. Cache Design | "Do not cache broad paths that may contain credentials" | 動的(jev-lint,0.5) | 上と同じ規則 | なし | 残す | | (なし) | 同 7. Cache Design | "Measure representative cold and warm runs…",cache scope の説明,外部 backend で untrusted workflow に書かせない | 文章のまま | — | — | 残す(計測の手順と文脈で,ワークフローの構文に現れない.zizmor `cache-poisoning` は一部だけ覆う) | | (なし) | 同 8. Workflow File Names | "Name workflow files in kebab-case with the `.yml` extension" | 文章のまま | — | — | 残す(template-minimal の `.ls-lint.yml` に `.github/workflows` の kebab-case 規則は無い.agent-config 自身の `.ls-lint.yml` にだけある.節番号は 6 に変わった) | ## 波 2: linter で有効化する規則 なし.この PR で消した文章は,すべて既に有効な linter(shellcheck と shfmt は agent-config の `lefthook.yml`,zizmor と actionlint は `furedea/reusable-workflows` の `gha-lint`,ls-lint は `.ls-lint.yml`)が覆う. 注: Bash 向けのテンプレートは無く,`template-python` などの `lefthook.yml` に shellcheck と shfmt は無い.Bash を書く他のリポジトリでは,agent-config と同じ `lefthook.yml` の設定が要る(このリポジトリの対象外). ## 現在の hit(読み取りのみ.修正はこの PR に含めない) `ast-grep scan --config agents/hooks/lint/sgconfig.yml --no-ignore hidden .`(`.github` は隠しディレクトリのため).agent-harness の `bash_usage_function` は隠しディレクトリ内の script を含めて 7 件. | 規則 | agent-config | agent-harness | dotfiles | | --- | --- | --- | --- | | `bash_shebang_env_bash` | 1(`tests/hooks/fake_herdr.sh`,意図した POSIX `sh` の stub) | 0 | 3 | | `bash_strict_mode_header`(新しい緩い定義) | 1(同じ `fake_herdr.sh`.`sh` は `pipefail` を持たない) | 0 | 0 | | `bash_local_underscore_prefix`(既存) | 0 | 0 | 6 | | `bash_function_name_snake_case` | 0 | 0 | 0 | | `bash_readonly_constant_name` | 0 | 0 | 0 | | `gha_workflow_permissions_deny_all` / `gha_job_timeout_minutes` / `gha_workflow_default_shell` / `gha_workflow_concurrency` / `gha_pinned_uses_version_comment` | 0 | 0 | 0 | 新しい strict-mode 規則では,dotfiles の違反は 0 件(`-C` を外し,表記を問わなくした結果.旧定義では 21 件).shebang の規則も `sh` / `bash` だけを見る形になり,24 件から 3 件に減った.dotfiles は修正していない. ## 検証 - `nix develop --command ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests`: 20 規則すべて通過. - `jev-lint rules --no-config -R agents/hooks/lint/model-rules`: 19 規則・エラー 0.`jev-lint check --dry-run --show-subjects` で Bash の 5 規則と YAML の `job-permissions-least-privilege` が意図した対象を選ぶことを確認した(`usage-help-and-error-exits` と `cache-key-and-trust` は試料に該当が無く未確認). - `REQUIRE_AST_GREP=1 nix develop --command uv run pytest`: 4877 件通過,3 件失敗.失敗は `tests/test_workflow_skill_layout.py` の 3 件で,この worktree にだけある `.claude/.cc-writes`(Claude Code のサンドボックスが作る未追跡ディレクトリ)を skill ディレクトリと読むため.CI の checkout には無く,この PR の変更とは無関係. - lefthook の pre-commit(shfmt,shellcheck,ls-lint,ruff,ty,file-length)通過. ## 残りの作業 - [x] #196 `gha_workflow_concurrency` が単一引用符の `'on':` キーを認識しない: 修正(a3ac148,invalid 例を追加). - [x] 方針(template-* の linter が覆う文章は削除): template-minimal の ls-lint が覆う bats の `snake_case` は削除.template に設定の無い shfmt のインデントと workflow ファイル名の kebab-case は残す.shellcheck と zizmor / actionlint(template-minimal の gha-lint)で消した文章はそのまま. - レビュー上限(#196 の修正後の再レビュー 3 回)で見送った指摘(フォローアップ Issue で扱う): - `usage-help-and-error-exits`: `if (( $# == 0 ))` のような引数不足の分岐が subject にならない. - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_default_shell`: 引用符付きの `"run":` キーを run step と認識しない.~~ - `cache-key-and-trust`: flow mapping 形式の step(`- {uses: actions/cache@v4, …}`)が subject にならない. - `gha_workflow_permissions_deny_all`: 引用符付きの `"jobs":` キーを workflow と認識しない. - zizmor の既定が `actions/*` を tag 固定で許すという指摘(SKILL の Version Pinning 削除): 再現しない.zizmor 1.31.0 は設定なしで `actions/checkout@v4` に `unpinned-uses`(blanket policy で hash 固定を要求)を出す.CI の gha-lint は 1.32.0.確認の上で見送り,スレッドは解決済み. - レビュー上限(template 方針の変更後の再レビュー 3 回)で見送った指摘: - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_concurrency`: block sequence 形式の `on:`(`- push`)の trigger を認識しない.~~ - `gha_pinned_uses_version_comment`: `action.yml` 内の tag 参照は,この規則も zizmor(workflow のみ)も検出しない. - SKILL の Version Pinning 削除と zizmor の既定方針(再現しない.上に記載). - レビュー上限(最終決定の反映後の再レビュー 3 回)で見送った指摘: - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_default_shell`: 複数 job で 1 つの job だけが `defaults.run.shell` を持つと,別の job の `run:` も通ってしまう(job ごとの対応付けが要る).~~ - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_concurrency`: 引用符付きの `"cancel-in-progress"` キーを認識しない.~~ - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_concurrency`: block sequence 形式の `on:`(`- push`)を認識しない(上と同じ.再指摘).~~ - (obsolete: 規則を jev-lint に降格したため不要)~~`bash_strict_mode_header`: 後続の無関係な `set`(`set +u` の後の `set -x`)があると無効化を見逃す.~~ - (obsolete: 規則を jev-lint に降格したため不要)~~`bash_strict_mode_header`: 無効化の後に別の `set` があるだけで免除してしまう(実際に再有効化する場合だけ免除すべき).~~ - `usage-help-and-error-exits`(jev-lint): `getopts h opt` の bare `h` ラベルが subject にならない. - `gha_workflow_permissions_deny_all`: ルート全体が flow mapping の workflow を認識しない. - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_default_shell`: `strategy.matrix.defaults` など無関係な `shell` を `defaults.run.shell` と取り違える.~~ - `job-permissions-least-privilege`(jev-lint): flow 形式の job の `permissions` が subject にならない. - `function-variables-local-near-use`(jev-lint): `: "$((count++))"` の代入が subject にならない. - (obsolete: 規則を jev-lint に降格したため不要)~~`bash_strict_mode_header`: 同じ `set` コマンド内の再無効化(`set -euo pipefail +e`)を見逃す.~~ - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_default_shell`: block sequence の要素が flow mapping の `run` step(`- {run: …}`)を見逃す.~~ - レビュー上限(再実行後の再レビュー)で見送った指摘(#196 に追記済み): - `bash_readonly_constant_name`: 関数内の `readonly` を一律に除外している(`local -r` だけを除外すべき). - `bash_readonly_constant_name`: `declare -r NAME=…` を選択しない. - `gha_job_timeout_minutes`: `jobs` 自体が flow mapping の workflow を見逃す. - `gha_pinned_uses_version_comment`: `action.yml` の tag 参照を検出しない(上と同じ.再指摘). - (obsolete: 規則を jev-lint に降格したため不要)~~`gha_workflow_default_shell`: `shell: env pipefail=1 bash -e {0}` を適合扱いにする(`pipefail` が環境変数名として現れるだけ).~~ - (obsolete: 規則を jev-lint に降格したため不要)~~`bash_strict_mode_header`: `set +e` の後ろの `set` が実際に再有効化するかを見ていない(上の再指摘).`gha_workflow_concurrency` の block sequence 形式の `on:` も再指摘.~~ - `gha_job_timeout_minutes` / `gha_workflow_default_shell`: 引用符付きの `"jobs":` キーを認識しない. - `cache-key-and-trust`(jev-lint): flow 形式の cache step(`steps: [{uses: …}]`)が subject にならない. - [x] 誤検出の修正: `gha_job_timeout_minutes` の flow mapping の分岐が `jobs` 配下の job に限定されず,step の `with: {runs-on: …}` を報告していた.job の値である flow mapping だけを対象にした(valid 例 2 件を先に追加して失敗を確認). - [x] `bash_readonly_constant_name` が `readonly OUTPUT="$input"` の右辺を定数名として検査するという指摘: 現行の規則では再現しなかった(右辺の変数は `simple_expansion` 配下で,`declaration_command` の直下ではない).再発防止のため,この形の valid 例を 2 件追加した. - [x] 誤検出の修正(ユーザーの常時許可): `bash_shebang_env_bash` が先頭以外のコメントの `#!` を報告していた.ファイルの最初の node だけを shebang とするように直し,先に valid 例(後ろのコメントの `#!/bin/bash`,先頭がコメントの場合)を追加して失敗を確かめてから修正した. - [x] 同じ誤検出の修正: `bash_strict_mode_header` も先頭以外のコメントの `#!` を shebang と読んでいた.最初の node だけに限定した(valid 例を先に追加して失敗を確認). - [x] 誤検出の修正(続き): `gha_workflow_default_shell` が flow 形式の `defaults: {run: {shell: bash}}`(規則自身の `note` の直し方)を受け付けなかった,`gha_workflow_permissions_deny_all` が引用符付きの `"permissions": {}` を受け付けなかった,`bash_strict_mode_header` が後で再有効化する `set +e … set -e` を誤検出した.いずれも valid 例を先に追加して直した.`gha_workflow_concurrency` の `note` は group を引用符で囲み,YAML として有効にした. - [x] main の新しいテスト(`tests/test_ast_grep_rules.py` の file-scoped 規則の flagged / clean パス)に追従した: main に rebase し(CI の `test` が落ちた原因),5 つの workflow 規則の flagged(`.github/workflows/ci.yml`,pin 規則は `action.yml` も)と clean(`config/ci.yml`)のパスを追加した.`.github` は隠しディレクトリのため,その走査に `--no-ignore hidden` を足した. - [x] `rule_notes.md`(全ブロック規則に message と note)は適用済みであることを確認した. - [x] #196 `.bats` を Bash として読めるか: 追加しない.調べた結果は下記. - jev-lint 規則 7 件の fixtures,eval,しきい値の調整,昇格(その後に文章を削除). - `.bats` の規則(調査済み,下記): `sgconfig.yml` の `languageGlobs` で `.bats` を Bash として読めるか,`@test` の構文エラーをどう扱うかを調べる必要がある.この PR では共有設定を変えなかった. ## ast-grep から外した規則と理由 ブロックする規則は結果が安定していなければならない.次の規則は review のたびに新しい指摘が出続け(1 規則あたり 11〜15 件のスレッド),収束しなかった.そのためユーザーの判断で,既存のツールに任せるか jev-lint に降格した.この基準は ADR-0021 に記録する. | 規則 | 行き先 | review の指摘数 | 不安定の型 | 例 | | --- | --- | --- | --- | --- | | `gha_workflow_default_shell` | jev-lint(`model-rules/yaml/workflow-default-shell`,助言) | 15 | 2, 3, 4 | `shell: env pipefail=1 bash -e {0}` を適合扱いにした(`pipefail` という文字列だけを正規表現で見ていた).別 job の `defaults.run.shell` で複数 job の `run:` が通った. | | `gha_workflow_concurrency` | jev-lint(`model-rules/yaml/workflow-concurrency`,助言.zizmor の `concurrency-limits` は pedantic persona のみ) | 12 | 3, 4 | `on:` が `- push` の block sequence や `'on':` の引用符付きキーだと認識しない. | | `bash_strict_mode_header` | jev-lint(`model-rules/bash/strict-mode-header`,助言) | 11 | 2, 3, 4 | `set +e` の後に `set -x` があるだけで免除してしまう.`set -euo pipefail +e` の同一コマンド内の再無効化を見逃す.`-Eeuo` や `-o errexit` など同じ意味の書き方が多い. | | `bash_usage_function` | 削除(prose の `usage` の節は残し,引数を取るスクリプトに限定) | 0 | —(ユーザーの判断.引数を取るかどうかは文脈で決まる) | — | 残した 6 件の ast-grep 規則(`bash_shebang_env_bash`,`bash_function_name_snake_case`,`bash_readonly_constant_name`,`gha_workflow_permissions_deny_all`,`gha_job_timeout_minutes`,`gha_pinned_uses_version_comment`)の指摘数は 3〜7 件で,誤検出は修正し,見逃しは #196 に送った. ## `.bats` を ast-grep で Bash として読めるか(#196) `languageGlobs` は不要で,追加しなかった.ast-grep 0.42.1 は `.bats` を既に Bash として読む(`tests/codex/execpolicy.bats` の shebang コメントに Bash 規則が一致した.上の bats shebang の例外はこのため).ただし構文は正しく読めない.`@test "name" {` は関数ではなく 1 つの `command`(`@test` が名前,`"name"` と `{` が引数)になり,本体は兄弟の文として並ぶ.`run` コマンドを `kind: command` で選んでも 0 件だった(実際には多数ある).構文エラーとして報告はされないため,誤検出の代わりに見逃しが静かに起きる.よって `@test` の中を見る規則は書けず,bats の規則は文章のままにした. ## review の扱い(最終方針) - ブロックする ast-grep 規則の誤検出は,テストを先に書いて修正する. - jev-lint モデル規則の指摘(マッチャー,criteria,しきい値)は,ユーザーの判断で検証を後回しにし,[#196 の jev-lint verification notes](#196 (comment)) に記録して解決済みにする. - ルール以外のコード(hooks,docs)の実害は修正する. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Refs #74(段階 2C)
概要
スタイル文章のうち,ast-grep で少ない誤検出で判定でき,有効な linter 規則が覆っていない 10 規則を追加する.設計変更(registry を置かず,各ツールの設定を正とする)に従う.
agents/hooks/lint/rules/<language>/<id>.yml.ast-grep のネイティブな規則 YAML だけで,独自フィールドは持たない.agents/hooks/lint/rule-tests/<id>.yml.ast-grep ネイティブのvalid/invalid(各規則 2〜4 件以上).agents/hooks/lint/sgconfig.yml.tests/test_ast_grep_rules.pyがast-grep testを実行し,規則と tests の対応も確かめる(CI の test ジョブは dev shell で動くので workflow の変更は不要).agents/hooks/lint/(hook bundle にコピーされる)から読むため,規則一式をそこへ置く.対応表のrules/...とrule-tests/...はagents/hooks/lint/からの相対パス.ast-grep(nixpkgs 0.42.1)はmainに既にあるため,この PR では追加しない.実行:
nix develop --command ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests文章と規則の対応表
@staticmethodを使わない@dataclassはすべてslots=True(cached_propertyを使うクラスは除外)frozen=Trueは文章のまま.値オブジェクトかどうかは構文から判別できない.pydantic と__post_init__も規則が覆わない)unittestを使わないunittest」だけ削除,「pytest を使う」は残すunittest.mockを直接使わないunittest.mockdirectly」だけ削除,「mocker を使う」は残すstrict=Truemocker.patchはautospec=True==や文字列で比較しない_test.goは除外)+errorlint==で比較しない(errorlint)」は残す(規則は sentinel との==を覆わない).tsxは同じ規則のtsx_no_namespace_import(rules/typescript/tsx_no_namespace_import.yml,rule-tests/tsx_no_namespace_import.yml)が覆う)local変数は_で始めるlocalで宣言する」は規則が覆わない)選んだ理由と,選ばなかった候補
既存 linter が覆う規則は外した(ruff は agent-config と dotfiles の
pyproject.toml,golangci-lint は rater,oxlint は template-typescript の設定をmainで確認).typing.Listなど built-in genericsUP006/UP035が有効global/nonlocalglobalは ruffPLW0603が有効.nonlocalは稀で,10 規則に入れなかったtodo!/dbg!/unimplemented!/ glob importtodo/dbg_macro/unimplemented/pedantic(wildcard_imports)が有効unwrap/expect/ 直接 indexany/import typeutils.pyなど)ascastRust の規則は,この段階では 0 件.clippy が覆わない文章規則は,構文だけでは誤検出なく判定できなかった.
現在の hit(修正はこの PR に含めない)
ローカル checkout に
ast-grep scan --config agents/hooks/lint/sgconfig.yml <path>を読み取りのみで実行した.agent-config
dotfiles
すべて規則が意図した違反(dotfiles の
py_dataclass_slots2 件は,どちらもfrozen=Trueでslotsの無い値オブジェクトで確認済み).当初はfrozen=Trueも要求していたが,可変なクラス(_Capture,OptionScan)が誤検出になったため,slots=Trueだけを要求する規則に分け,frozen=Trueは文章のままにした(hit は agent-config 25 → 23).py_mocker_patch_autospecはnew=/new_callable=/spec=/spec_set=/wraps=を持つ呼び出しと,newを位置引数で渡す呼び出しを除外している(autospecと併用できない).既知の限界
mainに入っている.ci.ymlにREQUIRE_AST_GREP: "1"を足す変更は別コミット(.github/workflowsのため,ユーザーが push する).go_error_no_string_matchingはswitch err.Error()と_test.goを判定しない.bash_local_underscore_prefixは大文字で始まる名前(IFS,OPTINDなど特殊変数)を除外する.検証
ast-grep test: 10 規則(.tsx用の同じ規則 1 件を加えて 11 ファイル),すべて通過uv run pytest(tests/test_ast_grep_rules.pyほか skill の整合性テスト): 通過uv run ruff check,ruff format --check,ty check,ls_lint: 通過🤖 Generated with Claude Code