├── .nvmrc ├── .husky ├── .gitignore └── pre-commit ├── .github ├── FUNDING.yml ├── renovate.json ├── actions │ └── prepare │ │ └── action.yml ├── SECURITY.md ├── ISSUE_TEMPLATE.md ├── workflows │ ├── contributors.yml │ ├── compliance.yml │ ├── pr-review-requested.yml │ ├── octoguide.yml │ └── ci.yml ├── PULL_REQUEST_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── 02-documentation.yml │ ├── 04-tooling.yml │ ├── 03-feature.yml │ └── 01-bug.yml ├── DEVELOPMENT.md ├── CODE_OF_CONDUCT.md └── CONTRIBUTING.md ├── pnpm-workspace.yaml ├── .gitignore ├── .prettierignore ├── packages ├── eslint-plugin-sentences-per-line │ ├── src │ │ ├── rules │ │ │ ├── index.ts │ │ │ ├── ruleTester.ts │ │ │ ├── one.test.ts │ │ │ └── one.ts │ │ └── index.ts │ ├── .eslint-doc-generatorrc.js │ ├── tsconfig.json │ ├── docs │ │ └── rules │ │ │ └── one.md │ ├── package.json │ └── README.md ├── sentences-per-line │ ├── tsconfig.json │ ├── src │ │ ├── index.ts │ │ ├── doesEndWithIgnoredWord.ts │ │ ├── getIndexBeforeSecondSentence.test.ts │ │ ├── doesEndWithIgnoredWord.test.ts │ │ └── getIndexBeforeSecondSentence.ts │ ├── CHANGELOG.md │ ├── package.json │ └── README.md ├── prettier-plugin-sentences-per-line │ ├── tsconfig.json │ ├── src │ │ ├── modifications │ │ │ ├── insertNewlineAt.ts │ │ │ └── modifyNodeIfMultipleSentencesInLine.ts │ │ ├── types │ │ │ └── mdast.d.ts │ │ ├── index.ts │ │ └── index.test.ts │ ├── package.json │ └── README.md └── markdownlint-sentences-per-line │ ├── tsconfig.json │ ├── package.json │ ├── src │ ├── index.ts │ ├── markdownlintSentencesPerLine.ts │ └── markdownlintSentencesPerLine.test.ts │ └── README.md ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── tsconfig.json ├── cspell.json ├── .prettierrc ├── tsconfig.build.json ├── tsconfig.base.json ├── vitest.config.ts ├── knip.json ├── LICENSE.md ├── .all-contributorsrc ├── package.json ├── eslint.config.js └── README.md /.nvmrc: -------------------------------------------------------------------------------- 1 | 24.12.0 2 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | npx lint-staged 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: JoshuaKGoldberg 2 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "packages/*" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tsbuildinfo 2 | coverage/ 3 | lib/ 4 | node_modules/ 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .all-contributorsrc 2 | .husky/ 3 | coverage/ 4 | lib/ 5 | packages/*/lib 6 | pnpm-lock.yaml 7 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/src/rules/index.ts: -------------------------------------------------------------------------------- 1 | import { one } from "./one.ts"; 2 | 3 | export const rules = { 4 | one, 5 | }; 6 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "esbenp.prettier-vscode", 5 | "streetsidesoftware.code-spell-checker" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/sentences-per-line/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "rootDir": "src" 5 | }, 6 | "extends": "../../tsconfig.base.json", 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/.eslint-doc-generatorrc.js: -------------------------------------------------------------------------------- 1 | /** @type {import('eslint-doc-generator').GenerateOptions} */ 2 | const config = { 3 | ruleDocTitleFormat: "prefix-name", 4 | }; 5 | 6 | export default config; 7 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "rootDir": "src", 5 | "types": ["node", "mdast"] 6 | }, 7 | "extends": "../../tsconfig.base.json", 8 | "include": ["src"] 9 | } 10 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "automerge": true, 4 | "internalChecksFilter": "strict", 5 | "labels": ["dependencies"], 6 | "minimumReleaseAge": "3 days", 7 | "postUpdateOptions": ["pnpmDedupe"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "rootDir": "src" 5 | }, 6 | "extends": "../../tsconfig.base.json", 7 | "include": ["src"], 8 | "references": [{ "path": "../sentences-per-line" }] 9 | } 10 | -------------------------------------------------------------------------------- /packages/markdownlint-sentences-per-line/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "rootDir": "src" 5 | }, 6 | "extends": "../../tsconfig.base.json", 7 | "include": ["src"], 8 | "references": [{ "path": "../sentences-per-line" }] 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "composite": false, 5 | "declaration": false, 6 | "declarationMap": false, 7 | "noEmit": true 8 | }, 9 | "extends": "./tsconfig.base.json", 10 | "include": ["*.config.*", "packages/*/.*rc.js"] 11 | } 12 | -------------------------------------------------------------------------------- /cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "dictionaries": ["typescript"], 3 | "ignorePaths": [ 4 | ".github", 5 | "*.tsbuildinfo", 6 | "*.snap", 7 | "CHANGELOG.md", 8 | "coverage", 9 | "node_modules", 10 | "packages/*/lib", 11 | "pnpm-lock.yaml" 12 | ], 13 | "words": ["commonmark", "eslint-doc-generatorrc"] 14 | } 15 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/prettierrc", 3 | "overrides": [{ "files": ".nvmrc", "options": { "parser": "yaml" } }], 4 | "plugins": [ 5 | "prettier-plugin-curly", 6 | "prettier-plugin-sh", 7 | "prettier-plugin-packagejson", 8 | "./packages/prettier-plugin-sentences-per-line/lib/index.js" 9 | ], 10 | "useTabs": true 11 | } 12 | -------------------------------------------------------------------------------- /.github/actions/prepare/action.yml: -------------------------------------------------------------------------------- 1 | description: Prepares the repo for a typical CI job 2 | 3 | name: Prepare 4 | 5 | runs: 6 | steps: 7 | - uses: pnpm/action-setup@v4 8 | - uses: actions/setup-node@v6 9 | with: 10 | cache: pnpm 11 | node-version: "24" 12 | - run: pnpm install --frozen-lockfile 13 | shell: bash 14 | using: composite 15 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | We take all security vulnerabilities seriously. 4 | If you have a vulnerability or other security issues to disclose: 5 | 6 | - Thank you very much, please do! 7 | - Please send them to us by emailing `github@joshuakgoldberg.com` 8 | 9 | We appreciate your efforts and responsible disclosure and will make every effort to acknowledge your contributions. 10 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noEmit": false 4 | }, 5 | "extends": "./tsconfig.base.json", 6 | "files": [], 7 | "references": [ 8 | { "path": "./packages/eslint-plugin-sentences-per-line" }, 9 | { "path": "./packages/markdownlint-sentences-per-line" }, 10 | { "path": "./packages/prettier-plugin-sentences-per-line" }, 11 | { "path": "./packages/sentences-per-line" } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/sentences-per-line/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | doesEndWithIgnoredWord, 3 | ignoredWords, 4 | } from "./doesEndWithIgnoredWord.ts"; 5 | export { getIndexBeforeSecondSentence } from "./getIndexBeforeSecondSentence.ts"; 6 | 7 | export default (): never => { 8 | throw new Error( 9 | "The Markdownlint sentences-per-line plugin is now in the dedicated markdownlint-sentences-per-line package.", 10 | ); 11 | }; 12 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "declaration": true, 5 | "declarationMap": true, 6 | "esModuleInterop": true, 7 | "module": "NodeNext", 8 | "moduleResolution": "NodeNext", 9 | "resolveJsonModule": true, 10 | "rewriteRelativeImportExtensions": true, 11 | "skipLibCheck": true, 12 | "sourceMap": true, 13 | "strict": true, 14 | "target": "ES2022" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/src/rules/ruleTester.ts: -------------------------------------------------------------------------------- 1 | import markdown from "@eslint/markdown"; 2 | import { RuleTester } from "eslint"; 3 | import * as vitest from "vitest"; 4 | 5 | RuleTester.it = vitest.it; 6 | RuleTester.itOnly = vitest.it.only; 7 | RuleTester.describe = vitest.describe; 8 | 9 | export const ruleTester = new RuleTester({ 10 | language: "markdown/commonmark", 11 | plugins: { markdown }, 12 | }); 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ## Overview 8 | 9 | ... 10 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "args": ["run", "${relativeFile}"], 5 | "autoAttachChildProcesses": true, 6 | "console": "integratedTerminal", 7 | "name": "Debug Current Test File", 8 | "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", 9 | "request": "launch", 10 | "skipFiles": ["/**", "**/node_modules/**"], 11 | "smartStep": true, 12 | "type": "node" 13 | } 14 | ], 15 | "version": "0.2.0" 16 | } 17 | -------------------------------------------------------------------------------- /vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { readdirSync } from "node:fs"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | test: { 6 | coverage: { 7 | include: ["packages/*/src/"], 8 | }, 9 | 10 | projects: readdirSync("./packages").map((name) => ({ 11 | test: { 12 | clearMocks: true, 13 | include: ["**/src/**/*.test.ts"], 14 | name, 15 | root: `./packages/${name}`, 16 | setupFiles: ["console-fail-test/setup"], 17 | }, 18 | })), 19 | }, 20 | }); 21 | -------------------------------------------------------------------------------- /knip.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/knip@latest/schema.json", 3 | "ignoreExportsUsedInFile": { "interface": true, "type": true }, 4 | "workspaces": { 5 | "packages/eslint-plugin-sentences-per-line": { 6 | "entry": [".eslint-doc-generatorrc.js"] 7 | }, 8 | "packages/markdownlint-sentences-per-line": { 9 | "entry": ["src/index.ts!"], 10 | "project": ["src/**/*.ts!"] 11 | }, 12 | "packages/sentences-per-line": { 13 | "entry": ["src/index.ts!"], 14 | "project": ["src/**/*.ts!"] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.fixAll.eslint": "explicit" 4 | }, 5 | "editor.defaultFormatter": "esbenp.prettier-vscode", 6 | "editor.formatOnSave": true, 7 | "editor.rulers": [80], 8 | "eslint.probe": [ 9 | "javascript", 10 | "javascriptreact", 11 | "json", 12 | "jsonc", 13 | "markdown", 14 | "typescript", 15 | "typescriptreact", 16 | "yaml" 17 | ], 18 | "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }], 19 | "typescript.tsdk": "node_modules/typescript/lib" 20 | } 21 | -------------------------------------------------------------------------------- /.github/workflows/contributors.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | contributors: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 6 | with: 7 | fetch-depth: 0 8 | - uses: ./.github/actions/prepare 9 | - env: 10 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} 11 | uses: JoshuaKGoldberg/all-contributors-auto-action@944abe4387e751b5bbb38616cb25cf4a4ca998f2 # v0.5.0 12 | 13 | name: Contributors 14 | 15 | on: 16 | push: 17 | branches: 18 | - main 19 | -------------------------------------------------------------------------------- /.github/workflows/compliance.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | compliance: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: mtfoley/pr-compliance-action@main 6 | with: 7 | body-auto-close: false 8 | ignore-authors: |- 9 | allcontributors 10 | allcontributors[bot] 11 | renovate 12 | renovate[bot] 13 | ignore-team-members: false 14 | 15 | name: Compliance 16 | 17 | on: 18 | pull_request: 19 | branches: 20 | - main 21 | types: 22 | - edited 23 | - opened 24 | - reopened 25 | - synchronize 26 | 27 | permissions: 28 | pull-requests: write 29 | -------------------------------------------------------------------------------- /packages/sentences-per-line/src/doesEndWithIgnoredWord.ts: -------------------------------------------------------------------------------- 1 | /** List of words to ignore when determining sentence boundaries */ 2 | export const ignoredWords = [ 3 | "eg.", 4 | "e.g.", 5 | "etc.", 6 | "ex.", 7 | "ie.", 8 | "i.e.", 9 | "vs.", 10 | ]; 11 | 12 | /** 13 | * Given a lint of text, determine if it ends with an ignored word. 14 | */ 15 | export const doesEndWithIgnoredWord = ( 16 | input: string, 17 | customIgnoredWords: string[] = [], 18 | ): boolean => { 19 | const allIgnoredWords = [...ignoredWords, ...customIgnoredWords]; 20 | return allIgnoredWords.some((word) => 21 | input.toLowerCase().endsWith(word.toLowerCase()), 22 | ); 23 | }; 24 | -------------------------------------------------------------------------------- /.github/workflows/pr-review-requested.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | pr_review_requested: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions-ecosystem/action-remove-labels@2ce5d41b4b6aa8503e285553f75ed56e0a40bae0 # v1 6 | with: 7 | labels: "status: waiting for author" 8 | - if: failure() 9 | run: | 10 | echo "Don't worry if the previous step failed." 11 | echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221." 12 | 13 | name: PR Review Requested 14 | 15 | on: 16 | pull_request_target: 17 | types: 18 | - review_requested 19 | 20 | permissions: 21 | pull-requests: write 22 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/src/modifications/insertNewlineAt.ts: -------------------------------------------------------------------------------- 1 | import type { SentenceNodeChild } from "mdast"; 2 | 3 | export function insertNewlineAt( 4 | children: SentenceNodeChild[], 5 | index: number, 6 | insertion: string, 7 | ) { 8 | const newWhitespace: SentenceNodeChild = { 9 | hasLeadingPunctuation: false, 10 | hasTrailingPunctuation: false, 11 | isCJ: false, 12 | kind: "whitespace", 13 | type: "word", 14 | value: insertion, 15 | }; 16 | 17 | if (children[index + 1].type === "whitespace") { 18 | children[index + 1] = newWhitespace; 19 | } else { 20 | children.splice(index + 1, 0, newWhitespace); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/sentences-per-line/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.3.0](https://github.com/JoshuaKGoldberg/sentences-per-line/compare/0.2.2...0.3.0) (2024-12-13) 4 | 5 | ### Features 6 | 7 | - add auto-fixes ([#637](https://github.com/JoshuaKGoldberg/sentences-per-line/issues/637)) ([5d5536e](https://github.com/JoshuaKGoldberg/sentences-per-line/commit/5d5536e4a8424dfdb2c01c9ad6b01613cee719ed)), closes [#24](https://github.com/JoshuaKGoldberg/sentences-per-line/issues/24) 8 | 9 | ## 0.2.2 (2024-12-13) 10 | 11 | ### Bug Fixes 12 | 13 | - explicitly indicate parser: none ([72d28b8](https://github.com/JoshuaKGoldberg/sentences-per-line/commit/72d28b84af5277bf5249f43d1a7ebd6b663da673)) 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | ## PR Checklist 6 | 7 | - [ ] Addresses an existing open issue: fixes #000 8 | - [ ] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) 9 | - [ ] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/sentences-per-line/blob/main/.github/CONTRIBUTING.md) were taken 10 | 11 | ## Overview 12 | 13 | 14 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettier-plugin-sentences-per-line", 3 | "version": "0.2.0", 4 | "description": "Prettier plugin for limiting sentences per line. 📐", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/JoshuaKGoldberg/sentences-per-line", 8 | "directory": "packages/prettier-plugin-sentences-per-line" 9 | }, 10 | "license": "MIT", 11 | "type": "module", 12 | "main": "lib/index.js", 13 | "files": [ 14 | "lib/" 15 | ], 16 | "dependencies": { 17 | "sentences-per-line": "workspace:~" 18 | }, 19 | "devDependencies": { 20 | "@types/mdast": "^4.0.4", 21 | "prettier": "^3.7.1" 22 | }, 23 | "peerDependencies": { 24 | "prettier": "^3" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/src/index.ts: -------------------------------------------------------------------------------- 1 | import { createRequire } from "node:module"; 2 | 3 | import { rules } from "./rules/index.ts"; 4 | 5 | const require = createRequire(import.meta.url || __filename); 6 | 7 | const { name, version } = require("../package.json") as { 8 | name: string; 9 | version: string; 10 | }; 11 | 12 | const plugin = { 13 | configs: { 14 | get recommended() { 15 | return { 16 | plugins: { 17 | "sentences-per-line": plugin, 18 | }, 19 | rules: Object.fromEntries( 20 | Object.entries(rules).map(([name]) => [ 21 | "sentences-per-line/" + name, 22 | "error" as const, 23 | ]), 24 | ), 25 | }; 26 | }, 27 | }, 28 | meta: { 29 | name, 30 | version, 31 | }, 32 | rules, 33 | }; 34 | 35 | export default plugin; 36 | -------------------------------------------------------------------------------- /packages/markdownlint-sentences-per-line/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdownlint-sentences-per-line", 3 | "version": "0.1.1", 4 | "description": "Markdownlint rule for limiting sentences per line. 📐", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/JoshuaKGoldberg/sentences-per-line", 8 | "directory": "packages/markdownlint-sentences-per-line" 9 | }, 10 | "license": "MIT", 11 | "type": "module", 12 | "main": "lib/index.js", 13 | "files": [ 14 | "lib/" 15 | ], 16 | "dependencies": { 17 | "markdownlint-rule-helpers": "^0.30.0", 18 | "sentences-per-line": "workspace:^" 19 | }, 20 | "devDependencies": { 21 | "@types/markdownlint-rule-helpers": "^0.21.6", 22 | "markdownlint": "^0.40.0" 23 | }, 24 | "peerDependencies": { 25 | "markdownlint": "^0.37.0 || ^0.39.0 || ^0.40.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/markdownlint-sentences-per-line/src/index.ts: -------------------------------------------------------------------------------- 1 | import { markdownlintSentencesPerLine } from "./markdownlintSentencesPerLine.ts"; 2 | 3 | // Ideally, Markdownlint CLIs should support default exports... 4 | export default markdownlintSentencesPerLine; 5 | 6 | // ...but practically, at least markdownlint-cli doesn't at time of writing. 7 | // It assumes the CJS-style module.exports = { ... } object shape. 8 | export const description = markdownlintSentencesPerLine.description; 9 | export const names = markdownlintSentencesPerLine.names; 10 | export const parser = markdownlintSentencesPerLine.parser; 11 | export const tags = markdownlintSentencesPerLine.tags; 12 | 13 | // Additionally, 'function' is an expected property name - and a reserved word. 14 | const ruleFunction = markdownlintSentencesPerLine.function; 15 | export { ruleFunction as function }; 16 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/docs/rules/one.md: -------------------------------------------------------------------------------- 1 | # sentences-per-line/one 2 | 3 | 💼 This rule is enabled in the ✅ `recommended` config. 4 | 5 | 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). 6 | 7 | 8 | 9 | This rule enforces that each at most one sentence appears per line in Markdown files. 10 | If two or more sentences appear on the same line, they will be split onto separate lines. 11 | 12 | ## Examples 13 | 14 | Example of **incorrect** code for this rule: 15 | 16 | 17 | 18 | ```md 19 | First sentence. Second sentence 20 | ``` 21 | 22 | 23 | 24 | Example of **correct** code for this rule: 25 | 26 | ```md 27 | First sentence. 28 | Second sentence 29 | ``` 30 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-plugin-sentences-per-line", 3 | "version": "0.1.0", 4 | "description": "ESLint plugin for limiting sentences per line in Markdown code. 📐", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/JoshuaKGoldberg/sentences-per-line", 8 | "directory": "packages/eslint-plugin-sentences-per-line" 9 | }, 10 | "license": "MIT", 11 | "type": "module", 12 | "main": "./lib/index.js", 13 | "files": [ 14 | "lib/" 15 | ], 16 | "scripts": { 17 | "build:docs": "eslint-doc-generator", 18 | "lint:docs": "eslint-doc-generator --check" 19 | }, 20 | "dependencies": { 21 | "@eslint/markdown": "^7.5.1", 22 | "eslint": ">=9", 23 | "sentences-per-line": "workspace:^" 24 | }, 25 | "devDependencies": { 26 | "@types/mdast": "^4.0.4", 27 | "eslint-doc-generator": "^2.3.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/src/types/mdast.d.ts: -------------------------------------------------------------------------------- 1 | export * from "mdast"; 2 | 3 | declare module "mdast" { 4 | interface PositionPoint { 5 | column: number; 6 | line: number; 7 | offset: number; 8 | } 9 | 10 | interface Position { 11 | end: PositionPoint; 12 | start: PositionPoint; 13 | } 14 | 15 | interface Node { 16 | position: Position; 17 | } 18 | 19 | interface WhitespaceNode { 20 | type: "whitespace"; 21 | value: string; 22 | } 23 | 24 | interface WordNode { 25 | hasLeadingPunctuation: boolean; 26 | hasTrailingPunctuation: boolean; 27 | isCJ: boolean; 28 | kind: string; 29 | type: "word"; 30 | value: string; 31 | } 32 | 33 | type SentenceNodeChild = WhitespaceNode | WordNode; 34 | 35 | interface SentenceNode { 36 | children: SentenceNodeChild[]; 37 | type: "sentence"; 38 | } 39 | 40 | interface PhrasingContentMap { 41 | sentence: SentenceNode; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/sentences-per-line/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sentences-per-line", 3 | "version": "0.5.0", 4 | "description": "Utility functions to detect the number of sentences per line in Markdown files. 📐", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/JoshuaKGoldberg/sentences-per-line", 8 | "directory": "packages/sentences-per-line" 9 | }, 10 | "license": "MIT", 11 | "author": { 12 | "name": "Josh Goldberg ✨", 13 | "email": "npm@joshuakgoldberg.com" 14 | }, 15 | "type": "module", 16 | "exports": { 17 | ".": "./src/index.ts", 18 | "./package.json": "./package.json" 19 | }, 20 | "main": "./src/index.ts", 21 | "files": [ 22 | "lib/" 23 | ], 24 | "engines": { 25 | "node": ">=22.14.0" 26 | }, 27 | "publishConfig": { 28 | "exports": { 29 | ".": { 30 | "types": "./lib/index.d.ts", 31 | "default": "./lib/index.js" 32 | }, 33 | "./package.json": "./package.json" 34 | }, 35 | "main": "./lib/index.js" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/octoguide.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | octoguide: 3 | if: ${{ !endsWith(github.actor, '[bot]') }} 4 | runs-on: ubuntu-latest 5 | steps: 6 | - uses: JoshuaKGoldberg/octoguide@a37cca1a4f04c9e07f0581c230d41d09a4571f92 # 0.18.1 7 | with: 8 | config: strict 9 | github-token: ${{ secrets.GITHUB_TOKEN }} 10 | 11 | name: OctoGuide 12 | 13 | on: 14 | discussion: 15 | types: 16 | - created 17 | - edited 18 | discussion_comment: 19 | types: 20 | - created 21 | - deleted 22 | - edited 23 | issue_comment: 24 | types: 25 | - created 26 | - deleted 27 | - edited 28 | issues: 29 | types: 30 | - edited 31 | - opened 32 | pull_request_review_comment: 33 | types: 34 | - created 35 | - deleted 36 | - edited 37 | pull_request_target: 38 | types: 39 | - edited 40 | - opened 41 | 42 | permissions: 43 | discussions: write 44 | issues: write 45 | pull-requests: write 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/02-documentation.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have pulled the latest `main` branch of the repository. 7 | required: true 8 | - label: I have [searched for related issues](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aissue) and found none that matched my issue. 9 | required: true 10 | type: checkboxes 11 | - attributes: 12 | description: What would you like to report? 13 | label: Overview 14 | type: textarea 15 | validations: 16 | required: true 17 | - attributes: 18 | description: Any additional info you'd like to provide. 19 | label: Additional Info 20 | type: textarea 21 | description: Report a typo or missing area of documentation 22 | labels: 23 | - "area: documentation" 24 | name: 📝 Documentation 25 | title: "📝 Documentation: " 26 | -------------------------------------------------------------------------------- /packages/sentences-per-line/src/getIndexBeforeSecondSentence.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, test } from "vitest"; 2 | 3 | import { getIndexBeforeSecondSentence } from "./index.ts"; 4 | 5 | describe(getIndexBeforeSecondSentence, () => { 6 | test.each([ 7 | ["", undefined], 8 | ["abc", undefined], 9 | ["abc.", undefined], 10 | ["Abc. Def.", 4], 11 | ["Abc def. Ghi jkl.", 8], 12 | ["`Abc. Def.`", undefined], 13 | ["`Abc.` Def.", undefined], 14 | ["`Abc.` `Def.`", undefined], 15 | ["``Abc.`` Def.", undefined], 16 | ["`Abc.` Def. Ghi", 11], 17 | ["```js```.", undefined], 18 | [ 19 | ` 20 | \`\`\`plaintext 21 | Abc. Def. 22 | \`\`\` 23 | `, 24 | undefined, 25 | ], 26 | [ 27 | ` 28 | \`\`\`plaintext 29 | Abc. Def. 30 | \`\`\` 31 | 32 | Abc. 33 | Def. 34 | `, 35 | undefined, 36 | ], 37 | [ 38 | ` 39 | \`\`\`plaintext 40 | Abc. Def. 41 | \`\`\` 42 | 43 | Abc. Def. 44 | `, 45 | 33, 46 | ], 47 | ] as const)("%s", (input, expected) => { 48 | const actual = getIndexBeforeSecondSentence(input); 49 | 50 | expect(actual).toBe(expected); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | 'Software'), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/src/rules/one.test.ts: -------------------------------------------------------------------------------- 1 | import { one } from "./one.ts"; 2 | import { ruleTester } from "./ruleTester.ts"; 3 | 4 | ruleTester.run("one", one, { 5 | invalid: [ 6 | { 7 | code: "Abc. Def.", 8 | errors: [ 9 | { 10 | column: 5, 11 | endColumn: 6, 12 | endLine: 1, 13 | line: 1, 14 | messageId: "multiple", 15 | }, 16 | ], 17 | output: "Abc. \nDef.", 18 | }, 19 | { 20 | code: ` 21 | \`\`\`plaintext 22 | Abc. Def. 23 | \`\`\` 24 | 25 | Abc. Def. 26 | `, 27 | errors: [ 28 | { 29 | column: 5, 30 | endColumn: 6, 31 | endLine: 6, 32 | line: 6, 33 | messageId: "multiple", 34 | }, 35 | ], 36 | output: ` 37 | \`\`\`plaintext 38 | Abc. Def. 39 | \`\`\` 40 | 41 | Abc. 42 | Def. 43 | `, 44 | }, 45 | ], 46 | valid: [ 47 | "", 48 | "abc", 49 | "abc.", 50 | "`Abc. Def.`", 51 | "`Abc.` Def.", 52 | "`Abc.` `Def.`", 53 | "``Abc.`` Def.", 54 | "```js```.", 55 | ` 56 | \`\`\`plaintext 57 | Abc. Def. 58 | \`\`\` 59 | `, 60 | ` 61 | \`\`\`plaintext 62 | Abc. Def. 63 | \`\`\` 64 | 65 | Abc. 66 | Def. 67 | `, 68 | ], 69 | }); 70 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/04-tooling.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have tried restarting my IDE and the issue persists. 7 | required: true 8 | - label: I have pulled the latest `main` branch of the repository. 9 | required: true 10 | - label: I have [searched for related issues](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aissue) and found none that matched my issue. 11 | required: true 12 | type: checkboxes 13 | - attributes: 14 | description: What did you expect to be able to do? 15 | label: Overview 16 | type: textarea 17 | validations: 18 | required: true 19 | - attributes: 20 | description: Any additional info you'd like to provide. 21 | label: Additional Info 22 | type: textarea 23 | description: Report a bug or request an enhancement in repository tooling 24 | labels: 25 | - "area: tooling" 26 | name: 🛠 Tooling 27 | title: "🛠 Tooling: " 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/03-feature.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have tried restarting my IDE and the issue persists. 7 | required: true 8 | - label: I have pulled the latest `main` branch of the repository. 9 | required: true 10 | - label: I have [searched for related issues](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aissue) and found none that matched my issue. 11 | required: true 12 | type: checkboxes 13 | - attributes: 14 | description: What did you expect to be able to do? 15 | label: Overview 16 | type: textarea 17 | validations: 18 | required: true 19 | - attributes: 20 | description: Any additional info you'd like to provide. 21 | label: Additional Info 22 | type: textarea 23 | description: Request that a new feature be added or an existing feature improved 24 | labels: 25 | - "type: feature" 26 | name: 🚀 Feature 27 | title: "🚀 Feature: " 28 | -------------------------------------------------------------------------------- /packages/sentences-per-line/src/doesEndWithIgnoredWord.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | 3 | import { 4 | doesEndWithIgnoredWord, 5 | ignoredWords, 6 | } from "./doesEndWithIgnoredWord.ts"; 7 | 8 | describe(doesEndWithIgnoredWord, () => { 9 | it.each(ignoredWords)( 10 | "should return true for standard ignored words alone (%s)", 11 | (word) => { 12 | expect(doesEndWithIgnoredWord(word)).toBe(true); 13 | }, 14 | ); 15 | 16 | it.each(ignoredWords)( 17 | "should return true for standard ignored words at the end of a line (%s)", 18 | (word) => { 19 | const input = `This is an example ${word}`; 20 | expect(doesEndWithIgnoredWord(input)).toBe(true); 21 | }, 22 | ); 23 | 24 | it.each(ignoredWords)( 25 | "should return false for standard ignored words at the start of a line (%s)", 26 | (word) => { 27 | const input = `${word} This is an example`; 28 | expect(doesEndWithIgnoredWord(input)).toBe(false); 29 | }, 30 | ); 31 | 32 | it("should return true for custom ignored words", () => { 33 | const customWords = ["custom.", "test."]; 34 | expect(doesEndWithIgnoredWord("This is a custom.", customWords)).toBe(true); 35 | expect(doesEndWithIgnoredWord("This is a test.", customWords)).toBe(true); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/01-bug.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have tried restarting my IDE and the issue persists. 7 | required: true 8 | - label: I have pulled the latest `main` branch of the repository. 9 | required: true 10 | - label: I have [searched for related issues](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aissue) and found none that matched my issue. 11 | required: true 12 | type: checkboxes 13 | - attributes: 14 | description: What did you expect to happen? 15 | label: Expected 16 | type: textarea 17 | validations: 18 | required: true 19 | - attributes: 20 | description: What happened instead? 21 | label: Actual 22 | type: textarea 23 | validations: 24 | required: true 25 | - attributes: 26 | description: Any additional info you'd like to provide. 27 | label: Additional Info 28 | type: textarea 29 | description: Report a bug trying to run the code 30 | labels: 31 | - "type: bug" 32 | name: 🐛 Bug 33 | title: "🐛 Bug: " 34 | -------------------------------------------------------------------------------- /packages/markdownlint-sentences-per-line/src/markdownlintSentencesPerLine.ts: -------------------------------------------------------------------------------- 1 | import type * as markdownlint from "markdownlint"; 2 | 3 | import helpers from "markdownlint-rule-helpers"; 4 | import { getIndexBeforeSecondSentence } from "sentences-per-line"; 5 | 6 | const visitLine = ( 7 | line: string, 8 | lineNumber: number, 9 | onError: markdownlint.RuleOnError, 10 | ) => { 11 | const start = getIndexBeforeSecondSentence(line); 12 | if (start) { 13 | helpers.addError( 14 | onError, 15 | lineNumber, 16 | undefined, 17 | line.slice(Math.max(0, start - 8), 14), 18 | undefined, 19 | { 20 | deleteCount: 1, 21 | editColumn: start + 1, 22 | insertText: "\n", 23 | lineNumber, 24 | }, 25 | ); 26 | } 27 | }; 28 | 29 | export const markdownlintSentencesPerLine = { 30 | description: "Each sentence should be on its own line", 31 | function: ( 32 | params: markdownlint.RuleParams, 33 | onError: markdownlint.RuleOnError, 34 | ) => { 35 | let inFenceLine = false; 36 | 37 | for (let i = 0; i < params.lines.length; i += 1) { 38 | const line = params.lines[i]; 39 | 40 | if (line.startsWith("```")) { 41 | inFenceLine = !inFenceLine; 42 | continue; 43 | } 44 | 45 | if (inFenceLine) { 46 | continue; 47 | } 48 | 49 | visitLine(line, i + 1, onError); 50 | } 51 | }, 52 | names: ["markdownlint-sentences-per-line"], 53 | parser: "none", 54 | tags: ["sentences"], 55 | } satisfies markdownlint.Rule; 56 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { RootContent } from "mdast"; 2 | import type { AstPath, Printer, StringArraySupportOption } from "prettier"; 3 | 4 | import * as markdown from "prettier/plugins/markdown"; 5 | 6 | import { modifyNodeIfMultipleSentencesInLine } from "./modifications/modifyNodeIfMultipleSentencesInLine.ts"; 7 | 8 | export const options = { 9 | sentencesPerLineAdditionalAbbreviations: { 10 | array: true, 11 | category: "Global", 12 | default: [{ value: [] }], 13 | description: 14 | "An array of custom abbreviations to ignore when determining sentence boundaries.", 15 | type: "string", 16 | }, 17 | } satisfies Record; 18 | 19 | export const parsers = { 20 | ...markdown.parsers, 21 | }; 22 | 23 | // @ts-expect-error -- markdown does not provide public exports 24 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access 25 | const mdastPrinter: Printer = markdown.printers.mdast; 26 | 27 | export const printers = { 28 | mdast: { 29 | ...mdastPrinter, 30 | print(path: AstPath, printOptions, print, args) { 31 | modifyNodeIfMultipleSentencesInLine(path, { 32 | customAbbreviations: 33 | printOptions.sentencesPerLineAdditionalAbbreviations as string[], 34 | }); 35 | return mdastPrinter.print(path, printOptions, print, args); 36 | }, 37 | }, 38 | } satisfies Record>; 39 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/src/rules/one.ts: -------------------------------------------------------------------------------- 1 | import { MarkdownRuleDefinition } from "@eslint/markdown"; 2 | import { Paragraph, Text } from "mdast"; 3 | import { getIndexBeforeSecondSentence } from "sentences-per-line"; 4 | 5 | export const one: MarkdownRuleDefinition = { 6 | create(context) { 7 | function checkTextNode(node: Text) { 8 | const index = getIndexBeforeSecondSentence(node.value); 9 | if (!index) { 10 | return; 11 | } 12 | 13 | /* eslint-disable @typescript-eslint/no-non-null-assertion */ 14 | const start = node.position!.start; 15 | const insertion = start.offset! + index + 1; 16 | /* eslint-enable @typescript-eslint/no-non-null-assertion */ 17 | 18 | context.report({ 19 | fix(fixer) { 20 | return fixer.insertTextAfterRange([insertion, insertion], "\n"); 21 | }, 22 | loc: { 23 | end: { 24 | column: start.column + index + 1, 25 | line: start.line, 26 | }, 27 | start: { 28 | column: start.column + index, 29 | line: start.line, 30 | }, 31 | }, 32 | messageId: "multiple", 33 | }); 34 | } 35 | 36 | return { 37 | paragraph(node: Paragraph) { 38 | for (const child of node.children) { 39 | if (child.type === "text") { 40 | checkTextNode(child); 41 | } 42 | } 43 | }, 44 | }; 45 | }, 46 | meta: { 47 | docs: { 48 | description: "Limits Markdown sentences to one per line.", 49 | }, 50 | fixable: "code", 51 | messages: { 52 | multiple: "Each sentence should be on its own line.", 53 | }, 54 | schema: [], 55 | type: "problem", 56 | }, 57 | }; 58 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "badgeTemplate": "\"All 👪\" src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>_👪-21bb42.svg\" />", 3 | "commit": false, 4 | "commitConvention": "angular", 5 | "contributors": [ 6 | { 7 | "avatar_url": "https://avatars.githubusercontent.com/u/3335181?v=4", 8 | "contributions": [ 9 | "tool", 10 | "code", 11 | "bug", 12 | "ideas", 13 | "maintenance", 14 | "infra" 15 | ], 16 | "login": "JoshuaKGoldberg", 17 | "name": "Josh Goldberg", 18 | "profile": "http://www.joshuakgoldberg.com" 19 | }, 20 | { 21 | "login": "andrewrynhard", 22 | "name": "Andrew Rynhard", 23 | "avatar_url": "https://avatars.githubusercontent.com/u/3383143?v=4", 24 | "profile": "https://github.com/andrewrynhard", 25 | "contributions": [ 26 | "ideas" 27 | ] 28 | }, 29 | { 30 | "login": "michaelfaith", 31 | "name": "michael faith", 32 | "avatar_url": "https://avatars.githubusercontent.com/u/8071845?v=4", 33 | "profile": "https://github.com/michaelfaith", 34 | "contributions": [ 35 | "bug", 36 | "code", 37 | "infra" 38 | ] 39 | } 40 | ], 41 | "contributorsPerLine": 7, 42 | "contributorsSortAlphabetically": true, 43 | "files": [ 44 | "README.md" 45 | ], 46 | "imageSize": 100, 47 | "projectName": "sentences-per-line", 48 | "projectOwner": "JoshuaKGoldberg", 49 | "repoHost": "https://github.com", 50 | "repoType": "github", 51 | "commitType": "docs" 52 | } 53 | -------------------------------------------------------------------------------- /packages/sentences-per-line/README.md: -------------------------------------------------------------------------------- 1 |

