Skip to content

Commit

Permalink
Merge pull request #511 from TheRealAgentK/507-undocument-configfile
Browse files Browse the repository at this point in the history
Merge changes
  • Loading branch information
TheRealAgentK authored Dec 30, 2017
2 parents e0e98aa + ae40200 commit ca12fd3
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 60 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The simplest options for executing CFLint is via the command line. CFLint curren

## Configuration

Alternatively to the command line, you can supply a global configuration via the `-configfile` switch or put `.cflintrc` files into certain directories. Configuring CFLint this way conceptually allows you to run specific rules in specific parts of your application.
Alternatively to the command line, you can put `.cflintrc` files into certain directories. Configuring CFLint this way conceptually allows you to run specific rules in specific parts of your application.

CFLint currently supports JSON- and XML-based configuration. XML-based configuration is deprecated in CFLint 1.3.0 and will be removed in CFLint 2.0.

Expand All @@ -101,9 +101,7 @@ When CFLint executes, it scans and parses your code (using CFParser). The syntax

### Global configuration

The `-configfile` options can be used to replace the standard global configuration file.

The standard configuration is [`/src/main/resources/cflint.definition.json`](/src/main/resources/cflint.definition.json). Common usage of CFLint usually does not require replacing this file.
The default and global configuration file is [`/src/main/resources/cflint.definition.json`](/src/main/resources/cflint.definition.json). Common usage of CFLint usually does not require replacing this file.

### Folder-based configuration

Expand Down Expand Up @@ -182,7 +180,7 @@ to ignore a rule violation on the next line.
Configuration of which plugins are run and which rules are included starts with the global configuration and flows through the command line parameters, folder level rules, and down to the annotations within the source.

* global configuration
* custom configuration file (`-configfile`)
* custom configuration file (`-configfile`, we do **not** encourage this option to be used in day-to-day operations of CFLint)
* rule groups (`-rulegroups`, default behavior is --rulegroups !Experimental)
* includes/excludes from the command line (`-includeRule` and `-excludeRule`)
* .cflintrc - folder level configuration, mostly for including/excluding specific messages
Expand All @@ -204,9 +202,9 @@ The flag `-xml` instructs CFLint to create XML. There are two options for XML re

The first option is what we call CFLint XML. It's an internal format that adheres to a basic schema provided [here](/src/main/resources/schemas/cflint-result.xsd). You could then use this format as-is or to do further processing of your choice.

The seconds option is FindBugs XML. The resulting XML document adheres to the current version of the FindBugs BugCollection [XML Schema Definition](src/main/resources/findbugs/bugcollection.xsd) and can be used in most CI-/Build-Server products. JetBrains TeamCity 10+ can import this format out of the box.
The second option is FindBugs XML. The resulting XML document adheres to the current version of the FindBugs BugCollection [XML Schema Definition](src/main/resources/findbugs/bugcollection.xsd) and can be used in most CI-/Build-Server products. JetBrains TeamCity 10+ can import this format out of the box.

*Please note*: Currently it's not possible to produce BOTH flavours of XML reports at the same time. This is a known limitation. If you feel this hinders your use of CFLint, please raise an issue.
*Please note*: Currently it's not possible to produce BOTH flavours of XML reports at the same time. This is a known limitation. This limitation will be removed as part of CFLint 2.0 (see [Issue #331](https://github.com/cflint/CFLint/issues/331)).

#### CFLint XML

Expand Down Expand Up @@ -326,7 +324,7 @@ Example of plain text output:

Issue counts:1
CFQUERYPARAM_REQ:4

Total issues:4
Total warnings:4

