ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Allow noqa on preceding line

Open NeilGirdhar opened this issue 1 year ago • 4 comments

Would it be possible to place the ignore comment on the preceding line? Something like:

    def to_exp(self) -> VonMisesFisherEP:
        q = self.mean_times_concentration
        kappa: RealArray = jnp.linalg.norm(q, 2, axis=-1, keepdims=True)
        # noqa: PLR2004
        return VonMisesFisherEP(jnp.where(kappa == 0.0, q, q * (_a_k(d, kappa) / kappa)))

in addition to

    def to_exp(self) -> VonMisesFisherEP:
        q = self.mean_times_concentration
        kappa: RealArray = jnp.linalg.norm(q, 2, axis=-1, keepdims=True)
        return VonMisesFisherEP(
            jnp.where(kappa == 0.0,  # noqa: PLR2004
                      q,
                      q * (_a_k(d, kappa) / kappa)))

The latter sometimes requires breaking long lines of code in unnatural places. The simple rule would be if noqa occurs on a line without any code, then it applies to the next line that has code in it.

This will be even more useful if human-friend rule names https://github.com/charliermarsh/ruff/issues/1773 are implemented since then the rule names will be longer, breaking even more lines of code.

NeilGirdhar avatar Feb 17 '23 23:02 NeilGirdhar

For reference, pylint has a disable-next directive, which accomplishes this nicely.

So similarly, there could be # noqa-next.

jamesbraza avatar May 26 '23 20:05 jamesbraza

noqa-next is a cool idea. If we're going down that road, you could also have:

  • noqa-file: At the top of a file to indicate blocking the whole file.
  • noqa-block: At the start of a block to indicate that it's for the entire block (function, if, while, etc.)

NeilGirdhar avatar Apr 07 '24 20:04 NeilGirdhar

I think if/when we go this route we'd use directives similar to the Rust ecosystem.

zanieb avatar Apr 07 '24 21:04 zanieb

@zanieb What are those like?

NeilGirdhar avatar Apr 08 '24 02:04 NeilGirdhar