sentences-per-line

2 | 3 |

Utility functions to enforce the number of sentences per line in Markdown files. 📐

4 | 5 |

6 | 🤝 Code of Conduct: Kept 7 | 📝 License: MIT 8 | 📦 npm version 9 | 💪 TypeScript: Strict 10 |

11 | 12 | ## Usage 13 | 14 | > Looking for the ESLint, Markdownlint, or Prettier plugins to enforce sentences-per-line? 15 | > See [../../README.md > ## Packages](../../README.md#packages). 16 | 17 | ```shell 18 | npm i sentences-per-line 19 | ``` 20 | 21 | ### `getIndexBeforeSecondSentence` 22 | 23 | Retrieves the first index after the period of the line's first sentence, if a second sentence follows it. 24 | This is the driving function behind enforcing one sentence per line in the sentences-per-line monorepo's packages. 25 | 26 | ```ts 27 | import { getIndexBeforeSecondSentence } from "sentences-per-line"; 28 | 29 | // undefined 30 | getIndexBeforeSecondSentence("The only sentence."); 31 | 32 | // 15 33 | getIndexBeforeSecondSentence("First sentence. Second sentence."); 34 | ``` 35 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/src/modifications/modifyNodeIfMultipleSentencesInLine.ts: -------------------------------------------------------------------------------- 1 | import type { Blockquote, Paragraph, RootContent, SentenceNode } from "mdast"; 2 | import type { AstPath } from "prettier"; 3 | 4 | import { doesEndWithIgnoredWord } from "sentences-per-line"; 5 | 6 | import { insertNewlineAt } from "./insertNewlineAt.ts"; 7 | 8 | export interface ModifyNodeOptions { 9 | customAbbreviations?: string[]; 10 | } 11 | 12 | export function modifyNodeIfMultipleSentencesInLine( 13 | path: AstPath, 14 | options: ModifyNodeOptions = {}, 15 | ) { 16 | const node = path.node; 17 | if (node.type === "blockquote") { 18 | modifyBlockquoteNode(node, options); 19 | } else if (node.type === "paragraph") { 20 | modifyParagraphNode(node, "\n", options); 21 | } 22 | } 23 | 24 | function modifyBlockquoteNode(node: Blockquote, options: ModifyNodeOptions) { 25 | for (const paragraph of node.children) { 26 | if (paragraph.type === "paragraph") { 27 | modifyParagraphNode(paragraph, "> ", options); 28 | } 29 | } 30 | } 31 | 32 | function modifyParagraphNode( 33 | node: Paragraph, 34 | insertion: string, 35 | options: ModifyNodeOptions, 36 | ) { 37 | for (const child of node.children) { 38 | if (child.type === "sentence") { 39 | modifySentenceNode(child, insertion, options); 40 | } 41 | } 42 | } 43 | 44 | function modifySentenceNode( 45 | sentence: SentenceNode, 46 | insertion: string, 47 | { customAbbreviations = [] }: ModifyNodeOptions, 48 | ) { 49 | for (let i = 0; i < sentence.children.length - 1; i++) { 50 | const child = sentence.children[i]; 51 | if ( 52 | child.type === "word" && 53 | child.value.endsWith(".") && 54 | // Skip any starting list number, e.g. "1. " or " 1. " 55 | !/^\s*\d+\./.test(child.value) && 56 | !doesEndWithIgnoredWord(child.value, customAbbreviations) 57 | ) { 58 | insertNewlineAt(sentence.children, i, insertion); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/sentences-per-line/src/getIndexBeforeSecondSentence.ts: -------------------------------------------------------------------------------- 1 | import { doesEndWithIgnoredWord } from "./doesEndWithIgnoredWord.ts"; 2 | 3 | /** 4 | * @returns The first index after the period of the line's first sentence, 5 | * if a second sentence follows it. 6 | */ 7 | export function getIndexBeforeSecondSentence(line: string) { 8 | let i: number | undefined = 0; 9 | 10 | // Ignore headings 11 | if (/^\s*#/.test(line)) { 12 | return undefined; 13 | } 14 | 15 | // Skip any starting list number, e.g. "1. " or " 1. " 16 | if (/^\s*\d+\./.test(line)) { 17 | i = line.indexOf(".") + 1; 18 | } 19 | 20 | for (; i < line.length - 2; i += 1) { 21 | i = getNextIndexNotInCode(line, i); 22 | if (i === undefined || i >= line.length - 2) { 23 | return undefined; 24 | } 25 | 26 | if ( 27 | line[i] === "." && 28 | line[i + 1] === " " && 29 | isCapitalizedAlphabetCharacter(line[i + 2]) && 30 | !doesEndWithIgnoredWord(line.substring(0, i + 1)) 31 | ) { 32 | return i + 1; 33 | } 34 | } 35 | } 36 | 37 | function getNextIndexNotInCode(line: string, i: number) { 38 | if (line[i] !== "`") { 39 | return i; 40 | } 41 | 42 | i += 1; 43 | 44 | // Get to the inside of this inline code segment 45 | while (line[i] === "`") { 46 | i += 1; 47 | 48 | if (i === line.length) { 49 | return undefined; 50 | } 51 | } 52 | 53 | // Get to the end of the inline code segment 54 | while (true) { 55 | i = line.indexOf("`", i); 56 | 57 | if (i === -1) { 58 | return undefined; 59 | } 60 | 61 | if (line[i - 1] !== "\\") { 62 | break; 63 | } 64 | } 65 | 66 | while (line[i] === "`") { 67 | i += 1; 68 | 69 | if (i === line.length) { 70 | return undefined; 71 | } 72 | } 73 | 74 | return i; 75 | } 76 | 77 | function isCapitalizedAlphabetCharacter(char: string) { 78 | const charCode = char.charCodeAt(0); 79 | 80 | return charCode >= "A".charCodeAt(0) && charCode <= "Z".charCodeAt(0); 81 | } 82 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sentences-per-line", 3 | "version": "0.0.0", 4 | "description": "Packages to enforce the number of sentences per line in Markdown files. 📐", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/JoshuaKGoldberg/sentences-per-line" 8 | }, 9 | "license": "MIT", 10 | "author": { 11 | "name": "Josh Goldberg ✨", 12 | "email": "npm@joshuakgoldberg.com" 13 | }, 14 | "type": "module", 15 | "scripts": { 16 | "build": "tsc -b tsconfig.build.json", 17 | "format": "prettier .", 18 | "lint": "eslint . --max-warnings 0", 19 | "lint:knip": "knip", 20 | "lint:packages": "pnpm dedupe --check", 21 | "lint:spelling": "cspell \"**\" \".github/**/*\"", 22 | "prepare": "husky", 23 | "test": "vitest" 24 | }, 25 | "lint-staged": { 26 | "*": "prettier --ignore-unknown --write" 27 | }, 28 | "devDependencies": { 29 | "@eslint-community/eslint-plugin-eslint-comments": "4.5.0", 30 | "@eslint/js": "9.39.2", 31 | "@eslint/markdown": "^7.5.1", 32 | "@types/node": "25.0.3", 33 | "@vitest/coverage-v8": "4.0.16", 34 | "@vitest/eslint-plugin": "1.5.4", 35 | "console-fail-test": "0.6.1", 36 | "cspell": "9.4.0", 37 | "eslint": "9.39.2", 38 | "eslint-plugin-jsdoc": "61.5.0", 39 | "eslint-plugin-jsonc": "2.21.0", 40 | "eslint-plugin-package-json": "0.85.0", 41 | "eslint-plugin-perfectionist": "5.0.0", 42 | "eslint-plugin-regexp": "2.10.0", 43 | "eslint-plugin-yml": "1.19.1", 44 | "husky": "9.1.7", 45 | "jsonc-eslint-parser": "2.4.2", 46 | "knip": "5.76.0", 47 | "lint-staged": "16.2.7", 48 | "prettier": "^3.7.3", 49 | "prettier-plugin-curly": "0.4.1", 50 | "prettier-plugin-packagejson": "2.5.20", 51 | "prettier-plugin-sh": "0.18.0", 52 | "typescript": "5.9.3", 53 | "typescript-eslint": "8.50.0", 54 | "vitest": "4.0.16" 55 | }, 56 | "packageManager": "pnpm@10.26.1", 57 | "engines": { 58 | "node": ">=18.3.0" 59 | }, 60 | "publishConfig": { 61 | "provenance": true 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/src/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as prettier from "prettier"; 2 | import { describe, expect, test } from "vitest"; 3 | 4 | import * as plugin from "./index.ts"; 5 | 6 | function format(code: string, options: prettier.Options) { 7 | return prettier.format(code, { 8 | ...options, 9 | parser: "markdown", 10 | plugins: [plugin], 11 | }); 12 | } 13 | 14 | describe("index", () => { 15 | test.each([ 16 | [""], 17 | [" ", ""], 18 | ["This is a sentence.", "This is a sentence.\n"], 19 | [ 20 | "This is a sentence `with. inline. code.`.", 21 | "This is a sentence `with. inline. code.`.\n", 22 | ], 23 | ["This is a sentence.\n"], 24 | ["1. List.\n"], 25 | ["## 1. List.\n"], 26 | ["First sentence. Second sentence.", "First sentence.\nSecond sentence.\n"], 27 | [ 28 | "First sentence.\tSecond sentence.", 29 | "First sentence.\nSecond sentence.\n", 30 | ], 31 | [ 32 | "First sentence. \t\t Second sentence.", 33 | "First sentence.\nSecond sentence.\n", 34 | ], 35 | [ 36 | "First sentence. Second sentence. Third sentence.", 37 | "First sentence.\nSecond sentence.\nThird sentence.\n", 38 | ], 39 | ["> First sentence.\n"], 40 | ["> First sentence.\n> Second sentence.\n"], 41 | ["This vs. that.\n"], 42 | ["e.g. first example.\n"], 43 | ["E.g. first example.\n"], 44 | ["ex. one.\n"], 45 | ["Ex. one.\n"], 46 | ["i.e. first example.\n"], 47 | ["I.E. first example.\n"], 48 | ])("%j", async (input, expected = input) => { 49 | const actual = await format(input, { filepath: "test.md" }); 50 | expect(actual).toBe(expected); 51 | }); 52 | 53 | test("with sentencesPerLineAdditionalAbbreviations", async () => { 54 | const input = "i.e. I.M. Pei."; 55 | const expected = "i.e. I.M. Pei.\n"; 56 | 57 | const actual = await format(input, { 58 | filepath: "test.md", 59 | sentencesPerLineAdditionalAbbreviations: ["I.M."], 60 | }); 61 | expect(actual).toBe(expected); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /packages/markdownlint-sentences-per-line/README.md: -------------------------------------------------------------------------------- 1 |

