SublimeLinter-pyflakes icon indicating copy to clipboard operation
SublimeLinter-pyflakes copied to clipboard

[Feature Request] Support for warnings

Open YonatanAhituv opened this issue 7 years ago • 9 comments

Currently, there is no differentiating between errors and warnings from pyflakes, however Atom's pyflakes linter managed to detected warnings from errors by looking for the following strings:

'used',
'redefines',
'shadowed'
'may be'

in the output. Maybe something like that could be integrated.

YonatanAhituv avatar Apr 08 '18 03:04 YonatanAhituv

That sounds like a good addition. Can you make a PR? If you don't know how to start just ask, I can guide you through.

kaste avatar Apr 08 '18 19:04 kaste

@kaste I tried, but the documentation isn't good, and I haven't done any work with regex. Really sorry.

YonatanAhituv avatar Apr 09 '18 00:04 YonatanAhituv

Basically you have to implement split_match

	def split_match(self, match):
		match, line, col, error, warning, message, near = super().split_match(match)
		if not match:
			return None

		# now parse and interpret 'message'
		# 'error' or 'warning' represent a 'code' or linter rule like 'W031' or 
		# '(no-redef)' etc. 
		if message is an error:
			error = 'error'
		else:
			warning = 'warning'
		return match, line, col, error, warning, message, near

kaste avatar Apr 09 '18 07:04 kaste

@kaste It uses regex though, I was able to remove all the code except for the variables and regex at the start and it all worked fine.

#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by Aparajita Fishman
# Copyright (c) 2015-2016 The SublimeLinter Community
# Copyright (c) 2013-2014 Aparajita Fishman
#
# License: MIT
#

"""This module exports the Pyflakes plugin linter class."""

from io import StringIO
from SublimeLinter.lint import PythonLinter


class Pyflakes(PythonLinter):
    """Provides an interface to the pyflakes python module/script."""

    syntax = 'python'
    cmd = 'pyflakes@python'
    version_args = '--version'
    version_re = r'(?P<version>\d+\.\d+\.\d+)'
    version_requirement = '>= 0.7.3'
    regex =  r'''(?x)
        .+?:\s*               # filename
        (?P<line>\d+):\s*     # line number

        # The rest of the line is the error message.
        # Within that, capture anything within single quotes as 'near'.
        (?P<message>[^\'\n\r]+(?P<near>\'.+?\')?.*)

        # The error message may be followed by the offending line of code...
        (?:\r?\n.*

        # and then another line with a caret (preceded by spaces)
        # pointing to the position where the error occurred.
        \r?\n(?P<col>[ ]+)\^)?
    '''
    multiline = True
    module = 'pyflakes.api'
    check_version = True

    # Internal
    reporter = None

YonatanAhituv avatar Apr 10 '18 00:04 YonatanAhituv

Sorry I don't know what you did here

kaste avatar Apr 10 '18 12:04 kaste

@kaste I'm using SL4. That removes the need for the functions.

YonatanAhituv avatar Apr 11 '18 00:04 YonatanAhituv

That's a bit odd. You should just use the version from master.

kaste avatar Apr 11 '18 11:04 kaste

@kaste I know, I was just having problems with pyflakes not running because it couldn't find the executable. I had to set it manually, and I needed SL4 to do that.

YonatanAhituv avatar Apr 11 '18 15:04 YonatanAhituv

Currently, there is no differentiating between errors and warnings from pyflakes, however Atom's pyflakes linter managed to detected warnings from errors by looking for the following strings:

'used',
'redefines',
'shadowed'
'may be'

in the output. Maybe something like that could be integrated.

Hi! :) take a look at #18

gorkicode avatar Oct 26 '21 04:10 gorkicode