Skip to content

Commit

Permalink
Merge pull request #17 from htmlhint/task/housekeeping
Browse files Browse the repository at this point in the history
Task/housekeeping
  • Loading branch information
mmaday authored Nov 24, 2019
2 parents 1ea6248 + 2d8fea2 commit 62ef89b
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging

import sublime
from SublimeLinter.lint import NodeLinter
from SublimeLinter.lint import LintMatch, NodeLinter


logger = logging.getLogger("SublimeLinter.plugin.htmlhint")
Expand All @@ -23,10 +23,8 @@ class Htmlhint(NodeLinter):

"""Provides an interface to htmlhint."""

cmd = ('htmlhint', '--format', 'json', '--nocolor', 'stdin')
defaults = {
'selector': 'text.html'
}
cmd = ("htmlhint", "--format", "json", "--nocolor", "stdin")
defaults = {"selector": "text.html"}

def find_errors(self, output):
"""
Expand All @@ -36,40 +34,37 @@ def find_errors(self, output):
"""
output_json = sublime.decode_value(output)

# logger.info('output_json:"{}", file: "{}"'.format(output_json, self.filename))
logger.debug('output_json:"%s", file: "%s"', output_json, self.filename)

for file in output_json:
for message in file['messages']:
for message in file["messages"]:
yield self.parse_message(message)

def parse_message(self, message):
"""Parse message object into standard elements of an error and return them."""
error_message = message['message']
line = message['line'] - 1
col = message['col']

# set error and warning flags based on message type
error = None
warning = None
if message['type'] == 'error':
error = True
warning = False
elif message['type'] == 'warning':
error = False
warning = True
elif message['type'] == 'info':
# ignore info messages by setting message to None
error_message = message["message"]
line = message["line"] - 1
col = message["col"]
error_type = message["type"]

# ignore message type of info
if error_type == "info":
message = None

message = 'message -- msg:"{}", line:{}, col:{}, error: {}, warning: {}, message_obj:{}'
logger.info(message.format(
logger.info(
'message -- msg:"%s", line:%s, col:%s, type: %s, message_obj:%s',
error_message,
line,
col,
error,
warning,
error_type,
message,
))

return message, line, col, error, warning, error_message, None
)
return LintMatch(
filename=self.filename,
line=line,
col=col,
error_type=error_type,
code=message.get("rule", {}).get("id", ""),
message=error_message,
match=str(message),
)

0 comments on commit 62ef89b

Please sign in to comment.