Skip to content

feat(forge lint): disable lints with inline comment #10776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Jun 13, 2025

ref:

Motivation

easily allow disabling lints with inline-config via comments

Implementation

having standardization in mind, i decided to follow the same naming convention as forge-fmt (and borrowed some code from https://github.com/foundry-rs/foundry/blob/dani/fmt-solar/crates/fmt-2/src/inline_config.rs)

because of that, these are the available config options:

  • forge-lint: disable-next-item
  • forge-lint: disable-line
  • forge-lint: disable-next-line
  • forge-lint: disable-start
  • forge-lint: disable-end

unlike when formatting though, devs can also inform the target lints by wrapping their ids in parentheses:

  • forge-lint: disable-next-line(asm-keccak256)
  • forge-lint: disable-next-line(asm-keccak256, mixed-case-variable)

if no lint ids are provided (or "all" is used), all lints will be disabled:

  • forge-lint: disable-next-line(all)
  • forge-lint: disable-next-line

@zerosnacks
Copy link
Member

having standardization in mind, i decided to follow the same naming convention as forge-fmt

Good call 👍

@grandizzy
Copy link
Collaborator

having standardization in mind, i decided to follow the same naming convention as forge-fmt

Good call 👍

let's keep the same name style as for forge-fmt, that is forge-lint?

@0xrusowsky 0xrusowsky marked this pull request as ready for review June 16, 2025 16:38
Comment on lines +102 to +119
InlineConfigItem::DisableNextItem(lint) => {
let lints = match validate_ids(&mut invalid_ids, lints, lint, sp) {
Some(lints) => lints,
None => continue,
};

let comment_end = sp.hi().to_usize();

if let Some(next_item) = NextItemFinder::new(comment_end).find(ast) {
for lint in lints {
disabled_ranges.entry(lint).or_default().push(DisabledRange {
start: next_item.lo().to_usize(),
end: next_item.hi().to_usize(),
loose: false,
});
}
};
}
Copy link
Contributor Author

@0xrusowsky 0xrusowsky Jun 16, 2025

Choose a reason for hiding this comment

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

@DaniPopes this is the only custom logic regarding InlineConfigItem "identification" (the others mimic your fmt-2 code).

your fmt code seemed to be targeting the next word for the fmt, but in my case i wanted to target the next AST item (fn, contract, etc).

lmk if this makes sense or if i should follow a different approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(forge lint): create syntax for ignoring a linting rule on a line-level (// forge-lint-ignore: foo-bar-baz)
4 participants