Expand All @@ -337,7 +335,7 @@ To interact directly with CFLint within the JVM use the CFLint API.
```java
import com.cflint.api.CFLintAPI;
import com.cflint.api.CFLintResult;

CFLintAPI api = new CFLintAPI();
CFLintResult result = api.scan(filename);
String jsonResult = result.getJSON();
Expand Down Expand Up @@ -530,3 +528,5 @@ Please note that the majority of the libraries and projects mentioned here are n
* [SonarQube plugin](https://github.com/stepstone-tech/sonar-coldfusion)
* [NPM wrapper](https://github.com/morgdenn/npm-cflint)
* Vim [Syntastic support for CFLint](https://github.com/cflint/cflint-syntastic)

If you have been working on (or are thinking about starting) a project related to CFLint, please let us know. We're happy to include relevant third-party projects to the list above.
171 changes: 120 additions & 51 deletions src/main/java/com/cflint/cli/CFLintCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import javax.xml.bind.JAXBException;
import javax.xml.transform.TransformerException;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.*;
import org.apache.commons.io.IOUtils;

import com.cflint.Version;
Expand All @@ -44,6 +36,7 @@

public class CFLintCLI {
private static final String CFLINT = "cflint";
private static final String CFLINT_USAGE = "java -jar CFLint-" + Version.getVersion() + "-all.jar";
private static final String FINDBUGS = "findbugs";
private static final String DISPLAY_THIS_HELP = "display this help";

Expand All @@ -69,52 +62,128 @@ public class CFLintCLI {
private boolean strictInclude;

public static void main(final String[] args) throws Exception {
final Options options = new Options();
options.addOption(Settings.MARKDOWN, false, "generate MarkDown of all supported rules");
options.addOption(Settings.RULES, false, "list of all supported rules");
options.addOption(Settings.CONFIG, false, "list of rules in config file");
options.addOption(Settings.INCLUDE_RULE, true, "specify rules to include");
options.addOption(Settings.EXCLUDE_RULE, true, "specify rules to exclude");
options.addOption(Settings.FOLDER, true, "folder(s) to scan");
options.addOption(Settings.FILE, true, "file(s) to scan");
options.addOption(Settings.FILTER_FILE, true, "filter file");
options.addOption(Settings.V, false, "verbose output");
options.addOption(Settings.VERSION, false, "show the version number");
options.addOption(Settings.VERBOSE, false, "verbose output");
options.addOption(Settings.STRICT_INCLUDE, false, "Check every include and try to parse it");
final Options commandOptions = new Options();
final Options helpOptions = new Options();

options.addOption(Settings.LOGERROR, false, "log parsing errors as bugs");
options.addOption(Settings.E, false, "log parsing errors as bugs");
options.addOption(Settings.QUIET, false, "less output");
options.addOption(Settings.Q, false, "less output");
options.addOption(Settings.HELP, false, DISPLAY_THIS_HELP);
options.addOption(Settings.QUESTION_MARK, false, DISPLAY_THIS_HELP);
options.addOption(Settings.H, false, DISPLAY_THIS_HELP);
options.addOption(Settings.XML, false, "output in xml format");
options.addOption(Settings.XMLFILE, true, "specify the output xml file (default: cflint-results.xml)");
options.addOption(Settings.XMLSTYLE, true, "cflint,findbugs");
options.addOption(Settings.HTML, false, "output in html format (default)");
options.addOption(Settings.HTMLFILE, true, "specify the output html file (default: cflint-results.html)");
options.addOption(Settings.HTMLSTYLE, true, "default,plain"); // fancy,fancy-hist,summary
options.addOption(Settings.JSON, false, "output in json format");
options.addOption(Settings.JSONFILE, true, "specify the output json file (default: cflint-results.json)");
options.addOption(Settings.TEXT, false, "output in plain text");
options.addOption(Settings.TEXTFILE, true, "specify the output text file (default: cflint-results.txt)");
options.addOption(Settings.EXTENSIONS, true,
"specify the extensions of the CF source files (default: .cfm,.cfc)");
options.addOption(Settings.CONFIGFILE, true, "specify the location of the config file");
options.addOption(Settings.STDIN, true, "use stdin for file input (default: source.cfc)");
options.addOption(Settings.STDOUT, false, "output to stdout only");
options.addOption(Settings.LIST_RULE_GROUPS, false, "list rule groups");
options.addOption(Settings.RULE_GROUPS, true, "rule groups");
// documented
Option optionMARKDOWN = new Option(Settings.MARKDOWN, false, "generate MarkDown of all supported rules");
Option optionRULES = new Option(Settings.RULES, false, "list of all supported rules");
Option optionCONFIG = new Option(Settings.CONFIG, false, "list of rules in config file");
Option optionINCLUDE_RULE = new Option(Settings.INCLUDE_RULE, true, "specify rules to include");
Option optionEXCLUDE_RULE = new Option(Settings.EXCLUDE_RULE, true, "specify rules to exclude");
Option optionFOLDER = new Option(Settings.FOLDER, true, "folder(s) to scan");
Option optionFILE = new Option(Settings.FILE, true, "file(s) to scan");
Option optionFILTER_FILE = new Option(Settings.FILTER_FILE, true, "filter file");
Option optionV = new Option(Settings.V, false, "verbose output");
Option optionVERSION = new Option(Settings.VERSION, false, "show the version number");
Option optionVERBOSE = new Option(Settings.VERBOSE, false, "verbose output");
Option optionSTRICT_INCLUDE = new Option(Settings.STRICT_INCLUDE, false, "Check every include and try to parse it");
Option optionLOGERROR = new Option(Settings.LOGERROR, false, "log parsing errors as bugs");
Option optionE = new Option(Settings.E, false, "log parsing errors as bugs");
Option optionQUIET = new Option(Settings.QUIET, false, "less output");
Option optionQ = new Option(Settings.Q, false, "less output");
Option optionHELP = new Option(Settings.HELP, false, DISPLAY_THIS_HELP);
Option optionQUESTION_MARK = new Option(Settings.QUESTION_MARK, false, DISPLAY_THIS_HELP);
Option optionH = new Option(Settings.H, false, DISPLAY_THIS_HELP);
Option optionXML = new Option(Settings.XML, false, "output in xml format");
Option optionXMLFILE = new Option(Settings.XMLFILE, true, "specify the output xml file (default: cflint-results.xml)");
Option optionXMLSTYLE = new Option(Settings.XMLSTYLE, true, "cflint,findbugs");
Option optionHTML = new Option(Settings.HTML, false, "output in html format (default)");
Option optionHTMLFILE = new Option(Settings.HTMLFILE, true, "specify the output html file (default: cflint-results.html)");
Option optionHTMLSTYLE = new Option(Settings.HTMLSTYLE, true, "default,plain"); // fancy,fancy-hist,summary
Option optionJSON = new Option(Settings.JSON, false, "output in json format");
Option optionJSONFILE = new Option(Settings.JSONFILE, true, "specify the output json file (default: cflint-results.json)");
Option optionTEXT = new Option(Settings.TEXT, false, "output in plain text");
Option optionTEXTFILE = new Option(Settings.TEXTFILE, true, "specify the output text file (default: cflint-results.txt)");
Option optionEXTENSIONS = new Option(Settings.EXTENSIONS, true, "specify the extensions of the CF source files (default: .cfm,.cfc)");
Option optionSTDIN = new Option(Settings.STDIN, true, "use stdin for file input (default: source.cfc)");
Option optionSTDOUT = new Option(Settings.STDOUT, false, "output to stdout only");
Option optionLIST_RULE_GROUPS = new Option(Settings.LIST_RULE_GROUPS, false, "list rule groups");
Option optionRULE_GROUPS = new Option(Settings.RULE_GROUPS, true, "rule groups");

// undocumented
Option optionCONFIGFILE = new Option(Settings.CONFIGFILE, true, "specify the location of the config file");

// supported options
commandOptions.addOption(optionMARKDOWN)
.addOption(optionRULES)
.addOption(optionCONFIG)
.addOption(optionINCLUDE_RULE)
.addOption(optionEXCLUDE_RULE)
.addOption(optionFOLDER)
.addOption(optionFILE)
.addOption(optionFILTER_FILE)
.addOption(optionV)
.addOption(optionVERSION)
.addOption(optionVERBOSE)
.addOption(optionSTRICT_INCLUDE)
.addOption(optionLOGERROR)
.addOption(optionE)
.addOption(optionQUIET)
.addOption(optionQ)
.addOption(optionHELP)
.addOption(optionQUESTION_MARK)
.addOption(optionH)
.addOption(optionXML)
.addOption(optionXMLFILE)
.addOption(optionXMLSTYLE)
.addOption(optionHTML)
.addOption(optionHTMLFILE)
.addOption(optionHTMLSTYLE)
.addOption(optionJSON)
.addOption(optionJSONFILE)
.addOption(optionTEXT)
.addOption(optionTEXTFILE)
.addOption(optionEXTENSIONS)
.addOption(optionSTDIN)
.addOption(optionSTDOUT)
.addOption(optionLIST_RULE_GROUPS)
.addOption(optionRULE_GROUPS)
.addOption(optionCONFIGFILE);

// documented options for HelpFormatter
helpOptions.addOption(optionMARKDOWN)
.addOption(optionRULES)
.addOption(optionCONFIG)
.addOption(optionINCLUDE_RULE)
.addOption(optionEXCLUDE_RULE)
.addOption(optionFOLDER)
.addOption(optionFILE)
.addOption(optionFILTER_FILE)
.addOption(optionV)
.addOption(optionVERSION)
.addOption(optionVERBOSE)
.addOption(optionSTRICT_INCLUDE)
.addOption(optionLOGERROR)
.addOption(optionE)
.addOption(optionQUIET)
.addOption(optionQ)
.addOption(optionHELP)
.addOption(optionQUESTION_MARK)
.addOption(optionH)
.addOption(optionXML)
.addOption(optionXMLFILE)
.addOption(optionXMLSTYLE)
.addOption(optionHTML)
.addOption(optionHTMLFILE)
.addOption(optionHTMLSTYLE)
.addOption(optionJSON)
.addOption(optionJSONFILE)
.addOption(optionTEXT)
.addOption(optionTEXTFILE)
.addOption(optionEXTENSIONS)
.addOption(optionSTDIN)
.addOption(optionSTDOUT)
.addOption(optionLIST_RULE_GROUPS)
.addOption(optionRULE_GROUPS);

final CommandLineParser parser = new GnuParser();
final CommandLine cmd = parser.parse(options, args);
final CommandLine cmd = parser.parse(commandOptions, args);
final CFLintCLI main = new CFLintCLI();

if (cmd.hasOption(Settings.H) || cmd.hasOption(Settings.HELP) || cmd.hasOption(Settings.QUESTION_MARK)) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(CFLINT, options);
formatter.printHelp(CFLINT_USAGE, helpOptions);
return;
}
if (cmd.hasOption(Settings.VERSION)) {
Expand Down Expand Up @@ -249,7 +318,7 @@ public static void main(final String[] args) throws Exception {
main.execute(configBuilder.build());
} else {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(CFLINT, options);
formatter.printHelp(CFLINT_USAGE, helpOptions);
}
}

Expand Down Expand Up @@ -333,7 +402,7 @@ private void display(final String text) {

private boolean isValid() {
if (folder.isEmpty() && !stdIn) {
System.err.println("Set -folder or -stdin");
System.err.println("Set -folder or -stdin to use CFLint");
return false;
}
return true;
Expand Down

0 comments on commit ca12fd3

Please sign in to comment.