Skip to content

Commit d9b17ff

Browse files
committedMar 10, 2024
feat(rule): latin
1 parent 856ac88 commit d9b17ff

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed
 

‎Crystal/Latin.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extends: substitution
2+
message: "Avoid latin. Use '%s' instead of '%s'."
3+
level: error
4+
ignorecase: true
5+
nonword: true
6+
action:
7+
name: replace
8+
swap:
9+
'\b(?:eg|e\.g\.)[\s,]': for example
10+
'\betc\.': and other(s)
11+
'\b(?:ie|i\.e\.)[\s,]': that is
12+
'\bvs\.': against
13+
versus: against

‎fixtures/Latin/.vale.ini

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
StylesPath = ../../
2+
3+
MinAlertLevel = suggestion
4+
5+
[*.md]
6+
Crystal.Latin = YES

‎fixtures/Latin/test.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Latin
2+
3+
<!-- e.g. -->
4+
The rocky planets (e.g., Mercury) are closest to our sun.
5+
Farmer Brown sells his produce (eg, apples, oranges, carrots) at the market.
6+
7+
<!-- etc. -->
8+
You can leave your coats, umbrellas, etc., at the door.
9+
10+
<!-- i.e. -->
11+
The rocky planets (i.e., Mercury, Venus, Earth, and Mars) are closest to our sun.
12+
Mercury, Venus, Earth and Mars (ie, the rocky planets) are closest to our sun.
13+
14+
<!-- vs. -->
15+
It'll be the Red Sox vs. the Yankees in tonight's game.
16+
17+
<!-- versus -->
18+
Monitor your liabilities versus your assets.

‎test/parameters/Latin/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default [
2+
"Latin",
3+
`
4+
test.md:4:20:Crystal.Latin:Avoid latin. Use 'for example' instead of 'e.g.,'.
5+
test.md:5:33:Crystal.Latin:Avoid latin. Use 'for example' instead of 'eg,'.
6+
test.md:8:38:Crystal.Latin:Avoid latin. Use 'and other(s)' instead of 'etc.'.
7+
test.md:11:20:Crystal.Latin:Avoid latin. Use 'that is' instead of 'i.e.,'.
8+
test.md:12:33:Crystal.Latin:Avoid latin. Use 'that is' instead of 'ie,'.
9+
test.md:15:22:Crystal.Latin:Avoid latin. Use 'against' instead of 'vs.'.
10+
test.md:18:26:Crystal.Latin:Avoid latin. Use 'against' instead of 'versus'.
11+
`
12+
];

‎test/parameters/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
import Latin from "./Latin/index.js";
2+
13
export default [
4+
Latin
25
];

‎test/rules.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ const args = [
1313
]
1414
const fixturesDirectory = "fixtures";
1515

16+
function trimEveryLine(multiline) {
17+
return multiline.trim().split(/\r?\n/)
18+
.map(line => line.trim())
19+
.join("\n");
20+
}
21+
1622
test.each(scenario)(`Testing %s`, async (rule, expected) => {
1723
let result;
1824
try {
@@ -23,5 +29,5 @@ test.each(scenario)(`Testing %s`, async (rule, expected) => {
2329
result = error.stdout;
2430
}
2531

26-
expect.soft(result.trim()).toBe(expected.trim());
32+
expect.soft(trimEveryLine(result)).toBe(trimEveryLine(expected));
2733
});

0 commit comments

Comments
 (0)