Skip to main content

CLASPLint

Python License PyPI

CLASP Stage 3.3 / 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 physical code line requires # Capitalized sentence. comment (import/class/def exempt)
  • Log messages — pre-defined string variables (6 allowed names), proper try-except chain with as variable naming, exc_info=True on error/critical/fatal, raise with from clause
  • Try-Except blocks — no tuple catching, alphabetical exception ordering, Exception last, whitelist as variable names, bare raise prohibited, raise XxxError(message_error) from e required
  • Docstrings — File: field-based format; Class: ATTRIBUTES/PUBLIC/PRIVATE/USAGE/WARNING; Method: Sphinx :param/:type/:return/:rtype/:raises with summary→detail→directives structure
  • Encoding declaration — file header must contain # -*- coding: utf-8 -*-
  • Single-line comments — each # comment is a self-contained sentence; multi-line comment blocks are forbidden
  • Symbol-line exemption — pure-symbol lines (only non-letter characters) are exempt from comment requirements and must not carry comments
  • Comment quality — detects weak comments that merely restate code rather than explain intent
  • Comment language — all comments must be written in English
  • Log quality — log message variable names must follow group1_group2 format; log message content must be in Chinese
  • Docstring quality — file-level docstrings must follow CLASP field-based format (MODULE, TYPE, DESCRIPTION...); class docstrings require ATTRIBUTES/PUBLIC METHODS/PRIVATE METHODS/USAGE/WARNING sections; docstring text is checked for capitalization, punctuation, and abbreviations
  • Review hints — advisory suggestions for overly long variable names (>15 chars or multi-word groups) excluded from total violation count

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,docstring,tryexcept}
                        only report violations of a specific category

Example Output

$ CLASPLint tests/test_violations.py

When violations exist:

=== Code Logging Annotation Standard Proposal (CLASP) Report ===

+-------------------------+
|     Total Reports     |
+-------------------------+

From 2026-07-06 02:00:00 to 2026-07-06 02:00:00, CLASPLint totally found 13 violation(s) in
1 of 1 file(s), as follows:

    COMMENT  :    5   violation(s)
    DICT_KEY :    3   violation(s)
    FUNCTION :    2   violation(s)
    VARIABLE :    3   violation(s)

+-------------------------+
|    Full Violations    |
+-------------------------+

[Comment Violations]:
  [1] tests/test_violations.py:8:
     Line 8 lacks a required preceding comment.
       Violation Content:
         badvar = 42
  [2] tests/test_violations.py:11:
     Comment must start with '# ' (hash, space).
       Violation Content:
         #Bad_Var
  ...

When clean:

=== Code Logging Annotation Standard Proposal (CLASP) Report ===

+-------------------------+
|     Total Reports     |
+-------------------------+

From 2026-07-06 02:00:00 to 2026-07-06 02:00:00, 0 violation(s) in 11 file(s).

CLASP Stage 3.3 / PEP 2606 Rules Summary

Category Rule
Variable group1_group2, one underscore, all lowercase, no abbreviations, ≤30 chars
Boolean is_ or has_ prefix (mandatory for bool-annotated and bool-literal variables)
Constant Lowercase group1_group2 format (ALL_CAPS prohibited)
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 physical line: # Capitalized sentence ending with period. (import/class/def exempt)
Control Flow Body first line must have a preceding comment (if/for/while)
Log Messages as pre-defined variables (6 allowed names), proper try-except chain, exc_info=True, fatal level
Docstring File: field-based format; Class: ATTRIBUTES/PUBLIC/PRIVATE/USAGE/WARNING; Method: Sphinx :param/:type/:return/:rtype/:raises
Try-Except No tuple catch, alphabetical exception order, Exception last, whitelist as names, raise XxxError(msg) from e pattern
Encoding # -*- coding: utf-8 -*- required at file top (line 1 or 2 after shebang)
Symbol Line Pure-symbol lines (no letters) are comment-exempt and must not carry comments
Multi-line Each comment must be a single self-contained line; blocks are forbidden
Weak Comment Comments must explain intent, not paraphrase conditions (no "Check if...")
Comment Lang All comments must be in English (ASCII only)
Log Lang Log messages must be in Chinese
Log Variable Log message variables limited to: message_info/debug/warning/error/critical/fatal
Review Advisory hints for long or multi-word variable names (excluded from total count)

Python Version Support

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

License

GPL-3.0-only — Copyright (C) 2026 Matt Belfast Brown



CLASPLint(中文)

Python License PyPI

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