markdownlint-sentences-per-line

2 | 3 |

4 | 🤝 Code of Conduct: Kept 5 | 📝 License: MIT 6 | 📦 npm version 7 | 💪 TypeScript: Strict 8 |

9 | 10 |

Markdownlint rule for limiting sentences per line. 📐

11 | 12 | ```diff 13 | - First sentence. Second sentence. 14 | + First sentence. 15 | + Second sentence. 16 | ``` 17 | 18 | markdownlint-sentences-per-line allows you to enforce that no line in your Markdown files contains more than one sentence. 19 | This is useful because: 20 | 21 | - Shorter lines result in simpler, easier-to-understand Git diffs 22 | - Longer lines are harder to read in source code 23 | 24 | ```diff 25 | - First sentence. Second sentence. 26 | + First sentence. 27 | + Second sentence. 28 | ``` 29 | 30 | ## Usage 31 | 32 | First install this package as a devDependency: 33 | 34 | ```shell 35 | npm i -D markdownlint-sentences-per-line 36 | ``` 37 | 38 | Then provide it to [markdownlint-cli's `--rules`](https://github.com/igorshubovych/markdownlint-cli#usage): 39 | 40 | ```shell 41 | markdownlint --rules markdownlint-sentences-per-line 42 | ``` 43 | 44 | ## Alternatives 45 | 46 | This package is part of the [sentences-per-line](https://github.com/JoshuaKGoldberg/sentences-per-line) family of packages. 47 | You might also consider: 48 | 49 | - [`eslint-plugin-sentences-per-line`](../eslint-plugin-sentences-per-line): [ESLint](https://eslint.org/) plugin to enforce sentences per line in Markdown files. 50 | - [`prettier-plugin-sentences-per-line`](../prettier-plugin-sentences-per-line): [Prettier](https://prettier.io) plugin to enforce sentences per line in Markdown files. 51 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | build: 3 | name: Build 4 | runs-on: ubuntu-latest 5 | steps: 6 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 7 | - uses: ./.github/actions/prepare 8 | - run: pnpm build 9 | lint: 10 | name: Lint 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 14 | - uses: ./.github/actions/prepare 15 | - run: pnpm build 16 | - run: pnpm lint 17 | lint_docs: 18 | name: Lint Docs 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 22 | - uses: ./.github/actions/prepare 23 | - run: pnpm build 24 | - run: pnpm run -r lint:docs 25 | lint_knip: 26 | name: Lint Knip 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 30 | - uses: ./.github/actions/prepare 31 | - run: pnpm lint:knip 32 | lint_packages: 33 | name: Lint Packages 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 37 | - uses: ./.github/actions/prepare 38 | - run: pnpm lint:packages 39 | lint_spelling: 40 | name: Lint Spelling 41 | runs-on: ubuntu-latest 42 | steps: 43 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 44 | - uses: ./.github/actions/prepare 45 | - run: pnpm lint:spelling 46 | prettier: 47 | name: Prettier 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 51 | - uses: ./.github/actions/prepare 52 | - run: pnpm build 53 | - run: pnpm format --list-different 54 | test: 55 | name: Test 56 | runs-on: ubuntu-latest 57 | steps: 58 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 59 | - uses: ./.github/actions/prepare 60 | - run: pnpm run build 61 | - run: pnpm run test --coverage 62 | - env: 63 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 64 | if: always() 65 | uses: codecov/codecov-action@v3 66 | type_check: 67 | name: Type Check 68 | runs-on: ubuntu-latest 69 | steps: 70 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6 71 | - uses: ./.github/actions/prepare 72 | - run: pnpm tsc 73 | 74 | name: CI 75 | 76 | on: 77 | pull_request: ~ 78 | push: 79 | branches: 80 | - main 81 | -------------------------------------------------------------------------------- /packages/markdownlint-sentences-per-line/src/markdownlintSentencesPerLine.test.ts: -------------------------------------------------------------------------------- 1 | import * as markdownlint from "markdownlint/sync"; 2 | import { describe, expect, test } from "vitest"; 3 | 4 | import { markdownlintSentencesPerLine } from "./markdownlintSentencesPerLine.ts"; 5 | 6 | describe("markdownlint-sentences-per-line", () => { 7 | test.each([ 8 | ["", undefined], 9 | ["abc", undefined], 10 | ["abc.", undefined], 11 | [ 12 | "Abc. Def.", 13 | "Abc. Def.", 14 | { 15 | fixInfo: { 16 | deleteCount: 1, 17 | editColumn: 5, 18 | insertText: "\n", 19 | lineNumber: 1, 20 | }, 21 | lineNumber: 1, 22 | }, 23 | ], 24 | [ 25 | "Abc def. Ghi jkl.", 26 | "Abc def. Ghi j", 27 | { 28 | fixInfo: { 29 | deleteCount: 1, 30 | editColumn: 9, 31 | insertText: "\n", 32 | lineNumber: 1, 33 | }, 34 | lineNumber: 1, 35 | }, 36 | ], 37 | ["`Abc. Def.`", undefined], 38 | ["`Abc.` Def.", undefined], 39 | ["`Abc.` `Def.`", undefined], 40 | ["``Abc.`` Def.", undefined], 41 | [ 42 | "`Abc.` Def. Ghi", 43 | "c.` Def. Gh", 44 | { 45 | fixInfo: { 46 | deleteCount: 1, 47 | editColumn: 12, 48 | insertText: "\n", 49 | lineNumber: 1, 50 | }, 51 | lineNumber: 1, 52 | }, 53 | ], 54 | ["```js```.", undefined], 55 | [ 56 | ` 57 | \`\`\`plaintext 58 | Abc. Def. 59 | \`\`\` 60 | `, 61 | undefined, 62 | ], 63 | [ 64 | ` 65 | \`\`\`plaintext 66 | Abc. Def. 67 | \`\`\` 68 | 69 | Abc. 70 | Def. 71 | `, 72 | undefined, 73 | ], 74 | [ 75 | ` 76 | \`\`\`plaintext 77 | Abc. Def. 78 | \`\`\` 79 | 80 | Abc. Def. 81 | `, 82 | "Abc. Def.", 83 | { 84 | fixInfo: { 85 | deleteCount: 1, 86 | editColumn: 5, 87 | insertText: "\n", 88 | lineNumber: 6, 89 | }, 90 | lineNumber: 6, 91 | }, 92 | ], 93 | ] as const)("%s", (input, errorContext, report?) => { 94 | const actual = markdownlint.lint({ 95 | config: { 96 | default: false, 97 | "markdownlint-sentences-per-line": true, 98 | }, 99 | customRules: [markdownlintSentencesPerLine], 100 | strings: { input }, 101 | }); 102 | 103 | expect(actual).toEqual({ 104 | input: errorContext 105 | ? [ 106 | { 107 | errorContext, 108 | errorDetail: null, 109 | errorRange: null, 110 | ruleDescription: "Each sentence should be on its own line", 111 | ruleInformation: null, 112 | ruleNames: ["markdownlint-sentences-per-line"], 113 | severity: "error", 114 | ...report, 115 | }, 116 | ] 117 | : [], 118 | }); 119 | }); 120 | }); 121 | -------------------------------------------------------------------------------- /packages/prettier-plugin-sentences-per-line/README.md: -------------------------------------------------------------------------------- 1 |

