License PyPI Build CodeQL pre-commit.ci status codecov.io readthedocs.org python3.10 Black isort pylint Security Status Known Vulnerabilities constcheck
Escape commas with \\ (\ when enclosed in single quotes)
Defaults can be configured in your pyproject.toml file
$ pip install constcheckusage: constcheck [-h] [-v] [-n] [-c INT] [-l INT] [-s STR] [-i LIST] [-I LIST] [--ignore-from [FILE=LIST [FILE=LIST ...]]] [path [path ...]] Check Python files for repeat use of strings. Escape commas with \\. Defaults can be configured in your pyproject.toml file. positional arguments: path path(s) to check files for (default: .) optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit -n, --no-ansi disable ansi output -c INT, --count INT minimum number of repeat strings (default: 3) -l INT, --length INT minimum length of repeat strings (default: 3) -s STR, --string STR parse a string instead of a file -i LIST, --ignore-strings LIST comma separated list of strings to exclude -I LIST, --ignore-files LIST comma separated list of files to exclude --ignore-from [FILE=LIST [FILE=LIST ...]] comma separated list of strings to exclude from file
>>> from constcheck import constcheck
>>> EXAMPLE = """ ... STRING_1 = "Hey" ... STRING_2 = "Hey" ... STRING_3 = "Hey" ... STRING_4 = "Hello" ... STRING_5 = "Hello" ... STRING_6 = "Hello" ... STRING_7 = "Hello" ... STRING_8 = "Hello, world" ... STRING_9 = "Hello, world" ... STRING_10 = "Hello, world" ... STRING_11 = "Hello, world" ... STRING_12 = "Hello, world" ... """
>>> constcheck(string=EXAMPLE, no_ansi=True) 3 | Hey 4 | Hello 5 | Hello, world <BLANKLINE> 1
With the count argument
>>> constcheck(string=EXAMPLE, count=4, no_ansi=True) 4 | Hello 5 | Hello, world <BLANKLINE> 1
With the length argument
>>> constcheck(string=EXAMPLE, length=6, no_ansi=True) 5 | Hello, world <BLANKLINE> 1
With the ignore_strings argument which accepts list of str objects
>>> constcheck(string=EXAMPLE, ignore_strings=["Hello, world", "Hello"], no_ansi=True) 3 | Hey <BLANKLINE> 1
All keyword arguments available to constcheck() can be configured in the pyproject.toml file
[tool.constcheck] path = "." count = 3 length = 3 ignore_strings = ["Hello", "Hello, world"] ignore_files = ["tests/__init__.py"] filter = false no_color = false [tool.constcheck.ignore_from] "tests/__init__.py" = ["Hello, world"]
constcheck can be used as a pre-commit hook
It can be added to your .pre-commit-config.yaml as follows:
repos: - repo: https://github.com/jshwi/constcheck rev: v0.7.0 hooks: - id: constcheck args: - "--count=3" - "--length=3"