Skip to main content

Lint for blocklisted words.

Project description

blocklint

PyPI version GitHub Actions (Tests) GitHub Actions (pre-commit) GitHub license

blocklint is a command line utility for finding non-inclusive wording. This project is inspired by Alex.js.

About

If you've used a modern IDE, you know the importance of immediate feedback for compilation errors or even stylistic slip ups. Knowing all variables should be declared or that lines must be less than 80 characters long is good, but adhering to those rules takes a back seat when in the flow of writing code. A linter brings these issues back into your consciousness by highlighting the problematic lines of code. Over time, the enforced style becomes more intuitive but the linter is always there to nudge you if you slip.

We are in the midst of changing attitudes towards words and phrases that are not inclusive. Not only are developers acknowledging the offensive history of terms like "master/slave" and "blacklist/whitelist", but we are taking active steps to remove their usage and replace them with more appropriate language. This tool is not a commentary on inclusion, but rather a utility to detect whatever words you'd like to remove from code.

Alex.js is one option for highlighting offensive language, but it is geared towards text documents such as markdown, misses common constructs in source code and is also overly broad and prone to false positives. Blocklint is built with source code in mind and is more limited in scope.

Requirements and Installation

Blocklint is written in python and uses minimal, standard libraries. It has been tested for python >= 2.7 To install:

pip install blocklint

into an appropriate environment.

Usage

Without any arguments, blocklint will search all files in the current directory for uses of master, slave, blacklist and whitelist:

$ pwd
/path/to/blocklint/blocklint
$ blocklint
/path/to/blocklint/blocklint/main.py:40:60: use of "blacklist"
/path/to/blocklint/blocklint/main.py:40:37: use of "master"
/path/to/blocklint/blocklint/main.py:40:44: use of "slave"
/path/to/blocklint/blocklint/main.py:40:50: use of "whitelist"
/path/to/blocklint/blocklint/main.py:55:53: use of "blacklist"
/path/to/blocklint/blocklint/main.py:55:30: use of "master"
/path/to/blocklint/blocklint/main.py:55:37: use of "slave"
/path/to/blocklint/blocklint/main.py:55:43: use of "whitelist"

Optionally, multiple files and directories can be specified to search. The detected words can be customized through several options; setting any will clear the defaults. Multiple words are specified as comma separated values:

  • blocklist: Will match any occurrence of the word, ignoring case and special characters.
  • wordlist: Will match the word, ignoring case and special characters but respecting word boundaries.
  • exactlist: Will match the word as entered respecting word boundaries.

Only the first match of a word in a line will be returned, but multiple words can match on a single line. Here are some examples:

$ blocklint --blocklist test,asdf <(echo thisTEST will match as will a_S-d:F)
/dev/fd/63:1:29: use of "asdf"
/dev/fd/63:1:5: use of "test"

$ blocklint --wordlist test,asdf <(echo thisTEST will not match but T=E-ST, will)
/dev/fd/63:1:29: use of "test"

$ blocklint --exactlist Test <(echo thisTest, tEST, T-est fail but Test! matches)
/dev/fd/63:1:32: use of "Test"

The -e,--end-pos flag will provide the end position of the match in addition to the start position.

The --stdin flag will take values from stdin instead of a file or directory.

The --skip-files flag takes a comma-or-newline separated list of paths to files that should not be checked by blocklint. This is useful when running blocklint on a large directory.

Configuration

Blocklint supports the standard ini configuration format used by many other linting tools, including flake8.

Command line arguments have highest priority, and override any arguments derived from configuration files. Next highest are local files tox.ini, setup.cfg, and .blocklint. Finally, a global config in ~/.blocklint may be used.

Config files should contain a blocklint section in ini format, for example:

[blocklint]
max_issue_threshold=10
blocklist=test,asdf
end_pos=store_true

Integrations

The integration directory contains information on using blocklint for:

Don't see the tool you use? Submit a pull request or issue!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blocklint-0.2.3.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

blocklint-0.2.3-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file blocklint-0.2.3.tar.gz.

File metadata

  • Download URL: blocklint-0.2.3.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.7

File hashes

Hashes for blocklint-0.2.3.tar.gz
Algorithm Hash digest
SHA256 b6c154b126dd605f8b66d6af9aa9c138ebbf08d184a1ad76e3ea2cb57155c9c5
MD5 804572e6d71b5a470e8b1fdbdef45099
BLAKE2b-256 59dbecc772e0f29e85cfd9e47cf82fe8bb5cbe85d5eeac68c348ba4c49df5991

See more details on using hashes here.

File details

Details for the file blocklint-0.2.3-py2.py3-none-any.whl.

File metadata

  • Download URL: blocklint-0.2.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.7

File hashes

Hashes for blocklint-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b3d983d047ff92b8c53215c7639ff89ad45fc8a98dd0281ea36c675df5764508
MD5 72507524e3c1a50bc9725d8932dc6b7e
BLAKE2b-256 050f8f81f5c2f0d905e4619d50765f5b2665c31729fdce8ec01809c0a95ccf72

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page