Skip to content

Commit 17f3286

Browse files
kubo39WebFreak001
authored andcommitted
Clearify key names
1 parent 433d1eb commit 17f3286

16 files changed

+62
-26
lines changed

src/dscanner/analysis/asm_style.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ final class AsmStyleCheck : BaseAnalyzer
3232
if (brExp.asmBrExp !is null && brExp.asmBrExp.asmUnaExp !is null
3333
&& brExp.asmBrExp.asmUnaExp.asmPrimaryExp !is null)
3434
{
35-
addErrorMessage(brExp, "dscanner.confusing.brexp",
35+
addErrorMessage(brExp, KEY,
3636
"This is confusing because it looks like an array index. Rewrite a[1] as [a + 1] to clarify.");
3737
}
3838
brExp.accept(this);
3939
}
40+
41+
private enum string KEY = "dscanner.confusing.brexp";
4042
}
4143

4244
unittest

src/dscanner/analysis/del.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ final class DeleteCheck : BaseAnalyzer
2727

2828
override void visit(const DeleteExpression d)
2929
{
30-
addErrorMessage(d.tokens[0], "dscanner.deprecated.delete_keyword",
30+
addErrorMessage(d.tokens[0], KEY,
3131
"Avoid using the 'delete' keyword.",
3232
[AutoFix.replacement(d.tokens[0], `destroy(`, "Replace delete with destroy()")
3333
.concat(AutoFix.insertionAfter(d.tokens[$ - 1], ")"))]);
3434
d.accept(this);
3535
}
36+
37+
private enum string KEY = "dscanner.deprecated.delete_keyword";
3638
}
3739

3840
unittest

src/dscanner/analysis/duplicate_attribute.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ final class DuplicateAttributeCheck : BaseAnalyzer
9393
if (hasAttribute)
9494
{
9595
string message = "Attribute '%s' is duplicated.".format(attributeName);
96-
addErrorMessage(tokens, "dscanner.unnecessary.duplicate_attribute", message,
96+
addErrorMessage(tokens, KEY, message,
9797
[AutoFix.replacement(tokens, "", "Remove second attribute " ~ attributeName)]);
9898
}
9999

@@ -149,6 +149,8 @@ final class DuplicateAttributeCheck : BaseAnalyzer
149149

150150
return null;
151151
}
152+
153+
private enum string KEY = "dscanner.unnecessary.duplicate_attribute";
152154
}
153155

154156
unittest

src/dscanner/analysis/enumarrayliteral.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class EnumArrayLiteralCheck : BaseAnalyzer
4747
if (part.initializer.nonVoidInitializer.arrayInitializer is null)
4848
continue;
4949
addErrorMessage(part.initializer.nonVoidInitializer,
50-
"dscanner.performance.enum_array_literal",
50+
KEY,
5151
"This enum may lead to unnecessary allocation at run-time."
5252
~ " Use 'static immutable "
5353
~ part.identifier.text ~ " = [ ...' instead.",
@@ -58,6 +58,8 @@ final class EnumArrayLiteralCheck : BaseAnalyzer
5858
}
5959
autoDec.accept(this);
6060
}
61+
62+
private enum string KEY = "dscanner.performance.enum_array_literal";
6163
}
6264

6365
unittest

src/dscanner/analysis/has_public_example.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ final class HasPublicExampleCheck : BaseAnalyzer
8888

8989
private:
9090

91+
enum string KEY = "dscanner.style.has_public_example";
92+
9193
bool hasDitto(Decl)(const Decl decl)
9294
{
9395
import ddoc.comments : parseComment;
@@ -164,7 +166,7 @@ private:
164166
{
165167
import std.string : format;
166168

167-
addErrorMessage(tokens, "dscanner.style.has_public_example", name is null
169+
addErrorMessage(tokens, KEY, name is null
168170
? "Public declaration has no documented example."
169171
: format("Public declaration '%s' has no documented example.", name));
170172
}

src/dscanner/analysis/ifelsesame.d

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class IfElseSameCheck : BaseAnalyzer
3939
// extend 1 past, so we include the `else` token
4040
tokens = (tokens.ptr - 1)[0 .. tokens.length + 1];
4141
addErrorMessage(tokens,
42-
"dscanner.bugs.if_else_same", "'Else' branch is identical to 'Then' branch.");
42+
IF_ELSE_SAME_KEY, "'Else' branch is identical to 'Then' branch.");
4343
}
4444
ifStatement.accept(this);
4545
}
@@ -50,7 +50,7 @@ final class IfElseSameCheck : BaseAnalyzer
5050
if (e !is null && assignExpression.operator == tok!"="
5151
&& e.ternaryExpression == assignExpression.ternaryExpression)
5252
{
53-
addErrorMessage(assignExpression, "dscanner.bugs.self_assignment",
53+
addErrorMessage(assignExpression, SELF_ASSIGNMENT_KEY,
5454
"Left side of assignment operatior is identical to the right side.");
5555
}
5656
assignExpression.accept(this);
@@ -62,7 +62,7 @@ final class IfElseSameCheck : BaseAnalyzer
6262
&& andAndExpression.left == andAndExpression.right)
6363
{
6464
addErrorMessage(andAndExpression.right,
65-
"dscanner.bugs.logic_operator_operands",
65+
LOGIC_OPERATOR_OPERANDS_KEY,
6666
"Left side of logical and is identical to right side.");
6767
}
6868
andAndExpression.accept(this);
@@ -74,11 +74,17 @@ final class IfElseSameCheck : BaseAnalyzer
7474
&& orOrExpression.left == orOrExpression.right)
7575
{
7676
addErrorMessage(orOrExpression.right,
77-
"dscanner.bugs.logic_operator_operands",
77+
LOGIC_OPERATOR_OPERANDS_KEY,
7878
"Left side of logical or is identical to right side.");
7979
}
8080
orOrExpression.accept(this);
8181
}
82+
83+
private:
84+
85+
enum string IF_ELSE_SAME_KEY = "dscanner.bugs.if_else_same";
86+
enum string SELF_ASSIGNMENT_KEY = "dscanner.bugs.self_assignment";
87+
enum string LOGIC_OPERATOR_OPERANDS_KEY = "dscanner.bugs.logic_operator_operands";
8288
}
8389