prettier-plugin-sentences-per-line

2 | 3 |

4 | 🤝 Code of Conduct: Kept 5 | 📝 License: MIT 6 | 📦 npm version 7 | 💪 TypeScript: Strict 8 |

9 | 10 |

Prettier plugin for limiting sentences per line. 📐

11 | 12 | prettier-plugin-sentences-per-line allows you to enforce that no line in your Markdown files contains more than one sentence. 13 | 14 | This is useful because: 15 | 16 | - Shorter lines result in simpler, easier-to-understand Git diffs 17 | - Longer lines are harder to read in source code 18 | 19 | ```diff 20 | - First sentence. Second sentence. 21 | + First sentence. 22 | + Second sentence. 23 | ``` 24 | 25 | ## Usage 26 | 27 | First install this package as a devDependency: 28 | 29 | ```shell 30 | npm i -D prettier-plugin-sentences-per-line 31 | ``` 32 | 33 | Then add it to your [Prettier config's `plugins`](https://prettier.io/docs/plugins): 34 | 35 | ```json 36 | { 37 | "plugins": ["prettier-plugin-sentences-per-line"] 38 | } 39 | ``` 40 | 41 | ### Options 42 | 43 | #### `sentencesPerLineAdditionalAbbreviations` 44 | 45 | An array of custom abbreviations to ignore when determining sentence boundaries. 46 | 47 | These will be added to the standard list of abbreviations below. 48 | 49 | `["eg.", "e.g.", "etc.", "ex.", "ie.", "i.e.", "vs."]` 50 | 51 | ```json 52 | { 53 | "plugins": ["prettier-plugin-sentences-per-line"], 54 | "sentencesPerLineAdditionalAbbreviations": ["I.M."] 55 | } 56 | ``` 57 | 58 | ## Alternatives 59 | 60 | This package is part of the [sentences-per-line](https://github.com/JoshuaKGoldberg/sentences-per-line) family of packages. 61 | 62 | You might also consider: 63 | 64 | - [`eslint-plugin-sentences-per-line`](../eslint-plugin-sentences-per-line): [ESLint](https://eslint.org/) plugin to enforce sentences per line in Markdown files. 65 | - [`markdownlint-sentences-per-line`](../markdownlint-sentences-per-line): [Markdownlint](https://github.com/DavidAnson/markdownlint) plugin to enforce sentences per line in Markdown files. 66 | -------------------------------------------------------------------------------- /packages/eslint-plugin-sentences-per-line/README.md: -------------------------------------------------------------------------------- 1 |

