Skip to content

feat(lint): add --rules / -r flag to isolate rule execution#683

Merged
ako merged 2 commits into
mendixlabs:mainfrom
Andries-Smit:feature/lint-rules-filter
Jun 24, 2026
Merged

feat(lint): add --rules / -r flag to isolate rule execution#683
ako merged 2 commits into
mendixlabs:mainfrom
Andries-Smit:feature/lint-rules-filter

Conversation

@Andries-Smit

Copy link
Copy Markdown
Contributor

Summary

  • Adds -r / --rules flag to mxcli lint that restricts execution to the specified rule IDs
  • When the flag is omitted all rules run as before — no behaviour change
  • --list-rules is unaffected and still shows the full rule catalogue

Motivation

During lint rule development, running all ~40 rules on every iteration is slow and noisy. This flag lets you pin execution to the rule(s) under development:

mxcli lint -p app.mpr -r MPR001
mxcli lint -p app.mpr -r MPR001 -r SEC001
mxcli lint -p app.mpr -r MPR001,SEC001   # comma form also works

Implementation

Reuses the existing Linter.ConfigureRule(id, RuleConfig{Enabled: false}) mechanism — no changes to linter.go or any rule files. After all rules (including Starlark) are registered, any rule whose ID is not in the allowlist is disabled before lint.Run() is called.

Test plan

  • mxcli lint -p app.mpr -r MPR001 — only MPR001 violations appear
  • mxcli lint -p app.mpr -r MPR001 -r SEC001 — only those two rules run
  • mxcli lint -p app.mpr — all rules still run (no regression)
  • mxcli lint -p app.mpr -r MPR001 --list-rules — full rule catalogue shown

🤖 Generated with Claude Code

https://claude.ai/code/session_01KeDQV2xS3xL16vEZWEDmaw

Add a -r / --rules flag to mxcli lint that restricts execution to
the specified rule IDs. Useful during rule development to avoid noise
from unrelated rules.

  mxcli lint -p app.mpr -r MPR001
  mxcli lint -p app.mpr -r MPR001 -r SEC001
  mxcli lint -p app.mpr -r MPR001,SEC001

When --rules is omitted all rules run as before (no behaviour change).
--list-rules is unaffected and still shows the full rule catalogue.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDQV2xS3xL16vEZWEDmaw
@github-actions

Copy link
Copy Markdown

AI Code Review

Critical Issues

  • Comma-separated rule IDs not parsed correctly: The PR states that -r MPR001,SEC001 (comma form) works, but the implementation does not split comma-separated values. The StringSlice flag collects each -r occurrence as separate slice elements, but does not split on commas within a single flag value. For example, -r MPR001,SEC001 results in onlyRules = []string{"MPR001,SEC001"}, causing the rule ID lookup to fail since no rule has ID "MPR001,SEC001". This must be fixed by splitting each flag value on commas.

Moderate Issues

None found.

Minor Issues

  • Missing test coverage: The diff shows no test file changes. While the PR includes a test plan checklist, no actual test modifications are visible. New CLI features should include unit tests (e.g., in cmd/mxcli/command_test.go or similar) to verify flag parsing and rule filtering behavior.
  • Flag help text inconsistency: The help text shows -r MPR001 -r SEC001 but omits the comma form example. While not critical, updating the help to reflect both formats would improve clarity.

What Looks Good

  • Scoped change: The PR correctly focuses on a single feature (lint rule filtering) without unrelated modifications.
  • Leverages existing mechanisms: Reuses Linter.ConfigureRule() without modifying core linter or rule files, maintaining consistency.
  • Non-regressive behavior: When -r is omitted, all rules run as before, preserving existing functionality.
  • Clear documentation: The PR summary and examples are well-written and match the implementation intent.

Recommendation

Request changes due to the critical issue with comma-separated rule ID parsing. Fix the flag parsing to split values on commas, and add test coverage for the new functionality before approval. Once addressed, the change is ready to merge.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

- Add linter_test.go with three tests covering the allowlist filter
  logic used by cmd_lint.go: single rule, multiple rules, and no filter
- Add comma-separated and multi-flag examples to mxcli lint help text

Addresses AI review feedback on PR mendixlabs#683.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDQV2xS3xL16vEZWEDmaw
Andries-Smit added a commit to Andries-Smit/mxcli that referenced this pull request Jun 23, 2026
- Add linter_test.go with three tests covering the allowlist filter
  logic used by cmd_lint.go: single rule, multiple rules, and no filter
- Add comma-separated and multi-flag examples to mxcli lint help text

Addresses AI review feedback on PR mendixlabs#683.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDQV2xS3xL16vEZWEDmaw
@Andries-Smit

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in the latest push:

Critical — comma-separated parsing: This is actually a non-issue. StringSliceP in pflag/cobra splits on commas by design-r MPR001,SEC001 produces []string{"MPR001", "SEC001"} as expected. Verified with a quick unit test.

Minor — missing test coverage: Added mdl/linter/linter_test.go with three tests covering the filter logic:

  • single rule allowlist
  • multi-rule allowlist
  • empty allowlist (all rules run, no regression)

