@@ -69,7 +69,7 @@ This is ignored.
6969 nodeTypes : [ ASTNodeTypes . Str ]
7070 }
7171 } ) ;
72-
72+
7373 textlint . setupFilterRules ( {
7474 filter : filterRule
7575 } ) ;
@@ -94,7 +94,7 @@ This is text.
9494 nodeTypes : [ ASTNodeTypes . Str ]
9595 }
9696 } ) ;
97-
97+
9898 textlint . setupFilterRules ( {
9999 filter : filterRule
100100 } ) ;
@@ -124,7 +124,7 @@ This is Error.
124124 nodeTypes : [ ASTNodeTypes . Str ]
125125 }
126126 } ) ;
127-
127+
128128 textlint . setupFilterRules ( {
129129 filter : filterRule
130130 } ) ;
@@ -147,7 +147,7 @@ This is text.
147147 nodeTypes : [ ASTNodeTypes . Str ]
148148 }
149149 } ) ;
150-
150+
151151 textlint . setupFilterRules ( {
152152 filter : filterRule
153153 } ) ;
@@ -176,7 +176,7 @@ This is text.
176176 nodeTypes : [ ASTNodeTypes . Str ]
177177 }
178178 } ) ;
179-
179+
180180 textlint . setupFilterRules ( {
181181 filter : filterRule
182182 } ) ;
@@ -195,5 +195,225 @@ This is Error of RuleA.
195195 } ) ;
196196 } ) ;
197197 } ) ;
198+
199+ context ( "description basics" , function ( ) {
200+ it ( "should ignore messages when using description in disable comment" , function ( ) {
201+ const textlint = new TextLintCore ( ) ;
202+ textlint . setupRules ( {
203+ ruleA : reportRule
204+ } , {
205+ ruleA : {
206+ nodeTypes : [ ASTNodeTypes . Str ]
207+ }
208+ } ) ;
209+
210+ textlint . setupFilterRules ( {
211+ filter : filterRule
212+ } ) ;
213+ return textlint . lintMarkdown ( `
214+ <!-- textlint-disable ruleA -- temporary -->
215+
216+ This is text.
217+
218+ <!-- textlint-enable ruleA -->
219+ ` ) . then ( ( { messages } ) => {
220+ assert . equal ( messages . length , 0 ) ;
221+ } ) ;
222+ } ) ;
223+
224+ it ( "should ignore messages when disabling multiple rules with description" , function ( ) {
225+ const textlint = new TextLintCore ( ) ;
226+ textlint . setupRules ( {
227+ ruleA : reportRule ,
228+ ruleB : reportRule
229+ } , {
230+ ruleA : {
231+ nodeTypes : [ ASTNodeTypes . Str ]
232+ } ,
233+ ruleB : {
234+ nodeTypes : [ ASTNodeTypes . Str ]
235+ }
236+ } ) ;
237+
238+ textlint . setupFilterRules ( {
239+ filter : filterRule
240+ } ) ;
241+ return textlint . lintMarkdown ( `
242+ <!-- textlint-disable ruleA,ruleB -- temporary -->
243+
244+ This is text.
245+
246+ <!-- textlint-enable -->
247+ ` ) . then ( ( { messages } ) => {
248+ assert . equal ( messages . length , 0 ) ;
249+ } ) ;
250+ } ) ;
251+
252+ it ( "should re-enable ruleA when using description in enable comment" , function ( ) {
253+ const textlint = new TextLintCore ( ) ;
254+ textlint . setupRules ( {
255+ ruleA : reportRule
256+ } , {
257+ ruleA : {
258+ nodeTypes : [ ASTNodeTypes . Str ]
259+ }
260+ } ) ;
261+
262+ textlint . setupFilterRules ( {
263+ filter : filterRule
264+ } ) ;
265+ return textlint . lintMarkdown ( `
266+ <!-- textlint-disable ruleA -->
267+
268+ This is text.
269+
270+ <!-- textlint-enable ruleA -- done -->
271+
272+ This is Error.
273+ ` ) . then ( ( { messages } ) => {
274+ assert . equal ( messages . length , 1 ) ;
275+ } ) ;
276+ } ) ;
277+
278+ it ( "should re-enable all when using description without rule ids in enable comment" , function ( ) {
279+ const textlint = new TextLintCore ( ) ;
280+ textlint . setupRules ( {
281+ report : reportRule
282+ } , {
283+ report : {
284+ nodeTypes : [ ASTNodeTypes . Str ]
285+ }
286+ } ) ;
287+
288+ textlint . setupFilterRules ( {
289+ filter : filterRule
290+ } ) ;
291+ return textlint . lintMarkdown ( `
292+ <!-- textlint-disable -->
293+
294+ This is text.
295+
296+ <!-- textlint-enable -- done -->
297+
298+ This is Error.
299+ ` ) . then ( ( { messages } ) => {
300+ assert . equal ( messages . length , 1 ) ;
301+ } ) ;
302+ } ) ;
303+ } ) ;
304+
305+ context ( "edge cases for comment descriptions with --" , function ( ) {
306+ it ( "should ignore messages when `--` appears before directive" , function ( ) {
307+ const textlint = new TextLintCore ( ) ;
308+ textlint . setupRules ( {
309+ ruleA : reportRule ,
310+ ruleB : reportRule
311+ } , {
312+ ruleA : {
313+ nodeTypes : [ ASTNodeTypes . Str ]
314+ } ,
315+ ruleB : {
316+ nodeTypes : [ ASTNodeTypes . Str ]
317+ }
318+ } ) ;
319+
320+ textlint . setupFilterRules ( {
321+ filter : filterRule
322+ } ) ;
323+ return textlint . lintMarkdown ( `
324+ <!-- -- textlint-disable ruleA -->
325+
326+ This is text.
327+
328+ <!-- textlint-enable -->
329+ ` ) . then ( ( { messages } ) => {
330+ assert . equal ( messages . length , 0 ) ;
331+ } ) ;
332+ } ) ;
333+
334+ it ( "should ignore messages when '---' follows directive" , function ( ) {
335+ const textlint = new TextLintCore ( ) ;
336+ textlint . setupRules ( {
337+ ruleA : reportRule ,
338+ ruleB : reportRule
339+ } , {
340+ ruleA : {
341+ nodeTypes : [ ASTNodeTypes . Str ]
342+ } ,
343+ ruleB : {
344+ nodeTypes : [ ASTNodeTypes . Str ]
345+ }
346+ } ) ;
347+
348+ textlint . setupFilterRules ( {
349+ filter : filterRule
350+ } ) ;
351+ return textlint . lintMarkdown ( `
352+ <!-- textlint-disable --- reason -->
353+
354+ This is text.
355+
356+ <!-- textlint-enable -->
357+ ` ) . then ( ( { messages } ) => {
358+ assert . equal ( messages . length , 0 ) ;
359+ } ) ;
360+ } ) ;
361+
362+ it ( "should ignore messages when '----' follows a rule id" , function ( ) {
363+ const textlint = new TextLintCore ( ) ;
364+ textlint . setupRules ( {
365+ ruleA : reportRule ,
366+ ruleB : reportRule
367+ } , {
368+ ruleA : {
369+ nodeTypes : [ ASTNodeTypes . Str ]
370+ } ,
371+ ruleB : {
372+ nodeTypes : [ ASTNodeTypes . Str ]
373+ }
374+ } ) ;
375+
376+ textlint . setupFilterRules ( {
377+ filter : filterRule
378+ } ) ;
379+ return textlint . lintMarkdown ( `
380+ <!-- textlint-disable ruleA ---- reason -->
381+
382+ This is text.
383+
384+ <!-- textlint-enable -->
385+ ` ) . then ( ( { messages } ) => {
386+ assert . equal ( messages . length , 0 ) ;
387+ } ) ;
388+ } ) ;
389+
390+ it ( "should ignore messages when multiple '--' are present" , function ( ) {
391+ const textlint = new TextLintCore ( ) ;
392+ textlint . setupRules ( {
393+ ruleA : reportRule ,
394+ ruleB : reportRule
395+ } , {
396+ ruleA : {
397+ nodeTypes : [ ASTNodeTypes . Str ]
398+ } ,
399+ ruleB : {
400+ nodeTypes : [ ASTNodeTypes . Str ]
401+ }
402+ } ) ;
403+
404+ textlint . setupFilterRules ( {
405+ filter : filterRule
406+ } ) ;
407+ return textlint . lintMarkdown ( `
408+ <!-- textlint-disable ruleA -- reason -- extra -->
409+
410+ This is text.
411+
412+ <!-- textlint-enable -->
413+ ` ) . then ( ( { messages } ) => {
414+ assert . equal ( messages . length , 0 ) ;
415+ } ) ;
416+ } ) ;
417+ } ) ;
198418 } ) ;
199419} ) ;
0 commit comments