功能特性

  • 变量名 —— group1_group2 两段下划线格式,全部小写,禁止缩写,支持类型/布尔前缀,≤30 字符
  • 字典键名 —— PascalCase 驼峰式,完整拼写,专有缩写保持大写
  • 函数与类名 —— 函数 snake_case,类 PascalCase,私有方法 _init_X_function_
  • 注释格式 —— 每条物理代码行前必须有 # 首字母大写英文句子并以句号结尾。(import/class/def 豁免)
  • 日志消息 —— 必须预定义为字符串变量(6种允许名称),完整 try-except 链条带 as 变量命名, 错误/严重/致命日志带 exc_info=True,raise 必须用 from 链接原始异常
  • 异常块 —— 禁止元组捕获,异常类型字母序排列,Exception 最后兜底,as 变量名须在白名单, 禁止裸 raise,必须 raise XxxError(message_error) from e
  • 文档字符串 —— 文件级:字段式格式;类级:ATTRIBUTES/PUBLIC/PRIVATE/USAGE/WARNING; 方法级:Sphinx :param/:type/:return/:rtype/:raises,概述→详述→指令三段式
  • 编码声明 —— 文件头必须包含 # -*- coding: utf-8 -*-
  • 单行注释 —— 每条 # 注释为独立单行句子;禁止多行注释块
  • 符号行豁免 —— 纯符号行(仅含非字母字符)免注释且不得带注释
  • 注释质量 —— 检测仅复述代码而非解释意图的弱注释
  • 注释语言 —— 所有注释必须使用英文
  • 日志语言 —— 日志消息必须使用中文;日志变量名须符合 group1_group2 格式
  • 文档字符串质量 —— 文件级 docstring 须符合 CLASP 字段式格式(MODULE/TYPE/DESCRIPTION...);类 docstring 须含 ATTRIBUTES/PUBLIC METHODS/PRIVATE METHODS/USAGE/WARNING 段;检查文本大小写、标点与缩写
  • Review 提示 —— 对过长变量名(>15 字符或多词拼接)提供建议性提示,不计入违规总数

安装

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,docstring,tryexcept}
                        仅报告指定类别的违规

输出示例

$ CLASPLint tests/test_violations.py

发现违规时:

=== Code Logging Annotation Standard Proposal (CLASP) Report ===

+-------------------------+
|     Total Reports     |
+-------------------------+

From 2026-07-06 02:00:00 to 2026-07-06 02:00:00, CLASPLint totally found 13 violation(s) in
1 of 1 file(s), as follows:

    COMMENT  :    5   violation(s)
    DICT_KEY :    3   violation(s)
    FUNCTION :    2   violation(s)
    VARIABLE :    3   violation(s)

+-------------------------+
|    Full Violations    |
+-------------------------+

[Comment Violations]:
  [1] tests/test_violations.py:8:
     Line 8 lacks a required preceding comment.
       Violation Content:
         badvar = 42
  [2] tests/test_violations.py:11:
     Comment must start with '# ' (hash, space).
       Violation Content:
         #Bad_Var
  ...

无违规时:

=== Code Logging Annotation Standard Proposal (CLASP) Report ===

+-------------------------+
|     Total Reports     |
+-------------------------+

From 2026-07-06 02:00:00 to 2026-07-06 02:00:00, 0 violation(s) in 11 file(s).

CLASP Stage 3.3 / PEP 2606 规则速查

类别 规则
变量 group1_group2,有且仅有一个下划线,全部小写,禁止缩写,≤30 字符
布尔值 is_has_ 前缀(bool 注解和 bool 字面量赋值强制)
常量 小写 group1_group2 格式(禁止 ALL_CAPS)
字典键 PascalCase 驼峰式,完整拼写,专有缩写大写(GPS、UTM、XML 等)
类名 PascalCase
函数名 snake_case,使用具体动词,≤30 字符
方法 公共:简短 snake_case;私有:_init_X_function_ ≤30 字符
注释 每条物理行:# Capitalized sentence ending with period.(import/class/def 豁免)
控制流 分支/循环体首行必须拥有前置注释(if/for/while)
日志 消息预定义为变量(6种允许名称),完整 try-except 日志链,exc_info=True,fatal 等级
文档字符串 文件级:字段式格式;类级:ATTRIBUTES/PUBLIC/PRIVATE/USAGE/WARNING;方法级:Sphinx :param/:type/:return/:rtype/:raises
异常块 禁止元组捕获,异常字母序,Exception 最后,as 白名单变量,raise XxxError(msg) from e
编码声明 文件顶部须有 # -*- coding: utf-8 -*-(第1行或shebang后第2行)
符号行 纯符号行(无字母)免注释且禁止带注释
单行注释 每条注释为独立单行句子;禁止多行注释块
弱注释 注释须解释意图,不得仅复述代码(禁止 "Check if...")
注释语言 所有注释须使用英文(仅 ASCII 字符)
日志语言 日志消息须使用中文
日志变量 日志变量名限定为:message_info/debug/warning/error/critical/fatal
Review 对过长或多词拼接变量名的建议性提示(不计入违规总数)

Python 版本支持

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

许可证

