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

Lint: Implement check for spaces, not tabs per PEP 12 #2379

Merged
merged 2 commits into from
Mar 5, 2022

Conversation

CAM-Gerlach
Copy link
Member

In a comment on #2374 , @hugovk mentioned that while PEP 12 unequivocally specifies that tabs should not be used in PEPs and spaces used instead, we don't currently have a linting check for this (which I thought we did). This allowed tabs to slip into list of core developers present in PEPs 8100-8103. Therefore, we convert them to spaces, in conformance with PEP 12 and the rest of the PEPs, and implement a simple linting check in case any sneak by in the future.

@CAM-Gerlach CAM-Gerlach added the lint Linter-related work and linting fixes on PEPs label Mar 4, 2022
@CAM-Gerlach CAM-Gerlach self-assigned this Mar 4, 2022
@CAM-Gerlach CAM-Gerlach requested a review from a team as a code owner March 4, 2022 02:23
@CAM-Gerlach CAM-Gerlach removed the request for review from njsmith March 4, 2022 02:24
@CAM-Gerlach CAM-Gerlach changed the title Lint: Implement check to require spaces, not tabs per PEP 12 Lint: Implement check for spaces, not tabs per PEP 12 Mar 4, 2022
@@ -70,6 +70,12 @@ repos:
# Local checks for PEP headers and more
- repo: local
hooks:
- id: check-no-tabs
Copy link
Member

Choose a reason for hiding this comment

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

We're using the remove-tabs hook (https://pre-commit.com/hooks) in another project that will not just flag tabs but also replace them with four spaces.

Shall we use that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that hook is what I use in my other projects as well. I didn't use that here since unlike on those projects, AFAIK most authors/editors don't run the hooks locally and instead its mostly run on CI, where the replacement doesn't matter, and it maintains the status quo of all the hooks we use being either first party or local, rather than on code from individual third party repos.

Copy link
Member

Choose a reason for hiding this comment

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

I've a strong preference for warn+fix over only warn.

For those authors/editors don't run it locally, it's all the same.

But autofix is really useful for those of us who do run locally.

I don't see a need to restrict to only first party or local, and we already have third-party https://github.com/codespell-project/codespell.

And infact we could add https://pre-commit.ci to autofix PRs. I'm also using this for other repos and I find it very useful: no need for a reviewer to ask the author to make changes, then wait for them to make them, and check they made them properly.

We also have a number autofixers from https://github.com/pre-commit/pre-commit-hooks as well which could benefit from https://pre-commit.ci.

There's precedence in this org, https://github.com/python/typeshed already uses https://pre-commit.ci (added in python/typeshed#5552).

@JelleZijlstra: how's your experience been with https://pre-commit.ci/ on https://github.com/python/typeshed?

Copy link
Member

Choose a reason for hiding this comment

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

It's been great on typeshed and saved a lot of time. It doesn't seem as important on this repo though because far fewer PRs run into CI issues that pre-commit could fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've a strong preference for warn+fix over only warn. For those authors/editors don't run it locally, it's all the same. But autofix is really useful for those of us who do run locally.

I strongly do so as well, and rely heavily on this in many other repos I maintain, but this is a bit of a special case. Based on this repo's history, this check should trigger quite rarely (one table in one series of PEPs as of now), we currently only rely on first or second-party hooks for checks that aren't manual-only, and this repo has (AFAIK) much more limited use of the hooks locally than any of the others I work on.

I don't see a need to restrict to only first party or local, and we already have third-party https://github.com/codespell-project/codespell.

That's true, but it isn't installed and run via pre-commit install or on CI; it must be explicitly requested manually by the user (typically after reading our docs explaining how to do so).

And infact we could add https://pre-commit.ci/ to autofix PRs. I'm also using this for other repos and I find it very useful: no need for a reviewer to ask the author to make changes, then wait for them to make them, and check they made them properly.

Pre-commit CI has some pretty serious limitations, particularly as to what hooks it can run; see pre-commit/action#118 . Furthermore, it is very unlikely to ever trigger (see above and next item), and I'd rather not spend this repo's limited churn budget adding it, especially when it is pretty strained already.

We also have a number autofixers from https://github.com/pre-commit/pre-commit-hooks as well which could benefit from https://pre-commit.ci/.

We only have a grand total of three hooks that offer autofixing:

  • mixed-line-ending, which is autofixed locally by our .gitattributes config (its only there as a backstop for the local checkout)
  • fix-byte-order-marker, which again is there as a backstop and I don't think I've actually seen trigger on any repo I manage
  • file-contents-sorter, which only affects the Codespell ignore words list which realistically is only going to be updated by you or me, who both presumably have pre-commit locally.

As @JelleZijlstra also alluded to, these autofixers should never actually trigger on CI (as opposed to locally), and I don't think I've seen a single PR on this repo on which they have (and even the other checks trigger pretty rarely). As mentioned above, the tab check is unlikely to trigger more than very rarely, and is a few seconds total to fix in any editor. So in total, it is likely that even 10 years from now it would never pay back even the time we've spent haggling about it 😆

Copy link
Member

Choose a reason for hiding this comment

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

Okay, this is still a good improvement, thanks!

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Approving PEP changes, no opinion on the particular 'hook' used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA signed lint Linter-related work and linting fixes on PEPs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants