Skip to content

Commit

Permalink
Add codes for rules – indent and parse-error for the two existing…
Browse files Browse the repository at this point in the history
… checks
  • Loading branch information
thibaudcolas committed May 3, 2020
1 parent fae35f1 commit d2d5172
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions curlylint/formatters/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def format_json(issues: List["Issue"]):
"line": issue.location.line,
"column": issue.location.column,
"message": issue.message,
"code": issue.code,
}
)

Expand Down
2 changes: 1 addition & 1 deletion curlylint/formatters/stylish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
9 changes: 6 additions & 3 deletions curlylint/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion curlylint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 4 additions & 2 deletions curlylint/rules/indent/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
WHITESPACE_INDENT_RE = re.compile(r"^\s*")
INDENT_RE = re.compile("^ *")

INDENT = "indent"

RULE = {
"type": "layout",
"docs": {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d2d5172

Please sign in to comment.