Skip to content

Commit 3176315

Browse files
authored
Enable pylint (#70)
1 parent cffd9f4 commit 3176315

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

Diff for: .pre-commit-config.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ repos:
2929
- types-setuptools
3030
- types-docutils
3131
- types-toml
32-
# TODO: activate pylint
33-
# - repo: https://github.com/PyCQA/pylint
34-
# rev: v2.9.3
35-
# hooks:
36-
# - id: pylint
37-
# additional_dependencies: []
32+
- repo: https://github.com/PyCQA/pylint
33+
rev: v2.11.1
34+
hooks:
35+
- id: pylint
36+
additional_dependencies:
37+
- docutils
38+
- restructuredtext-lint
39+
- stevedore

Diff for: .pylintrc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[MESSAGES CONTROL]
2+
3+
disable =
4+
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
5+
attribute-defined-outside-init,
6+
consider-using-f-string,
7+
invalid-name,
8+
missing-class-docstring,
9+
missing-function-docstring,
10+
missing-module-docstring,
11+
no-self-use,
12+
too-few-public-methods,
13+
too-many-arguments,
14+
too-many-branches,
15+
too-many-instance-attributes,
16+
too-many-locals,
17+
too-many-nested-blocks,
18+
too-many-statements,
19+
unused-variable,
20+
useless-object-inheritance,
21+
22+
[REPORTS]
23+
output-format = colorized

Diff for: doc/source/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
master_doc = "index"
2222

2323
# General information about the project.
24-
project = u"doc8"
25-
copyright = u"2013, OpenStack Foundation"
24+
project = "doc8"
25+
# pylint: disable=redefined-builtin
26+
copyright = "2013, OpenStack Foundation"
2627

2728
# The name of the Pygments (syntax highlighting) style to use.
2829
pygments_style = "sphinx"

Diff for: doc8/checks.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ def report_iter(self, parsed_file):
7272
class CheckNewlineEndOfFile(ContentCheck):
7373
REPORTS = frozenset(["D005"])
7474

75-
def __init__(self, cfg):
76-
super(CheckNewlineEndOfFile, self).__init__(cfg)
77-
7875
def report_iter(self, parsed_file):
76+
# pylint: disable=protected-access
7977
if parsed_file.lines and not (
8078
parsed_file.lines[-1].endswith(b"\n")
8179
or parsed_file._lines[-1].endswith(b"\r")
@@ -123,7 +121,7 @@ class CheckValidity(ContentCheck):
123121
]
124122

125123
def __init__(self, cfg):
126-
super(CheckValidity, self).__init__(cfg)
124+
super().__init__(cfg)
127125
self._sphinx_mode = cfg.get("sphinx")
128126

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

146144
def __init__(self, cfg):
147-
super(CheckMaxLineLength, self).__init__(cfg)
145+
super().__init__(cfg)
148146
self._max_line_length = self._cfg["max_line_length"]
149147
self._allow_long_titles = self._cfg["allow_long_titles"]
150148

@@ -255,11 +253,11 @@ def _rst_checker(self, parsed_file):
255253
directives = self._extract_directives(lines)
256254

257255
def find_containing_nodes(num):
258-
if num < first_line and len(nodes_lines):
256+
if num < first_line and nodes_lines:
259257
return [nodes_lines[0][0]]
260258
contained_in = []
261259
for (n, (line_min, line_max)) in nodes_lines:
262-
if num >= line_min and num <= line_max:
260+
if line_min <= num <= line_max:
263261
contained_in.append((n, (line_min, line_max)))
264262
smallest_span = None
265263
best_nodes = []
@@ -276,6 +274,7 @@ def find_containing_nodes(num):
276274
return best_nodes
277275

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

281280
skip_types = (docutils_nodes.target, docutils_nodes.literal_block)
@@ -288,7 +287,7 @@ def any_types(nodes, types):
288287
if len(line) > self._max_line_length:
289288
in_directive = False
290289
for (start, end) in directives:
291-
if i >= start and i <= end:
290+
if start <= i <= end:
292291
in_directive = True
293292
break
294293
if in_directive:

Diff for: doc8/main.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858

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

6262

6363
def merge_sets(sets):
@@ -79,7 +79,7 @@ def parse_ignore_path_errors(entries):
7979

8080
def from_ini(fp):
8181
parser = configparser.RawConfigParser()
82-
with open(fp, "r") as fh:
82+
with open(fp, "r", encoding="utf-8") as fh:
8383
parser.read_file(fh)
8484

8585
cfg = {}
@@ -518,8 +518,7 @@ def main():
518518

519519
if result.total_errors:
520520
return 1
521-
else:
522-
return 0
521+
return 0
523522

524523

525524
if __name__ == "__main__":

Diff for: doc8/tests/test_main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22

3-
from mock import patch, MagicMock
43
import os
54
from io import StringIO
65
import unittest
6+
from unittest.mock import patch, MagicMock
77
import shutil
88
import sys
99

@@ -118,7 +118,7 @@ def __exit__(self, *args):
118118
shutil.rmtree(self.path)
119119

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

124124
def mock(self):

0 commit comments

Comments
 (0)