Skip to content

Commit

Permalink
Logger housekeeping and use LintMatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaday committed Nov 24, 2019
1 parent b065baf commit 2d8fea2
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 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 @@ -39,35 +37,34 @@ def find_errors(self, output):
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

logger.info('message -- msg:"%s", line:%s, col:%s, error: %s, warning: %s, message_obj:%s',
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 2d8fea2

Please sign in to comment.