Skip to content
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

ruff check --preview --select=E303 #23155

Merged

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Dec 13, 2024

As requested at:

% ruff rule E303

too-many-blank-lines (E303)

Derived from the pycodestyle linter.

Fix is always available.

This rule is in preview and is not stable. The --preview flag is required for use.

What it does

Checks for extraneous blank lines.

Why is this bad?

PEP 8 recommends using blank lines as follows:

  • No more than two blank lines between top-level statements.
  • No more than one blank line between non-top-level statements.

Example

def func1():
    pass



def func2():
    pass

Use instead:

def func1():
    pass


def func2():
    pass

Typing stub files (.pyi)

The rule allows at most one blank line in typing stub files in accordance to the typing style guide recommendation.

Note: The rule respects the following isort settings when determining the maximum number of blank lines allowed between two statements:

  • [lint.isort.lines-after-imports]: For top-level statements directly following an import statement.
  • [lint.isort.lines-between-types]: For import statements directly following a from ... import ... statement or vice versa.

Options

  • lint.isort.lines-after-imports
  • lint.isort.lines-between-types

References

@@ -425,6 +425,7 @@ jobs:
- checkout
- pip-install
- run: ruff check
- run: ruff check --preview --select=E303
Copy link
Collaborator

@sbc100 sbc100 Dec 13, 2024

Choose a reason for hiding this comment

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

Is there any way to have ruff check include E303 without adding these extra command line argument?

I'm just thinking for local development its nice to just run ruff check from time to time.

Copy link
Contributor Author

@cclauss cclauss Dec 13, 2024

Choose a reason for hiding this comment

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

Nope. We need to target using both --preview and --select=E303. Without --preview, E303 will not be tested. Without --select=E303 then ruff check --preview with our current ruff config in pyproject.toml returns:

Found 17355 errors.
[*] 497 fixable with the --fix option (221 hidden fixes can be enabled with the --unsafe-fixes option).

I chose this approach because running both commands one after the other will take a small fraction of one second.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok that sounds like a reasonable solution for now. Can you add a comment explaining why this is needed? Is it simply that the ruff authors are still working on the E303 rule? Will it become stable at some point and we can remove this? Perhaps mention that in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cclauss
Copy link
Contributor Author

cclauss commented Dec 13, 2024

TODO (cclauss): When ruff supports rule E303 without --preview, remove

  1. lint.select E303
  2. lint.explicit-preview-rules = true, and
  3. lint.preview = true

@cclauss cclauss force-pushed the ruff_check_--preview_--select=E303 branch from 8422ad3 to 69c0b34 Compare December 13, 2024 20:59
@cclauss
Copy link
Contributor Author

cclauss commented Dec 13, 2024

I reverted to the original solution. tool.ruff.lint.explicit-preview-rules would have been much easier to use and understand if it took a list of rules but it is just a bool so it invoked ruff rule F841 but only when tuple unpacking. Too confusing.

@cclauss cclauss force-pushed the ruff_check_--preview_--select=E303 branch from 69c0b34 to 6918b4b Compare December 13, 2024 21:08
@sbc100 sbc100 merged commit dfe3356 into emscripten-core:main Dec 14, 2024
26 of 28 checks passed
@cclauss cclauss deleted the ruff_check_--preview_--select=E303 branch December 14, 2024 16:29
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
This rule was lost in the recent switch from flake8.

This change brings back that rule which is currently in preview in ruff.

See emscripten-core#23139 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants