From 5a534cb5e2cbe6c7bdf45682c3256b648ea04a1d Mon Sep 17 00:00:00 2001 From: Tom Conder Date: Tue, 31 Mar 2026 11:58:35 -0500 Subject: [PATCH] fix(build): add pre-commit --- .pre-commit-config.yaml | 48 +++++++++++++++++++++++++++++++++++++++++ README.md | 19 ++++++++++------ 2 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7b2fda2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,48 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +# To install the pre-commit hook: pre-commit install +# To run the command: pre-commit run --all-files + +fail_fast: false +repos: + - repo: https://github.com/gitleaks/gitleaks + rev: v8.30.0 + hooks: + - id: gitleaks + + - repo: https://github.com/sirosen/texthooks + rev: 0.7.1 + hooks: + - id: fix-smartquotes + exclude: assets/models|sponge/deps + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: detect-private-key + - id: detect-aws-credentials + args: ["--allow-missing-credentials"] + - id: mixed-line-ending + exclude: assets/models|sponge/deps + args: ["--fix=lf"] + - id: trailing-whitespace + exclude: assets/models|sponge/deps + - id: end-of-file-fixer + exclude: assets/models|sponge/deps + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-merge-conflict + + - repo: https://github.com/crate-ci/typos + rev: v1.44.0 + hooks: + - id: typos + exclude: .clang-tidy|assets/models|sponge/deps + + - repo: https://github.com/MaratFM/pre-commit-remark + rev: 1.0.0 + hooks: + - id: remark + args: ["--output", "--frail"] + files: "\\.md$" + exclude: assets/models|sponge/deps diff --git a/README.md b/README.md index 7ba6ba3..a53bdee 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,18 @@ A Go library demonstrating line-breaking algorithms with optimal text formatting. - ## Overview This project implements two line-breaking algorithms to format text within specified width constraints: -- **Greedy Algorithm**: Fast, simple approach that fits as many words as possible on each line -- **Knuth-Plass Algorithm**: Sophisticated dynamic programming solution that optimizes line breaks based on penalty functions +* **Greedy Algorithm**: Fast, simple approach that fits as many words as possible on each line +* **Knuth-Plass Algorithm**: Sophisticated dynamic programming solution that optimizes line breaks based on penalty functions ## Features -- **Multiple Algorithms:** Choose between greedy and Knuth-Plass line breaking -- **Dynamic Programming:** Efficiently computes optimal line breaks. It uses a penalty for trailing spaces to promote balanced text. -- **Unit Tested:** Includes unit tests to ensure quality and to allow future changes with confidence. +* **Multiple Algorithms:** Choose between greedy and Knuth-Plass line breaking +* **Dynamic Programming:** Efficiently computes optimal line breaks. It uses a penalty for trailing spaces to promote balanced text. +* **Unit Tested:** Includes unit tests to ensure quality and to allow future changes with confidence. ## Installation and Running @@ -36,11 +35,14 @@ go get github.com/tomconder/linebreak/pkg/linebreak The [greedy algorithm](https://en.wikipedia.org/wiki/Greedy_algorithm) breaks a sequence of words into lines. At each step it fits as many words as possible on each line within the given width. -For example, the following text with a given width of 14: +For example, the following text with a given width of 14: + ``` The lazy yellow dog was caught by the slow red fox as he lay sleeping in the sun ``` + gives the following result + ``` The lazy yellow dog was @@ -56,10 +58,13 @@ the sun The [Knuth-Plass line breaking algorithm](https://en.wikipedia.org/wiki/Knuth%E2%80%93Plass_line-breaking_algorithm) breaks a sequence of words into lines that do not exceed the given width. It uses [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) to determine optimal breakpoints based on a penalty function that discourages trailing empty spaces. For example, the following text with a given width of 14: + ``` The lazy yellow dog was caught by the slow red fox as he lay sleeping in the sun ``` + gives the following result + ``` The lazy yellow dog