-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.d
699 lines (572 loc) · 23.9 KB
/
run.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// Copyright Brian Schott (Hackerpilot) 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
module dscanner.analysis.run;
import core.memory : GC;
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.functional : toDelegate;
import std.file : mkdirRecurse;
import std.path : dirName;
import dparse.lexer;
import dparse.parser;
import dparse.ast;
import dparse.rollback_allocator;
import std.typecons : scoped;
import std.experimental.allocator : CAllocatorImpl;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.building_blocks.allocator_list : AllocatorList;
import dscanner.analysis.config;
import dscanner.analysis.base;
import dscanner.analysis.style;
import dscanner.analysis.enumarrayliteral;
import dscanner.analysis.pokemon;
import dscanner.analysis.del;
import dscanner.analysis.fish;
import dscanner.analysis.numbers;
import dscanner.analysis.objectconst;
import dscanner.analysis.range;
import dscanner.analysis.ifelsesame;
import dscanner.analysis.constructors;
import dscanner.analysis.unused_variable;
import dscanner.analysis.unused_label;
import dscanner.analysis.unused_parameter;
import dscanner.analysis.duplicate_attribute;
import dscanner.analysis.opequals_without_tohash;
import dscanner.analysis.length_subtraction;
import dscanner.analysis.builtin_property_names;
import dscanner.analysis.asm_style;
import dscanner.analysis.logic_precedence;
import dscanner.analysis.stats_collector;
import dscanner.analysis.undocumented;
import dscanner.analysis.comma_expression;
import dscanner.analysis.function_attributes;
import dscanner.analysis.local_imports;
import dscanner.analysis.unmodified;
import dscanner.analysis.if_statements;
import dscanner.analysis.redundant_parens;
import dscanner.analysis.mismatched_args;
import dscanner.analysis.label_var_same_name_check;
import dscanner.analysis.line_length;
import dscanner.analysis.auto_ref_assignment;
import dscanner.analysis.incorrect_infinite_range;
import dscanner.analysis.useless_assert;
import dscanner.analysis.alias_syntax_check;
import dscanner.analysis.static_if_else;
import dscanner.analysis.lambda_return_check;
import dscanner.analysis.auto_function;
import dscanner.analysis.imports_sortedness;
import dscanner.analysis.explicitly_annotated_unittests;
import dscanner.analysis.properly_documented_public_functions;
import dscanner.analysis.final_attribute;
import dscanner.analysis.vcall_in_ctor;
import dscanner.analysis.useless_initializer;
import dscanner.analysis.allman;
import dscanner.analysis.redundant_attributes;
import dscanner.analysis.has_public_example;
import dscanner.analysis.assert_without_msg;
import dscanner.analysis.if_constraints_indent;
import dscanner.analysis.trust_too_much;
import dscanner.analysis.redundant_storage_class;
import dscanner.analysis.unused_result;
import dscanner.analysis.cyclomatic_complexity;
import dsymbol.string_interning : internString;
import dsymbol.scope_;
import dsymbol.semantic;
import dsymbol.conversion;
import dsymbol.conversion.first;
import dsymbol.conversion.second;
import dsymbol.modulecache : ModuleCache;
import dscanner.utils;
import dscanner.reports : DScannerJsonReporter, SonarQubeGenericIssueDataReporter;
import dmd.astbase : ASTBase;
import dmd.parse : Parser;
import dmd.frontend;
import dmd.astcodegen;
bool first = true;
version (unittest)
enum ut = true;
else
enum ut = false;
private alias ASTAllocator = CAllocatorImpl!(
AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator));
immutable string defaultErrorFormat = "{filepath}({line}:{column})[{type}]: {message}";
void messageFunctionFormat(string format, Message message, bool isError)
{
auto s = format;
s = s.replace("{filepath}", message.fileName);
s = s.replace("{line}", to!string(message.line));
s = s.replace("{column}", to!string(message.column));
s = s.replace("{type}", isError ? "error" : "warn");
s = s.replace("{message}", message.message);
s = s.replace("{name}", message.checkName);
writefln("%s", s);
}
void messageFunction(Message message, bool isError)
{
messageFunctionFormat(defaultErrorFormat, message, isError);
}
void messageFunctionJSON(string fileName, size_t line, size_t column, string message, bool)
{
writeJSON(Message(fileName, line, column, "dscanner.syntax", message));
}
void writeJSON(Message message)
{
if (!first)
writeln(",");
else
first = false;
writeln(" {");
writeln(` "key": "`, message.key, `",`);
if (message.checkName !is null)
{
writeln(` "name": "`, message.checkName, `",`);
}
writeln(` "fileName": "`, message.fileName.replace("\\", "\\\\").replace(`"`, `\"`), `",`);
writeln(` "line": `, message.line, `,`);
writeln(` "column": `, message.column, `,`);
writeln(` "message": "`, message.message.replace("\\", "\\\\").replace(`"`, `\"`), `"`);
write(" }");
}
bool syntaxCheck(string[] fileNames, string errorFormat, ref StringCache stringCache, ref ModuleCache moduleCache)
{
StaticAnalysisConfig config = defaultStaticAnalysisConfig();
return analyze(fileNames, config, errorFormat, stringCache, moduleCache, false);
}
void generateReport(string[] fileNames, const StaticAnalysisConfig config,
ref StringCache cache, ref ModuleCache moduleCache, string reportFile = "")
{
auto reporter = new DScannerJsonReporter();
auto writeMessages = delegate void(string fileName, size_t line, size_t column, string message, bool isError){
reporter.addMessage(Message(fileName, line, column, "dscanner.syntax", message), isError);
};
first = true;
StatsCollector stats = new StatsCollector("");
ulong lineOfCodeCount;
foreach (fileName; fileNames)
{
auto code = readFile(fileName);
// Skip files that could not be read and continue with the rest
if (code.length == 0)
continue;
RollbackAllocator r;
const(Token)[] tokens;
const Module m = parseModule(fileName, code, &r, cache, tokens, writeMessages, &lineOfCodeCount, null, null);
stats.visit(m);
MessageSet messageSet = analyze(fileName, m, config, moduleCache, tokens, true);
reporter.addMessageSet(messageSet);
}
string reportFileContent = reporter.getContent(stats, lineOfCodeCount);
if (reportFile == "")
{
writeln(reportFileContent);
}
else
{
mkdirRecurse(reportFile.dirName);
toFile(reportFileContent, reportFile);
}
}
void generateSonarQubeGenericIssueDataReport(string[] fileNames, const StaticAnalysisConfig config,
ref StringCache cache, ref ModuleCache moduleCache, string reportFile = "")
{
auto reporter = new SonarQubeGenericIssueDataReporter();
auto writeMessages = delegate void(string fileName, size_t line, size_t column, string message, bool isError){
reporter.addMessage(Message(fileName, line, column, "dscanner.syntax", message), isError);
};
foreach (fileName; fileNames)
{
auto code = readFile(fileName);
// Skip files that could not be read and continue with the rest
if (code.length == 0)
continue;
RollbackAllocator r;
const(Token)[] tokens;
const Module m = parseModule(fileName, code, &r, cache, tokens, writeMessages, null, null, null);
MessageSet messageSet = analyze(fileName, m, config, moduleCache, tokens, true);
reporter.addMessageSet(messageSet);
}
string reportFileContent = reporter.getContent();
if (reportFile == "")
{
writeln(reportFileContent);
}
else
{
mkdirRecurse(reportFile.dirName);
toFile(reportFileContent, reportFile);
}
}
/**
* For multiple files
*
* Returns: true if there were errors or if there were warnings and `staticAnalyze` was true.
*/
bool analyze(string[] fileNames, const StaticAnalysisConfig config, string errorFormat,
ref StringCache cache, ref ModuleCache moduleCache, bool staticAnalyze = true)
{
import dmd.parse : Parser;
import dmd.astbase : ASTBase;
import dmd.id : Id;
import dmd.globals : global;
import dmd.identifier : Identifier;
import std.string : toStringz;
import dmd.arraytypes : Strings;
bool hasErrors;
foreach (fileName; fileNames)
{
auto dmdParentDir = dirName(dirName(dirName(dirName(__FILE_FULL_PATH__))));
global.params.useUnitTests = true;
global.path = new Strings();
global.path.push((dmdParentDir ~ "/dmd").ptr);
global.path.push((dmdParentDir ~ "/dmd/druntime/src").ptr);
initDMD();
auto code = readFile(fileName);
auto input = cast(char[]) code;
input ~= '\0';
auto t = dmd.frontend.parseModule(cast(const(char)[]) fileName, cast(const (char)[]) input);
// t.module_.fullSemantic();
// Skip files that could not be read and continue with the rest
if (code.length == 0)
continue;
RollbackAllocator r;
uint errorCount;
uint warningCount;
const(Token)[] tokens;
const Module m = parseModule(fileName, code, &r, errorFormat, cache, false, tokens,
null, &errorCount, &warningCount);
assert(m);
if (errorCount > 0 || (staticAnalyze && warningCount > 0))
hasErrors = true;
MessageSet results = analyze(fileName, m, config, moduleCache, tokens, staticAnalyze);
MessageSet resultsDmd = analyzeDmd(fileName, t.module_, getModuleName(t.module_.md), config);
foreach (result; resultsDmd[])
{
results.insert(result);
}
if (results is null)
continue;
foreach (result; results[])
{
hasErrors = true;
messageFunctionFormat(errorFormat, result, false);
}
}
return hasErrors;
}
const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
ref StringCache cache, ref const(Token)[] tokens,
MessageDelegate dlgMessage, ulong* linesOfCode = null,
uint* errorCount = null, uint* warningCount = null)
{
import dscanner.stats : isLineOfCode;
LexerConfig config;
config.fileName = fileName;
config.stringBehavior = StringBehavior.source;
tokens = getTokensForParser(code, config, &cache);
if (linesOfCode !is null)
(*linesOfCode) += count!(a => isLineOfCode(a.type))(tokens);
return dparse.parser.parseModule(tokens, fileName, p, dlgMessage, errorCount, warningCount);
}
const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
string errorFormat, ref StringCache cache, bool report, ref const(Token)[] tokens,
ulong* linesOfCode = null, uint* errorCount = null, uint* warningCount = null)
{
auto writeMessages = delegate(string fileName, size_t line, size_t column, string message, bool isError){
return messageFunctionFormat(errorFormat, Message(fileName, line, column, "dscanner.syntax", message), isError);
};
return parseModule(fileName, code, p, cache, tokens,
report ? toDelegate(&messageFunctionJSON) : writeMessages,
linesOfCode, errorCount, warningCount);
}
/**
Checks whether a module is part of a user-specified include/exclude list.
The user can specify a comma-separated list of filters, everyone needs to start with
either a '+' (inclusion) or '-' (exclusion).
If no includes are specified, all modules are included.
*/
bool shouldRun(check : BaseAnalyzer)(string moduleName, const ref StaticAnalysisConfig config)
{
enum string a = check.name;
if (mixin("config." ~ a) == Check.disabled)
return false;
// By default, run the check
if (!moduleName.length)
return true;
auto filters = mixin("config.filters." ~ a);
// Check if there are filters are defined
// filters starting with a comma are invalid
if (filters.length == 0 || filters[0].length == 0)
return true;
auto includers = filters.filter!(f => f[0] == '+').map!(f => f[1..$]);
auto excluders = filters.filter!(f => f[0] == '-').map!(f => f[1..$]);
// exclusion has preference over inclusion
if (!excluders.empty && excluders.any!(s => moduleName.canFind(s)))
return false;
if (!includers.empty)
return includers.any!(s => moduleName.canFind(s));
// by default: include all modules
return true;
}
/**
* Checks whether a module is part of a user-specified include/exclude list.
*
* The user can specify a comma-separated list of filters, everyone needs to start with
* either a '+' (inclusion) or '-' (exclusion).
*
* If no includes are specified, all modules are included.
*/
bool shouldRunDmd(check : BaseAnalyzerDmd)(const char[] moduleName, const ref StaticAnalysisConfig config)
{
enum string a = check.name;
if (mixin("config." ~ a) == Check.disabled)
return false;
// By default, run the check
if (!moduleName.length)
return true;
auto filters = mixin("config.filters." ~ a);
// Check if there are filters are defined
// filters starting with a comma are invalid
if (filters.length == 0 || filters[0].length == 0)
return true;
auto includers = filters.filter!(f => f[0] == '+').map!(f => f[1..$]);
auto excluders = filters.filter!(f => f[0] == '-').map!(f => f[1..$]);
// exclusion has preference over inclusion
if (!excluders.empty && excluders.any!(s => moduleName.canFind(s)))
return false;
if (!includers.empty)
return includers.any!(s => moduleName.canFind(s));
// by default: include all modules
return true;
}
///
unittest
{
bool test(string moduleName, string filters)
{
StaticAnalysisConfig config;
// it doesn't matter which check we test here
config.asm_style_check = Check.enabled;
// this is done automatically by inifiled
config.filters.asm_style_check = filters.split(",");
return shouldRun!AsmStyleCheck(moduleName, config);
}
// test inclusion
assert(test("std.foo", "+std."));
// partial matches are ok
assert(test("std.foo", "+bar,+foo"));
// full as well
assert(test("std.foo", "+bar,+std.foo,+foo"));
// mismatch
assert(!test("std.foo", "+bar,+banana"));
// test exclusion
assert(!test("std.foo", "-std."));
assert(!test("std.foo", "-bar,-std.foo"));
assert(!test("std.foo", "-bar,-foo"));
// mismatch
assert(test("std.foo", "-bar,-banana"));
// test combination (exclusion has precedence)
assert(!test("std.foo", "+foo,-foo"));
assert(test("std.foo", "+foo,-bar"));
assert(test("std.bar.foo", "-barr,+bar"));
}
MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig analysisConfig,
ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true)
{
import dsymbol.symbol : DSymbol;
if (!staticAnalyze)
return null;
string moduleName;
if (m !is null && m.moduleDeclaration !is null &&
m.moduleDeclaration.moduleName !is null &&
m.moduleDeclaration.moduleName.identifiers !is null)
moduleName = m.moduleDeclaration.moduleName.identifiers.map!(e => e.text).join(".");
scope first = new FirstPass(m, internString(fileName), &moduleCache, null);
first.run();
secondPass(first.rootSymbol, first.moduleScope, moduleCache);
auto moduleScope = first.moduleScope;
scope(exit) typeid(DSymbol).destroy(first.rootSymbol.acSymbol);
scope(exit) typeid(SemanticSymbol).destroy(first.rootSymbol);
scope(exit) typeid(Scope).destroy(first.moduleScope);
BaseAnalyzer[] checks;
GC.disable;
if (moduleName.shouldRun!AsmStyleCheck(analysisConfig))
checks ~= new AsmStyleCheck(fileName, moduleScope,
analysisConfig.asm_style_check == Check.skipTests && !ut);
if (moduleName.shouldRun!CommaExpressionCheck(analysisConfig))
checks ~= new CommaExpressionCheck(fileName, moduleScope,
analysisConfig.comma_expression_check == Check.skipTests && !ut);
if (moduleName.shouldRun!UnmodifiedFinder(analysisConfig))
checks ~= new UnmodifiedFinder(fileName, moduleScope,
analysisConfig.could_be_immutable_check == Check.skipTests && !ut);
if (moduleName.shouldRun!DuplicateAttributeCheck(analysisConfig))
checks ~= new DuplicateAttributeCheck(fileName, moduleScope,
analysisConfig.duplicate_attribute == Check.skipTests && !ut);
if (moduleName.shouldRun!PokemonExceptionCheck(analysisConfig))
checks ~= new PokemonExceptionCheck(fileName, moduleScope,
analysisConfig.exception_check == Check.skipTests && !ut);
if (moduleName.shouldRun!FloatOperatorCheck(analysisConfig))
checks ~= new FloatOperatorCheck(fileName, moduleScope,
analysisConfig.float_operator_check == Check.skipTests && !ut);
if (moduleName.shouldRun!FunctionAttributeCheck(analysisConfig))
checks ~= new FunctionAttributeCheck(fileName, moduleScope,
analysisConfig.function_attribute_check == Check.skipTests && !ut);
if (moduleName.shouldRun!IfElseSameCheck(analysisConfig))
checks ~= new IfElseSameCheck(fileName, moduleScope,
analysisConfig.if_else_same_check == Check.skipTests&& !ut);
if (moduleName.shouldRun!LabelVarNameCheck(analysisConfig))
checks ~= new LabelVarNameCheck(fileName, moduleScope,
analysisConfig.label_var_same_name_check == Check.skipTests && !ut);
if (moduleName.shouldRun!MismatchedArgumentCheck(analysisConfig))
checks ~= new MismatchedArgumentCheck(fileName, moduleScope,
analysisConfig.mismatched_args_check == Check.skipTests && !ut);
if (moduleName.shouldRun!NumberStyleCheck(analysisConfig))
checks ~= new NumberStyleCheck(fileName, moduleScope,
analysisConfig.number_style_check == Check.skipTests && !ut);
if (moduleName.shouldRun!RedundantParenCheck(analysisConfig))
checks ~= new RedundantParenCheck(fileName, moduleScope,
analysisConfig.redundant_parens_check == Check.skipTests && !ut);
if (moduleName.shouldRun!StyleChecker(analysisConfig))
checks ~= new StyleChecker(fileName, moduleScope,
analysisConfig.style_check == Check.skipTests && !ut);
if (moduleName.shouldRun!UndocumentedDeclarationCheck(analysisConfig))
checks ~= new UndocumentedDeclarationCheck(fileName, moduleScope,
analysisConfig.undocumented_declaration_check == Check.skipTests && !ut);
if (moduleName.shouldRun!UnusedLabelCheck(analysisConfig))
checks ~= new UnusedLabelCheck(fileName, moduleScope,
analysisConfig.unused_label_check == Check.skipTests && !ut);
if (moduleName.shouldRun!UnusedVariableCheck(analysisConfig))
checks ~= new UnusedVariableCheck(fileName, moduleScope,
analysisConfig.unused_variable_check == Check.skipTests && !ut);
if (moduleName.shouldRun!UnusedParameterCheck(analysisConfig))
checks ~= new UnusedParameterCheck(fileName, moduleScope,
analysisConfig.unused_parameter_check == Check.skipTests && !ut);
if (moduleName.shouldRun!LineLengthCheck(analysisConfig))
checks ~= new LineLengthCheck(fileName, tokens,
analysisConfig.max_line_length,
analysisConfig.long_line_check == Check.skipTests && !ut);
if (moduleName.shouldRun!UselessAssertCheck(analysisConfig))
checks ~= new UselessAssertCheck(fileName,
analysisConfig.useless_assert_check == Check.skipTests && !ut);
if (moduleName.shouldRun!StaticIfElse(analysisConfig))
checks ~= new StaticIfElse(fileName,
analysisConfig.static_if_else_check == Check.skipTests && !ut);
if (moduleName.shouldRun!LambdaReturnCheck(analysisConfig))
checks ~= new LambdaReturnCheck(fileName,
analysisConfig.lambda_return_check == Check.skipTests && !ut);
if (moduleName.shouldRun!VcallCtorChecker(analysisConfig))
checks ~= new VcallCtorChecker(fileName,
analysisConfig.vcall_in_ctor == Check.skipTests && !ut);
if (moduleName.shouldRun!UselessInitializerChecker(analysisConfig))
checks ~= new UselessInitializerChecker(fileName,
analysisConfig.useless_initializer == Check.skipTests && !ut);
if (moduleName.shouldRun!AllManCheck(analysisConfig))
checks ~= new AllManCheck(fileName, tokens,
analysisConfig.allman_braces_check == Check.skipTests && !ut);
if (moduleName.shouldRun!HasPublicExampleCheck(analysisConfig))
checks ~= new HasPublicExampleCheck(fileName, moduleScope,
analysisConfig.has_public_example == Check.skipTests && !ut);
if (moduleName.shouldRun!IfConstraintsIndentCheck(analysisConfig))
checks ~= new IfConstraintsIndentCheck(fileName, tokens,
analysisConfig.if_constraints_indent == Check.skipTests && !ut);
if (moduleName.shouldRun!TrustTooMuchCheck(analysisConfig))
checks ~= new TrustTooMuchCheck(fileName,
analysisConfig.trust_too_much == Check.skipTests && !ut);
if (moduleName.shouldRun!RedundantStorageClassCheck(analysisConfig))
checks ~= new RedundantStorageClassCheck(fileName,
analysisConfig.redundant_storage_classes == Check.skipTests && !ut);
if (moduleName.shouldRun!UnusedResultChecker(analysisConfig))
checks ~= new UnusedResultChecker(fileName, moduleScope,
analysisConfig.unused_result == Check.skipTests && !ut);
if (moduleName.shouldRun!CyclomaticComplexityCheck(analysisConfig))
checks ~= new CyclomaticComplexityCheck(fileName, moduleScope,
analysisConfig.cyclomatic_complexity == Check.skipTests && !ut,
analysisConfig.max_cyclomatic_complexity.to!int);
version (none)
if (moduleName.shouldRun!IfStatementCheck(analysisConfig))
checks ~= new IfStatementCheck(fileName, moduleScope,
analysisConfig.redundant_if_check == Check.skipTests && !ut);
MessageSet set = new MessageSet;
foreach (check; checks)
{
check.visit(m);
foreach (message; check.messages)
set.insert(message);
}
GC.enable;
return set;
}
MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleName, const StaticAnalysisConfig config)
{
MessageSet set = new MessageSet;
BaseAnalyzerDmd[] visitors;
if (moduleName.shouldRunDmd!(ObjectConstCheck!ASTCodegen)(config))
visitors ~= new ObjectConstCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(EnumArrayVisitor!ASTCodegen)(config))
visitors ~= new EnumArrayVisitor!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(DeleteCheck!ASTCodegen)(config))
visitors ~= new DeleteCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(FinalAttributeChecker!ASTCodegen)(config))
visitors ~= new FinalAttributeChecker!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(ImportSortednessCheck!ASTCodegen)(config))
visitors ~= new ImportSortednessCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(IncorrectInfiniteRangeCheck!ASTCodegen)(config))
visitors ~= new IncorrectInfiniteRangeCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(RedundantAttributesCheck!ASTCodegen)(config))
visitors ~= new RedundantAttributesCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(LengthSubtractionCheck!ASTCodegen)(config))
visitors ~= new LengthSubtractionCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(AliasSyntaxCheck!ASTCodegen)(config))
visitors ~= new AliasSyntaxCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(ExplicitlyAnnotatedUnittestCheck!ASTCodegen)(config))
visitors ~= new ExplicitlyAnnotatedUnittestCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(ConstructorCheck!ASTCodegen)(config))
visitors ~= new ConstructorCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(AssertWithoutMessageCheck!ASTCodegen)(config))
visitors ~= new AssertWithoutMessageCheck!ASTCodegen(
fileName,
config.assert_without_msg == Check.skipTests && !ut
);
if (moduleName.shouldRunDmd!(LocalImportCheck!ASTCodegen)(config))
visitors ~= new LocalImportCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(OpEqualsWithoutToHashCheck!ASTCodegen)(config))
visitors ~= new OpEqualsWithoutToHashCheck!ASTCodegen(
fileName,
config.opequals_tohash_check == Check.skipTests && !ut
);
if (moduleName.shouldRunDmd!(AutoRefAssignmentCheck!ASTCodegen)(config))
visitors ~= new AutoRefAssignmentCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(LogicPrecedenceCheck!ASTCodegen)(config))
visitors ~= new LogicPrecedenceCheck!ASTCodegen(
fileName,
config.logical_precedence_check == Check.skipTests && !ut
);
if (moduleName.shouldRunDmd!(BuiltinPropertyNameCheck!ASTCodegen)(config))
visitors ~= new BuiltinPropertyNameCheck!ASTCodegen(fileName);
if (moduleName.shouldRunDmd!(BackwardsRangeCheck!ASTCodegen)(config))
visitors ~= new BackwardsRangeCheck!ASTCodegen(
fileName,
config.backwards_range_check == Check.skipTests && !ut);
if (moduleName.shouldRunDmd!(AutoFunctionChecker!ASTCodegen)(config))
visitors ~= new AutoFunctionChecker!ASTCodegen(
fileName,
config.auto_function_check == Check.skipTests && !ut
);
if (moduleName.shouldRunDmd!(ProperlyDocumentedPublicFunctions!ASTCodegen)(config))
visitors ~= new ProperlyDocumentedPublicFunctions!ASTCodegen(
fileName,
config.properly_documented_public_functions == Check.skipTests && !ut
);
foreach (visitor; visitors)
{
m.accept(visitor);
foreach (message; visitor.messages)
set.insert(message);
}
return set;
}