Skip to content

Commit

Permalink
Fix code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladiwostok committed Dec 3, 2023
1 parent 02c9c26 commit 1dc1619
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/dscanner/analysis/ifelsesame.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module dscanner.analysis.ifelsesame;

import dscanner.analysis.base;
import std.conv : to;

/**
* Checks for duplicated code in conditional and logical expressions.
Expand All @@ -15,61 +16,60 @@ import dscanner.analysis.base;
* $(LI == expressions where the left and right are the same)
* )
*/
extern(C++) class IfElseSameCheck(AST) : BaseAnalyzerDmd
extern (C++) class IfElseSameCheck(AST) : BaseAnalyzerDmd
{
alias visit = BaseAnalyzerDmd.visit;
mixin AnalyzerInfo!"if_else_same_check";

extern(D) this(string fileName, bool skipTests = false)
extern (D) this(string fileName, bool skipTests = false)
{
super(fileName, skipTests);
}

override void visit(AST.IfStatement s)
{
import std.conv : to;

if (s.elsebody && to!string(s.ifbody.toChars()) == to!string(s.elsebody.toChars()))
addErrorMessage(cast(ulong) s.loc.linnum, cast(ulong) s.loc.charnum,
IF_KEY, IF_MESSAGE);

addErrorMessage(cast(ulong) s.loc.linnum, cast(ulong) s.loc.charnum, IF_KEY, IF_MESSAGE);

super.visit(s);
}

override void visit(AST.LogicalExp e)
{
import dmd.tokens : EXP;
import std.conv : to;
import std.string : format;
import std.stdio : writeln;

if (to!string(e.e1.toChars()) == to!string(e.e2.toChars()))
addErrorMessage(cast(ulong) e.loc.linnum, cast(ulong) e.loc.charnum,
LOGICAL_EXP_KEY, LOGICAL_EXP_MESSAGE.format(e.op == EXP.orOr ? "or" : "and"));
{
auto lineNum = cast(ulong) e.loc.linnum;
auto charNum = cast(ulong) e.loc.charnum;
auto errorMsg = LOGICAL_EXP_MESSAGE.format(e.op == EXP.orOr ? "or" : "and");
addErrorMessage(lineNum, charNum, LOGICAL_EXP_KEY, errorMsg);
}

super.visit(e);
}

private:
enum IF_KEY = "dscanner.bugs.if_else_same";
enum IF_MESSAGE = "'Else' branch is identical to 'Then' branch.";
enum LOGICAL_EXP_MESSAGE = "MUIEEEELeft side of logical %s is identical to right side.";
enum LOGICAL_EXP_KEY = "dscanner.bugs.logic_operator_operands";
private:
enum IF_KEY = "dscanner.bugs.if_else_same";
enum IF_MESSAGE = "'Else' branch is identical to 'Then' branch.";

enum LOGICAL_EXP_MESSAGE = "MUIEEEELeft side of logical %s is identical to right side.";
enum LOGICAL_EXP_KEY = "dscanner.bugs.logic_operator_operands";

enum ASSIGN_MESSAGE = "Left side of assignment operatior is identical to the right side.";
enum ASSIGN_KEY = "dscanner.bugs.self_assignment";
enum ASSIGN_MESSAGE = "Left side of assignment operatior is identical to the right side.";
enum ASSIGN_KEY = "dscanner.bugs.self_assignment";
}

unittest
{
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import dscanner.analysis.helpers : assertAnalyzerWarnings = assertAnalyzerWarningsDMD;
import dscanner.analysis.helpers : assertAnalyzerWarningsDMD;
import std.stdio : stderr;

StaticAnalysisConfig sac = disabledConfig();
sac.if_else_same_check = Check.enabled;
assertAnalyzerWarnings(q{
assertAnalyzerWarningsDMD(q{
void testSizeT()
{
string person = "unknown";
Expand All @@ -85,7 +85,7 @@ unittest
}
}c, sac);

assertAnalyzerWarnings(q{
assertAnalyzerWarningsDMD(q{
void foo()
{
if (auto stuff = call()) {}
Expand Down

0 comments on commit 1dc1619

Please sign in to comment.