You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any interest in using a # nolint next special comment to be applied to the next line of code?
Current special comments can look kind of intrusive and awkward for some lines. Using a next comment may look and feel a bit more natural.
# nolint
# nolint: line_length_linter. Lorem ipsum dolor sit amet, ornare ex et himenaeos aenean commodo auctor accumsan gravida.MyFunctionName<-function( # nolint: object_name_linter.a=1,
b=2
) {
a+b
}
# nolint start ... end
# nolint start: line_length_linter.# Lorem ipsum dolor sit amet, ornare ex et himenaeos aenean commodo auctor accumsan gravida.# nolint end: line_length_linter.# nolint start: object_name_linter.MyFunctionName<-function(
# nolint end: object_name_linter.a=1,
b=2
) {
a+b
}
# nolint next
# nolint next: line_length_linter.# Lorem ipsum dolor sit amet, ornare ex et himenaeos aenean commodo auctor accumsan gravida.# nolint next: object_name_linter.MyFunctionName<-function(
a=1,
b=2
) {
a+b
}
I'd be happy enough with a next line only implementation, but it might open up a possible request of # nolint next 5.
Attributes in Rust can suppress the native linters and behave in a similar way:
fnused_function(){}// `#[allow(dead_code)]` is an attribute that disables the `dead_code` lint#[allow(dead_code)]fnunused_function(){}fnnoisy_unused_function(){}// FIXME ^ Add an attribute to suppress the warningfnmain(){used_function();}
Not sure about the . in examples though, they run fine:
reprex
lintr::lint("# nolint: line_length_linter. Lorem ipsum dolor sit amet, ornare ex et himenaeos aenean commodo auctor accumsan gravida.MyFunctionName <- function( # nolint: object_name_linter a = 1, b = 2) { a + b}")
lintr::lint("# nolint start: line_length_linter# Lorem ipsum dolor sit amet, ornare ex et himenaeos aenean commodo auctor accumsan gravida.# nolint end: line_length_linter# nolint start: object_name_linterMyFunctionName <- function( # nolint end: object_name_linter a = 1, b = 2) { a + b}")
I think it's a great idea. It's especially a pain if a # nolint comment induces a line_length_linter() hit.
API-wise, I think we'll do well to avoid having both # nolint and # nolint next since the first matches the second. Is # nolint-next the best choice (only distinguished from # nolint by the subsequent - instead of or :?
We already have # nolint start clashing, so I wouldn't mind # nolint next.
I have a PR basically done implementing this (posting soon). One difference of the clash of # nolint start vs # nolint next is that the former applies to the current line while the latter doesn't.
Activity
AshesITR commentedon Dec 4, 2022
Out of curiosity, are there other linters / code analysis tools that provide such a feature?
I haven't seen it before.
Also NB in your example, you'll also want to add a
.after the linters to be suppressed even if there is no following comment.jmbarbone commentedon Dec 4, 2022
pylint has disable-next, which is basically the same thing.
Attributes in Rust can suppress the native linters and behave in a similar way:
Not sure about the
.in examples though, they run fine:reprex
Created on 2022-12-04 with reprex v2.0.2
AshesITR commentedon Dec 4, 2022
That's because they parse as unqualified
# nolintdirectives, suppressing all lints and not just the intended lint.MichaelChirico commentedon Aug 16, 2023
I think it's a great idea. It's especially a pain if a
# nolintcomment induces aline_length_linter()hit.API-wise, I think we'll do well to avoid having both
# nolintand# nolint nextsince the first matches the second. Is# nolint-nextthe best choice (only distinguished from# nolintby the subsequent-instead ofor:?AshesITR commentedon Aug 16, 2023
We already have
# nolint startclashing, so I wouldn't mind# nolint next.MichaelChirico commentedon Aug 17, 2023
I have a PR basically done implementing this (posting soon). One difference of the clash of
# nolint startvs# nolint nextis that the former applies to the current line while the latter doesn't.That makes something like this:
Harder to handle than something like this:
(I think it's not particularly relevant in practice, so I'll proceed by ignoring this situation)