File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // MIT © 2018 azu
2+ "use strict" ;
3+ import { ASTNodeTypes } from "@textlint/ast-node-types" ;
4+ import RuleHelper from "./textlint-rule-helper.js" ;
5+
6+ /**
7+ * @param {{ignoreNodeTypes:ASTNodeTypes[]} } options
8+ * @param {object } nodeHandlers
9+ */
10+ export function wrap ( options , nodeHandlers = { } ) {
11+ const ignoreNodeTypes = options . ignoreNodeTypes || [ ] ;
12+ const ruleHelper = new RuleHelper ( { } ) ;
13+ Object . keys ( nodeHandlers ) . forEach ( nodeType => {
14+ const nodeHandler = nodeHandlers [ nodeType ] ;
15+ const wrappedNodeHandler = ( node ) => {
16+ if ( ruleHelper . isChildNode ( node , ignoreNodeTypes ) ) {
17+ return ;
18+ }
19+ return nodeHandler ( node ) ;
20+ } ;
21+ nodeHandlers [ nodeType ] = wrappedNodeHandler
22+ } ) ;
23+ return nodeHandlers ;
24+ }
Original file line number Diff line number Diff line change 1+ // LICENSE : MIT
2+ import assert from 'assert'
3+ import { textlint } from "textlint"
4+ import { wrap } from "../src/wrapIgnore.js" ;
5+
6+ describe ( "wrap" , function ( ) {
7+ afterEach ( function ( ) {
8+ textlint . resetRules ( ) ;
9+ } ) ;
10+ describe ( "ignoreNodeTypes" , ( ) => {
11+ it ( "should ignore multiple nodes" , ( ) => {
12+ let isCalled = false ;
13+ textlint . setupRules ( {
14+ "rule-key" : function ( context ) {
15+ return wrap ( {
16+ ignoreNodeTypes : [ context . Syntax . BlockQuote ]
17+ } , {
18+ [ context . Syntax . Str ] ( node ) {
19+ isCalled = true
20+ }
21+ } )
22+ }
23+ } ) ;
24+ const text = `> This should be ignored.` ;
25+ return textlint . lintText ( text , ".md" ) . then ( ( ) => {
26+ assert . ok ( isCalled === false , "Str node handler should not be called" ) ;
27+ } ) ;
28+ } ) ;
29+ } ) ;
30+ } ) ;
You can’t perform that action at this time.
0 commit comments