Skip to content

Commit

Permalink
fix(src): should ignore comma in Code note
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 30, 2016
1 parent add521e commit 20477f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
10 changes: 7 additions & 3 deletions src/textlint-rule-max-comma.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
"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;
}
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;
Expand Down
1 change: 1 addition & 0 deletions test/textlint-rule-max-comma-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20477f8

Please sign in to comment.