Skip to content

Commit afb5cd7

Browse files
committed
fix(rule): counting padding from strNode position
1 parent 2e203d7 commit afb5cd7

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

src/max-ten.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,44 @@ export default function (context, options = {}) {
2828
}
2929
currentParagraphTexts.push(node);
3030
},
31-
[Syntax.Paragraph + ":exit"](pNode){
31+
[Syntax.Paragraph + ":exit"](){
3232
let currentTenCount = 0;
33-
let text = currentParagraphTexts.map(strNode => getSource(strNode)).join("\n");
34-
let characters = text.split("");// ["t","e","x","t"]
35-
36-
let paddingLine = 0;
37-
let paddingColumn = 0;
38-
characters.forEach(char => {
39-
if (char === "、") {
40-
currentTenCount++;
41-
}
42-
if (char === "。") {
43-
// reset
44-
currentTenCount = 0;
45-
}
46-
// report
47-
if (currentTenCount >= maxLen) {
48-
var ruleError = new context.RuleError(`一つの文で"、"を${maxLen}つ以上使用しています`, {
49-
line: paddingLine,
50-
column: paddingColumn
51-
});
52-
report(pNode, ruleError);
53-
currentTenCount = 0;
54-
}
55-
// calc padding{line,column}
56-
if (char === "\n") {
57-
paddingLine++;
58-
paddingColumn = 0;
59-
} else {
60-
paddingColumn++;
61-
}
33+
/*
34+
<p>
35+
<str><code><img><str>
36+
<str>
37+
</p>
38+
*/
39+
currentParagraphTexts.forEach(strNode => {
40+
let paddingLine = 0;
41+
let paddingColumn = 0;
42+
let text = getSource(strNode);
43+
let characters = text.split("");
44+
characters.forEach(char => {
45+
if (char === "、") {
46+
currentTenCount++;
47+
}
48+
if (char === "。") {
49+
// reset
50+
currentTenCount = 0;
51+
}
52+
// report
53+
if (currentTenCount >= maxLen) {
54+
var ruleError = new context.RuleError(`一つの文で"、"を${maxLen}つ以上使用しています`, {
55+
line: paddingLine,
56+
column: paddingColumn
57+
});
58+
report(strNode, ruleError);
59+
currentTenCount = 0;
60+
}
61+
// calc padding{line,column}
62+
if (char === "\n") {
63+
paddingLine++;
64+
paddingColumn = 0;
65+
} else {
66+
paddingColumn++;
67+
}
68+
});
6269
});
6370
}
6471
}

0 commit comments

Comments
 (0)