Skip to content

Commit

Permalink
feat: improve + standardize configs across projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ahgraber committed May 13, 2024
1 parent 4188a11 commit da10095
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 33 deletions.
14 changes: 13 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ charset = utf-8
[*.{bat,cmd,ps1}]
end_of_line = crlf

[*.{bash,sh}]
indent_style = space
indent_size = 4

[*.csv]
insert_final_newline = false

[*.md]
trim_trailing_whitespace = false
max_line_length = 119

[*.{py, ipynb}]
indent_size=4

[*.tsv]
indent_style = tab

[*.{yml,yaml}]
indent_style = space
indent_size = 2

[*.tsv]
[Makefile]
indent_style = tab
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ repos:
hooks:
- id: markdownlint
name: Lint markdown files
args: ["-f"]
args:
- --config=.markdownlint.yaml
- --fix
stages: [commit]
- repo: local
hooks:
Expand All @@ -119,7 +121,8 @@ repos:
hooks:
- id: shellcheck
name: Lint shell scripts
# args: ["--severity=warning"] # Optionally only show errors and warnings
# ignore '*.zsh" scripts'
exclude: "^.*zsh$"
stages: [commit]
- repo: https://github.com/scop/pre-commit-shfmt
rev: "v3.8.0-1"
Expand All @@ -142,7 +145,7 @@ repos:
args: ["--config", ".typos.toml"]
exclude: |
(?x)^(
^.*(typos\.toml).*$
^.*(\.typos\.toml).*$
)$
stages: [commit]
- repo: https://github.com/adrienverge/yamllint.git
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tabWidth: 2
semi: false
singleQuote: false
quoteProps: "consistent"
printWidth: 100
printWidth: 119
proseWrap: "always"
overrides:
- files: "*.md"
Expand Down
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Pre-commit Template

Provides a set of configuration files to standardize [pre-commit](https://pre-commit.com/) hooks
across repos.
Provides a set of configuration files to standardize [pre-commit](https://pre-commit.com/) hooks across repos.

[copier](https://copier.readthedocs.io/) is used to render a pre-commit config and associated tool
configurations based on answers to a survey during the setup phase.
[copier](https://copier.readthedocs.io/) is used to render a pre-commit config and associated tool configurations based
on answers to a survey during the setup phase.

## Quick Start

### Prerequisites

We will use [pipx](https://pipx.pypa.io/stable/) to install and run applications from isolated
globally-available python environments.
We will use [pipx](https://pipx.pypa.io/stable/) to install and run applications from isolated globally-available
python environments.

Some pre-commit hooks (`hadolint`, `prettier`), expect to find the tool available in your path.

Expand All @@ -35,10 +34,9 @@ pipx install pre-commit

2. Answer the questionnaire

`Copier` will render your configuration based on your selection. Then it will commit these new
changes automatically (but it will not push the commit). This allows you to have a clean git
status before running `pre-commit run --all-files` to ensure your repo is in compliance with your
new configuration.
`Copier` will render your configuration based on your selection. Then it will commit these new changes automatically
(but it will not push the commit). This allows you to have a clean git status before running
`pre-commit run --all-files` to ensure your repo is in compliance with your new configuration.

3. Run `pre-commit run --all-files` and fix any errors that pre-commit's checks have found
Expand All @@ -48,17 +46,14 @@ pipx install pre-commit
(opinionated) configuration of formatting and linting tools, including:
- [EditorConfig](https://editorconfig.org/) - Maintains consistent coding styles across various
editors and IDEs
- [hadolint](https://github.com/hadolint/hadolint) - A smarter Dockerfile linter that ensures best
practice Docker images
- [markdownlint](https://github.com/markdownlint/markdownlint) - A tool to check markdown files and
flag style issues
- [Prettier](https://github.com/prettier/prettier) - Opinionated code formatter (JS, TS, JSON, CSS,
HTML, Markdown, YAML)
- [EditorConfig](https://editorconfig.org/) - Maintains consistent coding styles across various editors and IDEs
- [hadolint](https://github.com/hadolint/hadolint) - A smarter Dockerfile linter that ensures best practice Docker
images
- [markdownlint](https://github.com/markdownlint/markdownlint) - A tool to check markdown files and flag style issues
- [Prettier](https://github.com/prettier/prettier) - Opinionated code formatter (JS, TS, JSON, CSS, HTML, Markdown,
YAML)
- [ruff](https://github.com/astral-sh/ruff) - An extremely fast Python linter and code formatter
- [shellcheck](https://github.com/koalaman/shellcheck) - A static analysis tool for shell scripts
(sh, bash)
- [shellcheck](https://github.com/koalaman/shellcheck) - A static analysis tool for shell scripts (sh, bash)
- [typos](https://github.com/crate-ci/typos) - A source code spell checker
- [yamllint](https://github.com/adrienverge/yamllint) - A linter for YAML files
Expand All @@ -81,9 +76,9 @@ pipx install pre-commit
copier update --trust . --answers-file .copier-answers.yaml
```
> If `copier` is unable to resolve the diff between current and latest revisions, it will create
> `*.rej` files that contain the unresolved differences. These must be reviewed (and
> resolved/implemented) prior to commit (this is enforced by `pre-commit`)
> If `copier` is unable to resolve the diff between current and latest revisions, it will create `*.rej` files that
> contain the unresolved differences. These must be reviewed (and resolved/implemented) prior to commit (this is
> enforced by `pre-commit`)
### What does `copier update` do?
Expand Down
9 changes: 6 additions & 3 deletions template/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ repos:
hooks:
- id: markdownlint
name: Lint markdown files
args: ["-f"]
args:
- --config=.markdownlint.yaml
- --fix
stages: [commit]
{%- endif %}{% if prettier %}
- repo: local
Expand Down Expand Up @@ -125,7 +127,8 @@ repos:
hooks:
- id: shellcheck
name: Lint shell scripts
# args: ["--severity=warning"] # Optionally only show errors and warnings
# ignore '*.zsh" scripts'
exclude: "^.*zsh$"
stages: [commit]
{%- endif %}{% if shfmt %}
- repo: https://github.com/scop/pre-commit-shfmt
Expand All @@ -150,7 +153,7 @@ repos:
args: ["--config", ".typos.toml"]
exclude: |
(?x)^(
^.*(typos\.toml).*$
^.*(\.typos\.toml)$
)$
stages: [commit]
{%- endif %}{% if yamllint %}
Expand Down
14 changes: 13 additions & 1 deletion template/{% if editorconfig %}.editorconfig{% endif %}.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ charset = utf-8
[*.{bat,cmd,ps1}]
end_of_line = crlf

[*.{bash,sh}]
indent_style = space
indent_size = 4

[*.csv]
insert_final_newline = false

[*.md]
trim_trailing_whitespace = false
max_line_length = 119

[*.{py, ipynb}]
indent_size=4

[*.tsv]
indent_style = tab

[*.{yml,yaml}]
indent_style = space
indent_size = 2

[*.tsv]
[Makefile]
indent_style = tab
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tabWidth: 2
semi: false
singleQuote: false
quoteProps: "consistent"
printWidth: 100
printWidth: 119
proseWrap: "always"
overrides:
- files: "*.md"
Expand Down

0 comments on commit da10095

Please sign in to comment.