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