Skip to content

feat(lints): Reject hard-coded GTS ID prefixes#81

Open
aviator5 wants to merge 1 commit into
constructorfabric:mainfrom
aviator5:dylint-no_hardcoded_gts_prefix
Open

feat(lints): Reject hard-coded GTS ID prefixes#81
aviator5 wants to merge 1 commit into
constructorfabric:mainfrom
aviator5:dylint-no_hardcoded_gts_prefix

Conversation

@aviator5

@aviator5 aviator5 commented Jul 16, 2026

Copy link
Copy Markdown
  • Add the DE0904 pre-expansion lint for literal prefixes in expressions, macro invocations, and attributes.
  • Document the rule and cover valid gts_id! usage alongside UI failures.

Summary by CodeRabbit

  • New Features
    • Added the DE0904 lint to flag hard-coded gts. prefixes when they appear in string literals, macro inputs, and attribute values.
    • Guidance now favors generating identifiers via gts_id!("<suffix>").
  • Documentation
    • Updated the DE09xx GTS Layer documentation with a new DE0904 rule description and examples.
  • Tests
    • Added UI test coverage for failing cases (direct literals, concat!, macros, attributes) and marker-based usage that should not be rejected.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4689f6d-d2f9-431f-aaae-aa7ca4d21568

📥 Commits

Reviewing files that changed from the base of the PR and between 50655e0 and 65b963a.

📒 Files selected for processing (18)
  • crates/cargo-gears-lints/Cargo.toml
  • crates/cargo-gears-lints/README.md
  • crates/cargo-gears-lints/docs/README.md
  • crates/cargo-gears-lints/docs/de09_gts_layer/de0904_no_hardcoded_gts_prefix/README.md
  • crates/cargo-gears-lints/src/de09_gts_layer/de0904_no_hardcoded_gts_prefix.rs
  • crates/cargo-gears-lints/src/lib.rs
  • crates/cargo-gears-lints/tests/ui/de0901_gts_string_pattern/invalid_cases.rs
  • crates/cargo-gears-lints/tests/ui/de0901_gts_string_pattern/permission_strings.rs
  • crates/cargo-gears-lints/tests/ui/de0901_gts_string_pattern/valid_use_cases.rs
  • crates/cargo-gears-lints/tests/ui/de0902_no_schema_for_on_gts_structs/gts_struct_schema_for.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/gts_id_marker.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_attributes.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_attributes.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_macros.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_macros.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/macro_markers.rs
🚧 Files skipped from review as they are similar to previous changes (13)
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/gts_id_marker.rs
  • crates/cargo-gears-lints/docs/README.md
  • crates/cargo-gears-lints/docs/de09_gts_layer/de0904_no_hardcoded_gts_prefix/README.md
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_macros.stderr
  • crates/cargo-gears-lints/Cargo.toml
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_attributes.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_macros.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_attributes.stderr
  • crates/cargo-gears-lints/README.md
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/macro_markers.rs
  • crates/cargo-gears-lints/src/lib.rs

📝 Walkthrough

Walkthrough

Adds DE0904, a deny-level pre-expansion lint that detects hard-coded gts. prefixes in literals, attributes, and macro calls. It registers and documents the lint, adds UI coverage for rejected and accepted patterns, and suppresses it in existing tests where needed.

Changes

DE0904 lint

Layer / File(s) Summary
Lint implementation and registration
crates/cargo-gears-lints/src/de09_gts_layer/..., crates/cargo-gears-lints/src/lib.rs
Implements span-based detection for literals, attributes, and macro calls, emits DE0904 diagnostics, and registers the pre-expansion lint and test metadata.
UI coverage and expected diagnostics
crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/*, crates/cargo-gears-lints/tests/ui/de0901_gts_string_pattern/*, crates/cargo-gears-lints/tests/ui/de0902_no_schema_for_on_gts_structs/*
Tests rejected prefixes in literals, attributes, and macros, accepted gts_id! marker patterns, expected diagnostics, and suppressions in existing tests.
Documentation and test target declarations
crates/cargo-gears-lints/Cargo.toml, crates/cargo-gears-lints/README.md, crates/cargo-gears-lints/docs/...
Adds five UI example targets and documents DE0904 and the gts_id!("<suffix>") form.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RustCompiler
  participant De0904NoHardcodedGtsPrefix
  participant source_contains_hardcoded_prefix
  participant emit_lint
  RustCompiler->>De0904NoHardcodedGtsPrefix: run pre-expansion checks
  De0904NoHardcodedGtsPrefix->>source_contains_hardcoded_prefix: inspect attribute or macro span
  source_contains_hardcoded_prefix-->>De0904NoHardcodedGtsPrefix: return prefix match
  De0904NoHardcodedGtsPrefix->>emit_lint: report matching literal or span
  emit_lint-->>RustCompiler: emit DE0904 deny diagnostic
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding a lint to reject hard-coded GTS ID prefixes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@crates/cargo-gears-lints/src/de09_gts_layer/de0904_no_hardcoded_gts_prefix.rs`:
- Around line 4-103: Refactor De0904NoHardcodedGtsPrefix to implement check_expr
and check_mac_call directly, preserving the existing literal and source-prefix
detection behavior. Remove HardcodedPrefixVisitor, check_item, manual AST
walking, lint_once, and the LINTED_SPANS thread-local state; report directly
through span_lint_and_then from each EarlyLintPass callback while retaining
ordinary-attribute handling in check_attribute.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be690f0d-224f-44a1-9ad0-4ffea3042c3d

📥 Commits

Reviewing files that changed from the base of the PR and between cdd838f and 50655e0.

📒 Files selected for processing (14)
  • crates/cargo-gears-lints/Cargo.toml
  • crates/cargo-gears-lints/README.md
  • crates/cargo-gears-lints/docs/README.md
  • crates/cargo-gears-lints/docs/de09_gts_layer/de0904_no_hardcoded_gts_prefix/README.md
  • crates/cargo-gears-lints/src/de09_gts_layer/de0904_no_hardcoded_gts_prefix.rs
  • crates/cargo-gears-lints/src/lib.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/gts_id_marker.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_attributes.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_attributes.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_macros.rs
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/hardcoded_prefix_in_macros.stderr
  • crates/cargo-gears-lints/tests/ui/de0904_no_hardcoded_gts_prefix/macro_markers.rs

- Add the DE0904 pre-expansion lint for literal prefixes in expressions, macro invocations, and attributes.
- Document the rule and cover valid gts_id! usage alongside UI failures.

Signed-off-by: Vasily Tsybenko <Vasily.Tsybenko@acronis.com>
@aviator5
aviator5 force-pushed the dylint-no_hardcoded_gts_prefix branch from 50655e0 to 65b963a Compare July 18, 2026 12:47
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