Skip to content

Commit

Permalink
style: enforce configs on .pylintrc
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Mar 9, 2021
1 parent 44d6cf4 commit b9c25e2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -38,7 +38,7 @@ disable=bad-continuation,bad-whitespace,
bad-functions=map,filter

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,e,ex,Run,_,id,rv,cf
good-names = i,j,k,e,ex,Run,_,id,rv

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|([a-z_][a-z0-9_]*)|(__.*__)|register|urlpatterns)$
Expand Down
1 change: 1 addition & 0 deletions nitpick-style.toml
Expand Up @@ -18,6 +18,7 @@ include = [
"styles/flake8",
"styles/isort",
"styles/mypy",
"styles/pylint",
"styles/pytest",
"styles/tox",
"styles/package-json",
Expand Down
5 changes: 2 additions & 3 deletions src/nitpick/generic.py
Expand Up @@ -6,7 +6,6 @@
"""
import re
from collections import OrderedDict
from functools import lru_cache
from pathlib import Path
from typing import Any, Dict, Iterable, List, MutableMapping, Optional, Tuple, Union

Expand Down Expand Up @@ -223,15 +222,15 @@ def is_url(url: str) -> bool:
return url.startswith("http")


@lru_cache()
def relative_to_current_dir(path_or_str: Optional[PathOrStr]) -> str:
"""Return a relative path to the current dir or an absolute path."""
if not path_or_str:
return ""

path = Path(path_or_str)
if str(path).startswith(str(Path.cwd())):
return str(path.relative_to(Path.cwd())).lstrip(".")
rv = str(path.relative_to(Path.cwd()))
return "" if rv == "." else rv

return str(path.absolute())

Expand Down
56 changes: 54 additions & 2 deletions styles/pylint.toml
@@ -1,2 +1,54 @@
["pyproject.toml".tool.poetry.dev-dependencies]
pylint = "*"
["pyproject.toml".tool.poetry.dependencies]
pylint = {version = "*", optional = true}

["pyproject.toml".tool.poetry.extras]
lint = ["pylint"]

[".pylintrc".MASTER]
# Use multiple processes to speed up Pylint.
jobs = 1

[".pylintrc".REPORTS]
# Set the output format. Available formats are text, parseable, colorized, msvs (visual studio) and html.
# You can also give a reporter class, eg mypackage.mymodule.MyReporterClass.
output-format = "colorized"

[".pylintrc"."MESSAGES CONTROL"]
# TODO: deal with character separated INI options in https://github.com/andreoliwa/nitpick/issues/271
# The "nitpick.files" section doesn't work out of the box for .pylintrc:
# [nitpick.files.".pylintrc"]
# comma_separated_values = ["MESSAGES CONTROL.disable"]
# This syntax will be deprecated anyway, so I won't make it work now
# Configurations for the black formatter
#disable = "bad-continuation,bad-whitespace,fixme,cyclic-import"

[".pylintrc".BASIC]
# List of builtins function names that should not be used, separated by a comma
bad-functions = "map,filter"
# Good variable names which should always be accepted, separated by a comma
good-names = "i,j,k,e,ex,Run,_,id,rv"

[".pylintrc".FORMAT]
# Maximum number of characters on a single line.
max-line-length = 120
# Maximum number of lines in a module
max-module-lines = 1000
# TODO: deal with empty options (strings with spaces and quotes); maybe it's a ConfigParser/ConfigUpdater thing
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 tab).
#indent-string = " "
# Number of spaces of indent required inside a hanging or continued line.
indent-after-paren = 4

[".pylintrc".SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines = 4
# Ignore comments when computing similarities.
ignore-comments = "yes"
# Ignore docstrings when computing similarities.
ignore-docstrings = "yes"
# Ignore imports when computing similarities.
ignore-imports = "no"

[".pylintrc".VARIABLES]
# A regular expression matching the name of dummy variables (i.e. expectedly not used).
dummy-variables-rgx = "_$|dummy"
5 changes: 3 additions & 2 deletions tests/test_generic.py
Expand Up @@ -6,7 +6,7 @@

from testfixtures import compare

from nitpick.constants import TOX_INI
from nitpick.constants import EDITOR_CONFIG, TOX_INI
from nitpick.generic import MergeDict, flatten, get_subclasses, relative_to_current_dir
from tests.helpers import assert_conditions

Expand Down Expand Up @@ -95,6 +95,7 @@ def test_relative_to_current_dir(home, cwd):
f"{home_dir}{sep}another": f"{home_dir}{sep}another",
Path(f"{home_dir}{sep}bla{sep}bla"): f"{home_dir}{sep}bla{sep}bla",
f"{project_dir}{sep}{TOX_INI}": TOX_INI,
f"{project_dir}{sep}{EDITOR_CONFIG}": EDITOR_CONFIG,
Path(f"{project_dir}{sep}apps{sep}manage.py"): f"apps{sep}manage.py",
f"{home_dir}{sep}another{sep}one{sep}bites.py": f"{home_dir}{sep}another{sep}one{sep}bites.py",
Path(f"{home_dir}{sep}bla{sep}bla.txt"): f"{home_dir}{sep}bla{sep}bla.txt",
Expand All @@ -119,4 +120,4 @@ def test_relative_to_current_dir(home, cwd):
)

for path, expected in examples.items():
assert relative_to_current_dir(path) == expected
compare(actual=relative_to_current_dir(path), expected=expected, prefix=f"Path: {path}")

0 comments on commit b9c25e2

Please sign in to comment.