Skip to content

Commit

Permalink
Enable pylint (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 10, 2021
1 parent cffd9f4 commit 3176315
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
14 changes: 8 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ repos:
- types-setuptools
- types-docutils
- types-toml
# TODO: activate pylint
# - repo: https://github.com/PyCQA/pylint
# rev: v2.9.3
# hooks:
# - id: pylint
# additional_dependencies: []
- repo: https://github.com/PyCQA/pylint
rev: v2.11.1
hooks:
- id: pylint
additional_dependencies:
- docutils
- restructuredtext-lint
- stevedore
23 changes: 23 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[MESSAGES CONTROL]

disable =
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
attribute-defined-outside-init,
consider-using-f-string,
invalid-name,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
no-self-use,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-locals,
too-many-nested-blocks,
too-many-statements,
unused-variable,
useless-object-inheritance,

[REPORTS]
output-format = colorized
5 changes: 3 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
master_doc = "index"

# General information about the project.
project = u"doc8"
copyright = u"2013, OpenStack Foundation"
project = "doc8"
# pylint: disable=redefined-builtin
copyright = "2013, OpenStack Foundation"

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand Down
15 changes: 7 additions & 8 deletions doc8/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ def report_iter(self, parsed_file):
class CheckNewlineEndOfFile(ContentCheck):
REPORTS = frozenset(["D005"])

def __init__(self, cfg):
super(CheckNewlineEndOfFile, self).__init__(cfg)

def report_iter(self, parsed_file):
# pylint: disable=protected-access
if parsed_file.lines and not (
parsed_file.lines[-1].endswith(b"\n")
or parsed_file._lines[-1].endswith(b"\r")
Expand Down Expand Up @@ -123,7 +121,7 @@ class CheckValidity(ContentCheck):
]

def __init__(self, cfg):
super(CheckValidity, self).__init__(cfg)
super().__init__(cfg)
self._sphinx_mode = cfg.get("sphinx")

def report_iter(self, parsed_file):
Expand All @@ -144,7 +142,7 @@ class CheckMaxLineLength(ContentCheck):
REPORTS = frozenset(["D001"])

def __init__(self, cfg):
super(CheckMaxLineLength, self).__init__(cfg)
super().__init__(cfg)
self._max_line_length = self._cfg["max_line_length"]
self._allow_long_titles = self._cfg["allow_long_titles"]

Expand Down Expand Up @@ -255,11 +253,11 @@ def _rst_checker(self, parsed_file):
directives = self._extract_directives(lines)

def find_containing_nodes(num):
if num < first_line and len(nodes_lines):
if num < first_line and nodes_lines:
return [nodes_lines[0][0]]
contained_in = []
for (n, (line_min, line_max)) in nodes_lines:
if num >= line_min and num <= line_max:
if line_min <= num <= line_max:
contained_in.append((n, (line_min, line_max)))
smallest_span = None
best_nodes = []
Expand All @@ -276,6 +274,7 @@ def find_containing_nodes(num):
return best_nodes

def any_types(nodes, types):
# pylint: disable=use-a-generator
return any([isinstance(n, types) for n in nodes])

skip_types = (docutils_nodes.target, docutils_nodes.literal_block)
Expand All @@ -288,7 +287,7 @@ def any_types(nodes, types):
if len(line) > self._max_line_length:
in_directive = False
for (start, end) in directives:
if i >= start and i <= end:
if start <= i <= end:
in_directive = True
break
if in_directive:
Expand Down
7 changes: 3 additions & 4 deletions doc8/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@


def split_set_type(text, delimiter=","):
return set([i.strip() for i in text.split(delimiter) if i.strip()])
return {i.strip() for i in text.split(delimiter) if i.strip()}


def merge_sets(sets):
Expand All @@ -79,7 +79,7 @@ def parse_ignore_path_errors(entries):

def from_ini(fp):
parser = configparser.RawConfigParser()
with open(fp, "r") as fh:
with open(fp, "r", encoding="utf-8") as fh:
parser.read_file(fh)

cfg = {}
Expand Down Expand Up @@ -518,8 +518,7 @@ def main():

if result.total_errors:
return 1
else:
return 0
return 0


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions doc8/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

from mock import patch, MagicMock
import os
from io import StringIO
import unittest
from unittest.mock import patch, MagicMock
import shutil
import sys

Expand Down Expand Up @@ -118,7 +118,7 @@ def __exit__(self, *args):
shutil.rmtree(self.path)

def create_file(self, filename, content):
with open(os.path.join(self.path, filename), "w") as file:
with open(os.path.join(self.path, filename), "w", encoding="utf-8") as file:
file.write(content)

def mock(self):
Expand Down

0 comments on commit 3176315

Please sign in to comment.