Skip to content

Commit 581460a

Browse files
committed
chore(npm): handle Paragraph
1 parent 0342065 commit 581460a

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@
3636
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.20",
3737
"babel-preset-es2015": "^6.1.18",
3838
"espower-babel": "^4.0.0",
39-
"mocha": "^2.3.3",
39+
"mocha": "^2.3.4",
4040
"power-assert": "^1.1.0",
4141
"sentence-splitter": "^1.0.2",
42-
"textlint": "^5.0.0",
42+
"textlint": "^5.0.2",
4343
"textlint-tester": "^0.4.0"
4444
},
4545
"dependencies": {
4646
"kuromojin": "^1.0.2",
4747
"sentence-splitter": "^1.0.1",
48-
"textlint-rule-helper": "^1.1.4"
48+
"textlint-rule-helper": "^1.1.4",
49+
"textlint-util-to-string": "^1.1.0"
4950
}
5051
}

src/no-doubled-joshi.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {RuleHelper} from "textlint-rule-helper";
44
import {getTokenizer} from "kuromojin";
55
import splitSentences, {Syntax as SentenceSyntax} from "sentence-splitter";
6+
import StringSource from "textlint-util-to-string";
67
/**
78
* create a object that
89
* map ={
@@ -45,11 +46,12 @@ export default function (context, options = {}) {
4546
let isStrict = options.strict || defaultOptions.strict;
4647
let {Syntax, report, getSource, RuleError} = context;
4748
return {
48-
[Syntax.Str](node){
49+
[Syntax.Paragraph](node){
4950
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
5051
return;
5152
}
52-
let text = getSource(node);
53+
const source = new StringSource(node);
54+
let text = source.toString();
5355
let sentences = splitSentences(text).filter(node => {
5456
return node.type === SentenceSyntax.Sentence;
5557
});
@@ -73,7 +75,7 @@ export default function (context, options = {}) {
7375
let tokens = joshiTokenSurfaceKeyMap[key];
7476
// strict mode ではない時例外を除去する
7577
if (!isStrict) {
76-
if(matchExceptionRule(tokens)) {
78+
if (matchExceptionRule(tokens)) {
7779
return;
7880
}
7981
}
@@ -87,11 +89,20 @@ export default function (context, options = {}) {
8789
// if difference
8890
let differenceIndex = otherPosition - startPosition;
8991
if (differenceIndex <= minInterval) {
92+
console.log(node);
93+
console.log(text);
94+
console.log(sentences);
95+
console.log(sentence.loc);
96+
console.log(current.word_position);
97+
let originalPosition = source.originalPositionFor({
98+
line: sentence.loc.start.line,
99+
column: sentence.loc.start.column + (current.word_position - 1)
100+
});
90101
report(node, new RuleError(`一文に二回以上利用されている助詞 "${key}" がみつかりました。`, {
91-
line: sentence.loc.start.line - 1,
102+
line: originalPosition.line - 1,
92103
// matchLastToken.word_position start with 1
93104
// this is padding column start with 0 (== -1)
94-
column: sentence.loc.start.column + (current.word_position - 1)
105+
column: originalPosition.column
95106
}));
96107
}
97108
return current;

test/fixtures/test.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TESTTTTT
2+
3+
`app.use(middleware)` という形で、_middleware_と呼ばれる関数には`request``response`といったオブジェクトが渡されます。
4+
この`request``response`を_middleware_で処理することでログを取ったり、任意のレスポンスを返しことができるようになっています。

test/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
import {TextLintCore} from "textlint";
4+
import rule from "../src/no-doubled-joshi";
5+
describe("text", function () {
6+
it("should handle", function () {
7+
let textlint = new TextLintCore();
8+
textlint.setupRules({
9+
"no-doubled-joshi": rule
10+
});
11+
return textlint.lintFile(__dirname + "/fixtures/test.md").then(result => {
12+
console.log(result);
13+
});
14+
});
15+
});

0 commit comments

Comments
 (0)