Skip to main content

HTML/CSS accessibility and design linter: contrast, touch targets, headings, form labels, leaked secrets. Stdlib-only Python port of @mukundakatta/designlint.

Project description

designlint-py

Python License: MIT

HTML/CSS accessibility and design linter for contrast, touch targets, heading hierarchy, form labels, and leaked secrets. Stdlib-only -- no parser dependencies.

Python port of @mukundakatta/designlint. The JS sibling has the broader ruleset (responsive images, viewport meta, etc.); this Python port focuses on the spec's five rule families and uses the standard library's html.parser for HTML walking.

Install

pip install designlint-py

Usage

from designlint import lint

html = """
<html>
  <body>
    <p style="color: #ccc; background-color: #fff">low contrast</p>
    <a style="display: inline-block; width: 20px; height: 20px;">tap</a>
    <h1>Title</h1>
    <h3>Skipped a level</h3>
    <input type="text">
    <pre>sk-ant-1234567890abcdef1234567890abcdef</pre>
  </body>
</html>
"""

findings = lint(html)
for f in findings:
    print(f.line, f.severity, f.rule_id, f.message)

Each finding is a dataclass:

Finding(
    rule_id="color-contrast",
    severity="error",
    message="Contrast ratio 1.61:1 is below WCAG AA minimum of 4.5:1.",
    line=4,
    snippet='<p style="color: #ccc; background-color: #fff">',
)

Rules

Rule id Severity Checks
color-contrast error Inline color vs background-color against WCAG 2.1 AA (4.5:1 normal, 3:1 large).
touch-target-size warning Interactive elements (a, button, input[type=button/submit]) below 24x24 CSS pixels.
heading-hierarchy warning First heading must be h1; no skipping levels (e.g. h1 -> h3).
form-label error input / select / textarea without an associated <label for> or aria-label.
leaked-secret error Provider-shaped API keys (OpenAI, Anthropic, GitHub, AWS, Slack, Stripe, Google AI) in any text content or attribute value.

API

  • lint(html_string) -> list[Finding] -- run the full ruleset.
  • Finding(rule_id, severity, message, line, snippet) -- result dataclass.
  • parse_color(value) -> RGBA | None, contrast_ratio(fg, bg) -> float, parse_css_size(value) -> float | None -- helpers exported for reuse.

API differences from the JS sibling

  • Stdlib-only: uses Python's html.parser instead of parse5 + css-tree. Selector matching for <style> blocks is therefore omitted; only inline style=... attributes contribute to contrast/size analysis.
  • Returns a flat list[Finding] instead of { issues, score, summary } -- matches the spec's lint(html_string) -> list[Finding] shape. Compute a score yourself if you need one.
  • Rule set is the spec's five families. The JS port has additional rules (responsive images, viewport meta, link rel-noopener) that aren't in scope here.

See the JS sibling's README for the broader rationale.

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

designlint_py-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

designlint_py-0.1.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for designlint_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 33f9f7833a0ed05c03fb9e61b04fbe4caf3bbf72826bd295334b3af4bf892190
MD5 fa9f0330041831812821b9b678326c1c
BLAKE2b-256 ae90f9157e03dc9545af0aedf40299ac213e4c1b10788edf70dc5ec6d33ba173

See more details on using hashes here.

File details

Details for the file designlint_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: designlint_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for designlint_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fd0d8ad86cc5aac2068e3c6b7f0c49892a4cffde1fc4fc60e9193dc72aea2e4
MD5 96ce335406aab8bc569e527664132e99
BLAKE2b-256 0a567f181a9cace16834641c63a1f5be89946d1951dd764e45a421dde9bd9c34

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