Gathering detailed insights and metrics for textlint-rule-helper
Gathering detailed insights and metrics for textlint-rule-helper
Gathering detailed insights and metrics for textlint-rule-helper
Gathering detailed insights and metrics for textlint-rule-helper
This is helper library for creating textlint rule.
npm install textlint-rule-helper
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
14 Stars
101 Commits
7 Forks
5 Watching
2 Branches
13 Contributors
Updated on 05 Oct 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-3.6%
18,493
Compared to previous day
Last week
7.8%
105,690
Compared to previous week
Last month
1.7%
437,133
Compared to previous month
Last year
-7.5%
4,717,614
Compared to previous year
This is helper library for creating textlint rule.
npm install textlint-rule-helper
Helper for traversing TxtAST.
Get parents of node.
The parent nodes are returned in order from the closest parent to the outer ones.
node
is not contained in the results.
Params
TxtNode
- the node is start point.Return true if node
is wrapped any one of node types
.
Params
TxtNode
- is target nodeArray.<string>
- are wrapped target nodeisPlainStrNode()
return true if the node is Str node and fill following conditions:
Params
TxtNode
- is target nodeThis function is useful for the common use case.
If you want to lint Str node, but you do not want to lint styled node, this function is useful.
The styled node is Link
, Strong
, BlockQuote
, Header
, and it may be written by other people.
For example, you have added a link to your document, the link's title is written by other people.
Opposite of it, The plain Str node is just under the Paragraph node, and it was written by you.
Examples
Return true
1str str str 2- list text
Return false
1# Header 2![alt text](https://example.com) 3[link title](https://example.com) 4> BlockQuote text 5**Strong text** 6[linkReference][] 7[^footnote text]
use case
You can manager ignoring range in texts.
Add the range of node
to ignoring range list.
Params
TxtNode
- target nodeAdd the range
to ignoring range list
Params
[number, number]
if the children node has the type that is included in ignoredNodeTypes
,
Add range of children node of node
to ignoring range list,
Params
TxtNode
- target nodeArray.<string>
- are node types for ignoringIf the index
is included in ignoring range list, return true.
index
should be absolute position.
Params
number
- index value start with 0If the range
is included in ignoring range list, return true.
range
should includes absolute positions.
Params
[number, number]
If the range
of node
is included in ignoring range list, return true.
Params
TxtNode
- target nodeA rule for textlint.
1import { RuleHelper } from "textlint-rule-helper"; 2import { IgnoreNodeManager } from "textlint-rule-helper"; 3export default function(context) { 4 var helper = new RuleHelper(context); 5 var ignoreNodeManager = new IgnoreNodeManager(); 6 var exports = {}; 7 var reportingErrors = []; 8 exports[context.Syntax.Paragraph] = function(node) { 9 // Add `Code` node to ignoring list 10 ignoreNodeManager.ignoreChildrenByTypes(node, [context.Syntax.Code]); 11 // do something 12 reportingErrors.push(node, ruleError); 13 }; 14 exports[context.Syntax.Str] = function(node) { 15 // parent nodes is any one Link or Image. 16 if (helper.isChildNode(node, [context.Syntax.Link, context.Syntax.Image])) { 17 return; 18 } 19 // get Parents 20 var parents = helper.getParents(node); 21 }; 22 exports[Syntax.Document + ":exit"] = function(node) { 23 reportingErrors.forEach(function(node, ruleError) { 24 // if the error is ignored, don't report 25 if (ignoreNodeManager.isIgnored(node)) { 26 return; 27 } 28 // report actual 29 }); 30 }; 31 return exports; 32};
wrapReportHandler(context, options, handler): TextlintRuleReportHandler
Params
TextlintRuleContent
- rule context object{{ignoreNodeTypes: TxtNodeType[]}}
- options(report: (node: AnyTxtNode, ruleError: TextlintRuleError) => void) => any
- handler should return a objectwrapReportHandler
is high level API that use RuleHelper
and IgnoreNodeManager
.
It aim to easy to ignore some Node type for preventing unnecessary error report.
Example: ignore BlockQuote
and Code
node.
1import { wrapReportHandler } from "textlint-rule-helper";
2const reporter = function (context) {
3 const { Syntax, getSource } = context;
4 return wrapReportHandler(context, {
5 ignoreNodeTypes: [Syntax.BlockQuote, Syntax.Code]
6 },report => { // <= wrap version of context.report
7 // handler should return a rule handler object
8 return {
9 [Syntax.Paragraph](node) {
10 const text = getSource(node);
11 const index = text.search("code");
12 /*
13 * Following text is matched, but it will not reported.
14 * ----
15 * This is `code`.
16 * > code
17 * ----
18 */
19 if(index === -1){
20 return;
21 }
22 report(node, new context.RuleError(item.name, {
23 index
24 }));
25 }
26 }
27 });
28};
29export default reporter;
The Mechanism of wrapReportHandler
: `
ignoreNodeTypes
.ignoreNodeTypes
.
wrapReportHandler
create custom report
function that ignore matched nodeYou can see real use-case of this helper library.
# watch
npm run watch
# build
npm run build
# test
npm run test
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 1/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More