eslint-plugin-sentences-per-line

2 | 3 |

4 | 🤝 Code of Conduct: Kept 5 | 📝 License: MIT 6 | 📦 npm version 7 | 💪 TypeScript: Strict 8 |

9 | 10 |

ESLint plugin for limiting sentences per line. 📐

11 | 12 | eslint-plugin-sentences-per-line allows you to enforce that no line in your Markdown files contains more than one sentence. 13 | This is useful because: 14 | 15 | - Shorter lines result in simpler, easier-to-understand Git diffs 16 | - Longer lines are harder to read in source code 17 | 18 | ```diff 19 | - First sentence. Second sentence. 20 | + First sentence. 21 | + Second sentence. 22 | ``` 23 | 24 | ## Usage 25 | 26 | > 👉 This ESLint plugin assumes you're using [`@eslint/markdown`](https://www.npmjs.com/package/@eslint/markdown). 27 | 28 | First install this package as a devDependency: 29 | 30 | ```shell 31 | npm i -D eslint-plugin-sentences-per-line 32 | ``` 33 | 34 | Then add the following options to your [ESLint configuration file](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new): 35 | 36 | ```ts 37 | import markdown from "@eslint/markdown"; 38 | import sentencesPerLine from "eslint-plugin-sentences-per-line"; 39 | 40 | export default [ 41 | // your other ESLint configurations 42 | { 43 | extends: [ 44 | markdown.configs.recommended, 45 | // 👇 Apply this config to your *.md files 46 | sentencesPerLine.configs.recommended, 47 | ], 48 | files: ["**/*.md"], 49 | }, 50 | ]; 51 | ``` 52 | 53 | ## Rules 54 | 55 | 56 | 57 | 58 | 💼 Configurations enabled in.\ 59 | ✅ Set in the `recommended` configuration.\ 60 | 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix). 61 | 62 | | Name | Description | 💼 | 🔧 | 63 | | :----------------------- | :----------------------------------------- | :- | :- | 64 | | [one](docs/rules/one.md) | Limits Markdown sentences to one per line. | ✅ | 🔧 | 65 | 66 | 67 | 68 | 69 | ## Alternatives 70 | 71 | This package is part of the [sentences-per-line](https://github.com/JoshuaKGoldberg/sentences-per-line) family of packages. 72 | You might also consider: 73 | 74 | - [`markdownlint-sentences-per-line`](../markdownlint-sentences-per-line): [Markdownlint](https://github.com/DavidAnson/markdownlint) rule to enforce sentences per line in Markdown files. 75 | - [`prettier-plugin-sentences-per-line`](../prettier-plugin-sentences-per-line): [Prettier](https://prettier.io) plugin to enforce sentences per line in Markdown files. 76 | -------------------------------------------------------------------------------- /.github/DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation): 4 | 5 | ```shell 6 | git clone https://github.com/ < your-name-here > /sentences-per-line 7 | cd sentences-per-line 8 | pnpm install 9 | ``` 10 | 11 | > This repository includes a list of suggested VS Code extensions. 12 | > It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development. 13 | 14 | ## Building 15 | 16 | Run [**tsup**](https://tsup.egoist.dev) locally to build source files from `src/` into output files in `lib/`: 17 | 18 | ```shell 19 | pnpm build 20 | ``` 21 | 22 | Add `--watch` to run the builder in a watch mode that continuously cleans and recreates `lib/` as you save files: 23 | 24 | ```shell 25 | pnpm build --watch 26 | ``` 27 | 28 | ## Formatting 29 | 30 | [Prettier](https://prettier.io) is used to format code. 31 | It should be applied automatically when you save files in VS Code or make a Git commit. 32 | 33 | To manually reformat all files, you can run: 34 | 35 | ```shell 36 | pnpm format --write 37 | ``` 38 | 39 | ## Linting 40 | 41 | This package includes several forms of linting to enforce consistent code quality and styling. 42 | Each should be shown in VS Code, and can be run manually on the command-line: 43 | 44 | - `pnpm lint` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files 45 | - `pnpm lint:knip` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports 46 | - `pnpm lint:packages` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the `pnpm-lock.yml` file 47 | - `pnpm lint:spelling` ([cspell](https://cspell.org)): Spell checks across all source files 48 | 49 | Read the individual documentation for each linter to understand how it can be configured and used best. 50 | 51 | For example, ESLint can be run with `--fix` to auto-fix some lint rule complaints: 52 | 53 | ```shell 54 | pnpm run lint --fix 55 | ``` 56 | 57 | Note that you'll likely need to run `pnpm build` before `pnpm lint` so that lint rules which check the file system can pick up on any built files. 58 | 59 | ## Testing 60 | 61 | [Vitest](https://vitest.dev) is used for tests. 62 | You can run it locally on the command-line: 63 | 64 | ```shell 65 | pnpm run test 66 | ``` 67 | 68 | Add the `--coverage` flag to compute test coverage and place reports in the `coverage/` directory: 69 | 70 | ```shell 71 | pnpm run test --coverage 72 | ``` 73 | 74 | Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. 75 | Calls to `console.log`, `console.warn`, and other console methods will cause a test to fail. 76 | 77 | ### Debugging Tests 78 | 79 | This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests. 80 | To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5). 81 | 82 | ## Type Checking 83 | 84 | You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files. 85 | 86 | However, it can be useful to run the TypeScript command-line (`tsc`) to type check all files in `src/`: 87 | 88 | ```shell 89 | pnpm tsc 90 | ``` 91 | 92 | Add `--watch` to keep the type checker running in a watch mode that updates the display as you save files: 93 | 94 | ```shell 95 | pnpm tsc --watch 96 | ``` 97 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import comments from "@eslint-community/eslint-plugin-eslint-comments/configs"; 2 | import js from "@eslint/js"; 3 | import markdown from "@eslint/markdown"; 4 | import vitest from "@vitest/eslint-plugin"; 5 | import jsdoc from "eslint-plugin-jsdoc"; 6 | import jsonc from "eslint-plugin-jsonc"; 7 | import packageJson from "eslint-plugin-package-json"; 8 | import perfectionist from "eslint-plugin-perfectionist"; 9 | import * as regexp from "eslint-plugin-regexp"; 10 | import yml from "eslint-plugin-yml"; 11 | import { defineConfig } from "eslint/config"; 12 | import tseslint from "typescript-eslint"; 13 | 14 | export default defineConfig( 15 | { 16 | ignores: [ 17 | "**/*.snap", 18 | "coverage", 19 | "lib", 20 | "node_modules", 21 | "packages/*/lib", 22 | "packages/*/tsconfig.tsbuildinfo", 23 | "packages/*/src/**/*.d.ts", 24 | "packages/*/src/**/*.js", 25 | "pnpm-lock.yaml", 26 | "pnpm-workspace.yaml", 27 | ], 28 | }, 29 | { linterOptions: { reportUnusedDisableDirectives: "error" } }, 30 | { 31 | extends: [ 32 | js.configs.recommended, 33 | // https://github.com/eslint-community/eslint-plugin-eslint-comments/issues/214 34 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access 35 | comments.recommended, 36 | jsdoc.configs["flat/contents-typescript-error"], 37 | jsdoc.configs["flat/logical-typescript-error"], 38 | jsdoc.configs["flat/stylistic-typescript-error"], 39 | ...tseslint.configs.strict, 40 | ...tseslint.configs.stylistic, 41 | perfectionist.configs["recommended-natural"], 42 | regexp.configs["flat/recommended"], 43 | ], 44 | files: ["**/*.js", "**/*.ts"], 45 | rules: { 46 | // These off-by-default rules work well for this repo and we like them on. 47 | "jsdoc/informative-docs": "error", 48 | 49 | // Stylistic concerns that don't interfere with Prettier 50 | "logical-assignment-operators": [ 51 | "error", 52 | "always", 53 | { enforceForIfStatements: true }, 54 | ], 55 | "no-useless-rename": "error", 56 | "object-shorthand": "error", 57 | "operator-assignment": "error", 58 | }, 59 | settings: { perfectionist: { partitionByComment: true, type: "natural" } }, 60 | }, 61 | { 62 | extends: [ 63 | ...tseslint.configs.strictTypeChecked, 64 | ...tseslint.configs.stylisticTypeChecked, 65 | ], 66 | files: ["**/*.js", "**/*.ts"], 67 | ignores: ["**/*.md/*", "packages/*/bin/*.js", "packages/*/*.config.*"], 68 | languageOptions: { 69 | parserOptions: { 70 | projectService: true, 71 | }, 72 | }, 73 | rules: { 74 | // These on-by-default rules work well for this repo if configured 75 | "@typescript-eslint/no-unnecessary-condition": [ 76 | "error", 77 | { 78 | allowConstantLoopConditions: "only-allowed-literals", 79 | }, 80 | ], 81 | }, 82 | }, 83 | { 84 | extends: jsonc.configs["flat/recommended-with-json"], 85 | files: ["**/*.json"], 86 | }, 87 | { 88 | extends: [packageJson.configs.recommended], 89 | files: ["**/package.json"], 90 | }, 91 | { 92 | extends: [markdown.configs.recommended], 93 | files: ["**/*.md"], 94 | language: "markdown/gfm", 95 | }, 96 | { 97 | extends: [vitest.configs.recommended], 98 | files: ["**/*.test.*"], 99 | settings: { vitest: { typecheck: true } }, 100 | }, 101 | { 102 | extends: [yml.configs["flat/recommended"], yml.configs["flat/prettier"]], 103 | files: ["**/*.{yml,yaml}"], 104 | rules: { 105 | "yml/file-extension": ["error", { extension: "yml" }], 106 | "yml/sort-keys": [ 107 | "error", 108 | { 109 | order: { type: "asc" }, 110 | pathPattern: "^.*$", 111 | }, 112 | ], 113 | "yml/sort-sequence-values": [ 114 | "error", 115 | { 116 | order: { type: "asc" }, 117 | pathPattern: "^.*$", 118 | }, 119 | ], 120 | }, 121 | }, 122 | ); 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

