sphinx-linter


Namesphinx-linter JSON
Version 0.0.11 PyPI version JSON
download
home_pageNone
SummaryA lightweight Python linter for checking Sphinx docstrings.
upload_time2025-10-20 08:38:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords python documentation linter developer-tools code-quality docstrings
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sphinx-linter

[![PyPI](https://img.shields.io/pypi/v/sphinx-linter.svg)](https://pypi.python.org/pypi/sphinx-linter)
[![CI](https://github.com/rmoralespp/sphinxlinter/workflows/CI/badge.svg)](https://github.com/rmoralespp/sphinxlinter/actions?query=event%3Arelease+workflow%3ACI)
[![codecov](https://codecov.io/gh/rmoralespp/sphinxlinter/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rmoralespp/sphinxlinter)
[![License](https://img.shields.io/github/license/rmoralespp/sphinxlinter.svg)](https://github.com/rmoralespp/sphinxlinter/blob/main/LICENSE)

A lightweight Python linter for **Sphinx-style docstrings**.  
It validates structure, field consistency, and alignment between documentation and code.

---

## Overview

Sphinx-style docstrings are widely used across Python projects, but existing tools such as
[pydocstyle](https://www.pydocstyle.org), [pydoclint](https://jsh9.github.io/pydoclint/),
and [ruff](https://docs.astral.sh/ruff/) focus primarily on general docstring formatting, PEP 257 compliance, and style
enforcement.

It is designed to **complement**, not overlap with, these tools.  
It targets **Sphinx-specific field list conventions** and performs **semantic consistency checks**
that go beyond what other linters cover.

Specifically, it focuses on:

- Enforcing **Sphinx field list syntax** (`:param:`, `:type:`, `:return:`, `:raises:`, etc.)
- Verifying **alignment** between documented fields and function signatures or type hints
- Validating **section order, duplication, type hints syntax and completeness**
- Producing **concise, CI-friendly reports** with structured rule codes

---

## Installation

Requires **Python ≥ 3.9**.

*No dependencies beyond the Python standard library.*

```bash
pip install sphinx-linter
```

---

## Quick Start

To use the standalone script, download the `sphinxlinter.py` script from
following [link](https://github.com/rmoralespp/sphinxlinter/archive/refs/heads/main.zip) and run it with Python:

```bash
python sphinxlinter.py path/to/source/
```

- Run in the current directory: `sphinxlinter .`
- Or use the short alias: `spxl .`

Run on specific files or directories:

```bash
spxl path/to/file.py path/to/package/
```

Directories are scanned recursively for `.py` files, ignoring virtual environments and cache folders.

---

## Command Line Usage

| Argument / Option | Description                                         |
|-------------------|-----------------------------------------------------|
| `[FILES]`         | Files or directories to lint.                       |
| `--help`          | Show help message and exit.                         |
| `--enable`        | Enable specific rule codes (or `ALL`).              |
| `--disable`       | Disable specific rule codes (overrides `--enable`). |
| `--ignore`        | Exclude directories (e.g. `venv`, `.cache`).        |
| `--statistics`    | Show per-rule violation counts.                     |
| `--quiet`         | Suppress all output except summary.                 |

---

## Output Format

Example:

```text
src/module.py:42: [DOC102] Invalid parameter type syntax ('List[int]')
src/module.py:10: [DOC101] Parameter documented but not in signature ('unused_param')
```

**Format:**  
`filename:line: [CODE] message`

**Categories:**

- `DOC0xx`: Structure and formatting issues
- `DOC1xx`: Parameter issues
- `DOC2xx`: Return issues
- `DOC3xx`: Raises issues
- `DOC4xx`: Variable issues

---

## Violation Codes

### DOC0xx — Structure

| Code   | Description                                      | Purpose                                                                         |
|--------|--------------------------------------------------|---------------------------------------------------------------------------------|
| DOC001 | Invalid docstring section                        | Detects unsupported Sphinx fields.                                              |
| DOC002 | Malformed section                                | Ensures valid field list syntax.                                                |
| DOC003 | Missing blank line after docstring               | Improves readability.                                                           |
| DOC004 | Missing blank line between summary and sections  | Enforces structure consistency.                                                 |
| DOC005 | Too many consecutive blank lines                 | Prevents unnecessary whitespace.                                                |
| DOC006 | Trailing empty lines                             | Keeps docstrings compact.                                                       |
| DOC007 | Misplaced section                                | Enforces section order and grouping.                                            |
| DOC008 | One-line docstring should end with a period      | Complies with [PEP 257](https://peps.python.org/pep-0257/#one-line-docstrings). |
| DOC009 | Docstring must not use more than 3 double quotes | Promotes consistent quoting.                                                    |

---

**DOC008**: This rule differs from Ruff’s similar rule [
`missing-trailing-period`](https://docs.astral.sh/ruff/rules/missing-trailing-period),
which enforces a trailing period on the first line of both one-line and multi-line docstrings. By contrast, the rule
**DOC008** only enforces a trailing period on *one-line* docstrings, following the recommendation
in [PEP 257](https://peps.python.org/pep-0257/#one-line-docstrings).

**DOC009**: Unlike Ruff [
`triple-single-quotes`](https://docs.astral.sh/ruff/rules/triple-single-quotes/#triple-single-quotes-d300),
this rule only checks that multi-line docstrings do not start or end with more than three double quotes.

---

### DOC1xx — Parameters

| Code   | Description                               | Purpose                                   |
|--------|-------------------------------------------|-------------------------------------------|
| DOC101 | Parameter documented but not in signature | Detects undocumented or extra parameters. |
| DOC102 | Invalid parameter type syntax             | Enforces valid Python type hints.         |
| DOC103 | Parameter type already in signature       | Avoids redundant type info.               |
| DOC104 | Parameter type mismatch with annotation   | Ensures consistency with annotations.     |
| DOC105 | Duplicated parameter                      | Prevents repetition.                      |

---

### DOC2xx — Returns

| Code   | Description                                            | Purpose                                 |
|--------|--------------------------------------------------------|-----------------------------------------|
| DOC201 | Return documented but function has no return statement | Detects unnecessary return sections.    |
| DOC202 | Invalid return type syntax                             | Enforces valid type expressions.        |
| DOC203 | Return type already in signature                       | Avoids redundancy.                      |
| DOC204 | Return type mismatch with annotation                   | Validates against function annotations. |
| DOC205 | Duplicated return section                              | Prevents duplication.                   |

---

### DOC3xx — Raises

| Code   | Description                   | Purpose                                |
|--------|-------------------------------|----------------------------------------|
| DOC302 | Invalid exception type syntax | Ensures valid Python exception syntax. |
| DOC305 | Duplicated exception type     | Prevents redundant entries.            |

---

### DOC4xx — Variables

| Code   | Description                               | Purpose                           |
|--------|-------------------------------------------|-----------------------------------|
| DOC402 | Invalid variable type syntax              | Enforces valid Python type hints. |
| DOC403 | Variable name contains invalid whitespace | Ensures valid identifiers.        |
| DOC405 | Duplicated variable                       | Prevents repetition.              |

---

## How It Works

The tool statically analyzes Python source code using the built-in AST module:

1. Parses `FunctionDef`, `AsyncFunctionDef`, `ClassDef`, and `Module` nodes.
2. Extracts Sphinx-style docstring fields.
3. Validates structure, syntax, and consistency with annotations.

The tool prints findings to stdout and never modifies source files.

**CI Integration:**  
Treat any output as a failure signal in your build pipeline.

---

## Development

**Setup**

```bash
python -m pip install --upgrade pip
pip install --group=test --group=lint
```

**Run Tests**

```bash
pytest tests/
pytest --cov sphinxlinter
```

**Run Linter**

```bash
ruff check .
```

---

## License

Licensed under the [MIT License](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sphinx-linter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "python, documentation, linter, developer-tools, code-quality, docstrings",
    "author": null,
    "author_email": "rmoralespp <rmoralespp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d4/7e/0a99026b20ceb5f3f688bdbdf4ed231137601436ca8da9d95d649fc93872/sphinx_linter-0.0.11.tar.gz",
    "platform": null,
    "description": "# sphinx-linter\n\n[![PyPI](https://img.shields.io/pypi/v/sphinx-linter.svg)](https://pypi.python.org/pypi/sphinx-linter)\n[![CI](https://github.com/rmoralespp/sphinxlinter/workflows/CI/badge.svg)](https://github.com/rmoralespp/sphinxlinter/actions?query=event%3Arelease+workflow%3ACI)\n[![codecov](https://codecov.io/gh/rmoralespp/sphinxlinter/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rmoralespp/sphinxlinter)\n[![License](https://img.shields.io/github/license/rmoralespp/sphinxlinter.svg)](https://github.com/rmoralespp/sphinxlinter/blob/main/LICENSE)\n\nA lightweight Python linter for **Sphinx-style docstrings**.  \nIt validates structure, field consistency, and alignment between documentation and code.\n\n---\n\n## Overview\n\nSphinx-style docstrings are widely used across Python projects, but existing tools such as\n[pydocstyle](https://www.pydocstyle.org), [pydoclint](https://jsh9.github.io/pydoclint/),\nand [ruff](https://docs.astral.sh/ruff/) focus primarily on general docstring formatting, PEP 257 compliance, and style\nenforcement.\n\nIt is designed to **complement**, not overlap with, these tools.  \nIt targets **Sphinx-specific field list conventions** and performs **semantic consistency checks**\nthat go beyond what other linters cover.\n\nSpecifically, it focuses on:\n\n- Enforcing **Sphinx field list syntax** (`:param:`, `:type:`, `:return:`, `:raises:`, etc.)\n- Verifying **alignment** between documented fields and function signatures or type hints\n- Validating **section order, duplication, type hints syntax and completeness**\n- Producing **concise, CI-friendly reports** with structured rule codes\n\n---\n\n## Installation\n\nRequires **Python \u2265 3.9**.\n\n*No dependencies beyond the Python standard library.*\n\n```bash\npip install sphinx-linter\n```\n\n---\n\n## Quick Start\n\nTo use the standalone script, download the `sphinxlinter.py` script from\nfollowing [link](https://github.com/rmoralespp/sphinxlinter/archive/refs/heads/main.zip) and run it with Python:\n\n```bash\npython sphinxlinter.py path/to/source/\n```\n\n- Run in the current directory: `sphinxlinter .`\n- Or use the short alias: `spxl .`\n\nRun on specific files or directories:\n\n```bash\nspxl path/to/file.py path/to/package/\n```\n\nDirectories are scanned recursively for `.py` files, ignoring virtual environments and cache folders.\n\n---\n\n## Command Line Usage\n\n| Argument / Option | Description                                         |\n|-------------------|-----------------------------------------------------|\n| `[FILES]`         | Files or directories to lint.                       |\n| `--help`          | Show help message and exit.                         |\n| `--enable`        | Enable specific rule codes (or `ALL`).              |\n| `--disable`       | Disable specific rule codes (overrides `--enable`). |\n| `--ignore`        | Exclude directories (e.g. `venv`, `.cache`).        |\n| `--statistics`    | Show per-rule violation counts.                     |\n| `--quiet`         | Suppress all output except summary.                 |\n\n---\n\n## Output Format\n\nExample:\n\n```text\nsrc/module.py:42: [DOC102] Invalid parameter type syntax ('List[int]')\nsrc/module.py:10: [DOC101] Parameter documented but not in signature ('unused_param')\n```\n\n**Format:**  \n`filename:line: [CODE] message`\n\n**Categories:**\n\n- `DOC0xx`: Structure and formatting issues\n- `DOC1xx`: Parameter issues\n- `DOC2xx`: Return issues\n- `DOC3xx`: Raises issues\n- `DOC4xx`: Variable issues\n\n---\n\n## Violation Codes\n\n### DOC0xx \u2014 Structure\n\n| Code   | Description                                      | Purpose                                                                         |\n|--------|--------------------------------------------------|---------------------------------------------------------------------------------|\n| DOC001 | Invalid docstring section                        | Detects unsupported Sphinx fields.                                              |\n| DOC002 | Malformed section                                | Ensures valid field list syntax.                                                |\n| DOC003 | Missing blank line after docstring               | Improves readability.                                                           |\n| DOC004 | Missing blank line between summary and sections  | Enforces structure consistency.                                                 |\n| DOC005 | Too many consecutive blank lines                 | Prevents unnecessary whitespace.                                                |\n| DOC006 | Trailing empty lines                             | Keeps docstrings compact.                                                       |\n| DOC007 | Misplaced section                                | Enforces section order and grouping.                                            |\n| DOC008 | One-line docstring should end with a period      | Complies with [PEP 257](https://peps.python.org/pep-0257/#one-line-docstrings). |\n| DOC009 | Docstring must not use more than 3 double quotes | Promotes consistent quoting.                                                    |\n\n---\n\n**DOC008**: This rule differs from Ruff\u2019s similar rule [\n`missing-trailing-period`](https://docs.astral.sh/ruff/rules/missing-trailing-period),\nwhich enforces a trailing period on the first line of both one-line and multi-line docstrings. By contrast, the rule\n**DOC008** only enforces a trailing period on *one-line* docstrings, following the recommendation\nin [PEP 257](https://peps.python.org/pep-0257/#one-line-docstrings).\n\n**DOC009**: Unlike Ruff [\n`triple-single-quotes`](https://docs.astral.sh/ruff/rules/triple-single-quotes/#triple-single-quotes-d300),\nthis rule only checks that multi-line docstrings do not start or end with more than three double quotes.\n\n---\n\n### DOC1xx \u2014 Parameters\n\n| Code   | Description                               | Purpose                                   |\n|--------|-------------------------------------------|-------------------------------------------|\n| DOC101 | Parameter documented but not in signature | Detects undocumented or extra parameters. |\n| DOC102 | Invalid parameter type syntax             | Enforces valid Python type hints.         |\n| DOC103 | Parameter type already in signature       | Avoids redundant type info.               |\n| DOC104 | Parameter type mismatch with annotation   | Ensures consistency with annotations.     |\n| DOC105 | Duplicated parameter                      | Prevents repetition.                      |\n\n---\n\n### DOC2xx \u2014 Returns\n\n| Code   | Description                                            | Purpose                                 |\n|--------|--------------------------------------------------------|-----------------------------------------|\n| DOC201 | Return documented but function has no return statement | Detects unnecessary return sections.    |\n| DOC202 | Invalid return type syntax                             | Enforces valid type expressions.        |\n| DOC203 | Return type already in signature                       | Avoids redundancy.                      |\n| DOC204 | Return type mismatch with annotation                   | Validates against function annotations. |\n| DOC205 | Duplicated return section                              | Prevents duplication.                   |\n\n---\n\n### DOC3xx \u2014 Raises\n\n| Code   | Description                   | Purpose                                |\n|--------|-------------------------------|----------------------------------------|\n| DOC302 | Invalid exception type syntax | Ensures valid Python exception syntax. |\n| DOC305 | Duplicated exception type     | Prevents redundant entries.            |\n\n---\n\n### DOC4xx \u2014 Variables\n\n| Code   | Description                               | Purpose                           |\n|--------|-------------------------------------------|-----------------------------------|\n| DOC402 | Invalid variable type syntax              | Enforces valid Python type hints. |\n| DOC403 | Variable name contains invalid whitespace | Ensures valid identifiers.        |\n| DOC405 | Duplicated variable                       | Prevents repetition.              |\n\n---\n\n## How It Works\n\nThe tool statically analyzes Python source code using the built-in AST module:\n\n1. Parses `FunctionDef`, `AsyncFunctionDef`, `ClassDef`, and `Module` nodes.\n2. Extracts Sphinx-style docstring fields.\n3. Validates structure, syntax, and consistency with annotations.\n\nThe tool prints findings to stdout and never modifies source files.\n\n**CI Integration:**  \nTreat any output as a failure signal in your build pipeline.\n\n---\n\n## Development\n\n**Setup**\n\n```bash\npython -m pip install --upgrade pip\npip install --group=test --group=lint\n```\n\n**Run Tests**\n\n```bash\npytest tests/\npytest --cov sphinxlinter\n```\n\n**Run Linter**\n\n```bash\nruff check .\n```\n\n---\n\n## License\n\nLicensed under the [MIT License](LICENSE).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A lightweight Python linter for checking Sphinx docstrings.",
    "version": "0.0.11",
    "project_urls": {
        "Changelog": "https://github.com/rmoralespp/sphinxlinter/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/rmoralespp/sphinxlinter",
        "Issues": "https://github.com/rmoralespp/sphinxlinter/issues",
        "Source": "https://github.com/rmoralespp/sphinxlinter"
    },
    "split_keywords": [
        "python",
        " documentation",
        " linter",
        " developer-tools",
        " code-quality",
        " docstrings"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c1f41b2365f7a568138d012d677fb9d969a9a6b93b8293a041bf11996c7bd92b",
                "md5": "072ca93322e950737dc5aca05fb16246",
                "sha256": "5683b03586fffc300930e22387178ebcef58a04e915a3c482f5bd93298a98fc9"
            },
            "downloads": -1,
            "filename": "sphinx_linter-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "072ca93322e950737dc5aca05fb16246",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 13300,
            "upload_time": "2025-10-20T08:38:14",
            "upload_time_iso_8601": "2025-10-20T08:38:14.874392Z",
            "url": "https://files.pythonhosted.org/packages/c1/f4/1b2365f7a568138d012d677fb9d969a9a6b93b8293a041bf11996c7bd92b/sphinx_linter-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d47e0a99026b20ceb5f3f688bdbdf4ed231137601436ca8da9d95d649fc93872",
                "md5": "11b54ef38bcb90b9b2056768cda2affa",
                "sha256": "961231532df332b533943d55d5b718cbbe46b76c9f445ee77bfc9af516b63c69"
            },
            "downloads": -1,
            "filename": "sphinx_linter-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "11b54ef38bcb90b9b2056768cda2affa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 18709,
            "upload_time": "2025-10-20T08:38:15",
            "upload_time_iso_8601": "2025-10-20T08:38:15.652119Z",
            "url": "https://files.pythonhosted.org/packages/d4/7e/0a99026b20ceb5f3f688bdbdf4ed231137601436ca8da9d95d649fc93872/sphinx_linter-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-20 08:38:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rmoralespp",
    "github_project": "sphinxlinter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sphinx-linter"
}
        
Elapsed time: 1.37598s