[Python] Replace global linting excludes with local line-level excludes ("noqa")

Replace the project global linting rule excludes (as defined in .pep8) with
fine-grained "# noqa" annotations.

By using noqa annotation the excludes are made on a per line basis instead of
globally.

These annotations are used where we make deliberate deviations from the standard
linting rules.

To lint the Python code in the project:

  $ flake8

To install flake8:

  $ pip install flake8

See https://flake8.readthedocs.org/en/latest/ for details.

To enable checking of the PEP-8 naming conventions, install the optional
extension pep8-naming:

  $ pip install pep8-naming

To enable checking of blind "except:" statements, install the optional
extension flake8-blind-except:

  $ pip install flake8-blind-except

To enable checking of import statement order, install the optional
extension flake8-import-order:

  $ pip install flake8-import-order
This commit is contained in:
practicalswift
2016-03-10 15:46:49 +01:00
parent 2eb227d7aa
commit d5326bfdc4
9 changed files with 25 additions and 22 deletions

View File

@@ -265,17 +265,20 @@ todo_include_todos = True
#
# Pull in the Swift lexers
from os.path import abspath, dirname, join as join_paths
from os.path import abspath, dirname, join as join_paths # noqa (E402)
sys.path = [
join_paths(dirname(dirname(abspath(__file__))), 'utils', 'pygments')
] + sys.path
import swift as swift_pygments_lexers
import swift as swift_pygments_lexers # noqa (E402 module level import not at top of file)
sys.path.pop(0)
# Monkeypatch pygments.lexers.get_lexer_by_name to return our lexers
from pygments.lexers import get_lexer_by_name as original_get_lexer_by_name
# Monkeypatch pygments.lexers.get_lexer_by_name to return our lexers. The
# ordering required to allow for monkeypatching causes the warning
# "I100 Import statements are in the wrong order." when linting using
# flake8-import-order. "noqa" is used to suppress this warning.
from pygments.lexers import get_lexer_by_name as original_get_lexer_by_name # noqa (E402)
def swift_get_lexer_by_name(_alias, *args, **kw):
@@ -286,5 +289,5 @@ def swift_get_lexer_by_name(_alias, *args, **kw):
else:
return original_get_lexer_by_name(_alias, *args, **kw)
import pygments.lexers
import pygments.lexers # noqa (I100 Import statements are in the wrong order.)
pygments.lexers.get_lexer_by_name = swift_get_lexer_by_name