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 pre-commit #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add pre-commit #82

wants to merge 3 commits into from

Conversation

ndmlny-qs
Copy link
Collaborator

This commit does not run pre-commit on the repo, it just adds it as a dev dependency, and adds the following checks.

  • prevents commits to the main branch
  • remove unused imports from python files
  • modifies all imports to be absolute for python files
  • removes commented out code in python files
  • runs isort on imports for python files
  • runs black on python files (formatting)
  • runs ruff on python files (linting)
  • fixes for the setup.cfg file
  • ensures json, yaml, and toml files are parseable (ignores the conda.recipe/meta.yaml file)
  • uses local installs of eslint and prettier for linting and formatting any [java|type]script files.

Also, three additional files have been added.

  • ipywidgets_bokeh/.eslintrc.js
  • ipywidgets_bokeh/.prettierrc

These files contain the formatting and linting rules as outlined in Bokeh.

The last file is a project.toml file that for the time being only contains preferences for ruff. In the future we can use it for complying with setuptools installs.

The package*.json files have also been modified to include eslint and prettier, as well as updating the lint script from a TODO to an actual linting action. This helps with the requests in #75

Resolves #80

This commit **does not** run pre-commit on the repo, it just adds it
as a dev dependency, and adds the following checks.

- prevents commits to the `main` branch
- remove unused imports from python files
- modifies all imports to be absolute for python files
- removes commented out code in python files
- runs `isort` on imports for python files
- runs `black` on python files (formatting)
- runs `ruff` on python files (linting)
- fixes for the `setup.cfg` file
- ensures `json`, `yaml`, and `toml` files are parseable (ignores the
  conda.recipe/meta.yaml file)
- uses local installs of eslint and prettier for linting and formatting
  any [java|type]script files.

Also, three additional files have been added.

- `ipywidgets_bokeh/.eslintrc.js`
- `ipywidgets_bokeh/.prettierrc`

These files contain the formatting and linting rules as outlined in
Bokeh.

The last file is a `project.toml` file that for the time being only
contains preferences for `ruff`. In the future we can use it for
complying with `setuptools` installs.

The `package*.json` files have also been modified to include eslint and
prettier, as well as updating the `lint` script from a `TODO` to an
actual linting action.
@ndmlny-qs ndmlny-qs added the enhancement New feature or request label Feb 7, 2023
@ndmlny-qs ndmlny-qs self-assigned this Feb 7, 2023
Noticed that two packages used for testing linting and formatting on
[Java|Type]Script files were left in the package.json file. These have
been removed as `pre-commit` is handling these checks.
The CI failures are associated with the `lint` script in `package.json`.
This commit removes the new command, as we have not run the new
pre-commit lints and formatters on the codebase yet.

It also adds `rimraf` as a dev dependency in `package.json`, as it was
previously missing.
@philippjfr
Copy link
Contributor

Happy to see this merged!

- python
# Lint Python files.
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.242
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be set up via an environment file instead of separately here?

- --verbose
- --diff
- --respect-gitignore
- --line-length=88
Copy link
Contributor

@mattpap mattpap Mar 18, 2023

Choose a reason for hiding this comment

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

This is pretty outdated limit and inconsistent with bokeh. We set this up higher in bokeh and bokehjs (~165) to avoid unnecessary line splitting. The same applies to setting up other tools, e.g. prettier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We definitely want to mimic what Bokeh does, and I'll update this to be 165

types_or:
- python
# Lint Python files.
- repo: https://github.com/charliermarsh/ruff-pre-commit
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this and similar repositories trustworthy enough? This is a lot of repositories that I don't know anything about.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a very good question. We could run bash scripts for the different linting/typing/formatting tools if a dev has them installed. Let me experiment with this idea more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mirror .pre-commit found in bokeh
3 participants