sentences-per-line

2 | 3 |

Packages to enforce the number of sentences per line in Markdown files. 📐

4 | 5 |

6 | 7 | 8 | All Contributors: 3 👪 9 | 10 | 11 | 🤝 Code of Conduct: Kept 12 | 📝 License: MIT 13 | 💪 TypeScript: Strict 14 |

15 | 16 | sentences-per-line's packages allow you to enforce that no line in your Markdown files contains more than one sentence. 17 | This is useful because: 18 | 19 | - Shorter lines result in simpler, easier-to-understand Git diffs 20 | - Longer lines are harder to read in source code 21 | 22 | ```diff 23 | - First sentence. Second sentence. 24 | + First sentence. 25 | + Second sentence. 26 | ``` 27 | 28 | ## Packages 29 | 30 | This monorepo provides: 31 | 32 | - [`eslint-plugin-sentences-per-line`](./packages/eslint-plugin-sentences-per-line): [ESLint](https://eslint.org/) plugin to enforce sentences per line in Markdown files. 33 | - [`markdownlint-sentences-per-line`](./packages/markdownlint-sentences-per-line): [Markdownlint](https://github.com/DavidAnson/markdownlint) rule to enforce sentences per line in Markdown files. 34 | - [`prettier-plugin-sentences-per-line`](./packages/prettier-plugin-sentences-per-line): [Prettier](https://prettier.io) plugin to enforce sentences per line in Markdown files. 35 | - [`sentences-per-line`](./packages/sentences-per-line): Utility functions to detect the number of sentences per line in Markdown files. 36 | 37 | ## Development 38 | 39 | See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md). 40 | Thanks! 💖 41 | 42 | ## Contributors 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
Andrew Rynhard
Andrew Rynhard

