From 20477f873706279202d6cc65c2b9d841d0227370 Mon Sep 17 00:00:00 2001 From: azu Date: Tue, 30 Aug 2016 14:47:42 +0900 Subject: [PATCH] fix(src): should ignore comma in `Code` note --- package.json | 5 +++-- src/textlint-rule-max-comma.js | 10 +++++++--- test/textlint-rule-max-comma-test.js | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 49cabb5..23cb445 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,12 @@ "babel-cli": "^6.7.7", "babel-preset-es2015": "^6.6.0", "babel-register": "^6.7.2", - "mocha": "^2.4.5", - "textlint-tester": "^1.2.0" + "mocha": "^3.0.2", + "textlint-tester": "^2.0.0" }, "dependencies": { "sentence-splitter": "^2.0.0", + "textlint-util-to-string": "^2.0.0", "unist-util-filter": "^0.2.1" } } diff --git a/src/textlint-rule-max-comma.js b/src/textlint-rule-max-comma.js index 158aca1..4abffa4 100644 --- a/src/textlint-rule-max-comma.js +++ b/src/textlint-rule-max-comma.js @@ -2,6 +2,7 @@ "use strict"; import {split, Syntax as SentenceSyntax} from "sentence-splitter"; const filter = require("unist-util-filter"); +const StringSource = require("textlint-util-to-string"); function countOfComma(text) { return text.split(",").length - 1; } @@ -9,13 +10,16 @@ const defaultOptions = { // default: max comma count is 4 max: 4 }; -module.exports = function (context, options = defaultOptions) { +module.exports = function(context, options = defaultOptions) { const maxComma = options.max || defaultOptions.max; const {Syntax, RuleError, report, getSource} = context; return { [Syntax.Paragraph](node){ - const nodeWithoutCode = filter(node, (node) => node.type !== Syntax.Code); - const text = getSource(nodeWithoutCode); + const nodeWithoutCode = filter(node, (node) => { + return node.type !== Syntax.Code; + }); + const source = new StringSource(nodeWithoutCode); + const text = source.toString(); const sentences = split(text).filter(node => node.type === SentenceSyntax.Sentence); sentences.forEach(sentence => { const sentenceValue = sentence.value; diff --git a/test/textlint-rule-max-comma-test.js b/test/textlint-rule-max-comma-test.js index fffa4fd..3c26690 100644 --- a/test/textlint-rule-max-comma-test.js +++ b/test/textlint-rule-max-comma-test.js @@ -8,6 +8,7 @@ tester.run("no-todo", rule, { "This is text.", // 3 "0, 1, 2, 3", + "`sum(0,1,2,3,4,5,6,7,8,9,10)` is ok", { options: { max: 5