-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Add pre-commit #82
Conversation
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.
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.
Happy to see this merged! |
- python | ||
# Lint Python files. | ||
- repo: https://github.com/charliermarsh/ruff-pre-commit | ||
rev: v0.0.242 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This commit does not run pre-commit on the repo, it just adds it as a dev dependency, and adds the following checks.
main
branchisort
on imports for python filesblack
on python files (formatting)ruff
on python files (linting)setup.cfg
filejson
,yaml
, andtoml
files are parseable (ignores the conda.recipe/meta.yaml file)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 forruff
. In the future we can use it for complying withsetuptools
installs.The
package*.json
files have also been modified to include eslint and prettier, as well as updating thelint
script from aTODO
to an actual linting action. This helps with the requests in #75Resolves #80