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

Add a basic pre-commit lint and autoformat #448

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

adehad
Copy link

@adehad adehad commented Jul 1, 2023

Following up on: #438

Summary of changes

  1. a pre-commit config file has been added with some simple rules
  2. Errors picked up during the linting have been addressed and added as separate commits for clarity

NOTE

Target branch

This is targetting the drop-py37 branch. As it was assumed this PR would be merged after #435 .

Running the lint

The assumption is that pre-commit.ci GitHub integration is going to be setup for this project and therefore a dedicate lint GHA has NOT been setup, although it may look like:

---
name: Lint

on:
  push:
    branches:
      - master
      - ci
  pull_request:
    branches:
      - master
  workflow_dispatch:
    inputs: {}

jobs:
  test:
    runs-on: ubuntu-latest

    defaults:
      run:
        shell: bash

    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
          submodules: true

      - name: pre-commit
        run: |
          python -m pip install pre-commit
          python -m pre_commit run --all-files

@edgedb-cla
Copy link

edgedb-cla bot commented Jul 1, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@adehad
Copy link
Author

adehad commented Jul 1, 2023

@fantix Might be an issue that tests aren't running on this PR yet (due to it not targetting the master branch).
Happy to wait for #435 to be merged first

Copy link

@chrisemke chrisemke left a comment

Choose a reason for hiding this comment

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

Consideration should be given to using the following hooks to enable it in the future:
id: blacken-docs (https://github.com/asottile/blacken-docs)
id: insert-license (https://github.com/Lucas-C/pre-commit-hooks)
id: conventional-pre-commit (https://github.com/compilerla/conventional-pre-commit)

Also re-enable mypy is very important for the future

Comment on lines +25 to +22
- id: check-yaml
files: .*\.(yaml|yml)$

Choose a reason for hiding this comment

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

Suggested change
- id: check-yaml
files: .*\.(yaml|yml)$
- id: check-yaml
files: .*\.(yaml|yml)$
- id: check-added-large-files
- id: check-toml

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

Choose a reason for hiding this comment

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

Add the name to make it more readable and beautiful when running

Suggested change
- id: black
- id: black
name: Black (Python formatter)

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.275"
hooks:
- id: ruff

Choose a reason for hiding this comment

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

Add the name to make it more readable and beautiful when running

Suggested change
- id: ruff
- id: ruff
name: Ruff (Python linter)

@chrisemke
Copy link

Another thing that would be really cool would be an edgedb hook to (but not limited to) verifying or formatting the .esdl and .edgeql files

@adehad
Copy link
Author

adehad commented Jul 11, 2023

@fantix feel free commit any of the suggestions.
(Personally I don't think the name addition to the pre-commit config adds much, I've mainly used it when I am running the same tool multiple times but with different configurations)

@fantix fantix deleted the branch edgedb:master September 14, 2023 20:04
@fantix fantix closed this Sep 14, 2023
@fantix
Copy link
Member

fantix commented Sep 14, 2023

Sorry, I didn't mean to close this PR.

@fantix fantix reopened this Sep 14, 2023
@adehad
Copy link
Author

adehad commented Sep 18, 2023

@fantix do let me know if you would like me to target the main branch instead of this drop-py37 branch

@fantix
Copy link
Member

fantix commented Sep 18, 2023

Yes, please! Let's retarget and rebase to the master branch, and get this merged 🙏

@adehad adehad changed the base branch from drop-py37 to master September 18, 2023 16:25
@adehad
Copy link
Author

adehad commented Sep 18, 2023

@fantix should be ready for review again now

@adehad
Copy link
Author

adehad commented Sep 29, 2023

Didn't realise there were merge conflicts, should now be resolved and ready for review @fantix

@adehad
Copy link
Author

adehad commented Oct 5, 2023

(bump) @fantix

@adehad
Copy link
Author

adehad commented Jan 15, 2024

@fantix have just rebased now

@fantix
Copy link
Member

fantix commented Jan 15, 2024

Thanks for the updates! I talked to the team and decided we don't want a pre-commit hook yet. However, I think the formatted code could stay (with a few nitpicking, for which I'll add comments on this PR) and we can probably have a test that runs the linter and formatter for checking.

@adehad
Copy link
Author

adehad commented Jan 15, 2024

and we can probably have a test that runs the linter and formatter for checking.

Yep, we do this too rather that as a pre-commit hook itself. I can recommend using the pre-commit.ci github action/app as this automates the process of checking PRs

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.

None yet

3 participants