feat(init): add --infer for tree-derived baseline configs#18
Merged
Conversation
`structlint init --infer` walks the actual tree (using the Snapshot API from spec 005) and generates a .structlint.yaml that describes what really exists. The primary property: `init --infer && validate` exits 0 on the same tree, so adopting structlint on a legacy codebase no longer means drowning in violations on day one. Spec: docs/specs/009-init-infer.md. Heuristics (deliberately shallow — a baseline, not a taxonomy): - allowedPaths: "." + depth-1 directories (name/** if it has children, bare name if empty). Root files never become path entries — they're covered by file_naming_pattern. - file_naming_pattern.allowed: one *.ext per unique extension seen + exact-name entries for extensionless files (Makefile, LICENSE, dot- files like .gitignore). *.yaml is force-included so the just-written config file itself passes on the next validate (chicken-and-egg fix). - required: only certainties (go.mod, README.md when present at root). A wrong required entry would break the primary property. - disallowed / disallowedPaths: empty; inferring prohibitions from absence is guesswork. - ignore: DefaultIgnore (.git, node_modules, vendor, dist, build, bin) applied during the walk and emitted verbatim. --infer is mutually exclusive with --type; --force guard unchanged. Output is rendered from a deterministic template (sorted sections) so the same tree always yields byte-identical bytes. Tests (test/init_infer_test.go, binary-based): - validate passes on the same tree (go/node/mixed fixtures) - depth-1 dirs: children → name/**, leaf → bare name - extensions + exact names both appear in allowed - required only seeded from certainties (both / neither) - --infer + --type errors - --force guard preserved - determinism: two runs, byte-identical output
StructLint — All checks passed123 rules validated against
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Heuristics (deliberately shallow)
Output is deterministic — same tree, byte-identical bytes.
Test plan