A Pylint plugin to analyze Flask applications.

Overview

pylint-flask

Build Status Coverage Status PyPI License

About

pylint-flask is Pylint plugin for improving code analysis when editing code using Flask. Inspired by pylint-django.

Problems pylint-flask solves:

  1. Recognize flask.ext.* style imports. Say you have the following code:

     from flask.ext import wtf
     from flask.ext.wtf import validators
    
     class PostForm(wtf.Form):
         content = wtf.TextAreaField('Content', validators=[validators.Required()])

    Normally, pylint will throw errors like:

     E:  1,0: No name 'wtf' in module 'flask.ext'
     E:  2,0: No name 'wtf' in module 'flask.ext'
     F:  2,0: Unable to import 'flask.ext.wtf'
    

    As pylint builds it's own abstract syntax tree, pylint-flask will translate the flask.ext imports into the actual module name, so pylint can continue checking your code.

Usage

Ensure pylint-flask is installed and on your path, and then run pylint using pylint-flask as a plugin.

pip install pylint-flask
pylint --load-plugins pylint_flask [..your module..]

Contributing

Pull requests are always welcome. Here's an outline of the steps you need to prepare your code.

  1. git clone https://github.com/jschaf/pylint-flask.git
  2. cd pylint-flask
  3. mkvirtualenv pylint-flask
  4. pip install -r dev-requirements.txt
  5. git checkout -b MY-NEW-FIX
  6. Hack away
  7. Make sure everything is green by running tox
  8. git push origin MY-NEW-FIX
  9. Create a pull request

License

pylint-flask is available under the GPLv2 license.

