Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make D403 weaker to avoid false positives #170

Merged
merged 7 commits into from Jan 21, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -13,8 +13,6 @@ matrix:
env: TOXENV=py26
- python: 2.7
env: TOXENV=py27
- python: 3.2
env: TOXENV=py32
- python: 3.3
env: TOXENV=py33
- python: 3.4
@@ -10,7 +10,7 @@ custom checks can be easily added, for example to cover
NumPy `docstring conventions
<https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`_.

**pep257** supports Python 2.6, 2.7, 3.2, 3.3, 3.4, 3.5, pypy and pypy3.
**pep257** supports Python 2.6, 2.7, 3.3, 3.4, 3.5, pypy and pypy3.

Quick Start
-----------
@@ -14,6 +14,7 @@
from __future__ import with_statement

import os
import string
import sys
import ast
import copy
@@ -152,6 +153,10 @@ class Module(Definition):
module = property(lambda self: self)
all = property(lambda self: self._all)

def __init__(self, *args, **kwargs):
super(Module, self).__init__(*args, **kwargs)
self.name = self.name.lower()

def __str__(self):
return 'at module level'

@@ -1618,6 +1623,11 @@ def check_capitalized(self, function, docstring):
"""
if docstring:
first_word = ast.literal_eval(docstring).split()[0]
if first_word == first_word.upper():
return
for char in first_word:
if char not in string.ascii_letters and char != "'":
return
if first_word != first_word.capitalize():
return D403(first_word.capitalize(), first_word)

@@ -18,7 +18,43 @@ def empty_docstring():
""""""


@expect("D403: First word of the first line should be properly capitalized "
"('Get', not 'GET')")
def all_caps():
"""GET the request."""


def non_letter_characters():
"""Create/Edit the doodli-do."""


def more_non_letter_characters():
"""(Un)register the user."""


def even_more_non_letter():
"""'laser' the planet."""


def dash():
"""git-push it."""


def digit_in_word():
"""sha1 the string."""


@expect("D403: First word of the first line should be properly capitalized "
"(\"Don't\", not \"Don'T\")")
def partial_caps():
"""Don'T do that."""


@expect("D403: First word of the first line should be properly capitalized "
"('Return', not 'ReTurn')")
def more_partial_caps():
"""ReTurn the field."""


@expect("D403: First word of the first line should be properly capitalized "
"('A', not 'a')")
def just_one_more_example():
"""a function."""
@@ -303,5 +303,5 @@ def inner_function():
"""Do inner something."""
return 0

expect(__file__ if __file__[-1] != 'c' else __file__[:-1],
expect(__file__.lower() if __file__[-1] != 'c' else __file__[:-1].lower(),
'D100: Missing docstring in public module')
@@ -109,12 +109,11 @@ def parse_errors(err):
while lines:
curr_line = lines.pop(0)
filename = curr_line[:curr_line.find(py_ext) + len(py_ext)]
if os.path.isfile(filename):
if lines:
err_line = lines.pop(0).strip()
err_code = err_line.split(':')[0]
basename = os.path.basename(filename)
result.setdefault(basename, set()).add(err_code)
if lines:
err_line = lines.pop(0).strip()
err_code = err_line.split(':')[0]
basename = os.path.basename(filename)
result.setdefault(basename, set()).add(err_code)

return result

@@ -495,10 +494,10 @@ def foo():
err = parse_errors(err)

assert code == 1
assert 'base.py' in err
assert 'a.py' not in err
assert 'D100' not in err['base.py']
assert 'D103' in err['base.py']
assert 'base.py' in err, err
assert 'a.py' not in err, err
assert 'D100' not in err['base.py'], err
assert 'D103' in err['base.py'], err


def test_config_file_cumulative_add_select():
@@ -539,10 +538,10 @@ def foo():
err = parse_errors(err)

assert code == 1
assert 'base.py' in err
assert 'a.py' in err
assert err['base.py'] == set(['D100'])
assert err['a.py'] == set(['D100', 'D103'])
assert 'base.py' in err, err
assert 'a.py' in err, err
assert err['base.py'] == set(['D100']), err
assert err['a.py'] == set(['D100', 'D103']), err


def test_config_file_convention_overrides_select():
@@ -578,9 +577,9 @@ def test_config_file_convention_overrides_select():
_, err, code = env.invoke_pep257()

assert code == 1
assert 'D100' in err
assert 'base.py' not in err
assert 'a.py' in err
assert 'D100' in err, err
assert 'base.py' not in err, err
assert 'a.py' in err, err


def test_cli_overrides_config_file():
@@ -616,10 +615,10 @@ def foo():
_, err, code = env.invoke_pep257(args="--convention=pep257")

assert code == 1
assert 'D100' in err
assert 'D103' not in err
assert 'base.py' in err
assert 'a.py' not in err
assert 'D100' in err, err
assert 'D103' not in err, err
assert 'base.py' in err, err
assert 'a.py' not in err, err


def test_cli_match_overrides_config_file():
@@ -656,10 +655,10 @@ def foo():
_, err, code = env.invoke_pep257(args="--match=a.py --match-dir=A")

assert code == 1
assert 'D100' in err
assert 'D103' not in err
assert 'base.py' not in err
assert 'a.py' in err
assert 'D100' in err, err
assert 'D103' not in err, err
assert 'base.py' not in err, err
assert 'a.py' in err, err


def test_config_file_convention_overrides_ignore():
@@ -698,10 +697,10 @@ def foo():
_, err, code = env.invoke_pep257()

assert code == 1
assert 'D100' in err
assert 'D103' in err
assert 'base.py' not in err
assert 'a.py' in err
assert 'D100' in err, err
assert 'D103' in err, err
assert 'base.py' not in err, err
assert 'a.py' in err, err


def test_config_file_ignore_overrides_select():
@@ -743,10 +742,10 @@ def bar():
err = parse_errors(err)

assert code == 1
assert 'base.py' in err
assert 'a.py' in err
assert err['base.py'] == set(['D100'])
assert err['a.py'] == set(['D100', 'D101'])
assert 'base.py' in err, err
assert 'a.py' in err, err
assert err['base.py'] == set(['D100']), err
assert err['a.py'] == set(['D100', 'D101']), err


def test_config_file_nearest_to_checked_file():
@@ -800,12 +799,12 @@ def bar():
err = parse_errors(err)

assert code == 1
assert 'base.py' in err
assert 'a.py' in err
assert 'b.py' in err
assert err['base.py'] == set(['D101', 'D102'])
assert err['a.py'] == set(['D101', 'D102'])
assert err['b.py'] == set(['D102'])
assert 'base.py' in err, err
assert 'a.py' in err, err
assert 'b.py' in err, err
assert err['base.py'] == set(['D101', 'D102']), err
assert err['a.py'] == set(['D101', 'D102']), err
assert err['b.py'] == set(['D102']), err


def test_config_file_nearest_match_re():
@@ -4,7 +4,7 @@
# install tox" and then run "tox" from this directory.

[tox]
envlist = py26, py27, py32, py33, py34, py35, pypy, pypy3, docs
envlist = py26, py27, py33, py34, py35, pypy, pypy3, docs

[testenv]
# Make sure reading the UTF-8 from test.py works regardless of the locale used.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.