Skip to content

Commit

Permalink
Merge pull request #3 from azu/fix_2
Browse files Browse the repository at this point in the history
Bug: differnce line - 1
  • Loading branch information
azu committed May 21, 2016
2 parents d9dd311 + 7ecf313 commit 178ba7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
],
"dependencies": {
"mdast-util-to-string": "^1.0.0",
"sentence-splitter": "^1.2.0",
"sentence-splitter": "^2.0.0",
"textlint-rule-helper": "^1.1.4"
},
"devDependencies": {
"babel-cli": "^6.1.18",
"babel-plugin-add-module-exports": "^0.1.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.1.18",
"espower-babel": "^4.0.0",
"mocha": "^2.3.3",
"power-assert": "^1.2.0",
"textlint-tester": "^0.4.0"
"textlint-tester": "^1.2.0"
}
}
10 changes: 5 additions & 5 deletions src/sentence-length.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// LICENSE : MIT
"use strict";
import sentenceSplitter from "sentence-splitter";
import {split} from "sentence-splitter";
import toString from 'mdast-util-to-string';
import {RuleHelper} from "textlint-rule-helper";
const defaultOptions = {
Expand All @@ -9,7 +9,7 @@ const defaultOptions = {
export default function (context, options = {}) {
const maxLength = options.max || defaultOptions.max;
const helper = new RuleHelper(context);
let { Syntax, RuleError, report } = context;
let {Syntax, RuleError, report} = context;
// toPlainText
return {
[Syntax.Paragraph](node){
Expand All @@ -18,7 +18,7 @@ export default function (context, options = {}) {
}
let text = toString(node);
// empty break line == split sentence
let sentences = sentenceSplitter(text, {
let sentences = split(text, {
newLineCharacters: "\n\n"
});
sentences.forEach(sentence => {
Expand All @@ -27,8 +27,8 @@ export default function (context, options = {}) {
// bigger than
if (sentenceText.length > maxLength) {
let currentLine = node.loc.start.line;
let paddingLine = sentence.loc.start.line - 1;
let paddingColumn = sentence.loc.start.line;
let paddingLine = Math.max(sentence.loc.start.line - 1, 0);
let paddingColumn = sentence.loc.start.column;
report(node, new RuleError(`Line ${currentLine + paddingLine} exceeds the maximum line length of ${maxLength}.`, {
line: paddingLine,
column: paddingColumn
Expand Down
15 changes: 15 additions & 0 deletions test/sentence-length-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ tester.run("textlint-rule-sentence-length", rule, {
message: `Line 3 exceeds the maximum line length of 5.`
}
]
},
{
text: `text
line3
line4
`,
options: {
max: 5
},
errors: [
{
message: `Line 3 exceeds the maximum line length of 5.`
}
]
}
]
});

0 comments on commit 178ba7b

Please sign in to comment.