11module dscanner.analysis.base ;
22
3- import dscanner.analysis.nolint;
43import dparse.ast;
54import dparse.lexer : IdType, str, Token , tok;
5+ import dscanner.analysis.nolint;
66import dsymbol.scope_ : Scope;
77import std.array ;
88import std.container ;
@@ -413,8 +413,9 @@ public:
413413 */
414414 override void visit (const (ModuleDeclaration) moduleDeclaration)
415415 {
416- if (stopLinting(moduleDeclaration))
417- return ;
416+ auto currNoLint = NoLintFactory.fromModuleDeclaration(moduleDeclaration);
417+ noLint.push(currNoLint);
418+ scope (exit) noLint.pop(currNoLint);
418419
419420 moduleDeclaration.accept(this );
420421 }
@@ -426,12 +427,11 @@ public:
426427 */
427428 override void visit (const (Declaration) decl)
428429 {
429- const msgDisabled = maybeDisableErrorMessage(decl);
430+ auto currNoLint = NoLintFactory.fromDeclaration(decl);
431+ noLint.push(currNoLint);
432+ scope (exit) noLint.pop(currNoLint);
430433
431434 decl.accept(this );
432-
433- if (msgDisabled)
434- reenableErrorMessage();
435435 }
436436
437437 AutoFix.CodeReplacement[] resolveAutoFix (
@@ -452,7 +452,7 @@ protected:
452452
453453 bool inAggregate;
454454 bool skipTests;
455- int errorMsgDisabled ;
455+ NoLint noLint ;
456456
457457 template visitTemplate (T)
458458 {
@@ -467,100 +467,61 @@ protected:
467467 deprecated (" Use the overload taking start and end locations or a Node instead" )
468468 void addErrorMessage (size_t line, size_t column, string key, string message)
469469 {
470- if (! errorMsgEnabled( ))
470+ if (noLint.containsCheck( this .getName() ))
471471 return ;
472472 _messages.insert(Message(fileName, line, column, key, message, getName()));
473473 }
474474
475475 void addErrorMessage (const BaseNode node, string key, string message, AutoFix[] autofixes = null )
476476 {
477- if (! errorMsgEnabled( ))
477+ if (noLint.containsCheck( this .getName() ))
478478 return ;
479479 addErrorMessage(Message.Diagnostic.from(fileName, node, message), key, autofixes);
480480 }
481481
482482 void addErrorMessage (const Token token, string key, string message, AutoFix[] autofixes = null )
483483 {
484- if (! errorMsgEnabled( ))
484+ if (noLint.containsCheck( this .getName() ))
485485 return ;
486486 addErrorMessage(Message.Diagnostic.from(fileName, token, message), key, autofixes);
487487 }
488488
489489 void addErrorMessage (const Token [] tokens, string key, string message, AutoFix[] autofixes = null )
490490 {
491- if (! errorMsgEnabled( ))
491+ if (noLint.containsCheck( this .getName() ))
492492 return ;
493493 addErrorMessage(Message.Diagnostic.from(fileName, tokens, message), key, autofixes);
494494 }
495495
496496 void addErrorMessage (size_t [2 ] index, size_t line, size_t [2 ] columns, string key, string message, AutoFix[] autofixes = null )
497497 {
498- if (! errorMsgEnabled( ))
498+ if (noLint.containsCheck( this .getName() ))
499499 return ;
500500 addErrorMessage(index, [line, line], columns, key, message, autofixes);
501501 }
502502
503503 void addErrorMessage (size_t [2 ] index, size_t [2 ] lines, size_t [2 ] columns, string key, string message, AutoFix[] autofixes = null )
504504 {
505- if (! errorMsgEnabled( ))
505+ if (noLint.containsCheck( this .getName() ))
506506 return ;
507507 auto d = Message.Diagnostic.from(fileName, index, lines, columns, message);
508508 _messages.insert(Message(d, key, getName(), autofixes));
509509 }
510510
511511 void addErrorMessage (Message.Diagnostic diagnostic, string key, AutoFix[] autofixes = null )
512512 {
513- if (! errorMsgEnabled( ))
513+ if (noLint.containsCheck( this .getName() ))
514514 return ;
515515 _messages.insert(Message(diagnostic, key, getName(), autofixes));
516516 }
517517
518518 void addErrorMessage (Message.Diagnostic diagnostic, Message.Diagnostic[] supplemental, string key, AutoFix[] autofixes = null )
519519 {
520- if (! errorMsgEnabled( ))
520+ if (noLint.containsCheck( this .getName() ))
521521 return ;
522522 _messages.insert(Message(diagnostic, supplemental, key, getName(), autofixes));
523523 }
524524
525- void reenableErrorMessage ()
526- in (this .errorMsgDisabled > 0 )
527- {
528- this .errorMsgDisabled-- ;
529- }
530-
531- bool errorMsgEnabled () const
532- {
533- return this .errorMsgDisabled == 0 ;
534- }
535-
536- // Disable error message if declaration contains UDA :
537- // @("nolint(..)") and @nolint(".."), ..
538- // that indicates to skip linting on this declaration
539- // Return wheter the message is actually disabled or not
540- bool maybeDisableErrorMessage (const Declaration decl)
541- {
542- if (stopLinting(decl))
543- {
544- this .errorMsgDisabled++ ;
545- return true ;
546- }
547- else
548- return false ;
549- }
550-
551- bool stopLinting (AstNode)(const AstNode node)
552- {
553- import std.typecons : Nullable;
554- Nullable! NoLint noLint;
555-
556- static if (is (AstNode == ModuleDeclaration))
557- noLint = NoLintFactory.fromModuleDeclaration(node);
558- else static if (is (AstNode == Declaration))
559- noLint = NoLintFactory.fromDeclaration(node);
560-
561- return ! noLint.isNull && noLint.get .containsCheck(this .getName());
562- }
563-
564525 /**
565526 * The file name
566527 */
0 commit comments