Comments
  • Support Astroid 2.0

    Support Astroid 2.0

    Based on #8, have changed nodes.ImportFrom rather than nodes.From.

    tox fails around flake8 commands (something about RecursionError: maximum recursion depth exceeded). New to flake8 so not sure what's happening there (or if it's just my machine).

    Have also tested in my own project with a pip install from Github, e.g. pip install "git+ssh://[email protected]/simpleweb/[email protected]", and no longer getAttributeError: module 'astroid.nodes' has no attribute 'From' `

    opened by henryaddison 6
  • doesn't support pylint >= 2

    doesn't support pylint >= 2

    Looks like the latest pylint requires astroid>=2.0.0 and pylint-flask doesn't support that atm. Any plans to fix anytime soon?

    Traceback (most recent call last):
      File "/opt/pyenv/versions/3.6.0/bin/pylint3", line 11, in <module>
        sys.exit(run_pylint())
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/pylint/__init__.py", line 19, in run_pylint
        Run(sys.argv[1:])
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/pylint/lint.py", line 1315, in __init__
        linter.load_plugin_modules(self._plugins)
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/pylint/lint.py", line 519, in load_plugin_modules
        module = modutils.load_module_from_name(modname)
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/astroid/modutils.py", line 196, in load_module_from_name
        return load_module_from_modpath(dotted_name.split('.'), path, use_sys)
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/astroid/modutils.py", line 239, in load_module_from_modpath
        module = imp.load_module(curname, mp_file, mp_filename, mp_desc)
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/imp.py", line 244, in load_module
        return load_package(name, filename)
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/imp.py", line 216, in load_package
        return _load(spec)
      File "<frozen importlib._bootstrap>", line 675, in _load
      File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
      File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/pylint_flask/__init__.py", line 79, in <module>
        MANAGER.register_transform(nodes.From,
    AttributeError: module 'astroid.nodes' has no attribute 'From'
    
    opened by kzidane 4
  • fix import order and run black for formatting

    fix import order and run black for formatting

    When using this plugin it ironically causes pylint to complain because astroid is imported before re. I constantly get the following diagnositcs message when using with vim which is fairly annoying.

    [pylint C0411] standard import "import re" should be placed before "from astroid import MANAGER" (wrong-import-order)

    Screen Shot 2021-01-07 at 1 13 25 AM

    Everything else besides switching the import order is just formatting from black, which I can create another pull request without if need be.

    opened by nicksherron 3
  • Removed unnecessary pass statement. Function has at least a docstring.

    Removed unnecessary pass statement. Function has at least a docstring.

    Removed unnecessary pass statement from init.py. Function has at least a docstring. A pass statement is necessary only when the function has none of the following:

    • docstring;
    • code.

    Pylint was constantly showing warnings (in VSCode at least) on an "unnecessary pass statement" on line 12 in init.py.

    opened by Deck451 2
  • Remove logilab-common from install_requires

    Remove logilab-common from install_requires

    logilab-common does not seem to be used anywhere in pylint-flask. So this PR removes logilab-common from install_requires. It also removes it from dev-requirements.txt since Travis and tox both succeeded without it.

    opened by sebastinas 2
  • tests/input in release tarball

    tests/input in release tarball

    Hi Joe,

    we're are packaging pylint-flask for Debian, and would like to run the tests automatically while building from the/a tarball. Could you please either tag the release(s) on Github or include test/input into the Pypi tarball (we could point to either)? Thx in advance, the package is coming up, soon!

    Best, DS

    opened by danstender 2
  • Check expressions for flask.ext style imports

    Check expressions for flask.ext style imports

    Right now, we only check from import and regular imports. A person could however write the following code.

    import flask.ext.admin, flask.ext.wtf
    
    A = flask.ext.admin
    W = flask.ext.wtf
    

    Since we only transform the imports, the W line gets left as flask.ext.admin instead of being translated into flask_admin.

    I'm not sure it's worth adding a transformation for every type of node that can take an expression. I'll leave this open to see if anyone hits this bug.

    opened by jschaf 1
  • Method 'logger' has no 'info' member

    Method 'logger' has no 'info' member

    Any calls to app.logger.info() or similar raise a no-member issue. Pylint-flask should be able to handle this

    {
    	"owner": "python",
    	"code": "no-member",
    	"severity": 8,
    	"message": "Method 'logger' has no 'info' member",
    	"source": "pylint",
    }
    
    opened by tgross35 0
  • distutils has been deprecated in Python 3.10

    distutils has been deprecated in Python 3.10

    PEP with some migration advice : https://www.python.org/dev/peps/pep-0632/#migration-advice

    https://github.com/jschaf/pylint-flask/blob/920d716303bd9ea28c456f6bf785e95f2c256142/setup.py#L2

    opened by tirkarthi 0
  • chore(deps-dev): bump flask from 0.10.1 to 1.0

    chore(deps-dev): bump flask from 0.10.1 to 1.0

    Bumps flask from 0.10.1 to 1.0.

    Release notes

    Sourced from flask's releases.

    1.0

    The Pallets team is pleased to release Flask 1.0. [Read the announcement on our blog.](https://www.palletsprojects.com/blog/flask-1-0-released/

    There are over a year's worth of changes in this release. Many features have been improved or changed. Read the changelog to understand how your project's code will be affected.

    JSON Security Fix

    Flask previously decoded incoming JSON bytes using the content type of the request. Although JSON should only be encoded as UTF-8, Flask was more lenient. However, Python includes non-text related encodings that could result in unexpected memory use by a request.

    Flask will now detect the encoding of incoming JSON data as one of the supported UTF encodings, and will not allow arbitrary encodings from the request.

    Install or Upgrade

    Install from PyPI with pip:

    pip install -U Flask
    

    0.12.4

    This is a repackage of 0.12.3 to fix an issue with how the package was built.

    Upgrade

    Upgrade from PyPI with pip. Use a version identifier if you want to stay at 0.12:

    pip install -U 'Flask~=0.12.4'
    

    0.12.3

    This release includes an important security fix for JSON and a minor backport for CLI support in PyCharm. It is provided for projects that cannot update to Flask 1.0 immediately. See the 1.0 announcement and update to it instead if possible.

    JSON Security Fix

    Flask previously decoded incoming JSON bytes using the content type of the request. Although JSON should only be encoded as UTF-8, Flask was more lenient. However, Python includes non-text related encodings that could result in unexpected memory use by a request.

    Flask will now detect the encoding of incoming JSON data as one of the supported UTF encodings, and will not allow arbitrary encodings from the request.

    Upgrade

    Upgrade from PyPI with pip. Use a version identifier if you want to stay at 0.12:

    pip install -U 'Flask~=0.12.3'
    
    ... (truncated)
    Changelog

    Sourced from flask's changelog.

    Version 1.0

    Released 2018-04-26

    • Python 2.6 and 3.3 are no longer supported.
    • Bump minimum dependency versions to the latest stable versions: Werkzeug >= 0.14, Jinja >= 2.10, itsdangerous >= 0.24, Click >= 5.1. :issue:2586
    • Skip :meth:app.run <Flask.run> when a Flask application is run from the command line. This avoids some behavior that was confusing to debug.
    • Change the default for :data:JSONIFY_PRETTYPRINT_REGULAR to False. :func:~json.jsonify returns a compact format by default, and an indented format in debug mode. :pr:2193
    • :meth:Flask.__init__ <Flask> accepts the host_matching argument and sets it on :attr:~Flask.url_map. :issue:1559
    • :meth:Flask.__init__ <Flask> accepts the static_host argument and passes it as the host argument when defining the static route. :issue:1559
    • :func:send_file supports Unicode in attachment_filename. :pr:2223
    • Pass _scheme argument from :func:url_for to :meth:~Flask.handle_url_build_error. :pr:2017
    • :meth:~Flask.add_url_rule accepts the provide_automatic_options argument to disable adding the OPTIONS method. :pr:1489
    • :class:~views.MethodView subclasses inherit method handlers from base classes. :pr:1936
    • Errors caused while opening the session at the beginning of the request are handled by the app's error handlers. :pr:2254
    • Blueprints gained :attr:~Blueprint.json_encoder and :attr:~Blueprint.json_decoder attributes to override the app's encoder and decoder. :pr:1898
    • :meth:Flask.make_response raises TypeError instead of ValueError for bad response types. The error messages have been improved to describe why the type is invalid. :pr:2256
    • Add routes CLI command to output routes registered on the application. :pr:2259
    • Show warning when session cookie domain is a bare hostname or an IP address, as these may not behave properly in some browsers, such as Chrome. :pr:2282
    • Allow IP address as exact session cookie domain. :pr:2282
    • SESSION_COOKIE_DOMAIN is set if it is detected through SERVER_NAME. :pr:2282
    • Auto-detect zero-argument app factory called create_app or make_app from FLASK_APP. :pr:2297
    • Factory functions are not required to take a script_info parameter to work with the flask command. If they take a single parameter or a parameter named script_info, the
    ... (truncated)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Request: Add app.logger support

    Request: Add app.logger support

    Pylint gives "method logger has no "warning" member" when trying to use app.logger.warning("test")

    https://stackoverflow.com/questions/51678585/pylint-false-positive-for-flasks-app-logger-e1101-method-logger-has-no-d

    opened by ngandhy 0
  • Is this now redundant (for users of Flask latest)?

    Is this now redundant (for users of Flask latest)?

    Hi

    I noticed this package on PyPI today, came to have a look. Since flask.ext is a deprecated method in Flask latest, is there anything else pylint-flask does to aid pylint in checking over flask code?

    Thanks

    opened by DuncanBetts 2
Owner
Joe Schafer
Joe Schafer
A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.

flake8-bugbear A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycode

Python Code Quality Authority 869 Dec 30, 2022
❄️ A flake8 plugin to help you write better list/set/dict comprehensions.

flake8-comprehensions A flake8 plugin that helps you write better list/set/dict comprehensions. Requirements Python 3.6 to 3.9 supported. Installation

Adam Johnson 398 Dec 23, 2022
Flake8 plugin that checks import order against various Python Style Guides

flake8-import-order A flake8 and Pylama plugin that checks the ordering of your imports. It does not check anything else about the imports. Merely tha

Python Code Quality Authority 270 Nov 24, 2022
flake8 plugin that integrates isort

Flake8 meet isort Use isort to check if the imports on your python files are sorted the way you expect. Add an .isort.cfg to define how you want your

Gil Forcada Codinachs 139 Nov 8, 2022
Flake8 plugin to find commented out or dead code

flake8-eradicate flake8 plugin to find commented out (or so called "dead") code. This is quite important for the project in a long run. Based on eradi

wemake.services 277 Dec 27, 2022
flake8 plugin to run black for checking Python coding style

flake8-black Introduction This is an MIT licensed flake8 plugin for validating Python code style with the command line code formatting tool black. It

Peter Cock 146 Dec 15, 2022
A plugin for flake8 integrating Mypy.

flake8-mypy NOTE: THIS PROJECT IS DEAD It was created in early 2017 when Mypy performance was often insufficient for in-editor linting. The Flake8 plu

Łukasz Langa 103 Jun 23, 2022
A plugin for Flake8 that checks pandas code

pandas-vet pandas-vet is a plugin for flake8 that provides opinionated linting for pandas code. It began as a project during the PyCascades 2019 sprin

Jacob Deppen 146 Dec 28, 2022
flake8 plugin to catch useless `assert` statements

flake8-useless-assert flake8 plugin to catch useless assert statements Download or install on the PyPI page Violations Code Description Example ULA001

null 1 Feb 12, 2022
Pylint plugin for improving code analysis for when using Django

pylint-django About pylint-django is a Pylint plugin for improving code analysis when analysing code using Django. It is also used by the Prospector t

Python Code Quality Authority 544 Jan 6, 2023
Vim python-mode. PyLint, Rope, Pydoc, breakpoints from box.

Python-mode, a Python IDE for Vim This project needs contributors. Documentation: :help pymode https://github.com/python-mode/python-mode/wiki Importa

The Python-Mode 5.4k Jan 1, 2023
A simple tool to extract python code from a Jupyter notebook, and then run pylint on it for static analysis.

Jupyter Pylinter A simple tool to extract python code from a Jupyter notebook, and then run pylint on it for static analysis. If you find this tool us

Edmund Goodman 10 Oct 13, 2022
IDA Pro Python plugin to analyze and annotate Linux kernel alternatives

About This is an IDA Pro (Interactive Disassembler) plugin allowing to automatically analyze and annotate Linux kernel alternatives (content of .altin

Open Source Security, Inc. 16 Oct 12, 2022
Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications.

Flask Sitemapper Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications. This allows you to create a nice and

null 6 Jan 6, 2023
flask-apispec MIT flask-apispec (🥉24 · ⭐ 520) - Build and document REST APIs with Flask and apispec. MIT

flask-apispec flask-apispec is a lightweight tool for building REST APIs in Flask. flask-apispec uses webargs for request parsing, marshmallow for res

Joshua Carp 617 Dec 30, 2022
More than 130 check plugins for Icinga and other Nagios-compatible monitoring applications. Each plugin is a standalone command line tool (written in Python) that provides a specific type of check.

Python-based Monitoring Check Plugins Collection This Enterprise Class Check Plugin Collection offers a package of more than 130 Python-based, Nagios-

Linuxfabrik 119 Dec 27, 2022
A toolbar overlay for debugging Flask applications

Flask Debug-toolbar This is a port of the excellent django-debug-toolbar for Flask applications. Installation Installing is simple with pip: $ pip ins

null 863 Dec 29, 2022
Socket.IO integration for Flask applications.

Flask-SocketIO Socket.IO integration for Flask applications. Installation You can install this package as usual with pip: pip install flask-socketio

Miguel Grinberg 4.9k Jan 3, 2023