@@ -14,6 +14,8 @@ import std.algorithm;
1414import std.range ;
1515import std.array ;
1616import std.functional : toDelegate;
17+ import std.file : mkdirRecurse;
18+ import std.path : dirName;
1719import dparse.lexer;
1820import dparse.parser;
1921import dparse.ast;
@@ -87,7 +89,7 @@ import dsymbol.conversion.second;
8789import dsymbol.modulecache : ModuleCache;
8890
8991import dscanner.utils;
90- import dscanner.reports : SonarQubeGenericIssueDataReporter;
92+ import dscanner.reports : DScannerJsonReporter, SonarQubeGenericIssueDataReporter;
9193
9294bool first = true ;
9395
@@ -146,10 +148,14 @@ bool syntaxCheck(string[] fileNames, string errorFormat, ref StringCache stringC
146148}
147149
148150void generateReport (string [] fileNames, const StaticAnalysisConfig config,
149- ref StringCache cache, ref ModuleCache moduleCache)
151+ ref StringCache cache, ref ModuleCache moduleCache, string reportFile = " " )
150152{
151- writeln(" {" );
152- writeln(` "issues": [` );
153+ auto reporter = new DScannerJsonReporter();
154+
155+ auto writeMessages = delegate void (string fileName, size_t line, size_t column, string message, bool isError){
156+ reporter.addMessage(Message(fileName, line, column, " dscanner.syntax" , message), isError);
157+ };
158+
153159 first = true ;
154160 StatsCollector stats = new StatsCollector(" " );
155161 ulong lineOfCodeCount;
@@ -161,29 +167,26 @@ void generateReport(string[] fileNames, const StaticAnalysisConfig config,
161167 continue ;
162168 RollbackAllocator r;
163169 const (Token )[] tokens;
164- const Module m = parseModule(fileName, code, &r, defaultErrorFormat, cache, true , tokens , &lineOfCodeCount);
170+ const Module m = parseModule(fileName, code, &r, cache, tokens, writeMessages , &lineOfCodeCount, null , null );
165171 stats.visit(m);
166- MessageSet results = analyze(fileName, m, config, moduleCache, tokens, true );
167- foreach (result; results[])
168- {
169- writeJSON(result);
170- }
172+ MessageSet messageSet = analyze(fileName, m, config, moduleCache, tokens, true );
173+ reporter.addMessageSet(messageSet);
174+ }
175+
176+ string reportFileContent = reporter.getContent(stats, lineOfCodeCount);
177+ if (reportFile == " " )
178+ {
179+ writeln(reportFileContent);
180+ }
181+ else
182+ {
183+ mkdirRecurse(reportFile.dirName);
184+ toFile(reportFileContent, reportFile);
171185 }
172- writeln();
173- writeln(" ]," );
174- writefln(` "interfaceCount": %d,` , stats.interfaceCount);
175- writefln(` "classCount": %d,` , stats.classCount);
176- writefln(` "functionCount": %d,` , stats.functionCount);
177- writefln(` "templateCount": %d,` , stats.templateCount);
178- writefln(` "structCount": %d,` , stats.structCount);
179- writefln(` "statementCount": %d,` , stats.statementCount);
180- writefln(` "lineOfCodeCount": %d,` , lineOfCodeCount);
181- writefln(` "undocumentedPublicSymbols": %d` , stats.undocumentedPublicSymbols);
182- writeln(" }" );
183186}
184187
185188void generateSonarQubeGenericIssueDataReport (string [] fileNames, const StaticAnalysisConfig config,
186- ref StringCache cache, ref ModuleCache moduleCache)
189+ ref StringCache cache, ref ModuleCache moduleCache, string reportFile = " " )
187190{
188191 auto reporter = new SonarQubeGenericIssueDataReporter();
189192
@@ -204,7 +207,16 @@ void generateSonarQubeGenericIssueDataReport(string[] fileNames, const StaticAna
204207 reporter.addMessageSet(messageSet);
205208 }
206209
207- writeln(reporter.getContent());
210+ string reportFileContent = reporter.getContent();
211+ if (reportFile == " " )
212+ {
213+ writeln(reportFileContent);
214+ }
215+ else
216+ {
217+ mkdirRecurse(reportFile.dirName);
218+ toFile(reportFileContent, reportFile);
219+ }
208220}
209221
210222/**
0 commit comments