-
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.
fix: update libraries and improve analysis
- Loading branch information
Showing
9 changed files
with
4,269 additions
and
46 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,20 @@ | ||
name: test | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
name: "Test on Node.js ${{ matrix.node-version }}" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [12, 14] | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
- name: setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install | ||
run: yarn install | ||
- name: Test | ||
run: yarn test |
This file was deleted.
Oops, something went wrong.
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
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,41 +1,41 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
import {split, Syntax as SentenceSyntax} from "sentence-splitter"; | ||
const filter = require("unist-util-filter"); | ||
import filter from "unist-util-filter"; | ||
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter"; | ||
import { StringSource } from "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) { | ||
export default function (context, options = defaultOptions) { | ||
const maxComma = options.max || defaultOptions.max; | ||
const {Syntax, RuleError, report, getSource} = context; | ||
const { Syntax, RuleError, report, getSource } = context; | ||
return { | ||
[Syntax.Paragraph](node){ | ||
[Syntax.Paragraph](node) { | ||
const nodeWithoutCode = filter(node, (node) => { | ||
return node.type !== Syntax.Code; | ||
}); | ||
if (!nodeWithoutCode) { | ||
return; | ||
} | ||
const texts = Array.isArray(nodeWithoutCode.children) ? nodeWithoutCode.children.map(child => { | ||
return getSource(child); | ||
}) : []; | ||
const text = texts.join(""); | ||
const sentences = split(text).filter(node => node.type === SentenceSyntax.Sentence); | ||
const sentences = splitAST(nodeWithoutCode).children.filter(node => node.type === SentenceSyntax.Sentence); | ||
sentences.forEach(sentence => { | ||
const sentenceValue = sentence.value; | ||
const source = new StringSource(sentence); | ||
const sentenceValue = source.toString(); | ||
console.log(sentenceValue); | ||
const count = countOfComma(sentenceValue); | ||
if (count > maxComma) { | ||
const paddingStart = { | ||
line: sentence.loc.start.line - 1, | ||
column: sentence.loc.start.column | ||
}; | ||
report(node, new RuleError(`This sentence exceeds the maximum count of comma. Maximum is ${maxComma}.`, paddingStart)); | ||
const lastCommandIndex = sentenceValue.lastIndexOf(","); | ||
report(node, new RuleError(`This sentence exceeds the maximum count of comma. Maximum is ${maxComma}.`, { | ||
index: source.originalIndexFromIndex(lastCommandIndex) | ||
})); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.