* Defaults to {@link CheckstyleFormatOption#PLAIN}. * * @param format the output format * @return the checkstyle operation */ public CheckstyleOperation format(CheckstyleFormatOption format) { options.put("-f", format.label.toLowerCase()); return this; } /** * Generates to output a suppression xml to use to suppress all violations from user's config. Instead of printing * every violation, all violations will be caught and single suppressions xml file will be printed out. * Used only with the {@link #configurationFile(String) configurationFile} option. Output location can be specified * with the {@link #outputPath(String) output} option. * * @param xPathSuppression {@code true} or {@code false} * @return the checkstyle operation */ public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression) { if (xPathSuppression) { options.put("-g", ""); } else { options.remove("-g"); } return this; } /* * Determines if a string is not blank. */ private boolean isNotBlank(String s) { return s != null && !s.isBlank(); } /** * This option is used to print the Parse Tree of the Javadoc comment. The file has to contain only Javadoc comment * content excluding '/**' and '*/' at the beginning and at the end respectively. It can only be used on a * single file and cannot be combined with other options. * * @param isTree {@code true} or {@code false} * @return the checkstyle operation */ public CheckstyleOperation javadocTree(boolean isTree) { if (isTree) { options.put("-j", ""); } else { options.remove("-j"); } return this; } /** * Sets the output file. *
* Defaults to stdout.
*
* @param file the output file
* @return the checkstyle operation
*/
public CheckstyleOperation outputPath(String file) {
if (isNotBlank(file)) {
options.put("-o", file);
}
return this;
}
/**
* Sets the property files to load.
*
* @param file the file
* @return the checkstyle operation
*/
public CheckstyleOperation propertiesFile(String file) {
if (isNotBlank(file)) {
options.put("-p", file);
}
return this;
}
/**
* Specified the file(s) or folder(s) containing the source files to check.
*
* @param dir one or more directories
* @return the checkstyle operation
* @see #sourceDir(Collection)
*/
public CheckstyleOperation sourceDir(String... dir) {
sourceDirs.addAll(Arrays.stream(dir).filter(this::isNotBlank).toList());
return this;
}
/**
* Specified the file(s) or folder(s) containing the source files to check.
*
* @param dirs the directories
* @return the checkstyle operation
* @see #sourceDir(String...)
*/
public CheckstyleOperation sourceDir(Collection
* Note that the generated result will have few queries, joined by pipe({@code |}). Together they will match all
* AST nodes on specified line and column. You need to choose only one and recheck that it works. Usage of all of
* them is also ok, but might result in undesirable matching and suppress other issues.
*
* @param lineColumnNumber the line column number
* @return the checkstyle operation
*/
public CheckstyleOperation suppressionLineColumnNumber(String lineColumnNumber) {
if (isNotBlank(lineColumnNumber)) {
options.put("-s", lineColumnNumber);
}
return this;
}
/**
* Sets the length of the tab character. Used only with the
* {@link #suppressionLineColumnNumber(String) suppressionLineColumnNumber} option.
*
* Default value is {@code 8}.
*
* @param length the length
* @return the checkstyle operation
*/
public CheckstyleOperation tabWith(int length) {
options.put("-w", String.valueOf(length));
return this;
}
/**
* This option is used to display the Abstract Syntax Tree (AST) without any comments of the specified file. It can
* only be used on a single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation tree(boolean isTree) {
if (isTree) {
options.put("-t", "");
} else {
options.remove("-t");
}
return this;
}
/**
* This option is used to display the Abstract Syntax Tree (AST) with comment nodes excluding Javadoc of the
* specified file. It can only be used on a single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation treeWithComments(boolean isTree) {
if (isTree) {
options.put("-T", "");
} else {
options.remove("-T");
}
return this;
}
/**
* This option is used to display the Abstract Syntax Tree (AST) with Javadoc nodes of the specified file. It can
* only be used on a single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation treeWithJavadoc(boolean isTree) {
if (isTree) {
options.put("-J", "");
} else {
options.remove("-J");
}
return this;
}
}