diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e9865b..1a5d009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Add support for configurable formatters with `--format` CLI parameter / `format` config attribute. - Add support for JSON formatting with `--format json --quiet`. - Add new `stylish` reporter and make it the default. `compact` is still available via `--format compact`. +- Add codes for rules – `indent` and `parse-error` for the two existing checks. ## [v0.7.0](https://github.com/thibaudcolas/curlylint/releases/tag/v0.7.0) 2020-04-16 diff --git a/curlylint/formatters/json.py b/curlylint/formatters/json.py index c2e8c8b..27af005 100644 --- a/curlylint/formatters/json.py +++ b/curlylint/formatters/json.py @@ -23,6 +23,7 @@ def format_json(issues: List["Issue"]): "line": issue.location.line, "column": issue.location.column, "message": issue.message, + "code": issue.code, } ) diff --git a/curlylint/formatters/stylish.py b/curlylint/formatters/stylish.py index 431f170..1773a50 100644 --- a/curlylint/formatters/stylish.py +++ b/curlylint/formatters/stylish.py @@ -22,5 +22,5 @@ def format_stylish(issues: List["Issue"]): loc = click.style( f"{issue.location.line}:{issue.location.column}", dim=True ) - print(f"{loc}\t{issue.message}") + print(f"{loc}\t{issue.message}\t{issue.code}") print("") diff --git a/curlylint/issue.py b/curlylint/issue.py index 5d960fe..a0c7e83 100644 --- a/curlylint/issue.py +++ b/curlylint/issue.py @@ -28,13 +28,16 @@ def from_ast(file_path, ast_location): class Issue: location = attr.ib() message = attr.ib() + code = attr.ib() def __str__(self): - return "{}: {}".format(self.location, self.message) + return f"{self.location}: {self.message} ({self.code})" def __attrs_post_init__(self): assert isinstance(self.location, IssueLocation) @staticmethod - def from_ast(file_path, ast_location, message): - return Issue(IssueLocation.from_ast(file_path, ast_location), message) + def from_ast(file_path, ast_location, message, code): + return Issue( + IssueLocation.from_ast(file_path, ast_location), message, code + ) diff --git a/curlylint/lint.py b/curlylint/lint.py index e3caa29..68b4cdd 100644 --- a/curlylint/lint.py +++ b/curlylint/lint.py @@ -32,7 +32,7 @@ def parse_file(path_and_config): return [], file except parsy.ParseError as error: location = get_parsy_error_location(error, path) - issue = Issue(location, "Parse error: " + str(error)) + issue = Issue(location, "Parse error: " + str(error), "parse-error") return [issue], None diff --git a/curlylint/rules/indent/indent.py b/curlylint/rules/indent/indent.py index 162ee82..f6f5c73 100644 --- a/curlylint/rules/indent/indent.py +++ b/curlylint/rules/indent/indent.py @@ -6,6 +6,8 @@ WHITESPACE_INDENT_RE = re.compile(r"^\s*") INDENT_RE = re.compile("^ *") +INDENT = "indent" + RULE = { "type": "layout", "docs": { @@ -57,7 +59,7 @@ def check_indentation(file, config): issues = [] def add_issue(location, msg): - issues.append(Issue.from_ast(file, location, msg)) + issues.append(Issue.from_ast(file, location, msg, INDENT)) def check_indent(expected_level, node, inline=False, allow_same_line=False): node_level = get_indent_level(file.source, node) @@ -345,7 +347,7 @@ def check_space_only_indent(file, config): indent = WHITESPACE_INDENT_RE.match(line).group(0) if not contains_exclusively(indent, " "): loc = IssueLocation(file_path=file.path, line=i, column=0) - issue = Issue(loc, "Should be indented with spaces") + issue = Issue(loc, "Should be indented with spaces", INDENT) issues.append(issue) return issues