From b065baf95503e6d03532321d2c3782c121695691 Mon Sep 17 00:00:00 2001 From: Mark Maday Date: Sat, 23 Nov 2019 17:07:17 -0800 Subject: [PATCH 1/2] Logger cleanup. --- linter.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/linter.py b/linter.py index a2faeb8..86838b9 100644 --- a/linter.py +++ b/linter.py @@ -36,8 +36,7 @@ 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']: @@ -62,14 +61,13 @@ def parse_message(self, message): # ignore info messages by setting message to None message = None - message = 'message -- msg:"{}", line:{}, col:{}, error: {}, warning: {}, message_obj:{}' - logger.info(message.format( + logger.info('message -- msg:"%s", line:%s, col:%s, error: %s, warning: %s, message_obj:%s', error_message, line, col, error, warning, message, - )) + ) return message, line, col, error, warning, error_message, None From 2d8fea23152afafde06123f9a9be09ac00474873 Mon Sep 17 00:00:00 2001 From: Mark Maday Date: Sat, 23 Nov 2019 18:09:04 -0800 Subject: [PATCH 2/2] Logger housekeeping and use LintMatch. --- linter.py | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/linter.py b/linter.py index 86838b9..b63018b 100644 --- a/linter.py +++ b/linter.py @@ -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") @@ -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): """ @@ -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), + )