Skip to content

Commit 9a60a73

Browse files
committed
update to make this a proper package, some minor updates and cleanup, fixes bug where triple quotes tracking was not cleaned up between modules.
1 parent ad0c100 commit 9a60a73

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pip install pylint-quotes
7070
## Usage
7171
To use pylint-quotes, it must loaded in as a plugin when running pylint
7272
```
73-
pylint --load-plugins pylint-quotes <file>
73+
pylint --load-plugins pylint_quotes <module-or-package>
7474
```
7575

7676
## Checks

pylint_quotes/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""pylint-quotes module"""
2+
from __future__ import absolute_import
3+
from pylint_quotes import plugin
4+
5+
__version__ = '0.1.3'
6+
7+
register = plugin.register
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Pylint plugin for checking quote type on strings.
22
"""
3+
34
from __future__ import absolute_import
45

56
import tokenize
67

78
from pylint.interfaces import ITokenChecker, IAstroidChecker
89
from pylint.checkers import BaseTokenChecker
910

11+
1012
CONFIG_OPTS = ('single', 'double')
1113

1214
QUOTES = ('\'', '"')
@@ -99,6 +101,20 @@ def visit_module(self, node):
99101
"""
100102
self._process_for_docstring(node, 'module')
101103

104+
# pylint: disable=unused-argument
105+
def leave_module(self, node):
106+
"""Leave module and check remaining triple quotes.
107+
108+
Args:
109+
node: the module node we are leaving.
110+
"""
111+
for triple_quote in self._tokenized_triple_quotes.values():
112+
self._check_triple_quotes(triple_quote)
113+
114+
# after we are done checking these, clear out the triple-quote
115+
# tracking collection so nothing is left over for the next module.
116+
self._tokenized_triple_quotes = {}
117+
102118
def visit_classdef(self, node):
103119
"""Visit class and check for docstring quote consistency.
104120
@@ -146,16 +162,6 @@ def _process_for_docstring(self, node, node_type):
146162
self._check_docstring_quotes(quote_record)
147163
del self._tokenized_triple_quotes[doc_row]
148164

149-
# pylint: disable=unused-argument
150-
def leave_module(self, node):
151-
"""Leave module and check remaining triple quotes.
152-
153-
Args:
154-
node: the module node we are leaving.
155-
"""
156-
for triple_quote in self._tokenized_triple_quotes.values():
157-
self._check_triple_quotes(triple_quote)
158-
159165
def process_tokens(self, tokens):
160166
"""Process the token stream.
161167
@@ -254,12 +260,3 @@ def _invalid_docstring_quote(self, quote, row):
254260
line=row,
255261
args=(quote, TRIPLE_QUOTE_OPTS.get(self.config.docstring_quote))
256262
)
257-
258-
259-
def register(linter):
260-
"""Required method to auto register this checker.
261-
262-
Args:
263-
linter: Main interface object for Pylint plugins.
264-
"""
265-
linter.register_checker(StringQuoteChecker(linter))

pylint_quotes/plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Module which defines the required register method
2+
for Pylint plugins.
3+
"""
4+
5+
from pylint_quotes.checker import StringQuoteChecker
6+
7+
8+
def register(linter):
9+
"""Required method to auto register this checker.
10+
11+
Args:
12+
linter: Main interface object for Pylint plugins.
13+
"""
14+
linter.register_checker(StringQuoteChecker(linter))

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
"""Setup for the pylint-quotes package.
22
"""
3-
from setuptools import setup
3+
4+
from setuptools import setup, find_packages
5+
6+
from pylint_quotes import __version__
47

58

69
setup(
710
name='pylint-quotes',
811
description='Quote consistency checker for Pylint',
912
long_description=open('README.md').read(),
1013
license='MIT',
11-
version='0.1.0',
14+
version=__version__,
1215
author='Erick Daniszewski',
1316
author_email='edaniszewski@gmail.com',
1417
url='https://github.com/edaniszewski/pylint-quotes',
1518
install_requires=[
1619
'pylint',
1720
],
18-
packages=[
19-
'',
20-
],
21+
packages=find_packages(),
2122
classifiers=[
2223
'Intended Audience :: Developers',
2324
'License :: OSI Approved :: MIT License',

0 commit comments

Comments
 (0)