🤔
Josh Goldberg
Josh Goldberg

🔧 💻 🐛 🤔 🚧 🚇
michael faith
michael faith

🐛 💻 🚇
57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | > 💙 This package was templated with [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app). 65 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to a positive environment for our community include: 12 | 13 | - Demonstrating empathy and kindness toward other people 14 | - Being respectful of differing opinions, viewpoints, and experiences 15 | - Giving and gracefully accepting constructive feedback 16 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 | - Focusing on what is best not just for us as individuals, but for the overall community 18 | 19 | Examples of unacceptable behavior include: 20 | 21 | - The use of sexualized language or imagery, and sexual attention or advances of any kind 22 | - Trolling, insulting or derogatory comments, and personal or political attacks 23 | - Public or private harassment 24 | - Publishing others' private information, such as a physical or email address, without their explicit permission 25 | - Other conduct which could reasonably be considered inappropriate in a professional setting 26 | 27 | ## Enforcement Responsibilities 28 | 29 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 32 | 33 | ## Scope 34 | 35 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. 36 | Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 37 | 38 | ## Enforcement 39 | 40 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at github@joshuakgoldberg.com. 41 | All complaints will be reviewed and investigated promptly and fairly. 42 | 43 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 44 | 45 | ## Enforcement Guidelines 46 | 47 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 48 | 49 | ### 1. Correction 50 | 51 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 52 | 53 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. 54 | A public apology may be requested. 55 | 56 | ### 2. Warning 57 | 58 | **Community Impact**: A violation through a single incident or series of actions. 59 | 60 | **Consequence**: A warning with consequences for continued behavior. 61 | No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. 62 | This includes avoiding interactions in community spaces as well as external channels like social media. 63 | Violating these terms may lead to a temporary or permanent ban. 64 | 65 | ### 3. Temporary Ban 66 | 67 | **Community Impact**: A serious violation of community standards, including 68 | sustained inappropriate behavior. 69 | 70 | **Consequence**: A temporary ban from any sort of interaction or public 71 | communication with the community for a specified period of time. 72 | No public or 73 | private interaction with the people involved, including unsolicited interaction 74 | with those enforcing the Code of Conduct, is allowed during this period. 75 | Violating these terms may lead to a permanent ban. 76 | 77 | ### 4. Permanent Ban 78 | 79 | **Community Impact**: Demonstrating a pattern of violation of community 80 | standards, including sustained inappropriate behavior, harassment of an 81 | individual, or aggression toward or disparagement of classes of individuals. 82 | 83 | **Consequence**: A permanent ban from any sort of public interaction within the 84 | community. 85 | 86 | ## Attribution 87 | 88 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 89 | version 2.1, available at 90 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 91 | 92 | Community Impact Guidelines were inspired by 93 | [Mozilla's code of conduct enforcement ladder][mozilla coc]. 94 | 95 | For answers to common questions about this code of conduct, see the FAQ at 96 | [https://www.contributor-covenant.org/faq][faq]. 97 | Translations are available at 98 | [https://www.contributor-covenant.org/translations][translations]. 99 | 100 | [homepage]: https://www.contributor-covenant.org 101 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 102 | [mozilla coc]: https://github.com/mozilla/diversity 103 | [faq]: https://www.contributor-covenant.org/faq 104 | [translations]: https://www.contributor-covenant.org/translations 105 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for your interest in contributing to `sentences-per-line`! 💖 4 | 5 | > After this page, see [DEVELOPMENT.md](./DEVELOPMENT.md) for local development instructions. 6 | 7 | ## Code of Conduct 8 | 9 | This project contains a [Contributor Covenant code of conduct](./CODE_OF_CONDUCT.md) all contributors are expected to follow. 10 | 11 | ## Reporting Issues 12 | 13 | Please do [report an issue on the issue tracker](https://github.com/JoshuaKGoldberg/sentences-per-line/issues/new/choose) if there's any bugfix, documentation improvement, or general enhancement you'd like to see in the repository! Please fully fill out all required fields in the most appropriate issue form. 14 | 15 | ## Sending Contributions 16 | 17 | Sending your own changes as contribution is always appreciated! 18 | There are two steps involved: 19 | 20 | 1. [Finding an Issue](#finding-an-issue) 21 | 2. [Sending a Pull Request](#sending-a-pull-request) 22 | 23 | ### Finding an Issue 24 | 25 | With the exception of very small typos, all changes to this repository generally need to correspond to an [unassigned open issue marked as `status: accepting prs` on the issue tracker](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aissue+is%3Aopen+label%3A%22status%3A+accepting+prs%22+no%3Aassignee+). 26 | If this is your first time contributing, consider searching for [unassigned issues that also have the `good first issue` label](https://github.com/JoshuaKGoldberg/sentences-per-line/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3A%22status%3A+accepting+prs%22+no%3Aassignee+). 27 | If the issue you'd like to fix isn't found on the issue, see [Reporting Issues](#reporting-issues) for filing your own (please do!). 28 | 29 | #### Issue Claiming 30 | 31 | We don't use any kind of issue claiming system. 32 | We've found in the past that they result in accidental ["licked cookie"](https://devblogs.microsoft.com/oldnewthing/20091201-00/?p=15843) situations where contributors claim an issue but run out of time or energy trying before sending a PR. 33 | 34 | If an unassigned issue has been marked as `status: accepting prs` and an open PR does not exist, feel free to send a PR. 35 | Please don't post comments asking for permission or stating you will work on an issue. 36 | 37 | ### Sending a Pull Request 38 | 39 | Once you've identified an open issue accepting PRs that doesn't yet have a PR sent, you're free to send a pull request. 40 | Be sure to fill out the pull request template's requested information -- otherwise your PR will likely be closed. 41 | 42 | PRs are also expected to have a title that adheres to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0). 43 | Only PR titles need to be in that format, not individual commits. 44 | Don't worry if you get this wrong: you can always change the PR title after sending it. 45 | Check [previously merged PRs](https://github.com/JoshuaKGoldberg/sentences-per-line/pulls?q=is%3Apr+is%3Amerged+-label%3Adependencies+) for reference. 46 | 47 | #### Draft PRs 48 | 49 | If you don't think your PR is ready for review, [set it as a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft). 50 | Draft PRs won't be reviewed. 51 | 52 | #### Granular PRs 53 | 54 | Please keep pull requests single-purpose: in other words, don't attempt to solve multiple unrelated problems in one pull request. 55 | Send one PR per area of concern. 56 | Multi-purpose pull requests are harder and slower to review, block all changes from being merged until the whole pull request is reviewed, and are difficult to name well with semantic PR titles. 57 | 58 | #### Pull Request Reviews 59 | 60 | When a PR is not in draft, it's considered ready for review. 61 | Please don't manually `@` tag anybody to request review. 62 | A maintainer will look at it when they're next able to. 63 | 64 | PRs should have passing [GitHub status checks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks) before review is requested (unless there are explicit questions asked in the PR about any failures). 65 | 66 | #### Asking Questions 67 | 68 | If you need help and/or have a question, posting a comment in the PR is a great way to do so. 69 | There's no need to tag anybody individually. 70 | One of us will drop by and help when we can. 71 | 72 | Please post comments as [line comments](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#adding-line-comments-to-a-pull-request) when possible, so that they can be threaded. 73 | You can [resolve conversations](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations) on your own when you feel they're resolved - no need to comment explicitly and/or wait for a maintainer. 74 | 75 | #### Requested Changes 76 | 77 | After a maintainer reviews your PR, they may request changes on it. 78 | Once you've made those changes, [re-request review on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review). 79 | 80 | Please try not to force-push commits to PRs that have already been reviewed. 81 | Doing so makes it harder to review the changes. 82 | We squash merge all commits so there's no need to try to preserve Git history within a PR branch. 83 | 84 | Once you've addressed all our feedback by making code changes and/or started a followup discussion, [re-request review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review) from each maintainer whose feedback you addressed. 85 | 86 | Once all feedback is addressed and the PR is approved, we'll ensure the branch is up to date with `main` and merge it for you. 87 | 88 | #### Post-Merge Recognition 89 | 90 | Once your PR is merged, if you haven't yet been added to the [_Contributors_ table in the README.md](../README.md#contributors) for its [type of contribution](https://allcontributors.org/docs/en/emoji-key "Allcontributors emoji key"), you should be soon. 91 | Please do ping the maintainer who merged your PR if that doesn't happen within 24 hours - it was likely an oversight on our end! 92 | 93 | ## Emojis & Appreciation 94 | 95 | If you made it all the way to the end, bravo dear user, we love you. 96 | Please include your favorite emoji in the bottom of your issues and PRs to signal to us that you did in fact read this file and are trying to conform to it as best as possible. 97 | 💖 is a good starter if you're not sure which to use. 98 | --------------------------------------------------------------------------------