From 77a7b4f5d2b895b27706713944c825e5c0dd9371 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Thu, 4 Jun 2015 16:50:29 -0700 Subject: [PATCH] Implement #239 --- src/analysis/run.d | 12 ++++++++---- src/main.d | 15 ++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/analysis/run.d b/src/analysis/run.d index 2d1a9e6..f137dbe 100644 --- a/src/analysis/run.d +++ b/src/analysis/run.d @@ -115,8 +115,11 @@ void generateReport(string[] fileNames, const StaticAnalysisConfig config) writeln("}"); } -/// For multiple files -/// Returns: true if there were errors +/** + * 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, bool staticAnalyze = true) { bool hasErrors = false; @@ -129,10 +132,11 @@ bool analyze(string[] fileNames, const StaticAnalysisConfig config, bool staticA ParseAllocator p = new ParseAllocator; StringCache cache = StringCache(StringCache.defaultBucketCount); uint errorCount = 0; + uint warningCount = 0; const Module m = parseModule(fileName, code, p, cache, false, null, - &errorCount, null); + &errorCount, &warningCount); assert (m); - if (errorCount > 0) + if (errorCount > 0 || (staticAnalyze && warningCount > 0)) hasErrors = true; MessageSet results = analyze(fileName, m, config, staticAnalyze); if (results is null) diff --git a/src/main.d b/src/main.d index 923d0cf..366d9a3 100644 --- a/src/main.d +++ b/src/main.d @@ -182,11 +182,11 @@ int main(string[] args) if (report) generateReport(expandArgs(args), config); else - analyze(expandArgs(args), config, true); + return analyze(expandArgs(args), config, true) ? 1 : 0; } else if (syntaxCheck) { - return .syntaxCheck(expandArgs(args)); + return .syntaxCheck(expandArgs(args)) ? 1 : 0; } else { @@ -265,6 +265,7 @@ int main(string[] args) return 0; } +private: string[] expandArgs(string[] args) { @@ -359,11 +360,13 @@ options: --syntaxCheck | -s [sourceFile] Lexes and parses sourceFile, printing the line and column number of any syntax errors to stdout. One error or warning is printed per line. - If no files are specified, input is read from stdin. + If no files are specified, input is read from stdin. %1$s will exit with + a status code of zero if no errors are found, 1 otherwise. --styleCheck | -S [sourceFiles] Lexes and parses sourceFiles, printing the line and column number of any - static analysis check failures stdout. + static analysis check failures stdout. %1$s will exit with a status code + of zero if no warnings or errors are found, 1 otherwise. --ctags | -c sourceFile Generates ctags information from the given source code file. Note that @@ -388,7 +391,9 @@ options: current working directory if none are specified. --report [sourceFiles sourceDirectories] - Generate a static analysis report in JSON format. Implies --styleCheck. + Generate a static analysis report in JSON format. Implies --styleCheck, + however the exit code will still be zero if errors or warnings are + found. --config configFile Use the given configuration file instead of the default located in