ruff icon indicating copy to clipboard operation
ruff copied to clipboard

New rule proposal: unnecessary-newline-at-start-of-file

Open CharlesPerrotMinotHCHB opened this issue 1 year ago • 3 comments

Hi,

I think it could be interesting for ruff to also check for unnecessary newlines at the start of files, a parallel (sort of) to to W292 https://docs.astral.sh/ruff/rules/missing-newline-at-end-of-file/ The idea being, ruff would prevent a file to start with a new line. Currently, ruff is perfectly fine with it.

For example, this works even with all rules selected:


from marshaling import AppSettings


class Settings(AppSettings):
    CI_VERSION: str
    ENVIRONMENT_NAME: str
    SYSTEM_JWT_KEY: str


settings = Settings()

CharlesPerrotMinotHCHB avatar Feb 22 '24 23:02 CharlesPerrotMinotHCHB

Thanks for the suggestion. Have you considered using ruff format? It removes the line automatically for you (and inserts the trailing new line)

MichaReiser avatar Feb 23 '24 07:02 MichaReiser

So, I recon it's bordeline, but also use ruff to check on files types (like behave files) that don't quite work ruff format unfortunately

CharlesPerrotMinotHCHB avatar May 13 '24 05:05 CharlesPerrotMinotHCHB

I'm sorry but I don't follow what you're trying to say here. Can you expand on what do you mean by "don't quite work ruff format"? Are you using any other filetypes which contains Python source code?

dhruvmanila avatar May 15 '24 09:05 dhruvmanila

I'm going to close this for now as we're trying to be very conservative in adding new formatting-only lint rules now that we have ruff format, since maintaining compatibility between ruff format and style rules is tricky.

charliermarsh avatar May 22 '24 02:05 charliermarsh