Skip to content

feat(lint): dogfood ast-grep rules#243

Merged
dpc merged 1 commit into
rustshop:masterfrom
dpc:dpc/jj-vktquwxrzmkx
Jul 24, 2026
Merged

feat(lint): dogfood ast-grep rules#243
dpc merged 1 commit into
rustshop:masterfrom
dpc:dpc/jj-vktquwxrzmkx

Conversation

@dpc

@dpc dpc commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Posted by Tau

Summary

Adopt the newly integrated ast-grep workflow in Flakebox itself with six conservative Rust rules, focused rule tests, and CI enforcement. Keep the rule implementation under .config/ast-grep/ while preserving standard root project discovery through sgconfig.yml.

Details

  • discourage production unwrap() while exempting conventional and structurally annotated test code
  • catch is_some/is_ok/is_err checks followed by corresponding unwrap calls
  • catch eager default construction passed to unwrap_or
  • hint on greater-than orientation only for side-effect-free identifier/integer comparisons
  • commit valid/invalid cases and diagnostic snapshots for every rule
  • add a flake check that runs tests, promotes behavioral findings to errors, and behaviorally verifies pathname exclusions

Testing

Run selfci check. For focused iteration, run ast-grep test and ast-grep scan.

### Summary

Adopt the ast-grep project layout in Flakebox itself with six conservative Rust rules. Keep rules and tests under `.config/ast-grep/`, retain root project discovery through `sgconfig.yml`, and add a flake check that scans the source and runs the rule test suite.

### Details

The rules discourage production `unwrap`, check-then-unwrap control flow for Option and Result, eager default construction, and greater-than comparison orientation for simple side-effect-free operands. CI promotes the five behavioral rules to errors while leaving comparison orientation as an interactive hint. Production unwrap permits explicit `expect`, ignores conventional test/example paths, and structurally excludes inline test functions, modules, and impl blocks across contiguous attributes. Each rule has valid/invalid cases and committed diagnostic snapshots; path scan fixtures verify every ignore and prove production violations fail CI. Existing findings were resolved by documenting the OpenSSL fixture invariant with `expect` and reversing one side-effect-free signal-state comparison.

### Reviews

The reviewer first found that warning-level scans could not fail CI, file ignores lacked behavioral coverage, test-code exemptions were incomplete, and unrestricted comparison orientation could pressure unsafe operand reordering. I promoted behavioral rules only, added positive and negative path fixtures, expanded structural test exemptions, and limited comparisons to identifiers and integer literals. Re-review then found multi-attribute and cfg(test) impl gaps; the final rule traverses only contiguous attributes and covers functions, modules, and impls. Final re-review passed with no issues.

### Verification

`selfci check --candidate lxuqqqqz` passed after all reviewed fixes.
@dpc
dpc marked this pull request as ready for review July 24, 2026 18:04
@dpc
dpc merged commit be65c49 into rustshop:master Jul 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant