Skip to content

Commit

Permalink
add BaseAnalyzerArguments to keep ctor changes sane
Browse files Browse the repository at this point in the history
also immediately makes tokens a part of it

This struct can for example precompute token indices for line endings
  • Loading branch information
WebFreak001 committed Oct 25, 2023
1 parent 1e8f1ec commit 704aa8a
Show file tree
Hide file tree
Showing 57 changed files with 268 additions and 240 deletions.
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

0 comments on commit 704aa8a

Please sign in to comment.