Minor — help text: Added comma-form and multi-flag examples to the mxcli lint help text.

@github-actions

Copy link
Copy Markdown

AI Code Review

Critical Issues

  • Comma-separated rule IDs not handled correctly: The PR states that -r MPR001,SEC001 (comma form) should work, but the current implementation treats the entire comma-separated string as a single rule ID. For example, -r MPR001,SEC001 would create an allowlist containing only the key "MPR001,SEC001" instead of "MPR001" and "SEC001". This causes the flag to fail silently (no rules match) or disable all rules incorrectly. The fix requires splitting each element in the onlyRules slice by commas and trimming whitespace before populating the allowlist.

Moderate Issues

None.

Minor Issues

None.

What Looks Good

  • Unit test coverage: Added comprehensive tests in mdl/linter/linter_test.go covering allowlist logic (empty, single, multiple rules).
  • Reuse of existing mechanism: Correctly uses Linter.ConfigureRule without modifying core linter or rule files.
  • Help text updated: Examples in cmd_lint.go clearly demonstrate usage (single flag, multiple flags, comma form).
  • No behavior change when flag omitted: Preserves existing behavior (all rules run) by default.
  • Flag definition consistent: Added via StringSliceP in main.go with appropriate shorthand (-r).

Recommendation

Request changes to fix comma-separated rule ID parsing. Update the allowlist population logic in cmd/mxcli/cmd_lint.go to split each flag value by commas and trim whitespace. Example fix:

allowed := make(map[string]bool, len(onlyRules))
for _, id := range onlyRules {
    for _, part := range strings.Split(id, ",") {
        trimmed := strings.TrimSpace(part)
        if trimmed != "" {
            allowed[trimmed] = true
        }
    }
}

After this fix, re-run the test plan to confirm:

  • mxcli lint -p app.mpr -r MPR001,SEC001 runs both rules
  • mxcli lint -p app.mpr -r MPR001 -r SEC001,QUAL001 runs three rules
  • All existing test cases still pass

Once fixed, the PR is ready for approval. No other checklist items apply (no MDL syntax changes, no full-stack consistency requirements for CLI flags).


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

@Andries-Smit

Copy link
Copy Markdown
Contributor Author

Manual tested and can confirm, the Comma-separated rule IDs do work. Its a false positive

@ako

ako commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Reviewed the implementation — change is small, correct, and well-scoped. Confirmed the disputed point and verified the rest:

Comma-separated parsing is a non-issue (agree with @Andries-Smit). pflag.StringSlice parses through a CSV reader and splits on commas by design, so -r MPR001,SEC001 yields ["MPR001","SEC001"]. The bot's "critical" finding is a false positive.

Also verified:

  • --list-rules is unaffected — Linter.Rules() returns the full slice; Enabled:false only gates Run() (linter.go:141).
  • No regression when the flag is omitted — the whole block is guarded by len(onlyRules) > 0.
  • New tests pass (ok github.com/mendixlabs/mxcli/mdl/linter).

Two minor, non-blocking gaps:

  1. Tests don't exercise the real code path. linter_test.go re-implements the allowlist loop inline rather than driving cmd_lint.go / cobra flag parsing — so the comma-form (the one thing actually questioned) is only verified manually, not by a test. A test that parses -r MPR001,SEC001 through the command would close that loop.
  2. Silent on typos. A misspelled ID (-r MPRO01) disables every rule and reports zero violations with no warning — the "no silent side effects on typos" checklist item. A warning when an allowlisted ID matches no registered rule would help.

Neither blocks merge.

@ako ako closed this Jun 24, 2026
@ako ako reopened this Jun 24, 2026
@ako ako merged commit 7db756d into mendixlabs:main Jun 24, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

None found.

What Looks Good

  • Scope & atomicity: The PR is tightly scoped to adding a single feature (--rules flag for lint isolation) with no unrelated changes. Each commit does one thing (CLI flag addition, implementation, tests).
  • Overlap & duplication: No duplication detected - reuses existing Linter.ConfigureRule mechanism without modifying linter/core logic. The flag is new and doesn't conflict with existing functionality.
  • Test coverage: Added comprehensive unit tests in mdl/linter/linter_test.go covering:
    • Single rule allowlist
    • Multiple rule allowlist (via multiple flags and comma-separated form)
    • Empty allowlist (no flag) runs all rules
    • Proper rule ID matching
  • CLI implementation:
    • Properly updates help text and examples in cmd_lint.go
    • Adds flag definition in main.go with correct shorthand (-r)
    • Implementation correctly builds allowlist map and disables non-allowed rules
    • Preserves existing behavior when flag omitted (all rules run)
    • --list-rules remains unaffected as required
  • Code quality:
    • Clean, readable implementation using standard Go patterns
    • No silent side effects or error handling gaps
    • Consistent with existing CLI patterns in the project
    • No manual lists or maintenance risks introduced

Recommendation

Approve - The PR is ready for merging. It implements the requested feature correctly, follows project conventions, includes adequate test coverage, and maintains backward compatibility. No changes are needed.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

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.

2 participants