Skip to content

Commit b16b977

Browse files
committed
chore(rule): use StringSource for plain text
1 parent ce154f2 commit b16b977

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"dependencies": {
4747
"object-assign": "^4.0.1",
4848
"rousseau": "^1.0.0",
49-
"textlint-rule-helper": "^1.2.0"
49+
"textlint-rule-helper": "^1.2.0",
50+
"textlint-util-to-string": "^1.2.0"
5051
}
5152
}

src/textlint-rule-rousseau.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// LICENSE : MIT
22
"use strict";
33
import {RuleHelper, IgnoreNodeManger} from "textlint-rule-helper";
4+
const StringSource = require("textlint-util-to-string").default;
45
const rousseau = require("rousseau");
56
const ObjectAssign = require("object-assign");
67
const defaultOptions = {
@@ -72,7 +73,7 @@ export default function textlintRousseau(context, options = defaultOptions) {
7273
return "=> " + value;
7374
}).join("\n");
7475
};
75-
const reportError = (node, result) => {
76+
const reportError = (node, source, result) => {
7677
const level = result.level;
7778
const type = result.type;
7879
// if not contains showing options, ignore this result
@@ -82,9 +83,9 @@ export default function textlintRousseau(context, options = defaultOptions) {
8283
if (!isShowType(type)) {
8384
return;
8485
}
85-
const index = result.index;
86+
const index = source.originalIndexFromIndex(result.index);
8687
// if already ignored, should not report
87-
if(ignoreNodeManager.isIgnoredIndex(index)){
88+
if (ignoreNodeManager.isIgnoredIndex(index)) {
8889
return;
8990
}
9091
const suggestions = createSuggest(result.replacements);
@@ -103,9 +104,11 @@ export default function textlintRousseau(context, options = defaultOptions) {
103104
// ignore if contain child node types
104105
ignoreNodeManager.ignoreChildrenByTypes(node, ignoreInlineNodeTypes);
105106
// check
106-
const text = getSource(node);
107+
108+
const source = new StringSource(node);
109+
const text = source.toString();
107110
const reportSourceError = (results) => {
108-
reportError(node, results);
111+
reportError(node, source, results);
109112
};
110113
rousseau(text, function (err, results) {
111114
if (err) {

test/textlint-rule-rousseau-test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tester.run("rousseau", rule, {
1313
"This is *pen*.",
1414
"This is **pen**.",
1515
"This is __pen__.",
16+
"`this` is pen.",
1617
{
1718
text: "this is pen.",
1819
options: {
@@ -59,6 +60,28 @@ A number of pen.`,
5960
column: 1
6061
}
6162
]
62-
}
63+
}, {
64+
text: `There are a pen.
65+
A number of pen.`,
66+
errors: [
67+
{
68+
message: `suggestion(simplicity) "A number of" has a simpler alternative\nSuggestions:\n=> Many, some`,
69+
line: 2,
70+
column: 1
71+
}
72+
]
73+
},
74+
{
75+
text: "this is `pen`.`this is pen code`",
76+
errors: [
77+
{
78+
message: `error(sentence:uppercase) sentence should start with an uppercase letter
79+
Suggestions:
80+
=> This`,
81+
line: 1,
82+
column: 1
83+
}
84+
]
85+
},
6386
]
6487
});

0 commit comments

Comments
 (0)