From da1009515e54ae8038c8239820cbfb1a002e0761 Mon Sep 17 00:00:00 2001 From: ahgraber Date: Sun, 12 May 2024 20:41:58 -0400 Subject: [PATCH] feat: improve + standardize configs across projects --- .editorconfig | 14 ++++++- .pre-commit-config.yaml | 9 ++-- .prettierrc.yaml | 2 +- README.md | 41 ++++++++----------- template/.pre-commit-config.yaml.jinja | 9 ++-- ...torconfig %}.editorconfig{% endif %}.jinja | 14 ++++++- ...ettier %}.prettierrc.yaml{% endif %}.jinja | 2 +- 7 files changed, 58 insertions(+), 33 deletions(-) diff --git a/.editorconfig b/.editorconfig index 34b7ee5..19d0f99 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 64b5909..f2a01a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -92,7 +92,9 @@ repos: hooks: - id: markdownlint name: Lint markdown files - args: ["-f"] + args: + - --config=.markdownlint.yaml + - --fix stages: [commit] - repo: local hooks: @@ -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" @@ -142,7 +145,7 @@ repos: args: ["--config", ".typos.toml"] exclude: | (?x)^( - ^.*(typos\.toml).*$ + ^.*(\.typos\.toml).*$ )$ stages: [commit] - repo: https://github.com/adrienverge/yamllint.git diff --git a/.prettierrc.yaml b/.prettierrc.yaml index 567e91c..88a85d3 100644 --- a/.prettierrc.yaml +++ b/.prettierrc.yaml @@ -4,7 +4,7 @@ tabWidth: 2 semi: false singleQuote: false quoteProps: "consistent" -printWidth: 100 +printWidth: 119 proseWrap: "always" overrides: - files: "*.md" diff --git a/README.md b/README.md index e0c01eb..307d229 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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 @@ -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? diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja index 38e7fd1..b933925 100644 --- a/template/.pre-commit-config.yaml.jinja +++ b/template/.pre-commit-config.yaml.jinja @@ -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 @@ -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 @@ -150,7 +153,7 @@ repos: args: ["--config", ".typos.toml"] exclude: | (?x)^( - ^.*(typos\.toml).*$ + ^.*(\.typos\.toml)$ )$ stages: [commit] {%- endif %}{% if yamllint %} diff --git a/template/{% if editorconfig %}.editorconfig{% endif %}.jinja b/template/{% if editorconfig %}.editorconfig{% endif %}.jinja index 34b7ee5..19d0f99 100644 --- a/template/{% if editorconfig %}.editorconfig{% endif %}.jinja +++ b/template/{% if editorconfig %}.editorconfig{% endif %}.jinja @@ -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 diff --git a/template/{% if prettier %}.prettierrc.yaml{% endif %}.jinja b/template/{% if prettier %}.prettierrc.yaml{% endif %}.jinja index 567e91c..88a85d3 100644 --- a/template/{% if prettier %}.prettierrc.yaml{% endif %}.jinja +++ b/template/{% if prettier %}.prettierrc.yaml{% endif %}.jinja @@ -4,7 +4,7 @@ tabWidth: 2 semi: false singleQuote: false quoteProps: "consistent" -printWidth: 100 +printWidth: 119 proseWrap: "always" overrides: - files: "*.md"