GithubHelp home page GithubHelp logo

jayvdb / flake8-putty Goto Github PK

View Code? Open in Web Editor NEW
37.0 4.0 6.0 96 KB

Flake8 plugin to control reporting per file and line

License: MIT License

Python 100.00%
flake8-plugin linter monkey-patching

flake8-putty's Introduction

Flake8 Putty

Build Status

Coverage Status

Code Quality

Pypi Entry

image

Flake8 Putty allows more control over errors reported by flake8, without adding noqa for every erroneous or undesirable error detected.

See https://gitlab.com/pycqa/flake8/issues/89 for some of the motivation for this extension.

If you only want better noqa support, flake8-respect-noqa is a simpler extension which works only when multiprocessing is disabled.

flake8-putty requires flake8 2. If you are looking for an extension compatible with flake8 3 that supports a subset of flake8-putty, see flake8-per-file-ignores.

Disabling erroneous or undesirable errors by adding noqa in the code may be undesirable for a number of reasons, including:

  • the 'error' appears frequently
  • the module is strictly in maintenance mode only
  • it causes a line to break the line length rule
  • the error should be ignored on only some versions or platforms

Installation

Simply:

$ pip install flake8-putty

Check that flake8 finds it:

$ flake8 --version

2.4.1 (pep8: 1.5.7, flake8-putty: 0.3.2, mccabe: 0.3.1, pyflakes: 0.8.1) CPython 2.7.6 on Linux

Usage

flake8-putty is not activated unless putty-auto-ignore, putty-ignore or putty-select appear in the configuration file or command line options.

Auto ignore detects comments on each line like .. # flake8: disable=xxxx.

putty-ignore and putty-select both support multiline values, and each line is a rule which should have the format:

<selectors> : <modifier><codes>

The codes are flake8 codes to use when the rule is matched. The only modifier is + which appends the codes to the list of codes from other rules.

Selectors may contain one or more of: - file patterns - line regexes - flake8 codes

When multiple file pattern selectors are used, only one of the file patterns needs to match the filename. Likewise only one of many regex and only one of many codes needs to be matched.

However when different types of selectors are combined in one rule, each type of selector must be matched.

e.g. when two filenames and two regex are used, at least one filename and one regex must match before the rule is activated.

All matching rules are processed.

Examples

Disable only D102 on foo.py:

putty-ignore =
  foo.py : D102

Disable D205, D400 and D401 for __init__ methods:

putty-ignore =
  /__init__/ : +D205,D400,D401

Disable T001 only when it is explicitly mentioned:

putty-ignore =
  /# !qa:.*T001/ : +T001

Disable any code that is explicitly mentioned:

putty-ignore =
  /# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)

Disable any code that occurs after # flake8: disable=:

putty-auto-ignore = True

flake8-putty's People

Contributors

dirn avatar dvarrazzo avatar jayvdb avatar snoack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flake8-putty's Issues

Logical line support

While building a generic solution for #10 , I started investigating logical lines, as provided by pep8 . This is another special case of #4 . A logical line provides a tightest reasonable scope for the multi line regex to be constrained inside of, and it happens to be very efficient as pep8 already provides it.

The logical lines branch has working code and tests. The next step is to define selector semantics for this. Im currently using /.../l for logical line regex.

flake8 3.0 includes per line noqa

This will at least make some parts of flake8-putty unnecessary, similar to spookylukey/flake8-respect-noqa#3

Should this plugin only support flake8 2.x and recommend that requests for similar functionality in flake8 3.x be requested as features for the main utility, at least until there is push back from the maintainers like there was in flake8 2.x.

comment in tox dependencies causes packaging.InvalidRequirement

The flake8 jobs (except on Python 3.2) are currently failing due to something determining there is a syntax error in tox.ini

Invalid requirement: 'flake8-import-order  # hacking has a similar rule'
Traceback (most recent call last):
  File "/home/travis/build/jayvdb/flake8-putty/.tox/v241/lib/python2.6/site-packages/pip/req/req_install.py", line 78, in __init__
    req = Requirement(req)
  File "/home/travis/build/jayvdb/flake8-putty/.tox/v241/lib/python2.6/site-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
InvalidRequirement: Invalid requirement, parse error at "'# hackin'"

Also occurring in py27, https://travis-ci.org/jayvdb/flake8-putty/jobs/140301311

This is strange because the last successful build used pip 6.0.7 and tox 2.3.1, and the new error is reported by the same version.

The only obvious difference since the last successful build is that virtualenv was 15.0.1 but it is now 15.0.2
Installing virtualenv v13 fixes the problem, but installing 14.0.6 or 15.0.1 doesnt :/

Multiline regex pattern

To disable some pep257 checks for @property methods I would like to match on that and ignore some stuff on the next line. Is this possible in some way? If not were should I look to implement this?

Newbie question on how to actual get putty to be applied

Here are the packages installed:

$ flake8 --version

2.6.2 (
  pycodestyle: 2.0.0, 
  pyflakes: 1.2.3, 
  flake8-putty: 0.4.0, 
  flake8_quotes: 0.8.1, 
  mccabe: 0.5.2, 
  naming: 0.4.1
) 

CPython 3.5.1 on Darwin

I'm calling flake8 like so:

flake8 --putty-auto-ignore example.py

Here is example.py:

# pylint: disable=blacklisted-name
# flake8: disable=E302

import pdb

def baz(msg):
    print(msg)
    pdb.set_trace()
    print('done')

def bar(msg):
    baz(msg)

def foo(msg):
    bar(msg)

foo('hai')

But I'm still seeing in the terminal, the output:

$ flake8 --putty-auto-ignore debugging.py 

