Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BaseAnalyzerArguments to keep ctor changes sane #939

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dscanner/analysis/alias_syntax_check.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ final class AliasSyntaxCheck : BaseAnalyzer

mixin AnalyzerInfo!"alias_syntax_check";

this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

override void visit(const AliasDeclaration ad)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/allman.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ final class AllManCheck : BaseAnalyzer
mixin AnalyzerInfo!"allman_braces_check";

///
this(string fileName, const(Token)[] tokens, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
foreach (i; 1 .. tokens.length - 1)
{
const curLine = tokens[i].line;
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/always_curly.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ final class AlwaysCurlyCheck : BaseAnalyzer
alias visit = BaseAnalyzer.visit;

///
this(string fileName, const(Token)[] tokens, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

void test(L, B)(L loc, B s, string stmtKind)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/asm_style.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ final class AsmStyleCheck : BaseAnalyzer

mixin AnalyzerInfo!"asm_style_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const AsmBrExp brExp)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/assert_without_msg.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ final class AssertWithoutMessageCheck : BaseAnalyzer
mixin AnalyzerInfo!"assert_without_msg";

///
this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const AssertExpression expr)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/auto_function.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public:
mixin AnalyzerInfo!"auto_function_check";

///
this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

package static const(Token)[] findAutoReturnType(const(FunctionDeclaration) decl)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/auto_ref_assignment.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ final class AutoRefAssignmentCheck : BaseAnalyzer
mixin AnalyzerInfo!"auto_ref_assignment_check";

///
this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

override void visit(const Module m)
Expand Down
40 changes: 34 additions & 6 deletions src/dscanner/analysis/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,41 @@ mixin template AnalyzerInfo(string checkName)
}
}

struct BaseAnalyzerArguments
{
string fileName;
const(Token)[] tokens;
const Scope* sc;
bool skipTests = false;

BaseAnalyzerArguments setSkipTests(bool v)
{
auto ret = this;
ret.skipTests = v;
return ret;
}
}

