prettier-plugin-sentences-per-line 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +47 -0
  3. package/lib/index.d.ts +30 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +18 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/index.test.d.ts +2 -0
  8. package/lib/index.test.d.ts.map +1 -0
  9. package/lib/index.test.js +43 -0
  10. package/lib/index.test.js.map +1 -0
  11. package/lib/modifications/insertNewlineAt.d.ts +3 -0
  12. package/lib/modifications/insertNewlineAt.d.ts.map +1 -0
  13. package/lib/modifications/insertNewlineAt.js +17 -0
  14. package/lib/modifications/insertNewlineAt.js.map +1 -0
  15. package/lib/modifications/modifyNodeIfMultipleSentencesInLine.d.ts +4 -0
  16. package/lib/modifications/modifyNodeIfMultipleSentencesInLine.d.ts.map +1 -0
  17. package/lib/modifications/modifyNodeIfMultipleSentencesInLine.js +32 -0
  18. package/lib/modifications/modifyNodeIfMultipleSentencesInLine.js.map +1 -0
  19. package/lib/modifyNodeIfMultipleSentencesInLine.d.ts +4 -0
  20. package/lib/modifyNodeIfMultipleSentencesInLine.d.ts.map +1 -0
  21. package/lib/modifyNodeIfMultipleSentencesInLine.js +49 -0
  22. package/lib/modifyNodeIfMultipleSentencesInLine.js.map +1 -0
  23. package/lib/predicates.d.ts +6 -0
  24. package/lib/predicates.d.ts.map +1 -0
  25. package/lib/predicates.js +13 -0
  26. package/lib/predicates.js.map +1 -0
  27. package/lib/types/nodes.d.ts +31 -0
  28. package/lib/types/nodes.d.ts.map +1 -0
  29. package/lib/types/nodes.js +2 -0
  30. package/lib/types/nodes.js.map +1 -0
  31. package/lib/types/positions.d.ts +13 -0
  32. package/lib/types/positions.d.ts.map +1 -0
  33. package/lib/types/positions.js +2 -0
  34. package/lib/types/positions.js.map +1 -0
  35. package/lib/types.d.ts +2 -0
  36. package/lib/types.d.ts.map +1 -0
  37. package/lib/types.js +2 -0
  38. package/lib/types.js.map +1 -0
  39. package/package.json +22 -0
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
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.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ <h1 align="center">prettier-plugin-sentences-per-line</h1>
2
+
3
+ <p align="center">
4
+ <a href="https://github.com/JoshuaKGoldberg/sentences-per-line/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
5
+ <a href="https://github.com/JoshuaKGoldberg/sentences-per-line/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg" /></a>
6
+ <a href="http://npmjs.com/package/prettier-plugin-sentences-per-line" target="_blank"><img alt="📦 npm version" src="https://img.shields.io/npm/v/prettier-plugin-sentences-per-line?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
7
+ <img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
8
+ </p>
9
+
10
+ <p align="center">Prettier plugin for limiting sentences per line. 📐</p>
11
+
12
+ prettier-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
+ First install this package as a devDependency:
27
+
28
+ ```shell
29
+ npm i -D prettier-plugin-sentences-per-line
30
+ ```
31
+
32
+ Then add it to your [Prettier config's `plugins`](https://prettier.io/docs/plugins):
33
+
34
+ ```json
35
+ {
36
+ "plugins": ["prettier-plugin-sentences-per-line"],
37
+ "useTabs": true
38
+ }
39
+ ```
40
+
41
+ ## Alternatives
42
+
43
+ This package is part of the [sentences-per-line](https://github.com/JoshuaKGoldberg/sentences-per-line) family of packages.
44
+ You might also consider:
45
+
46
+ - [`eslint-plugin-sentences-per-line`](../eslint-plugin-sentences-per-line): [ESLint](https://eslint.org/) plugin to enforce sentences per line in Markdown files.
47
+ - [`markdownlint-sentences-per-line`](../markdownlint-sentences-per-line): [Markdownlint](https://github.com/DavidAnson/markdownlint) plugin to enforce sentences per line in Markdown files.
package/lib/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { AstPath } from "prettier";
2
+ import { AnyNode } from "./types/nodes.js";
3
+ export declare const parsers: {
4
+ markdown: import("prettier").Parser;
5
+ mdx: import("prettier").Parser;
6
+ remark: import("prettier").Parser;
7
+ };
8
+ export declare const printers: {
9
+ mdast: {
10
+ print(path: AstPath<AnyNode>, options: import("prettier").ParserOptions<any>, print: (path: AstPath<any>) => import("prettier").Doc, args: unknown): import("prettier/doc.js").builders.Doc;
11
+ printPrettierIgnored?(path: AstPath<any>, options: import("prettier").ParserOptions<any>, print: (path: AstPath<any>) => import("prettier").Doc, args?: unknown): import("prettier").Doc;
12
+ embed?: ((path: AstPath, options: import("prettier").Options) => ((textToDoc: (text: string, options: import("prettier").Options) => Promise<import("prettier").Doc>, print: (selector?: string | number | Array<string | number> | AstPath) => import("prettier").Doc, path: AstPath, options: import("prettier").Options) => Promise<import("prettier").Doc | undefined> | import("prettier").Doc | undefined) | import("prettier").Doc | null) | undefined;
13
+ preprocess?: ((ast: any, options: import("prettier").ParserOptions<any>) => any) | undefined;
14
+ insertPragma?: (text: string) => string;
15
+ massageAstNode?: ((original: any, cloned: any, parent: any) => any) | undefined;
16
+ hasPrettierIgnore?: ((path: AstPath<any>) => boolean) | undefined;
17
+ canAttachComment?: ((node: any, ancestors: any[]) => boolean) | undefined;
18
+ isBlockComment?: ((node: any) => boolean) | undefined;
19
+ willPrintOwnComments?: ((path: AstPath<any>) => boolean) | undefined;
20
+ printComment?: ((commentPath: AstPath<any>, options: import("prettier").ParserOptions<any>) => import("prettier").Doc) | undefined;
21
+ getCommentChildNodes?: ((node: any, options: import("prettier").ParserOptions<any>) => any[] | undefined) | undefined;
22
+ handleComments?: {
23
+ ownLine?: ((commentNode: any, text: string, options: import("prettier").ParserOptions<any>, ast: any, isLastComment: boolean) => boolean) | undefined;
24
+ endOfLine?: ((commentNode: any, text: string, options: import("prettier").ParserOptions<any>, ast: any, isLastComment: boolean) => boolean) | undefined;
25
+ remaining?: ((commentNode: any, text: string, options: import("prettier").ParserOptions<any>, ast: any, isLastComment: boolean) => boolean) | undefined;
26
+ } | undefined;
27
+ getVisitorKeys?: ((node: any, nonTraversableKeys: Set<string>) => string[]) | undefined;
28
+ };
29
+ };
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,UAAU,CAAC;AAKjD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,eAAO,MAAM,OAAO;;;;CAEnB,CAAC;AAMF,eAAO,MAAM,QAAQ;;oBAGP,OAAO,CAAC,OAAO,CAAC;;8LAM08a,CAAC;;;;;;;;;;;;;;;;;CADt8a,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import * as markdown from "prettier/plugins/markdown";
2
+ import { modifyNodeIfMultipleSentencesInLine } from "./modifications/modifyNodeIfMultipleSentencesInLine.js";
3
+ export const parsers = {
4
+ ...markdown.parsers,
5
+ };
6
+ // @ts-expect-error -- markdown does not provide public exports
7
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
8
+ const mdastPrinter = markdown.printers.mdast;
9
+ export const printers = {
10
+ mdast: {
11
+ ...mdastPrinter,
12
+ print(path, options, print, args) {
13
+ modifyNodeIfMultipleSentencesInLine(path);
14
+ return mdastPrinter.print(path, options, print, args);
15
+ },
16
+ },
17
+ };
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAE,mCAAmC,EAAE,MAAM,wDAAwD,CAAC;AAG7G,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,GAAG,QAAQ,CAAC,OAAO;CACnB,CAAC;AAEF,+DAA+D;AAC/D,+GAA+G;AAC/G,MAAM,YAAY,GAAY,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;AAEtD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,KAAK,EAAE;QACN,GAAG,YAAY;QACf,KAAK,CAAC,IAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI;YACjD,mCAAmC,CAAC,IAAI,CAAC,CAAC;YAC1C,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC;KACD;CACiC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import * as prettier from "prettier";
2
+ import { describe, expect, test } from "vitest";
3
+ import * as plugin from "./index.js";
4
+ function format(code, options) {
5
+ return prettier.format(code, {
6
+ ...options,
7
+ parser: "markdown",
8
+ plugins: [plugin],
9
+ });
10
+ }
11
+ describe("Tests", () => {
12
+ test.each([
13
+ ["", ""],
14
+ [" ", ""],
15
+ ["This is a sentence.", "This is a sentence.\n"],
16
+ [
17
+ "This is a sentence `with. inline. code.`.",
18
+ "This is a sentence `with. inline. code.`.\n",
19
+ ],
20
+ ["This is a sentence.\n"],
21
+ ["1. List.\n", "1. List.\n"],
22
+ ["## 1. List.\n", "## 1. List.\n"],
23
+ ["First sentence. Second sentence.", "First sentence.\nSecond sentence.\n"],
24
+ [
25
+ "First sentence.\tSecond sentence.",
26
+ "First sentence.\nSecond sentence.\n",
27
+ ],
28
+ [
29
+ "First sentence. \t\t Second sentence.",
30
+ "First sentence.\nSecond sentence.\n",
31
+ ],
32
+ [
33
+ "First sentence. Second sentence. Third sentence.",
34
+ "First sentence.\nSecond sentence.\nThird sentence.\n",
35
+ ],
36
+ ["> First sentence.\n"],
37
+ ["> First sentence.\n> Second sentence.\n"],
38
+ ])("%j", async (input, expected = input) => {
39
+ const actual = await format(input, { filepath: "test.md" });
40
+ expect(actual).toBe(expected);
41
+ });
42
+ });
43
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src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0 +1,3 @@
1
+ import { SentenceNodeChild } from "../types/nodes.js";
2
+ export declare function insertNewlineAt(children: SentenceNodeChild[], index: number, insertion: string): void;
3
+ //# sourceMappingURL=insertNewlineAt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertNewlineAt.d.ts","sourceRoot":"","sources":["../../src/modifications/insertNewlineAt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,QAgBjB"}
@@ -0,0 +1,17 @@
1
+ export function insertNewlineAt(children, index, insertion) {
2
+ const newWhitespace = {
3
+ hasLeadingPunctuation: false,
4
+ hasTrailingPunctuation: false,
5
+ isCJ: false,
6
+ kind: "whitespace",
7
+ type: "word",
8
+ value: insertion,
9
+ };
10
+ if (children[index + 1].type === "whitespace") {
11
+ children[index + 1] = newWhitespace;
12
+ }
13
+ else {
14
+ children.splice(index + 1, 0, newWhitespace);
15
+ }
16
+ }
17
+ //# sourceMappingURL=insertNewlineAt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertNewlineAt.js","sourceRoot":"","sources":["../../src/modifications/insertNewlineAt.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAC9B,QAA6B,EAC7B,KAAa,EACb,SAAiB;IAEjB,MAAM,aAAa,GAAsB;QACxC,qBAAqB,EAAE,KAAK;QAC5B,sBAAsB,EAAE,KAAK;QAC7B,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,SAAS;KAChB,CAAC;IAEF,IAAI,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/C,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC;IACrC,CAAC;SAAM,CAAC;QACP,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;IAC9C,CAAC;AACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AstPath } from "prettier";
2
+ import { AnyNode } from "../types/nodes.js";
3
+ export declare function modifyNodeIfMultipleSentencesInLine(path: AstPath<AnyNode>): void;
4
+ //# sourceMappingURL=modifyNodeIfMultipleSentencesInLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modifyNodeIfMultipleSentencesInLine.d.ts","sourceRoot":"","sources":["../../src/modifications/modifyNodeIfMultipleSentencesInLine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EACN,OAAO,EAIP,MAAM,mBAAmB,CAAC;AAG3B,wBAAgB,mCAAmC,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,QAMzE"}
@@ -0,0 +1,32 @@
1
+ import { insertNewlineAt } from "./insertNewlineAt.js";
2
+ export function modifyNodeIfMultipleSentencesInLine(path) {
3
+ if (path.node.type === "blockquote") {
4
+ modifyBlockquoteNode(path.node);
5
+ }
6
+ else if (path.node.type === "paragraph") {
7
+ modifyParagraphNode(path.node, "\n");
8
+ }
9
+ }
10
+ function modifyBlockquoteNode(node) {
11
+ for (const paragraph of node.children) {
12
+ modifyParagraphNode(paragraph, "> ");
13
+ }
14
+ }
15
+ function modifyParagraphNode(node, insertion) {
16
+ for (const child of node.children) {
17
+ if (child.type === "sentence") {
18
+ modifySentenceNode(child, insertion);
19
+ }
20
+ }
21
+ }
22
+ function modifySentenceNode(sentence, insertion) {
23
+ for (let i = 0; i < sentence.children.length - 1; i++) {
24
+ const child = sentence.children[i];
25
+ if (child.type === "word" &&
26
+ child.value.endsWith(".") &&
27
+ !/^\s*\d+\./.test(child.value)) {
28
+ insertNewlineAt(sentence.children, i, insertion);
29
+ }
30
+ }
31
+ }
32
+ //# sourceMappingURL=modifyNodeIfMultipleSentencesInLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modifyNodeIfMultipleSentencesInLine.js","sourceRoot":"","sources":["../../src/modifications/modifyNodeIfMultipleSentencesInLine.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,mCAAmC,CAAC,IAAsB;IACzE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACrC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3C,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;AACF,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAoB;IACjD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;AACF,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAmB,EAAE,SAAiB;IAClE,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC/B,kBAAkB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACtC,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAsB,EAAE,SAAiB;IACpE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnC,IACC,KAAK,CAAC,IAAI,KAAK,MAAM;YACrB,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;YACzB,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAC7B,CAAC;YACF,eAAe,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;QAClD,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AstPath } from "prettier";
2
+ import { AnyNode } from "./types/nodes.js";
3
+ export declare function modifyNodeIfMultipleSentencesInLine(path: AstPath<AnyNode>): void;
4
+ //# sourceMappingURL=modifyNodeIfMultipleSentencesInLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modifyNodeIfMultipleSentencesInLine.d.ts","sourceRoot":"","sources":["../src/modifyNodeIfMultipleSentencesInLine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EACN,OAAO,EAKP,MAAM,kBAAkB,CAAC;AAE1B,wBAAgB,mCAAmC,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,QAMzE"}
@@ -0,0 +1,49 @@
1
+ export function modifyNodeIfMultipleSentencesInLine(path) {
2
+ if (path.node.type === "blockquote") {
3
+ modifyBlockquoteNode(path.node);
4
+ }
5
+ else if (path.node.type === "paragraph") {
6
+ modifyParagraphNode(path.node, "\n");
7
+ }
8
+ }
9
+ function insertNewlineAt(children, index, insertion) {
10
+ const newWhitespace = {
11
+ hasLeadingPunctuation: false,
12
+ hasTrailingPunctuation: false,
13
+ isCJ: false,
14
+ kind: "whitespace",
15
+ type: "word",
16
+ value: insertion,
17
+ };
18
+ if (children[index + 1].type === "whitespace") {
19
+ children[index + 1] = newWhitespace;
20
+ }
21
+ else {
22
+ children.splice(index + 1, 0, newWhitespace);
23
+ }
24
+ }
25
+ function modifyBlockquoteNode(node) {
26
+ for (const paragraph of node.children) {
27
+ modifyParagraphNode(paragraph, "> ");
28
+ }
29
+ }
30
+ function modifyParagraphNode(node, insertion) {
31
+ for (const child of node.children) {
32
+ if (child.type === "sentence") {
33
+ modifySentenceNode(child, insertion);
34
+ }
35
+ }
36
+ }
37
+ function modifySentenceNode(sentence, insertion) {
38
+ if (sentence.children.length > 1) {
39
+ for (let i = 0; i < sentence.children.length - 1; i++) {
40
+ const child = sentence.children[i];
41
+ if (child.type === "word" &&
42
+ child.value.endsWith(".") &&
43
+ !/^\s*\d+\./.test(child.value)) {
44
+ insertNewlineAt(sentence.children, i, insertion);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ //# sourceMappingURL=modifyNodeIfMultipleSentencesInLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modifyNodeIfMultipleSentencesInLine.js","sourceRoot":"","sources":["../src/modifyNodeIfMultipleSentencesInLine.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,mCAAmC,CAAC,IAAsB;IACzE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACrC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3C,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;AACF,CAAC;AAED,SAAS,eAAe,CACvB,QAA6B,EAC7B,KAAa,EACb,SAAiB;IAEjB,MAAM,aAAa,GAAsB;QACxC,qBAAqB,EAAE,KAAK;QAC5B,sBAAsB,EAAE,KAAK;QAC7B,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,SAAS;KAChB,CAAC;IAEF,IAAI,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/C,QAAQ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ode, BlockquoteNode, ParagraphNode, SentenceNode, WordNode } from "./types/nodes.js";
2
+ export declare function isBlockquoteNode(node: AnyNode): node is BlockquoteNode;
3
+ export declare function isParagraphNode(node: AnyNode): node is ParagraphNode;
4
+ export declare function isSentenceNode(node: AnyNode): node is SentenceNode;
5
+ export declare function isWordNode(node: AnyNode): node is WordNode;
6
+ //# sourceMappingURL=predicates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,cAAc,EACd,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,MAAM,kBAAkB,CAAC;AAE1B,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,cAAc,CAEtE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,aAAa,CAEpE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,YAAY,CAElE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,QAAQ,CAE1D"}
@@ -0,0 +1,13 @@
1
+ export function isBlockquoteNode(node) {
2
+ return node.type === "blockquote";
3
+ }
4
+ export function isParagraphNode(node) {
5
+ return node.type === "paragraph";
6
+ }
7
+ export function isSentenceNode(node) {
8
+ return node.type === "sentence";
9
+ }
10
+ export function isWordNode(node) {
11
+ return node.type === "word";
12
+ }
13
+ //# sourceMappingURL=predicates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.js","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC7C,OAAO,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAa;IAC5C,OAAO,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAa;IAC3C,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAa;IACvC,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { WithPosition } from "./positions.js";
2
+ /**
3
+ * Non-exhaustive list of AST nodes equivalent to \@types/mdast.
4
+ */
5
+ export type AnyNode = BlockquoteNode | ParagraphNode | SentenceNode | WhitespaceNode | WordNode;
6
+ export interface BlockquoteNode extends WithPosition {
7
+ children: ParagraphNode[];
8
+ type: "blockquote";
9
+ }
10
+ export interface ParagraphNode extends WithPosition {
11
+ children: AnyNode[];
12
+ type: "paragraph";
13
+ }
14
+ export interface SentenceNode extends WithPosition {
15
+ children: SentenceNodeChild[];
16
+ type: "sentence";
17
+ }
18
+ export type SentenceNodeChild = WhitespaceNode | WordNode;
19
+ export interface WhitespaceNode {
20
+ type: "whitespace";
21
+ value: string;
22
+ }
23
+ export interface WordNode {
24
+ hasLeadingPunctuation: boolean;
25
+ hasTrailingPunctuation: boolean;
26
+ isCJ: boolean;
27
+ kind: string;
28
+ type: "word";
29
+ value: string;
30
+ }
31
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/types/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,OAAO,GAChB,cAAc,GACd,aAAa,GACb,YAAY,GACZ,cAAc,GACd,QAAQ,CAAC;AAEZ,MAAM,WAAW,cAAe,SAAQ,YAAY;IACnD,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,IAAI,EAAE,YAAY,CAAC;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IAClD,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;CAClB;AAED,MAAM,WAAW,YAAa,SAAQ,YAAY;IACjD,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,IAAI,EAAE,UAAU,CAAC;CACjB;AAED,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACxB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sBAAsB,EAAE,OAAO,CAAC;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/types/nodes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ export interface Position {
2
+ end: PositionPoint;
3
+ start: PositionPoint;
4
+ }
5
+ export interface PositionPoint {
6
+ column: number;
7
+ line: number;
8
+ offset: number;
9
+ }
10
+ export interface WithPosition {
11
+ position: Position;
12
+ }
13
+ //# sourceMappingURL=positions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../src/types/positions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACxB,GAAG,EAAE,aAAa,CAAC;IACnB,KAAK,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,QAAQ,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=positions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positions.js","sourceRoot":"","sources":["../../src/types/positions.ts"],"names":[],"mappings":""}
package/lib/types.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type CollectibleNode = unknown;
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC"}
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "prettier-plugin-sentences-per-line",
3
+ "version": "0.1.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
+ "devDependencies": {
17
+ "prettier": "^3.7.1"
18
+ },
19
+ "peerDependencies": {
20
+ "prettier": "^3"
21
+ }
22
+ }