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

[Pre-commit] Expand Pre-commit Hooks #213

Closed
pishoyg opened this issue Aug 23, 2024 · 2 comments
Closed

[Pre-commit] Expand Pre-commit Hooks #213

pishoyg opened this issue Aug 23, 2024 · 2 comments
Labels
dev Why: Developer experience

Comments

@pishoyg
Copy link
Owner

pishoyg commented Aug 23, 2024

Time for some developer experience improvements!

@pishoyg pishoyg added the dev Why: Developer experience label Aug 23, 2024
@pishoyg pishoyg added this to the Developer Experience milestone Aug 23, 2024
@pishoyg pishoyg self-assigned this Aug 23, 2024
pishoyg added a commit that referenced this issue Aug 24, 2024
I don't know exactly what was wrong with the
`Object.entries(...).forEach(([key, value]), () => {});` syntax, but
`fixmyjs` kept complaining about an `Unexpected token =>` for this loop
in particular, so we changed the loop to make it happy.
pishoyg added a commit that referenced this issue Aug 24, 2024
`jshint`:
- Make `.jshint` configuration stricter. Notice that we disabled some of
  the rules that we can't force the TypeScript compiler to respect.

`mypy`:
- We disable `mypy` (temporarily) because it requires extensive fixes.
  Filed #215 to reenable it.
- Ignore `.mypy_cache` in `.gitignore`, `stats.sh`, and `.helpers`.

YAML Hooks
- Add `yamllint` hook.
- Add a `.yamlfmt` and `.yamllint` configuration files. Account for them
  in `stats.sh`. The files were required in order to make the two
  linters compatible.

