-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: master
Are you sure you want to change the base?
Conversation
Good call 👍 |
let's keep the same name style as for |
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, | ||
}); | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
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
ref:
forge lint
): create syntax for ignoring a linting rule on a line-level (// forge-lint-ignore: foo-bar-baz
) #10769 (comment)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