Skip to content

Commit

Permalink
Merge a4c7e7a into dc0365b
Browse files Browse the repository at this point in the history
  • Loading branch information
alykhank committed Mar 10, 2016
2 parents dc0365b + a4c7e7a commit c609170
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Options:
-c,--config=<path/to/.tailor.yml> specify configuration file
--debug print ANTLR error messages when parsing error occurs
--except=<rule1,rule2,...> run all rules except the specified ones
-f,--format=<xcode|json> select an output format
-f,--format=<xcode|json|cc> select an output format
-h,--help display help
--invert-color invert colorized console output
-l,--max-line-length=<0-999> maximum Line length (in characters)
Expand Down
4 changes: 4 additions & 0 deletions config/checkstyle/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
<property name="eachLine" value="true"/>
</module>

<!-- Differs from Google style: Added SuppressWarningsFilter module -->
<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
<!-- Differs from Google style: Added SuppressWarningsHolder module -->
<module name="SuppressWarningsHolder" />
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
Expand Down
4 changes: 4 additions & 0 deletions config/checkstyle/google_test_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
<property name="eachLine" value="true"/>
</module>

<!-- Differs from Google style: Added SuppressWarningsFilter module -->
<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
<!-- Differs from Google style: Added SuppressWarningsHolder module -->
<module name="SuppressWarningsHolder" />
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
Expand Down
2 changes: 1 addition & 1 deletion man/tailor.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Tailor is a cross-platform static analysis and lint tool for source code written
* `--except`=<rule1,rule2,...>:
run all rules except the specified ones

* `-f`,`--format`=<xcode|json>:
* `-f`,`--format`=<xcode|json|cc>:
select an output format