abstract class BaseAnalyzer : ASTVisitor
{
public:
deprecated("Don't use this constructor, use the one taking BaseAnalyzerArguments")
this(string fileName, const Scope* sc, bool skipTests = false)
{
this.sc = sc;
this.fileName = fileName;
this.skipTests = skipTests;
BaseAnalyzerArguments args = {
fileName: fileName,
sc: sc,
skipTests: skipTests
};
this(args);
}

this(BaseAnalyzerArguments args)
{
this.sc = args.sc;
this.tokens = args.tokens;
this.fileName = args.fileName;
this.skipTests = args.skipTests;
_messages = new MessageSet;
}

Expand Down Expand Up @@ -453,6 +480,7 @@ protected:

bool inAggregate;
bool skipTests;
const(Token)[] tokens;
NoLint noLint;

template visitTemplate(T)
Expand Down Expand Up @@ -550,9 +578,9 @@ const(Token)[] findTokenForDisplay(const Token[] tokens, IdType type, const(Toke
abstract class ScopedBaseAnalyzer : BaseAnalyzer
{
public:
this(string fileName, const Scope* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}


Expand Down Expand Up @@ -698,7 +726,7 @@ unittest
{
this(size_t codeLine)
{
super("stdin", null, false);
super(BaseAnalyzerArguments("stdin"));

this.codeLine = codeLine;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/body_on_disabled_funcs.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ final class BodyOnDisabledFuncsCheck : BaseAnalyzer

mixin AnalyzerInfo!"body_on_disabled_func_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

static foreach (AggregateType; AliasSeq!(InterfaceDeclaration, ClassDeclaration,
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/builtin_property_names.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ final class BuiltinPropertyNameCheck : BaseAnalyzer

mixin AnalyzerInfo!"builtin_property_names_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const FunctionDeclaration fd)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/comma_expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class CommaExpressionCheck : BaseAnalyzer

mixin AnalyzerInfo!"comma_expression_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const Expression ex)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/constructors.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ final class ConstructorCheck : BaseAnalyzer

mixin AnalyzerInfo!"constructor_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const ClassDeclaration classDeclaration)
Expand Down
5 changes: 2 additions & 3 deletions src/dscanner/analysis/cyclomatic_complexity.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ final class CyclomaticComplexityCheck : BaseAnalyzer
int maxCyclomaticComplexity;

///
this(string fileName, const(Scope)* sc, bool skipTests = false,
int maxCyclomaticComplexity = 50)
this(BaseAnalyzerArguments args, int maxCyclomaticComplexity = 50)
{
super(fileName, sc, skipTests);
super(args);
this.maxCyclomaticComplexity = maxCyclomaticComplexity;
}

Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/del.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class DeleteCheck : BaseAnalyzer

mixin AnalyzerInfo!"delete_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const DeleteExpression d)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/duplicate_attribute.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ final class DuplicateAttributeCheck : BaseAnalyzer

mixin AnalyzerInfo!"duplicate_attribute";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const Declaration node)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/enumarrayliteral.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ final class EnumArrayLiteralCheck : BaseAnalyzer

mixin AnalyzerInfo!"enum_array_literal_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

bool looking;
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/explicitly_annotated_unittests.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class ExplicitlyAnnotatedUnittestCheck : BaseAnalyzer
mixin AnalyzerInfo!"explicitly_annotated_unittests";

///
this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

override void visit(const Declaration decl)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/final_attribute.d
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public:
};

///
this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

override void visit(const(StructDeclaration) sd)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/fish.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ final class FloatOperatorCheck : BaseAnalyzer
enum string KEY = "dscanner.deprecated.floating_point_operators";
mixin AnalyzerInfo!"float_operator_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const RelExpression r)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/function_attributes.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ final class FunctionAttributeCheck : BaseAnalyzer

mixin AnalyzerInfo!"function_attribute_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const InterfaceDeclaration dec)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/has_public_example.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ final class HasPublicExampleCheck : BaseAnalyzer

mixin AnalyzerInfo!"has_public_example";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const Module mod)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/if_constraints_indent.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class IfConstraintsIndentCheck : BaseAnalyzer
mixin AnalyzerInfo!"if_constraints_indent";

///
this(string fileName, const(Token)[] tokens, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);

// convert tokens to a list of token starting positions per line

Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/if_statements.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ final class IfStatementCheck : BaseAnalyzer
alias visit = BaseAnalyzer.visit;
mixin AnalyzerInfo!"redundant_if_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const IfStatement ifStatement)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/ifelsesame.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class IfElseSameCheck : BaseAnalyzer

mixin AnalyzerInfo!"if_else_same_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

override void visit(const IfStatement ifStatement)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/imports_sortedness.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class ImportSortednessCheck : BaseAnalyzer
mixin AnalyzerInfo!"imports_sortedness";

///
this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

mixin ScopedVisit!Module;
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/incorrect_infinite_range.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ final class IncorrectInfiniteRangeCheck : BaseAnalyzer
mixin AnalyzerInfo!"incorrect_infinite_range_check";

///
this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

override void visit(const StructBody structBody)
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/label_var_same_name_check.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ final class LabelVarNameCheck : ScopedBaseAnalyzer
{
mixin AnalyzerInfo!"label_var_same_name_check";

this(string fileName, const(Scope)* sc, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, sc, skipTests);
super(args);
}

mixin AggregateVisit!ClassDeclaration;
Expand Down
4 changes: 2 additions & 2 deletions src/dscanner/analysis/lambda_return_check.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ final class LambdaReturnCheck : BaseAnalyzer

mixin AnalyzerInfo!"lambda_return_check";

this(string fileName, bool skipTests = false)
this(BaseAnalyzerArguments args)
{
super(fileName, null, skipTests);
super(args);
}

override void visit(const FunctionLiteralExpression fLit)
Expand Down
Loading
Loading