Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"esbuild": "^0.20.2",
"textlint-rule-period-in-list-item": "^1.0.1",
"textlint-rule-preset-ja-technical-writing": "^12.0.2",
"textlint-rule-sentence-length": "5.2.1",
"textlint-scripts": "^14.0.4",
"textlint-tester": "^14.0.4",
"typescript": "^5.4.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= element immediately below a comment

// Single line comment
#let some_element = _ => {
let this_means_nothing = "Fake"
let another_meaningless_variable = 12345
// ...
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= figure

#figure(
image("glacier.jpg", width: 70%),
caption: [
_Glaciers_ form an important part
of the earth's climate system.
],
) <glaciers>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
= sentence in list

- List

Too long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long sentence.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
= math

$
"Too long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long math sentence."
$
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
= multiline comment

/*
Multiline comments should be ignored.
Too long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long sentence.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
= nested content blocks

#[
Some short sentence 1.

#[
Some short sentence 2.
Some short sentence 3.
Some short sentence 4.
Some short sentence 5.
]

#let some_element = _ => {
let this_means_nothing = "Fake"
let another_meaningless_variable = 12345
// ...
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
= nested list

- Item 1

- Nested Item 1
- Nested Item 2

- Item 2

#let some_element = _ => {
let this_means_nothing = "Fake"
let another_meaningless_variable = 12345
// ...
}

- Item 3

$
"Too long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long math sentence."
$

- Item 4

#figure(
image("glacier.jpg", width: 70%),
caption: [
_Glaciers_ form an important part
of the earth's climate system.
],
) <glaciers>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= single line comment

// Single line comments should be ignored.
// Too long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long sentence.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= sentence in term list

/ Term: Too long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long sentence.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
= term list

/ Term 1: First line.

Second line.
Third line.

/ Nested Term 1: First line.

Lorem ipsum dolor sit amet, consectetur.

/ Term 2: First line.
/ Term 3: Third line.
114 changes: 114 additions & 0 deletions test/integration/linting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
rulesConfig as textlintRulePresetJaTechnicalWritingRulesConfig,
// @ts-expect-error
} from "textlint-rule-preset-ja-technical-writing";
// @ts-expect-error
import textlintRuleSentenceLength from "textlint-rule-sentence-length";

import { beforeAll, describe, expect, it } from "vitest";

Expand Down Expand Up @@ -261,5 +263,117 @@ describe("linting", () => {
);
});
});
describe("textlint-rule-sentence-length", () => {
const lintFile = async (fileName: string) => {
const kernel = new TextlintKernel();
return await kernel.lintText(
fs.readFileSync(
path.join(
__dirname,
`./fixtures/smoke/textlint-rule-sentence-length/${fileName}`,
),
"utf-8",
),
{
ext: ".typ",
plugins: [
{
pluginId: "typst",
plugin: typstPlugin,
},
],
rules: [
{
ruleId: "sentence-length",
rule: textlintRuleSentenceLength,
options: {
max: 50,
},
},
],
},
);
};

const getViolations = (result: TextlintResult) => {
return result.messages.filter(
(message) => message.ruleId === "sentence-length",
);
};

it("should ignore single line comments", async () => {
const result = await lintFile("single_line_comment_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

it("should ignore multiline comments", async () => {
const result = await lintFile("multiline_comment_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

// see: https://github.com/textlint/textlint-plugin-typst/pull/31
it.fails(
"should handle elements immediately below comments",
async () => {
const result = await lintFile(
"element_immediately_below_comment_valid.typ",
);
const violations = getViolations(result);
expect(violations).toEqual([]);
},
);

it("should handle term lists", async () => {
const result = await lintFile("term_list_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

// see: https://github.com/textlint/textlint-plugin-typst/pull/31
it.fails("should handle nested lists", async () => {
const result = await lintFile("nested_list_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

it("should ignore math blocks", async () => {
const result = await lintFile("math_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

it("should handle figures", async () => {
const result = await lintFile("figure_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

it("should handle nested content blocks", async () => {
const result = await lintFile("nested_content_blocks_valid.typ");
const violations = getViolations(result);
expect(violations).toEqual([]);
});

it("should detect violations in lists", async () => {
const result = await lintFile("list_invalid.typ");
const violations = getViolations(result);
expect(
violations.length,
`Expected 1 violation but got ${violations.length}. Violations: ${JSON.stringify(violations, null, 2)}`,
).toBe(1);
});

// see: https://github.com/textlint/textlint-plugin-typst/pull/31
it.fails("should detect violations in term lists", async () => {
const result = await lintFile("term_list_invalid.typ");
const violations = getViolations(result);
expect(
violations.length,
`Expected 1 violation but got ${violations.length}. Violations: ${JSON.stringify(violations, null, 2)}`,
).toBe(1);
});
});
});
});