This repository was archived by the owner on Dec 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
135: Support autoformatting and linting with Therapist (#142)
This changeset contains a number of squashed commits towards standardising the formatting and linting of the devportal project. (It wasn't bad before, just good to get this in during a quietish patch of development). **Please view the README and start using `therapist` to avoid other developers' commits containing formatting changes to parts of files they didn't explicitly work on** Closes #135 ## Summarised changes: * full-codebase passes made with `black`, `isort`, `flake8`, `eslint` and `prettier` to bring everything into line * add [`therapist`](https://github.com/rehandalal/therapist) as a framework for running the above tooling (either via a pre-commit hook or directly - both paths are available) +7,255 -3,637 looks huge, but the vast majority of the diff is standardising formatting ## Squashed commits: * 135: Full pass with `black`as first step towards autoformatting 252 files reformatted, 42 files left unchanged. Done with `black --exclude node_modules .` to avoid unnecessarily reformatting third-party package helper Python in JS deps Includes migration files for consistency, even though it adds noise (209/252 files are migrations...) Tests still passing. * 135: add isort with black-compatible config Created a separate .isort.cfg to make it explicit Tests passing fine after changes * 135: tighten up flake8 to also enforce 88-char lines, matching black This commit contains some (manual) changes to over-long lines caught by flake8 that black _didn't_ auto-fix, because they were long strings (see psf/black#182) * 135: Run prettier across all SCSS, ahead of hooking it into therapist's pre-commit tasks * 135: Tune prettier and eslint's ignore options Specifically: - prettier: ignore HTML, SVG, JSON and Python - eslint: ignore HTML, SVG and Python While this wouldn't be needed for editor-based formatting or linting, nor linting explicitly staged/passed files, this change is so that when we _do_ run them across the entire `developerportal` module (eg, in CI), they won't gripe about things they are not intented to be looking at anyway. * 135: Add Therapist to the project, running the linters and formatters recently added/tweaked At this point, the assumption is you have the following installed on your host: * black * flake8 * eslint and eslint-config-prettier * isort * prettier (I'll deal with making that easier in a different commit.) Install `therapist` (https://github.com/rehandalal/therapist): $ pip install therapist Now install the pre-commit hook that will trigger Therapist automatically: $ therapist install Installing pre-commit hook... DONE Now, when you commit a change, the staged changes will be checked by one or more of black, isort, eslint and prettier, as appropriate. See `.therapist.yml` for the configuration. Alternatively, if you wanted to run it across the whole codebase (as we might well do in CI), run: $ therapist run developerportal/ black ............................................................... [SUCCESS] ESLint .............................................................. [SKIPPED] flake8 .............................................................. [SUCCESS] isort ............................................................... [SUCCESS] Prettier ............................................................ [SUCCESS] ------------------------------------------------------------------------------- Completed in: 3.67s And if you want therapist to auto-fix things using black, prettier and/or eslint, run: $ therapist run developerportal --fix * 135: Update Readme to mention how to set up and use `therapist` as a linter/formatter runner
- Loading branch information
Steve Jalim
authored
Sep 18, 2019
1 parent
a19a976
commit bcf5684
Showing
280 changed files
with
7,255 additions
and
3,637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
dist | ||
*.scss | ||
*.py | ||
*.pyc | ||
*.html | ||
*.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[settings] | ||
known_first_party=developerportal | ||
known_third_party=wagtail,modelcluster,six,requests,willow,pillow,taggit | ||
known_django=django | ||
default_section=FIRSTPARTY | ||
skip=migrations | ||
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER | ||
multi_line_output=3 | ||
include_trailing_comma=True | ||
force_grid_wrap=0 | ||
use_parentheses=True | ||
line_length=88 | ||
skip=node_modules,migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
dist | ||
*.py | ||
*.pyc | ||
*.html | ||
*.svg | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
actions: | ||
# Python linting and formatting | ||
isort: | ||
run: isort --check {files} | ||
fix: isort --apply {files} | ||
include: '*.py' | ||
exclude: | ||
- 'node_modules' | ||
- 'migrations' | ||
flake8: | ||
run: flake8 {files} | ||
include: '*.py' | ||
exclude: | ||
- 'node_modules' | ||
- 'migrations' | ||
black: | ||
run: black {files} | ||
include: '*.py' | ||
exclude: | ||
- 'node_modules' | ||
- 'migrations' | ||
- '*.pyc' | ||
|
||
# JS linting | ||
eslint: | ||
description: ESLint | ||
run: $(npm bin)/eslint {files} | ||
fix: $(npm bin)/eslint --fix {files} | ||
exclude: | ||
- '*.html' | ||
- '*.md' | ||
- '*.py' | ||
- '*.pyc' | ||
- '*.scss' | ||
- '*.svg' | ||
- 'developerportal/apps/common/fixtures/common.json' | ||
|
||
# JS and SCSS autoformatting | ||
prettier: | ||
description: Prettier | ||
run: $(npm bin)/prettier -c {files} | ||
fix: $(npm bin)/prettier --write {files} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.