Skip to main content

CLASP 3.0 / PEP 2606 Static Analysis Tool — enforces naming and comment conventions beyond PEP 8.

Project description

CLASPLint

Python License PyPI

CLASP 3.0 / PEP 2606 static analysis tool. Enforces naming and comment conventions beyond PEP 8 — checks variables, dictionary keys, functions, classes, comments, and log messages for standards compliance.


Features

  • Variable namesgroup1_group2 format, all lowercase, no abbreviations, type/boolean prefixes, ≤30 chars
  • Dictionary keys — PascalCase, full spelling, acronyms kept uppercase
  • Function & class names — snake_case for functions, PascalCase for classes, private methods _init_X_function_
  • Comment format — every control-flow line requires # Capitalized sentence. comment
  • Log messages — pre-defined string variables, proper try-except chains, exc_info=True on errors

Installation

pip install CLASPLint

Or from source:

git clone https://github.com/thedayofthedoctor/clasplint.git
cd clasplint
pip install -e .

Quick Start

# Check a single file
CLASPLint path/to/file.py

# Check all Python files in a directory (recursive)
CLASPLint src/

# Show only summary, no per-violation output
CLASPLint --quiet src/

# Filter by violation category
CLASPLint --category variable src/

Usage

usage: CLASPLint [-h] [--version] [--no-recursive] [--quiet] [-c CATEGORY] [paths ...]

positional arguments:
  paths                 Python files or directories to check (default: current directory)

options:
  --version             show version number and exit
  --no-recursive        do not recursively check subdirectories
  --quiet, -q           suppress individual violation output; show only summary
  --category, -c {variable,dict_key,function,comment,log}
                        only report violations of a specific category

Example Output

$ CLASPLint tests/test_violations.py

CLASPLint: 30 violation(s) in 1 of 1 file(s).
  comment: 8
  dict_key: 4
  function: 3
  log: 4
  variable: 11

  tests/test_violations.py:8  [variable] Variable 'badvar' must have exactly one underscore ...
  tests/test_violations.py:11 [variable] Variable 'Bad_Var' contains uppercase letters ...
  ...

CLASP 3.0 / PEP 2606 Rules Summary

Category Rule
Variable group1_group2, one underscore, all lowercase, no abbreviations, ≤30 chars
Boolean is_ or has_ prefix
Dict Key PascalCase, full spelling, acronyms uppercase (GPS, UTM, XML, etc.)
Class PascalCase
Function snake_case, specific verb, ≤30 chars
Method Public: short snake_case; Private: _init_X_function_ ≤30 chars
Comment Every control-flow line: # Capitalized sentence ending with period.
Log Messages as variables, proper try-except logging chain, exc_info=True

Python Version Support

CLASPLint supports Python 3.8 through 3.13+. The minimum version is 3.8 due to ast.Constant, ast.NamedExpr, and ast.get_docstring() usage.

License

GPL-3.0-or-later — Copyright (C) 2019-2024 Matt Belfast Brown



CLASPLint(中文)

Python License PyPI

CLASP 3.0 / PEP 2606 静态分析工具。在 PEP 8 之上强制执行命名与注释规范 —— 检查变量、字典键、函数、类、注释和日志消息是否符合标准。


功能特性

  • 变量名 —— group1_group2 两段下划线格式,全部小写,禁止缩写,支持类型/布尔前缀,≤30 字符
  • 字典键名 —— PascalCase 驼峰式,完整拼写,专有缩写保持大写
  • 函数与类名 —— 函数 snake_case,类 PascalCase,私有方法 _init_X_function_
  • 注释格式 —— 每条控制流语句前必须有 # 首字母大写英文句子并以句号结尾。
  • 日志消息 —— 必须预定义为字符串变量,完整的 try-except 链条,错误日志带 exc_info=True

安装

pip install CLASPLint

或从源码安装:

git clone https://github.com/thedayofthedoctor/clasplint.git
cd clasplint
pip install -e .

快速开始

# 检查单个文件
CLASPLint path/to/file.py

# 递归检查目录下所有 Python 文件
CLASPLint src/

# 仅显示摘要,不输出逐条违规
CLASPLint --quiet src/

# 按类别过滤
CLASPLint --category variable src/

命令行用法

usage: CLASPLint [-h] [--version] [--no-recursive] [--quiet] [-c CATEGORY] [paths ...]

位置参数:
  paths                 要检查的 Python 文件或目录(默认:当前目录)

可选参数:
  --version             显示版本号并退出
  --no-recursive        不递归检查子目录
  --quiet, -q           仅显示摘要,抑制逐条违规输出
  --category, -c {variable,dict_key,function,comment,log}
                        仅报告指定类别的违规

输出示例

$ CLASPLint tests/test_violations.py

CLASPLint: 30 violation(s) in 1 of 1 file(s).
  comment: 8
  dict_key: 4
  function: 3
  log: 4
  variable: 11

  tests/test_violations.py:8  [variable] Variable 'badvar' must have exactly one underscore ...
  tests/test_violations.py:11 [variable] Variable 'Bad_Var' contains uppercase letters ...
  ...

CLASP 3.0 / PEP 2606 规则速查

类别 规则
变量 group1_group2,有且仅有一个下划线,全部小写,禁止缩写,≤30 字符
布尔值 is_has_ 前缀
字典键 PascalCase 驼峰式,完整拼写,专有缩写大写(GPS、UTM、XML 等)
类名 PascalCase
函数名 snake_case,使用具体动词,≤30 字符
方法 公共:简短 snake_case;私有:_init_X_function_ ≤30 字符
注释 每条控制流语句前:# Capitalized sentence ending with period.
日志 消息预定义为变量,完整 try-except 日志链,exc_info=True

Python 版本支持

CLASPLint 支持 Python 3.8 至 3.14+。最低版本为 3.8,原因在于使用了 ast.Constantast.NamedExprast.get_docstring()

许可证

GPL-3.0-or-later — Copyright (C) 2019-2024 Matt Belfast Brown

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

clasplint-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

clasplint-0.1.0-cp314-none-any.whl (25.7 kB view details)

Uploaded CPython 3.14

clasplint-0.1.0-cp313-none-any.whl (25.7 kB view details)

Uploaded CPython 3.13

clasplint-0.1.0-cp312-none-any.whl (25.7 kB view details)

Uploaded CPython 3.12

clasplint-0.1.0-cp311-none-any.whl (25.7 kB view details)

Uploaded CPython 3.11

clasplint-0.1.0-cp310-none-any.whl (25.7 kB view details)

Uploaded CPython 3.10

clasplint-0.1.0-cp39-none-any.whl (25.7 kB view details)

Uploaded CPython 3.9

clasplint-0.1.0-cp38-none-any.whl (25.7 kB view details)

Uploaded CPython 3.8

File details

Details for the file clasplint-0.1.0.tar.gz.

File metadata

  • Download URL: clasplint-0.1.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68454195ec6cd698293ec1831744b14353525f03ca3b993d5774bb497e0a449d
MD5 916a9dd13c079bd357e978ac60935cb5
BLAKE2b-256 a8a3eb0ec447f9c15a4a74870f1192a772e998e7ecec51d15c6f17930703b400

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp314-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp314-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.14
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp314-none-any.whl
Algorithm Hash digest
SHA256 2b815feeb140a8efd595ea0cb4ee9aafa6d7d8739076f7b8e8b7373347b3e026
MD5 111321eb58f2cba67fea41dca44f1d12
BLAKE2b-256 0efd99dbcda1bbcafdc4c949a7b40301146a73af98da5ea4a4060e1b12a0006d

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp313-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp313-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.13
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp313-none-any.whl
Algorithm Hash digest
SHA256 8884c1c8daff4b69daad44f2d3cf40b5e7c83222bb9e3a5e91c6302b48ef9cd3
MD5 10867242ec8f263aadbc5d150ed1154b
BLAKE2b-256 50225a8d3a14e9a477ccd16c7197d8c952f27352087b27f8e5734f6b5a3340d9

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp312-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp312-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.12
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp312-none-any.whl
Algorithm Hash digest
SHA256 911a4a996c73a24853173b4a4838b1e7cef6a9b3cb0b096e3e7ebcb87c437230
MD5 24723a3dcd6ebbcc8c6db762e07af712
BLAKE2b-256 76440ff78b18a16cf2d8186f6395709e383a60a5fb2f6a039473f971288ee5c7

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp311-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp311-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.11
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp311-none-any.whl
Algorithm Hash digest
SHA256 1dc61c3147429284412941af01a3a9588d4d67adee78c1502a2fdc62f4eb4631
MD5 787f09e3585dbbfd907afd8c98690ffa
BLAKE2b-256 6053a8978ef9bb97404274fd85c7495ed0a638ec457d82c36a071e8925590721

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp310-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp310-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.10
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp310-none-any.whl
Algorithm Hash digest
SHA256 70c6547cabc593d27689267f80f475ce7e57bb7688bd56401950dec0c1a67b98
MD5 e9ea53f4a4a82351aced0370ed60e1c4
BLAKE2b-256 ad3a8b5923755effa7572d9fd672e4c072b7676d269c5ec573c2b3e3c51da018

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp39-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp39-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp39-none-any.whl
Algorithm Hash digest
SHA256 ecd244727dd9903faec4e792508498e82bef951098d5673bcd276e4bd6799ca2
MD5 343160c588b13bd94f6ad034ba729711
BLAKE2b-256 321ee1facbdc1f4aecfe9ee4a84280178d1416857a6eaaca1fd7b209d2be55fe

See more details on using hashes here.

File details

Details for the file clasplint-0.1.0-cp38-none-any.whl.

File metadata

  • Download URL: clasplint-0.1.0-cp38-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for clasplint-0.1.0-cp38-none-any.whl
Algorithm Hash digest
SHA256 6fcd9e5eca3f6e5edf68659ef2642f755164f0e504f89742b8681604a0f73d69
MD5 2e972070e0b7ab84b2dae8414929f01f
BLAKE2b-256 b9814fe85ca05eb046150044130bc4cadf28c1f99a2d34b9d7b8652b69fd508b

See more details on using hashes here.

Supported by

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