8490
unittest

src/dscanner/analysis/label_var_same_name_check.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ final class LabelVarNameCheck : ScopedBaseAnalyzer
6060

6161
private:
6262

63+
enum string KEY = "dscanner.suspicious.label_var_same_name";
64+
6365
Thing[string][] stack;
6466

6567
template AggregateVisit(NodeType)
@@ -88,7 +90,7 @@ private:
8890
{
8991
immutable thisKind = fromLabel ? "Label" : "Variable";
9092
immutable otherKind = thing.isVar ? "variable" : "label";
91-
addErrorMessage(name, "dscanner.suspicious.label_var_same_name",
93+
addErrorMessage(name, KEY,
9294
thisKind ~ " \"" ~ fqn ~ "\" has the same name as a "
9395
~ otherKind ~ " defined on line " ~ to!string(thing.line) ~ ".");
9496
}

src/dscanner/analysis/length_subtraction.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import dsymbol.scope_;
1818
*/
1919
final class LengthSubtractionCheck : BaseAnalyzer
2020
{
21+
private enum string KEY = "dscanner.suspicious.length_subtraction";
22+
2123
alias visit = BaseAnalyzer.visit;
2224

2325
mixin AnalyzerInfo!"length_subtraction_check";
@@ -40,7 +42,7 @@ final class LengthSubtractionCheck : BaseAnalyzer
4042
if (l.identifierOrTemplateInstance is null
4143
|| l.identifierOrTemplateInstance.identifier.text != "length")
4244
goto end;
43-
addErrorMessage(addExpression, "dscanner.suspicious.length_subtraction",
45+
addErrorMessage(addExpression, KEY,
4446
"Avoid subtracting from '.length' as it may be unsigned.",
4547
[
4648
AutoFix.insertionBefore(l.tokens[0], "cast(ptrdiff_t) ", "Cast to ptrdiff_t")

src/dscanner/analysis/local_imports.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class LocalImportCheck : BaseAnalyzer
5959
if (singleImport.rename.text.length == 0)
6060
{
6161
addErrorMessage(singleImport,
62-
"dscanner.suspicious.local_imports", "Local imports should specify"
62+
KEY, "Local imports should specify"
6363
~ " the symbols being imported to avoid hiding local symbols.");
6464
}
6565
}
@@ -68,6 +68,8 @@ final class LocalImportCheck : BaseAnalyzer
6868

6969
private:
7070

71+
enum string KEY = "dscanner.suspicious.local_imports";
72+
7173
mixin template visitThing(T)
7274
{
7375
override void visit(const T thing)

src/dscanner/analysis/numbers.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ public:
3939
&& ((t.text.startsWith("0b") && !t.text.matchFirst(badBinaryRegex)
4040
.empty) || !t.text.matchFirst(badDecimalRegex).empty))
4141
{
42-
addErrorMessage(t, "dscanner.style.number_literals",
42+
addErrorMessage(t, KEY,
4343
"Use underscores to improve number constant readability.");
4444
}
4545
}
4646

4747
private:
48+
49+
enum string KEY = "dscanner.style.number_literals";
50+
4851
auto badBinaryRegex = ctRegex!(`^0b[01]{9,}`);
4952
auto badDecimalRegex = ctRegex!(`^\d{5,}`);
5053
}

src/dscanner/analysis/objectconst.d

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ final class ObjectConstCheck : BaseAnalyzer
6868
if (inAggregate && !constColon && !constBlock && !isDeclationDisabled
6969
&& isInteresting(fd.name.text) && !hasConst(fd.memberFunctionAttributes))
7070
{
71-
addErrorMessage(d.functionDeclaration.name, "dscanner.suspicious.object_const",
71+
addErrorMessage(d.functionDeclaration.name, KEY,
7272
"Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.");
7373
}
7474
}
@@ -81,23 +81,26 @@ final class ObjectConstCheck : BaseAnalyzer
8181
constBlock = false;
8282
}
8383

84-
private static bool hasConst(const MemberFunctionAttribute[] attributes)
84+
private:
85+
86+
enum string KEY = "dscanner.suspicious.object_const";
87+
88+
static bool hasConst(const MemberFunctionAttribute[] attributes)
8589
{
8690
import std.algorithm : any;
8791

8892
return attributes.any!(a => a.tokenType == tok!"const"
8993
|| a.tokenType == tok!"immutable" || a.tokenType == tok!"inout");
9094
}
9195

92-
private static bool isInteresting(string name)
96+
static bool isInteresting(string name)
9397
{
9498
return name == "opCmp" || name == "toHash" || name == "opEquals"
9599
|| name == "toString" || name == "opCast";
96100
}
97101

98-
private bool constBlock;
99-
private bool constColon;
100-
102+
bool constBlock;
103+
bool constColon;
101104
}
102105

103106
unittest

src/dscanner/analysis/redundant_storage_class.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ final class RedundantStorageClassCheck : BaseAnalyzer
5959
return;
6060
auto t = vd.declarators[0].name;
6161
string message = REDUNDANT_VARIABLE_ATTRIBUTES.format(t.text, globalAttributes);
62-
addErrorMessage(t, "dscanner.unnecessary.duplicate_attribute", message);
62+
addErrorMessage(t, KEY, message);
6363
}
6464
}
65+
66+
private enum string KEY = "dscanner.unnecessary.duplicate_attribute";
6567
}
6668

