Skip to content

Commit e294481

Browse files
committed
UDA to disable linting: cleaning
1 parent e5a816e commit e294481

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

src/dscanner/analysis/base.d

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,14 @@ public:
422422
/**
423423
* Visits a declaration.
424424
*
425-
* When overriden, make sure to disable and reenable error messages
425+
* When overriden, make sure to keep this structure
426426
*/
427427
override void visit(const(Declaration) decl)
428428
{
429-
const msgDisabled = maybeDisableErrorMessage(decl);
429+
if(stopLinting(decl))
430+
return;
430431

431432
decl.accept(this);
432-
433-
if(msgDisabled)
434-
reenableErrorMessage();
435433
}
436434

437435
AutoFix.CodeReplacement[] resolveAutoFix(
@@ -452,7 +450,6 @@ protected:
452450

453451
bool inAggregate;
454452
bool skipTests;
455-
int errorMsgDisabled;
456453

457454
template visitTemplate(T)
458455
{
@@ -467,87 +464,45 @@ protected:
467464
deprecated("Use the overload taking start and end locations or a Node instead")
468465
void addErrorMessage(size_t line, size_t column, string key, string message)
469466
{
470-
if(!errorMsgEnabled())
471-
return;
472467
_messages.insert(Message(fileName, line, column, key, message, getName()));
473468
}
474469

475470
void addErrorMessage(const BaseNode node, string key, string message, AutoFix[] autofixes = null)
476471
{
477-
if(!errorMsgEnabled())
478-
return;
479472
addErrorMessage(Message.Diagnostic.from(fileName, node, message), key, autofixes);
480473
}
481474

482475
void addErrorMessage(const Token token, string key, string message, AutoFix[] autofixes = null)
483476
{
484-
if(!errorMsgEnabled())
485-
return;
486477
addErrorMessage(Message.Diagnostic.from(fileName, token, message), key, autofixes);
487478
}
488479

489480
void addErrorMessage(const Token[] tokens, string key, string message, AutoFix[] autofixes = null)
490481
{
491-
if(!errorMsgEnabled())
492-
return;
493482
addErrorMessage(Message.Diagnostic.from(fileName, tokens, message), key, autofixes);
494483
}
495484

496485
void addErrorMessage(size_t[2] index, size_t line, size_t[2] columns, string key, string message, AutoFix[] autofixes = null)
497486
{
498-
if(!errorMsgEnabled())
499-
return;
500487
addErrorMessage(index, [line, line], columns, key, message, autofixes);
501488
}
502489

503490
void addErrorMessage(size_t[2] index, size_t[2] lines, size_t[2] columns, string key, string message, AutoFix[] autofixes = null)
504491
{
505-
if(!errorMsgEnabled())
506-
return;
507492
auto d = Message.Diagnostic.from(fileName, index, lines, columns, message);
508493
_messages.insert(Message(d, key, getName(), autofixes));
509494
}
510495

511496
void addErrorMessage(Message.Diagnostic diagnostic, string key, AutoFix[] autofixes = null)
512497
{
513-
if(!errorMsgEnabled())
514-
return;
515498
_messages.insert(Message(diagnostic, key, getName(), autofixes));
516499
}
517500

518501
void addErrorMessage(Message.Diagnostic diagnostic, Message.Diagnostic[] supplemental, string key, AutoFix[] autofixes = null)
519502
{
520-
if(!errorMsgEnabled())
521-
return;
522503
_messages.insert(Message(diagnostic, supplemental, key, getName(), autofixes));
523504
}
524505

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-
551506
bool stopLinting(AstNode)(const AstNode node)
552507
{
553508
import std.typecons: Nullable;

src/dscanner/analysis/useless_initializer.d

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@ public:
9191

9292
override void visit(const(Declaration) decl)
9393
{
94-
_inStruct.insert(decl.structDeclaration !is null);
94+
if(stopLinting(decl))
95+
return;
9596

96-
const msgDisabled = maybeDisableErrorMessage(decl);
97+
_inStruct.insert(decl.structDeclaration !is null);
9798

9899
decl.accept(this);
99100

100-
if(msgDisabled)
101-
reenableErrorMessage();
102-
103101
if (_inStruct.length > 1 && _inStruct[$-2] && decl.constructor &&
104102
((decl.constructor.parameters && decl.constructor.parameters.parameters.length == 0) ||
105103
!decl.constructor.parameters))

0 commit comments

Comments
 (0)