GPL-3.0-only — Copyright (C) 2026 Matt Belfast Brown

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.5.1.tar.gz (98.1 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.5.1-cp314-none-any.whl (107.0 kB view details)

Uploaded CPython 3.14

clasplint-0.5.1-cp313-none-any.whl (107.2 kB view details)

Uploaded CPython 3.13

clasplint-0.5.1-cp312-none-any.whl (107.2 kB view details)

Uploaded CPython 3.12

clasplint-0.5.1-cp311-none-any.whl (107.2 kB view details)

Uploaded CPython 3.11

clasplint-0.5.1-cp310-none-any.whl (107.2 kB view details)

Uploaded CPython 3.10

clasplint-0.5.1-cp39-none-any.whl (107.2 kB view details)

Uploaded CPython 3.9

clasplint-0.5.1-cp38-none-any.whl (107.2 kB view details)

Uploaded CPython 3.8

File details

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

File metadata

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

File hashes

Hashes for clasplint-0.5.1.tar.gz
Algorithm Hash digest
SHA256 5616b46a21aa5ee5f6155cc376009d31c628731517140e6551b586766d409fd8
MD5 ee0f5ac3143e9195f04c1dd215d9e4c5
BLAKE2b-256 ce39077f3e1f7bd9df8f8d3a9aa5ab68f597f9a4b5cda0c9c16157731d999cbc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp314-none-any.whl
  • Upload date:
  • Size: 107.0 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.5.1-cp314-none-any.whl
Algorithm Hash digest
SHA256 8d07b412d324484b8f1aa041d7da9b4e03d153b3160b5a77818b6d70e8692b09
MD5 d7b71a3bd59d84396e75e0b075d15011
BLAKE2b-256 4e9dd43c256cde505d746603a9f3f5d200bda54c7672f7bd41e5446279928476

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp313-none-any.whl
  • Upload date:
  • Size: 107.2 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.5.1-cp313-none-any.whl
Algorithm Hash digest
SHA256 b5008e47303e7e42d0e6f17c4e2d06cee5b9dbd8784b9cf8bb2936f15c511aff
MD5 e0a1e6e06808f7cbcb2af79df3e1b685
BLAKE2b-256 ee742e8f5ffc6d8e1b39a1f475c6e36b6eb3bfd652b2dff40da4756da28efa4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp312-none-any.whl
  • Upload date:
  • Size: 107.2 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.5.1-cp312-none-any.whl
Algorithm Hash digest
SHA256 b1f4926ac94c6393dcf47f2ef8561b0692445ab0d3286854084dfe5c2d833e4b
MD5 9a865a82683e28564935018f1b521864
BLAKE2b-256 dfab3893e13d33fc93bc0a6d2aafe988bd0b8c021ba49e222a140d47f3940769

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp311-none-any.whl
  • Upload date:
  • Size: 107.2 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.5.1-cp311-none-any.whl
Algorithm Hash digest
SHA256 f9bc8798d77c313a7e6aab19fc8233e1fd5920c0102609ee886117a6e19c6d42
MD5 436a9b013478e1d6ab270969741cea39
BLAKE2b-256 c5d4808ff5b565b897e1cf0a90946e17351d1a3f8e9317e56fac0f15f64b2c6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp310-none-any.whl
  • Upload date:
  • Size: 107.2 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.5.1-cp310-none-any.whl
Algorithm Hash digest
SHA256 7fabd605416bc538e4d2d76f975559b835e639eab2addde2fe5ce1039d28693a
MD5 470a6dc1ec3cdb0eb3ba2ba54f485be4
BLAKE2b-256 93d78725beade6840fea48bf971fdedcbc20e57a8e1ee49c09349768d67bb25c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp39-none-any.whl
  • Upload date:
  • Size: 107.2 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.5.1-cp39-none-any.whl
Algorithm Hash digest
SHA256 39e3b16449b8c16b85d712ffd0e200e8153563067b3f6be7d92cf6b82f7df451
MD5 f7d8667a0f4d9c6234e75b4b98bfeb11
BLAKE2b-256 4c66cc12f36531ada993f17611c3389da519068729eb88b491d38710488921df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clasplint-0.5.1-cp38-none-any.whl
  • Upload date:
  • Size: 107.2 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.5.1-cp38-none-any.whl
Algorithm Hash digest
SHA256 c623e8ea280cbc4ce1ed003e8e11b157e4d736013ad6b78c8b13b8104b6499d3
MD5 c252a441d40b11a4deaef5c9b7c1c687
BLAKE2b-256 c2d1ed5c365138ec2e6e11e526a8721ac13fcbc94e8887f1bb0370205725d3ee

See more details on using hashes here.

Release history Release notifications | RSS feed

0.7.0

8 files

0.6.2

8 files

0.6.1

8 files

0.6.0

8 files

0.5.5

8 files

0.5.4

8 files

0.5.3

8 files

0.5.2

8 files

This release

0.5.1 This release

8 files

0.5.0

8 files

0.4.4

8 files

0.4.3

8 files

0.4.2

8 files

0.4.1

8 files

0.4.0

8 files

0.3.0

8 files

0.2.0

8 files

0.1.0

8 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page