From 46b59d743eaf6294a518145fb5d0fefaa9c3e60e Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Wed, 29 Apr 2026 20:54:05 -0400 Subject: [PATCH] feat: custom lint rule, fixed readme --- .markdownlint-cli2.jsonc | 14 ++++++ .markdownlint-rules/one-sentence-per-line.mjs | 48 +++++++++++++++++++ .markdownlint.yml | 17 ------- README.md | 5 +- 4 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 .markdownlint-cli2.jsonc create mode 100644 .markdownlint-rules/one-sentence-per-line.mjs delete mode 100644 .markdownlint.yml diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc new file mode 100644 index 0000000..7fbd1c4 --- /dev/null +++ b/.markdownlint-cli2.jsonc @@ -0,0 +1,14 @@ +{ + "customRules": [".markdownlint-rules/one-sentence-per-line.mjs"], + "config": { + "default": true, + "heading-style": { "style": "atx" }, + "ul-indent": { "indent": 2 }, + "line-length": false, + "no-duplicate-heading": { "siblings_only": true }, + "no-inline-html": { + "allowed_elements": ["br", "code", "details", "summary", "img", "picture", "source"] + }, + "first-line-heading": true + } +} diff --git a/.markdownlint-rules/one-sentence-per-line.mjs b/.markdownlint-rules/one-sentence-per-line.mjs new file mode 100644 index 0000000..afcf664 --- /dev/null +++ b/.markdownlint-rules/one-sentence-per-line.mjs @@ -0,0 +1,48 @@ +// @ts-check + +/** + * @typedef {object} ErrorInfo + * @property {number} lineNumber + * @property {string} [context] + * @property {string} [detail] + * @property {[number, number]} [range] + */ + +/** + * @typedef {object} Params + * @property {string[]} lines + */ + +/** @typedef {(error: ErrorInfo) => void} OnError */ + +/** + * @typedef {object} Rule + * @property {string[]} names + * @property {string} description + * @property {string[]} tags + * @property {(params: Params, onError: OnError) => void} function + */ + +/** @type {Rule} */ +export default { + names: ["one-sentence-per-line"], + description: "Each sentence must be on its own line", + tags: ["sentences"], + function: function (params, onError) { + let inFence = false; + params.lines.forEach((line, index) => { + if (/^```/.test(line)) { + inFence = !inFence; + return; + } + if (inFence) return; + // Skip headings, blank lines, HTML, table rows + if (/^(#|\s*[|<]|>|\s*$)/.test(line)) return; + // Strip list marker before checking + const text = line.replace(/^\s*(?:[-*+]|\d+\.)\s+/, ""); + if (/[.!?]\s+[A-Z]/.test(text)) { + onError({ lineNumber: index + 1, context: text.trim() }); + } + }); + }, +}; diff --git a/.markdownlint.yml b/.markdownlint.yml deleted file mode 100644 index f15868f..0000000 --- a/.markdownlint.yml +++ /dev/null @@ -1,17 +0,0 @@ -default: true -heading-style: - style: atx -ul-indent: - indent: 2 -line-length: false -no-duplicate-heading: - siblings_only: true -no-inline-html: - allowed_elements: - - br - - details - - summary - - img - - picture - - source -first-line-heading: true diff --git a/README.md b/README.md index 3ad99b0..567934a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # Go Cuckoo, by `mvhutz`. Go Cuckoo -A hash table that uses cuckoo hashing to achieve a worst-case O(1) lookup time. Read more about it in [the package documentation](https://pkg.go.dev/git.maximhutz.com/tools/go-cuckoo). +A hash table that uses cuckoo hashing to achieve a worst-case O(1) lookup time. +Read more about it in [the package documentation][docs]. + +[docs]: https://pkg.go.dev/git.maximhutz.com/tools/go-cuckoo