6769
unittest

src/dscanner/analysis/undocumented.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ final class UndocumentedDeclarationCheck : BaseAnalyzer
146146

147147
private:
148148

149+
enum string KEY = "dscanner.style.undocumented_declaration";
150+
149151
mixin template V(T)
150152
{
151153
override void visit(const T declaration)
@@ -223,7 +225,7 @@ private:
223225
{
224226
import std.string : format;
225227

226-
addErrorMessage(range, "dscanner.style.undocumented_declaration", name is null
228+
addErrorMessage(range, KEY, name is null
227229
? "Public declaration is undocumented."
228230
: format("Public declaration '%s' is undocumented.", name));
229231
}

src/dscanner/analysis/unmodified.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ final class UnmodifiedFinder : BaseAnalyzer
189189

190190
private:
191191

192+
enum string KEY = "dscanner.suspicious.unmodified";
193+
192194
template PartsMightModify(T)
193195
{
194196
override void visit(const T t)
@@ -300,7 +302,7 @@ private:
300302
{
301303
immutable string errorMessage = "Variable " ~ vi.name
302304
~ " is never modified and could have been declared const or immutable.";
303-
addErrorMessage(vi.token, "dscanner.suspicious.unmodified", errorMessage);
305+
addErrorMessage(vi.token, KEY, errorMessage);
304306
}
305307
tree = tree[0 .. $ - 1];
306308
}

src/dscanner/analysis/unused_label.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ final class UnusedLabelCheck : BaseAnalyzer
115115

116116
private:
117117

118+
enum string KEY = "dscanner.suspicious.unused_label";
119+
118120
static struct Label
119121
{
120122
string name;
@@ -144,7 +146,7 @@ private:
144146
}
145147
else if (!label.used)
146148
{
147-
addErrorMessage(label.token, "dscanner.suspicious.unused_label",
149+
addErrorMessage(label.token, KEY,
148150
"Label \"" ~ label.name ~ "\" is not used.");
149151
}
150152
}

src/dscanner/analysis/useless_initializer.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class UselessInitializerChecker : BaseAnalyzer
3434

3535
private:
3636

37-
enum key = "dscanner.useless-initializer";
37+
enum string KEY = "dscanner.useless-initializer";
3838

3939
version(unittest)
4040
{
@@ -161,15 +161,15 @@ public:
161161
{
162162
void warn(const BaseNode range)
163163
{
164-
addErrorMessage(range, key, msg);
164+
addErrorMessage(range, KEY, msg);
165165
}
166166
}
167167
else
168168
{
169169
import std.format : format;
170170
void warn(const BaseNode range)
171171
{
172-
addErrorMessage(range, key, msg.format(declarator.name.text));
172+
addErrorMessage(range, KEY, msg.format(declarator.name.text));
173173
}
174174
}
175175

0 commit comments

Comments
 (0)