-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"es2015" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
const splitSentences = require("sentence-splitter").split; | ||
const Syntax = require("sentence-splitter").Syntax; | ||
module.exports = function (context) { | ||
import {split, Syntax as SentenceSyntax} from "sentence-splitter"; | ||
const filter = require("unist-util-filter"); | ||
function countOfComma(text) { | ||
return text.split(",").length - 1; | ||
} | ||
const defaultOptions = { | ||
// default: max comma count is 4 | ||
max: 4 | ||
}; | ||
module.exports = function (context, options = defaultOptions) { | ||
const maxComma = options.max || defaultOptions.max; | ||
const {Syntax, RuleError, report, getSource} = context; | ||
return { | ||
[Syntax.Paragraph](node){ | ||
const text = getSource(node); | ||
const sentences = splitSentences(text).filter(node => node.type === Syntax.Sentence) | ||
const nodeWithoutCode = filter(node, (node) => node.type !== Syntax.Code); | ||
const text = getSource(nodeWithoutCode); | ||
const sentences = split(text).filter(node => node.type === SentenceSyntax.Sentence); | ||
sentences.forEach(sentence => { | ||
const sentenceValue = sentence.value; | ||
const count = countOfComma(sentenceValue); | ||
if(count > maxComma) { | ||
report(node, new RuleError(`This sentence exceeds the maximum count of comma. Maximum is ${maxComma}.`, sentence)); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--compilers js:babel-register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters