An opinionated comment style checker.
Project description
comment_style
About
comment_style
is an opinionated tool that highlights issues related to comment
formatting.
Usage
Create a sample comment_style.yaml
:
# The set of paths to test is built up in a sequence of inclusions and
# exclusions.
- paths:
- include: '**/*.go'
- exclude: 'target/**'
comment_markers:
line: '//'
# The `block` field is optional. Any lines starting with a block comment
# marker will be flagged as an error.
block: '/*'
allow:
# See the "False positives" section for more details on why it may be
# necessary to allow `trailing_comment` violations.
- trailing_comment
- paths:
- include: '**/*.py'
- exclude: 'target/**'
comment_markers:
line: '#'
comment_style.py
can then be run with the given configuration file:
$ python3 comment_style.py comment_style.yaml
The above will output any rule violations found in the discovered Go source files. The configuration file contains a list of rules to enable checking for different comment markers with a single configuration file.
Rules/Codes
Note that tagged comments are those that start with TODO
, NOTE
or FIXME
.
block_comment
: Block comments aren't allowed.block_starts_empty
: Comment blocks can't start with an empty line.block_ends_empty
: Comment blocks can't end with an empty line.no_leading_space
: Non-empty line comments must start with a space.no_leading_space_after_tag
: Tagged comments must start with a space.starts_with_lowercase
: Letters at the start of comments must be capitalised.starts_with_lowercase_after_tag
: Letters at the start of tagged comments must be capitalised.no_section_ending_punctuation
: Sections of comment blocks must end with.
or:
.no_ending_punctuation
: Comment blocks must end with.
.trailing_comment
: Comments must be on their own line.
False positives
The check for the trailing_comment
attempts to check whether the comment
marker is within a string to avoid false positives. However, to do this in a
language-independent way, comment_style.py
uses a heuristic approach rather
than a syntactic one. Because of this, and because the heuristic only applies to
individual lines and not groups of lines, false positives (and false negatives)
can occur. This is especially so in the case of multi-line strings. Depending on
the scenario it may be necessary to allow violations of the trailing_comment
rule.
As an example, this project checks for #
comments in shell scripts (.sh
files). However, #
can naturally occur in shell scripts in the context of
$#
. This gives a false-positive trailing_comment
violation, so this is
allowed in the comment_style.yaml
that this project uses.
Development
Build environment
The build environment for the project is defined in build.Dockerfile
. The
build environment can be replicated locally by following the setup defined in
the Dockerfile, or Docker can be used to mount the local directory in the build
environment by running the following:
$ bash scripts/with_build_env.sh bash
Note that the requirements for the project must be installed before doing anything. These can be installed locally, or through the interactive Bash session started above:
$ python3 -m pip install -r requirements.txt
These can also be installed in the build environment from the host:
$ bash scripts/with_build_env.sh python3 -m pip install -r requirements.txt
The installed packages will persist between containers for the build environment using named volumes.
Testing
The project can be tested locally using make check
, or can be tested using the
Docker build environment by running the following:
$ bash scripts/with_build_env.sh make check
Note that the environment will need to have the project requirements installed as detailed in the previous section.
Upload
The package is built and upload using the following sequence:
$ python3 setup.py sdist bdist_wheel --universal
$ python3 -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file comment_style-0.1.1.tar.gz
.
File metadata
- Download URL: comment_style-0.1.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b86002fc5aca5101a93fe069af8f782805326f37d4df9912dce4c6a9cb3eb82 |
|
MD5 | f243bfe7eb4b75d458ee93d4c67a0578 |
|
BLAKE2b-256 | 324fa4f5d0c319975a28de064b53945b87a1b9657e252bb7a3ab8d249573b49a |
File details
Details for the file comment_style-0.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: comment_style-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca149aa76732d20446c230ccf292368445bd711b198fb19df329cf12be41aab8 |
|
MD5 | 2bc896044f2af572e915ea557675ab98 |
|
BLAKE2b-256 | 98965d8be19b0da01f01ae0b1a4e68ae4f4ae66e04221150fa11ebaae6f1806a |