├── .gitignore ├── .python-version ├── .travis.yml ├── LICENSE ├── README.md ├── linter.py ├── messages.json └── messages └── install.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.6" 4 | install: 5 | - pip install flake8 6 | script: 7 | - flake8 . --max-line-length=120 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-pyflakes 2 | ========================= 3 | 4 | [![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-pyflakes.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-pyflakes) 5 | 6 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [pyflakes](https://github.com/pyflakes/pyflakes). 7 | It will be used with files that have the "Python" syntax. 8 | 9 | 10 | ## Installation 11 | 12 | SublimeLinter must be installed in order to use this plugin. 13 | 14 | Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 15 | 16 | Before installing this plugin, ensure that `pyflakes` (0.7.3 or later) is installed on your system. 17 | To install `pyflakes`, do the following: 18 | 19 | 1. Install [Python](http://python.org) and [pip](http://www.pip-installer.org/en/latest/installing.html). If you plan to code in Python 3, you will need to install `pip` for Python 3 as well. 20 | 21 | 1. Install `pyflakes` by typing the following in a terminal, replacing ‘x’ with the minor version installed on your system: 22 | ``` 23 | # For python 2.x 24 | [sudo] pip-2.x install pyflakes 25 | 26 | # For python 3.x 27 | [sudo] pip-3.x install pyflakes 28 | ``` 29 | 30 | Please make sure that the path to `pyflakes` is available to SublimeLinter. 31 | The docs cover [troubleshooting PATH configuration](http://sublimelinter.com/en/latest/troubleshooting.html#finding-a-linter-executable). 32 | 33 | 34 | ## Settings 35 | 36 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 37 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 38 | 39 | 40 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | from SublimeLinter.lint import PythonLinter 2 | import re 3 | 4 | 5 | class Pyflakes(PythonLinter): 6 | cmd = 'pyflakes' 7 | regex = r'''(?x) 8 | ^(?P.+?):(?P\d+):((?P\d+):?)?\s 9 | 10 | # The rest of the line is the error message. 11 | # Within that, capture anything within single quotes as `near`. 12 | (?P[^\'\n\r]*(?P\'.+?\')?.*) 13 | ''' 14 | multiline = True 15 | # stderr has all syntax errors, parse it via our regex 16 | on_stderr = None 17 | defaults = { 18 | 'selector': 'source.python' 19 | } 20 | 21 | def reposition_match(self, line, col, match, vv): 22 | if 'imported but unused' in match.message: 23 | # Consider: 24 | # from foo import bar 25 | # import foo.bar 26 | # In both cases `pyflakes` reports `'foo.bar' ... unused`. 27 | 28 | import_id = re.escape(match.near[1:-1]) # unquote 29 | last_part = import_id.split('.')[-1] 30 | 31 | # So we match either `bar` or `foo.bar` against the line content 32 | text = vv.select_line(line) 33 | pattern = r"\s({}|{})".format(last_part, import_id) 34 | 35 | re_match = re.search(pattern, text) 36 | if re_match: 37 | return line, re_match.start(1), re_match.end(1) 38 | 39 | return super().reposition_match(line, col, match, vv) 40 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt" 3 | } 4 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-pyflakes 2 | ------------------------------- 3 | This linter plugin for SublimeLinter provides an interface to pyflakes. 4 | 5 | Please read the installation instructions at: 6 | 7 | https://github.com/SublimeLinter/SublimeLinter-pyflakes 8 | --------------------------------------------------------------------------------