11// LICENSE : MIT
22"use strict" ;
3- const { RuleHelper} = require ( "textlint-rule-helper" ) ;
3+ import { RuleHelper , IgnoreNodeManger } from "textlint-rule-helper" ;
44const StringSource = require ( "textlint-util-to-string" ) . default ;
55const rousseau = require ( "rousseau" ) ;
66const ObjectAssign = require ( "object-assign" ) ;
@@ -27,6 +27,7 @@ const mapNode = function (ast, mapFn) {
2727
2828export default function textlintRousseau ( context , options = defaultOptions ) {
2929 const helper = new RuleHelper ( context ) ;
30+ const ignoreNodeManager = new IgnoreNodeManger ( ) ;
3031 const { Syntax, RuleError, report, getSource} = context ;
3132 const showLevels = options . showLevels || defaultOptions . showLevels ;
3233 const ignoreTypes = options . ignoreTypes || defaultOptions . ignoreTypes ;
@@ -83,6 +84,10 @@ export default function textlintRousseau(context, options = defaultOptions) {
8384 return ;
8485 }
8586 const index = source . originalIndexFromIndex ( result . index ) ;
87+ // if already ignored, should not report
88+ if ( ignoreNodeManager . isIgnoredIndex ( index ) ) {
89+ return ;
90+ }
8691 const suggestions = createSuggest ( result . replacements ) ;
8792 const ruleError = new RuleError ( `${ level } (${ type } ) ${ result . message } ${ suggestions } ` , {
8893 index
@@ -92,25 +97,15 @@ export default function textlintRousseau(context, options = defaultOptions) {
9297
9398 return {
9499 [ Syntax . Paragraph ] ( node ) {
100+ // ignore if wrapped node types
95101 if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
96102 return ;
97103 }
98- const filteredNode = mapNode ( node , ( node ) => {
99- const index = ignoreInlineNodeTypes . indexOf ( node . type ) ;
100- if ( index === - 1 ) {
101- return node ;
102- }
103- /*
104- `xxx` => code
105- */
106- return ObjectAssign ( { } , node , {
107- value : node . type . toLocaleLowerCase ( )
108- } ) ;
109- } ) ;
110- if ( ! filteredNode ) {
111- return ;
112- }
113- const source = new StringSource ( filteredNode ) ;
104+ // ignore if contain child node types
105+ ignoreNodeManager . ignoreChildrenByTypes ( node , ignoreInlineNodeTypes ) ;
106+ // check
107+
108+ const source = new StringSource ( node ) ;
114109 const text = source . toString ( ) ;
115110 const reportSourceError = ( results ) => {
116111 reportError ( node , source , results ) ;
0 commit comments