debugging.py:6:1: E302 expected 2 blank lines, found 1
debugging.py:11:1: E302 expected 2 blank lines, found 1
debugging.py:14:1: E302 expected 2 blank lines, found 1

putty is not flake8 v3 compatible

flake8_putty is broken for pywikibot, likely due to a change in either flake8 or pep8/pycodestyle.

18:31:33 + tox -v
18:31:33 using tox.ini: /home/jenkins/workspace/tox-jessie/tox.ini
18:31:33 using tox-1.9.2 from /usr/local/lib/python2.7/dist-packages/tox/__init__.pyc
18:31:33 flake8 create: /home/jenkins/workspace/tox-jessie/.tox/flake8
18:31:33   /home/jenkins/workspace/tox-jessie/.tox$ /usr/bin/python -m virtualenv --setuptools --python /usr/bin/python2.7 flake8 >/home/jenkins/workspace/tox-jessie/.tox/flake8/log/flake8-0.log
18:31:36 flake8 installdeps: flake8, pyflakes >= 1.1, hacking, flake8-docstrings>=0.2.6, flake8-putty>=0.3.2, flake8-coding, flake8-future-import, flake8-string-format, flake8-import-order, flake8-tuple>=0.2.8, flake8-print>=2.0.1, git+https://github.com/jayvdb/flake8-mock@use-ascii-readme
18:31:36   /home/jenkins/workspace/tox-jessie$ /home/jenkins/workspace/tox-jessie/.tox/flake8/bin/pip install --process-dependency-links --pre flake8 pyflakes >= 1.1 hacking flake8-docstrings>=0.2.6 flake8-putty>=0.3.2 flake8-coding flake8-future-import flake8-string-format flake8-import-order flake8-tuple>=0.2.8 flake8-print>=2.0.1 git+https://github.com/jayvdb/flake8-mock@use-ascii-readme >/home/jenkins/workspace/tox-jessie/.tox/flake8/log/flake8-1.log
18:31:40 flake8 develop-inst: /home/jenkins/workspace/tox-jessie
18:31:40   /home/jenkins/workspace/tox-jessie$ /home/jenkins/workspace/tox-jessie/.tox/flake8/bin/pip install --process-dependency-links --pre -e /home/jenkins/workspace/tox-jessie >/home/jenkins/workspace/tox-jessie/.tox/flake8/log/flake8-2.log
18:31:42 flake8 runtests: PYTHONHASHSEED='646594070'
18:31:42   /home/jenkins/workspace/tox-jessie$ /home/jenkins/workspace/tox-jessie/.tox/flake8/bin/flake8 --version 
18:31:42 Traceback (most recent call last):
18:31:42   File ".tox/flake8/bin/flake8", line 11, in <module>
18:31:42     sys.exit(main())
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
18:31:42     app.run(argv)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/main/application.py", line 292, in run
18:31:42     self._run(argv)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/main/application.py", line 278, in _run
18:31:42     self.initialize(argv)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/main/application.py", line 269, in initialize
18:31:42     self.register_plugin_options()
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/main/application.py", line 149, in register_plugin_options
18:31:42     self.check_plugins.register_options(self.option_manager)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/plugins/manager.py", line 378, in register_options
18:31:42     list(self.manager.map(call_register_options))
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/plugins/manager.py", line 252, in map
18:31:42     yield func(self.plugins[name], *args, **kwargs)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/plugins/manager.py", line 348, in generated_function
18:31:42     return method(optmanager, *args, **kwargs)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8/plugins/manager.py", line 198, in register_options
18:31:42     add_options(optmanager)
18:31:42   File "/home/jenkins/workspace/tox-jessie/.tox/flake8/local/lib/python2.7/site-packages/flake8_putty/extension.py", line 118, in add_options
18:31:42     parser.config_options.append('putty-select')
18:31:42 AttributeError: 'OptionManager' object has no attribute 'config_options'
18:31:42 ERROR: InvocationError: '/home/jenkins/workspace/tox-jessie/.tox/flake8/bin/flake8 --version'

investigating...

require code

Add ability to disable checks when the module does not include any code; e.g. empty __init__ modules.

comments at end of line are not stripped

Currently a # comment is only removed if it is one a separate line.

i.e. A rule like

    tests/textlib_tests.py,/self.assert.*{{/ : +P103 # invalidly detected as {} format string

will add P103 # invalidly detected as {} format string as one of the codes to ignore, instead of ignoring P103.

The stripping needs to done in such as way that # is possible in the regex.

line continuation operator

When there is a line continuation operator, any auto-ignore comments on the last continued line should apply to all lines. This is another example of the multi-line regex problem (#4). In this case, it is an implicit multi-line regex, and can be implemented only for auto-ignore comments, which may be easier than the more generic solution.

The reason is that comments can not appear after line continuation operator. The following is a SyntaxError:

if True \  # flake8: xxx
        and False:
    print('not reached')

So, it must be

if True \
        and False:  # flake8: xxx
    print('not reached')

And that comment needs to apply to the previous line as well, in a predicable manner (strip all whitespace).

Predefined ignore patterns

IMHO it'd be nice to have a # flake8: disable=X000 pattern for every code without having to explicitly define them. The syntax is similar to pylint's, but another syntax would work as well.

Filename matcher doesn't work?

I'm probably doing something wrong, but I can't figure out what it is ๐Ÿ˜‰

I'm using this in my config:

putty-ignore =
    test_*.py : +D100,D101,D202

However I still get those messages, e.g.:

./tests/unit/misc/test_sessions.py:48:1: D101 Missing docstring in public class

I tried different variations (test_*, tests/*/*/test_*.py, etc.) but I didn't get any of those to work. Any idea why?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.