* `-h`,`--help`:
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/sleekbyte/tailor/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Output messages.
*/
public class Messages {
public abstract class Messages {

// Message styles
public static final String WARNING = "warning";
Expand Down Expand Up @@ -173,6 +173,22 @@ public class Messages {
public static final String ERRORS_KEY = "errors";
public static final String WARNINGS_KEY = "warnings";

// Code Climate Format messages
public static final String BEGIN_KEY = "begin";
public static final String END_KEY = "end";
public static final String POSITIONS_KEY = "positions";
public static final String LINES_KEY = "lines";
public static final String CHECK_NAME_KEY = "check_name";
public static final String BODY_KEY = "body";
public static final String CONTENT_KEY = "content";
public static final String DESCRIPTION_KEY = "description";
public static final String TYPE_KEY = "type";
public static final String ISSUE_VALUE = "issue";
public static final String CATEGORIES_KEY = "categories";
public static final String REMEDIATION_POINTS_KEY = "remediation_points";
public static final String STYLE_CATEGORY = "Style";
public static final String BUG_RISK_CATEGORY = "Bug Risk";

// Error messages
public static final String NO_SWIFT_FILES_FOUND = "No Swift source files were found.";
public static final String COULD_NOT_BE_PARSED = " could not be parsed successfully, skipping...";
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/sleekbyte/tailor/common/RuleCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sleekbyte.tailor.common;

/**
* Categories of {@link Rules}.
*/
public enum RuleCategory {
BUG_RISK("Bug Risk"),
CLARITY("Clarity"),
COMPATIBILITY("Compatibility"),
COMPLEXITY("Complexity"),
DUPLICATION("Duplication"),
PERFORMANCE("Performance"),
SECURITY("Security"),
STYLE("Style");

private final String category;

RuleCategory(String category) {
this.category = category;
}

@Override
public String toString() {
return category;
}
}
50 changes: 50 additions & 0 deletions src/main/java/com/sleekbyte/tailor/common/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ public enum Rules {
UPPER_CAMEL_CASE;

private static final String BASE_STYLE_GUIDE_LINK = "https://github.com/sleekbyte/tailor/wiki/Rules#";
public static final int REMEDIATION_POINTS = 50000;
private String name;
private RuleCategory category;
private String className;
private String description;

public String getName() {
return this.name;
}

public String getCategory() {
return this.category.toString();
}

public String getClassName() {
return this.className;
}
Expand All @@ -76,143 +82,187 @@ public String getDescription() {
return this.description;
}

public String getInformation() {
return this.getDescription() + " View code samples in the [Style Guide](" + this.getLink() + ").";
}

public String getLink() {
return BASE_STYLE_GUIDE_LINK + this.getName();
}

/**
* Provide a rough estimate for how long it would take to resolve the reported issue.
*
* @return an integer indicating the effort involved to remedy the issue
*/
public int getRemediationPoints() {
return REMEDIATION_POINTS;
}

static {
ARROW_WHITESPACE.name = "arrow-whitespace";
ARROW_WHITESPACE.description = "Flags all return arrows (->) that are not space delimited.";
ARROW_WHITESPACE.className = ArrowWhitespaceListener.class.getName();
ARROW_WHITESPACE.category = RuleCategory.STYLE;

ANGLE_BRACKET_WHITESPACE.name = "angle-bracket-whitespace";
ANGLE_BRACKET_WHITESPACE.description = "Ensure no whitespace is present immediately before/after an opening"
+ " chevron and before the closing chevron.";
ANGLE_BRACKET_WHITESPACE.className = AngleBracketWhitespaceListener.class.getName();
ANGLE_BRACKET_WHITESPACE.category = RuleCategory.STYLE;

BRACE_STYLE.name = "brace-style";
BRACE_STYLE.description = "Definitions of constructs should follow the One True Brace Style (1TBS).";
BRACE_STYLE.className = BraceStyleListener.class.getName();
BRACE_STYLE.category = RuleCategory.STYLE;

COLON_WHITESPACE.name = "colon-whitespace";
COLON_WHITESPACE.description = "Flag whitespace violations around colons (:).";
COLON_WHITESPACE.className = ColonWhitespaceListener.class.getName();
COLON_WHITESPACE.category = RuleCategory.STYLE;

COMMA_WHITESPACE.name = "comma-whitespace";
COMMA_WHITESPACE.description = "Flags all commas (,) that are not left associated.";
COMMA_WHITESPACE.className = CommaWhitespaceListener.class.getName();
COMMA_WHITESPACE.category = RuleCategory.STYLE;

COMMENT_WHITESPACE.name = "comment-whitespace";
COMMENT_WHITESPACE.description = "Ensure at least one whitespace character after a comment opening symbol"
+ " (// or /*) and at least one whitespace character before a comment closing symbol (*/).";
COMMENT_WHITESPACE.className = CommentWhitespaceListener.class.getName();
COMMENT_WHITESPACE.category = RuleCategory.STYLE;

CONSTANT_K_PREFIX.name = "constant-k-prefix";
CONSTANT_K_PREFIX.description = "Flag constants with prefix k.";
CONSTANT_K_PREFIX.className = KPrefixListener.class.getName();
CONSTANT_K_PREFIX.category = RuleCategory.STYLE;

CONSTANT_NAMING.name = "constant-naming";
CONSTANT_NAMING.description = "Global constants should follow either UpperCamelCase or lowerCamelCase naming "
+ "conventions. Local constants should follow lowerCamelCase naming conventions.";
CONSTANT_NAMING.className = ConstantNamingListener.class.getName();
CONSTANT_NAMING.category = RuleCategory.STYLE;

FORCED_TYPE_CAST.name = "forced-type-cast";
FORCED_TYPE_CAST.description = "Flag uses of the forced form of the type cast operator (as!).";
FORCED_TYPE_CAST.className = ForceTypeCastListener.class.getName();
FORCED_TYPE_CAST.category = RuleCategory.BUG_RISK;

FUNCTION_WHITESPACE.name = "function-whitespace";
FUNCTION_WHITESPACE.description = "Every function declaration except those at the start and end of file "
+ "should have one blank line before and after itself.";
FUNCTION_WHITESPACE.className = BlankLineListener.class.getName();
FUNCTION_WHITESPACE.category = RuleCategory.STYLE;

LEADING_WHITESPACE.name = "leading-whitespace";
LEADING_WHITESPACE.description = "Verify that source files begin with a non-whitespace character.";
LEADING_WHITESPACE.className = FileListener.class.getName();
LEADING_WHITESPACE.category = RuleCategory.STYLE;

LOWER_CAMEL_CASE.name = "lower-camel-case";
LOWER_CAMEL_CASE.description = "Method and variable names should follow lowerCamelCase naming convention.";
LOWER_CAMEL_CASE.className = LowerCamelCaseListener.class.getName();
LOWER_CAMEL_CASE.category = RuleCategory.STYLE;

MAX_CLASS_LENGTH.name = CLIArgumentParser.MAX_CLASS_LENGTH_OPT;
MAX_CLASS_LENGTH.description = "Enforce a line limit on the lengths of class bodies.";
MAX_CLASS_LENGTH.className = FileListener.class.getName();
MAX_CLASS_LENGTH.category = RuleCategory.COMPLEXITY;

MAX_CLOSURE_LENGTH.name = CLIArgumentParser.MAX_CLOSURE_LENGTH_OPT;
MAX_CLOSURE_LENGTH.description = "Enforce a line limit on the lengths of closure bodies.";
MAX_CLOSURE_LENGTH.className = FileListener.class.getName();
MAX_CLOSURE_LENGTH.category = RuleCategory.COMPLEXITY;

MAX_FILE_LENGTH.name = CLIArgumentParser.MAX_FILE_LENGTH_OPT;
MAX_FILE_LENGTH.description = "Enforce a line limit on each file.";
MAX_FILE_LENGTH.className = FileListener.class.getName();
MAX_FILE_LENGTH.category = RuleCategory.COMPLEXITY;

MAX_FUNCTION_LENGTH.name = CLIArgumentParser.MAX_FUNCTION_LENGTH_OPT;
MAX_FUNCTION_LENGTH.description = "Enforce a line limit on the lengths of function bodies.";
MAX_FUNCTION_LENGTH.className = FileListener.class.getName();
MAX_FUNCTION_LENGTH.category = RuleCategory.COMPLEXITY;

MAX_LINE_LENGTH.name = CLIArgumentParser.MAX_LINE_LENGTH_LONG_OPT;
MAX_LINE_LENGTH.description = "Enforce a character limit on the length of each line.";
MAX_LINE_LENGTH.className = FileListener.class.getName();
MAX_LINE_LENGTH.category = RuleCategory.COMPLEXITY;

MAX_NAME_LENGTH.name = CLIArgumentParser.MAX_NAME_LENGTH_OPT;
MAX_NAME_LENGTH.description = "Enforce a character limit on the length of each construct name.";
MAX_NAME_LENGTH.className = FileListener.class.getName();
MAX_NAME_LENGTH.category = RuleCategory.STYLE;

MAX_STRUCT_LENGTH.name = CLIArgumentParser.MAX_STRUCT_LENGTH_OPT;
MAX_STRUCT_LENGTH.description = "Enforce a line limit on the lengths of struct bodies.";
MAX_STRUCT_LENGTH.className = FileListener.class.getName();
MAX_STRUCT_LENGTH.category = RuleCategory.COMPLEXITY;

MIN_NAME_LENGTH.name = CLIArgumentParser.MIN_NAME_LENGTH_OPT;
MIN_NAME_LENGTH.description = "Enforce a minimum character limit on the length of each construct name.";
MIN_NAME_LENGTH.className = FileListener.class.getName();
MIN_NAME_LENGTH.category = RuleCategory.STYLE;

MULTIPLE_IMPORTS.name = "multiple-imports";
MULTIPLE_IMPORTS.description = "Multiple import statements should not be defined on a single line.";
MULTIPLE_IMPORTS.className = MultipleImportListener.class.getName();
MULTIPLE_IMPORTS.category = RuleCategory.STYLE;

OPERATOR_WHITESPACE.name = "operator-whitespace";
OPERATOR_WHITESPACE.description = "Flags operators that are not space delimited in operator declarations.";
OPERATOR_WHITESPACE.className = OperatorWhitespaceListener.class.getName();
OPERATOR_WHITESPACE.category = RuleCategory.STYLE;

PARENTHESIS_WHITESPACE.name = "parenthesis-whitespace";
PARENTHESIS_WHITESPACE.description = "Ensure no whitespace is present immediately before/after an opening"
+ " parenthesis and before the closing parenthesis.";
PARENTHESIS_WHITESPACE.className = ParenthesisWhitespaceListener.class.getName();
PARENTHESIS_WHITESPACE.category = RuleCategory.STYLE;

REDUNDANT_OPTIONAL_BINDING.name = "redundant-optional-binding";
REDUNDANT_OPTIONAL_BINDING.description = "Flag redundant 'let'/'var' bindings in optional binding lists.";
REDUNDANT_OPTIONAL_BINDING.className = OptionalBindingListener.class.getName();
REDUNDANT_OPTIONAL_BINDING.category = RuleCategory.STYLE;

REDUNDANT_PARENTHESES.name = "redundant-parentheses";
REDUNDANT_PARENTHESES.description = "Control flow constructs, exception handling constructs, and "
+ "values assigned in variable/constant declarations should not be enclosed in parentheses.";
REDUNDANT_PARENTHESES.className = RedundantParenthesesListener.class.getName();
REDUNDANT_PARENTHESES.category = RuleCategory.STYLE;

TERMINATING_NEWLINE.name = "terminating-newline";
TERMINATING_NEWLINE.description = "Verify that source files terminate with exactly one '\\n' character.";
TERMINATING_NEWLINE.className = FileListener.class.getName();
TERMINATING_NEWLINE.category = RuleCategory.STYLE;

TERMINATING_SEMICOLON.name = "terminating-semicolon";
TERMINATING_SEMICOLON.description = "Statements should not be terminated with semicolons.";
TERMINATING_SEMICOLON.className = SemicolonTerminatedListener.class.getName();
TERMINATING_SEMICOLON.category = RuleCategory.STYLE;

TODO_SYNTAX.name = "todo-syntax";
TODO_SYNTAX.description = "TODO comments should follow either <TODO: description> or"
+ " <TODO(dev-name): description> format.";
TODO_SYNTAX.className = TodoCommentListener.class.getName();
TODO_SYNTAX.category = RuleCategory.STYLE;

TRAILING_CLOSURE.name = "trailing-closure";
TRAILING_CLOSURE.description = "Functions that have a closure as their last argument should be called"
+ "using trailing closure syntax.";
TRAILING_CLOSURE.className = TrailingClosureListener.class.getName();
TRAILING_CLOSURE.category = RuleCategory.STYLE;

TRAILING_WHITESPACE.name = "trailing-whitespace";
TRAILING_WHITESPACE.description = "Flag whitespace after the last non-whitespace character on each line "
+ "until the newline.";
TRAILING_WHITESPACE.className = FileListener.class.getName();
TRAILING_WHITESPACE.category = RuleCategory.STYLE;

UPPER_CAMEL_CASE.name = "upper-camel-case";
UPPER_CAMEL_CASE.description = "Class, enum, enum value, struct, and protocol names should follow"
+ " UpperCamelCase naming convention.";
UPPER_CAMEL_CASE.className = UpperCamelCaseListener.class.getName();
UPPER_CAMEL_CASE.category = RuleCategory.STYLE;
}
}
Loading

0 comments on commit c609170

Please sign in to comment.