jshwi / constcheck

Check code for strings that could be constants

Home Page:https://constcheck.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

constcheck

License

PyPI

Build

CodeQL

pre-commit.ci status

codecov.io

readthedocs.org

python3.8

Black

isort

docformatter

pylint

Security Status

Known Vulnerabilities

constcheck

Check Python files for repeat use of strings

Escape commas with \\ (\ when enclosed in single quotes)

Defaults can be configured in your pyproject.toml file

Installation

$ pip install constcheck

Usage

Commandline

usage: 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

API

With the count argument

With the length argument

With the ignore_strings argument which accepts list of str objects

Config

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"]

pre-commit

constcheck can be used as a pre-commit hook

It can be added to your .pre-commit-config.yaml as follows:

About

Check code for strings that could be constants

https://constcheck.readthedocs.io

License:MIT License


Languages

Language:Python 98.1%Language:Makefile 1.9%