`.pre-commit-config.yaml`
  - Reformatted the file to accommodate the new linter requirements:
    - Add a document start, denoted by `---`.
    - Set the maximum line length to 80. Rewrite many strings, e.g. by
      removing the unnecessary quotes, or using the block scalar
      (denoted by `>` or `|`), or single quotes in order to enable
      splitting strings to multiple lines.
      NOTE: https://yaml-multiline.info/ explains YAML strings well.
    - Rewrote many of the `bash` scripts contained within the file,
      thanks to the newly-discovered YAML string powers:
      - Include `set -o nounset` in many of the `bash` scripts.
      - NOTE: check-do-not-submit` has been fixed. Fix #199.
  - Delete some redundant `types` specifications.
  - Delete the `.git` suffix from The paths of a couple of repos.
  - Changed the TODO about fail-fast to a NOTE because there is
    currently no action required.
  - Changed the TODO about installing more hooks from
    https://pre-commit.com/hooks.html to make it Python-specific,
    because we already acquired most of the other commits.

`json-tool`:
- Run on `.csslintrc` and `.jshintrc` as well.

`typos`:
- Add a new spell-checking hook. (It was problematic, but we're trying
  to retain it.)

Security Hooks:
- We add a few hooks that check for leaked secrets.

Misc:
- Where possible, add links to the configuration pages inside the hook
  config files. The links don't need to be added to
  `.pre-commit-config.yaml`, because it already has links to the rpos
  (albeit not directly to the config pages). But it's helpful to have
  links in such files as `.yamlfmt`, `.yamllint`, and
  `eslint.config.mjs`.
@pishoyg pishoyg removed their assignment Aug 24, 2024
pishoyg added a commit that referenced this issue Aug 25, 2024
- Run most bash hooks with stricter options whenever possible.
- Fix bug in commit-file-sizes. Use `"${@}"` in order to be able to
  handle files with spaces in their names.
- Delete redundant `pass_filenames: true`. This is the default value.
- Delete redundant `always_run: true`. This is the default behaviour
  when there are no filters.
- Refactor `check-one-readme` to look only at new / modified files,
  rather than all files in the repo.
- Some commands fail when `"${@}"` is empty, so we check for `"$#" == 0`
  before proceeding. This may be unnecessary in many cases, but we do it
  anyway.
- `check-do-not-submit` mangles the regex instead of excluding
  `.pre-commit-config.yaml`.
@pishoyg
Copy link
Owner Author

pishoyg commented Aug 25, 2024

TODO: Likely, the only thing left for this is adding some Python hooks (see). We want to add them (as we did for many others) just because they're recommended on pre-commit.com!

I don't think we will have anything else to do for this issue afterwards.

NOTE: There is also #215, which concerns mypy. It has its own issue because work for it seemed substantial.

pishoyg added a commit that referenced this issue Aug 26, 2024
This is to make it compatible with other Python tools that we are about
to adopt.
pishoyg added a commit that referenced this issue Aug 26, 2024
pishoyg added a commit that referenced this issue Aug 26, 2024
Side change:
- Remove an override of the name of `isort`.
pishoyg added a commit that referenced this issue Aug 26, 2024
The biggest change is the addition of trailing commas which, in
combination with Black's interpretation of trailing commas, results in
many parameter lists being spread over several lines instead of being
compactly pressed on one line.[1]

[1] https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#the-magic-trailing-comma
pishoyg added a commit that referenced this issue Aug 26, 2024
It conflicts with a standard library package[1], so our linters and
formatters get really confused by it!

[1] https://docs.python.org/3.9/library/parser.html
pishoyg added a commit that referenced this issue Aug 26, 2024
- Delete some dead code.
- Disable `dead` in some locations using `# dead: disable`.
pishoyg added a commit that referenced this issue Aug 26, 2024
The helper was introduced in 5fcee4c
when the severity of the `dead` pre-commit was reduced to warning.
pishoyg added a commit that referenced this issue Aug 26, 2024
It's very unlikely to be used, given that we always mirror our GHSEET
files to a local TSV before using them.
@pishoyg pishoyg modified the milestones: Developer Experience, Platform Aug 26, 2024
pishoyg added a commit that referenced this issue Aug 27, 2024
pishoyg added a commit that referenced this issue Sep 1, 2024
This picks up the updated email (#98). It also picks up a small change
from f24753d. This should be all.
@pishoyg
Copy link
Owner Author

pishoyg commented Sep 2, 2024

We were about to adopt this config for Tidy:

break-before-br: yes
enclose-block-text: yes
enclose-text: yes
indent-spaces: 2
indent: auto
join-classes: yes
priority-attributes: id,name,class
punctuation-wrap: yes
quiet: yes
sort-attributes: alpha
strict-tags-attributes: yes
tidy-mark: no
vertical-space: yes
wrap: 80
write-back: yes

NOTE: It caused some issues with the site_publish pipeline, so we reverted it!

pishoyg added a commit that referenced this issue Sep 4, 2024
- Unset `noreturnawait` for `jshint`.
  I don't fully understand the utility of this flag at this point, but
  it's causing some trouble. I don't know whether it's worth appeasing
  this flag, so I will simply unset it.
- Add `Response` as a known global.

P.S. `jshint` is so far useless, and hard to appease.
pishoyg added a commit that referenced this issue Sep 4, 2024
It's creating toil, but has no value. We don't write JavaScript in the
first place. We write TypeScript, and transpile it to JavaScript.
pishoyg added a commit that referenced this issue Sep 4, 2024
We open raw HTML files often. Prettifying them even further will be
helpful to us. It's a huge commit, but we don't have concerns about
commit sizes at the moment.
pishoyg added a commit that referenced this issue Sep 4, 2024
See the comment in `pre-commit-config.yaml` about fail fast.
pishoyg added a commit that referenced this issue Sep 5, 2024
The bug was introduced in 754d887. We
moved the hook without moving its `exclude` parameter along with it.
pishoyg added a commit that referenced this issue Sep 5, 2024
- Introduce a new script,
  `dictionary/marcion.sourceforge.net/appendices.py`, that is
  responsible for all the appendices-related actions. Currently, the
  actions are downloading the sheets into the local mirrors, and
  validating the content.
- The script replaces the following:
  - The Makefile recipe that downloads the sheets and performs some
    basic validation. The recipe has been replaced with a new recipe
    that simply calls the script mentioned above.
  - The logic in the Flashcards pipeline doesn't need to perform any
    validation, it can take the integrity of the data for granted thanks
    to the pre-commit hooks.

Python is more versatile and suitable for this use case. This
definitely didn't belong in a Makefile recipe!
This is also consistent with the pattern that we have followed for Crum
images.
@pishoyg pishoyg added this to coptic Sep 11, 2024
pishoyg added a commit that referenced this issue Oct 8, 2024
This is the (main) reason they are not compatible:
CSSLint/csslint#792.
pishoyg added a commit that referenced this issue Oct 8, 2024
pishoyg added a commit that referenced this issue Oct 9, 2024
The `clean-css` Hook was added in
94b69ae. It was implemented in
JavaScript, not TypeScript, because the TypeScript package[^1] is
outdated.
We required a `clean-css` version >= 5.0 for our use case; in
particularly, we want to assign numerical values for line breaks, not
just a boolean (see `pre-commit/clean-css.js`).

[^1] https://www.npmjs.com/package/@types/clean-css
pishoyg added a commit that referenced this issue Oct 9, 2024
pishoyg added a commit that referenced this issue Oct 17, 2024
The name is different on this machine, for some reason!
pishoyg added a commit that referenced this issue Oct 21, 2024
It was added in 21dd272, but we didn't
include installation steps in `Makefile`.
pishoyg added a commit that referenced this issue Nov 27, 2024
Notice that this requires modifying the `eslint` config in order to
avoid conflict with the new hook.
pishoyg added a commit that referenced this issue Nov 27, 2024
Notice that this requires modifying the `eslint` config in order to
avoid conflict with the new hook.
pishoyg added a commit that referenced this issue Nov 27, 2024
`prettier` already supports JSON. There is no need for us to maintain
our own hook.
Indeed, `prettier` does a better job at producing elegant JSON than
`json-tool`.
pishoyg added a commit that referenced this issue Nov 27, 2024
`prettier` already supports JSON. There is no need for us to maintain
our own hook.
Indeed, `prettier` does a better job at producing elegant JSON than
`json-tool`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev Why: Developer experience
Projects
Archived in project
Development

No branches or pull requests

1 participant