diff --git a/package.json b/package.json index 3d09b18..b8577e6 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/sentence-length.js b/src/sentence-length.js index 8ed4217..c39f200 100644 --- a/src/sentence-length.js +++ b/src/sentence-length.js @@ -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 = { @@ -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){ @@ -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 => { @@ -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 diff --git a/test/sentence-length-test.js b/test/sentence-length-test.js index edd778e..909bb03 100644 --- a/test/sentence-length-test.js +++ b/test/sentence-length-test.js @@ -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.` + } + ] } ] });