Skip to main content

CSS naming hierarchy enforcer

Project description

A CSS naming hierarchy enforcer.

PyPI Version Documentation Status

What is chcss?

chcss is a PyParsing based grammar for parsing and verifying that CSS class names are used in the correct hierarchy in HTML files. chcss parses HTML files into a DOM model, and then walks the tree checking class identifiers to ensure they are arranged hierarchically.

The basic grammar is:

namespace-function((-component)+(-element(-modifier)*)?)?

So long as identifiers are correctly nested, the program returns with exit status 0. If errors are detected, the program returns with exit status 1 and a hopefully helpful error message as to which identifier on which element caused the first violation, with the goal being easy integration into a git commit-msg hook or pre-commit.

Roadmap

  • Implement testing, build, documentation, and CI.

  • Implement class identifier parser.

  • Implement parser field definitions in configuration file.

  • Implement ignorable class identifiers in configuration file (i.e. Bootstrap).

  • Implement HTML DOM parser (from library).

  • Produce class identifiers from HTML DOM.

  • Verify class identifier hierarchy.

  • Use information from HTML DOM and class identifier parser to raise exceptions and provide useful error messages.

  • Implement hierarchical id identifier parsing (maybe; target: post 1.0.0).

Installation

Install chcss with:

pip install chcss
pip freeze > requirements.txt

or add as a poetry dev-dependency.

If you desire a package locally built with poetry, download the source, change the appropriate lines in pyproject.toml, and rebuild.

To use as a git commit-msg hook, copy the script chcss to .git/hooks/commit-msg and set the file as executable or integrate the script or module into your existing commit-msg hook. Running chcss as a hook relies on git setting the current working directory of the script to the root of the repository (where pyproject.toml or package.json typically lives). If this is not the repository default, pass the configuration file path as an argument or symlink from the current working directory to an appropriate configuration file. Optimally, run chcss from pre-commit to check HTML files as necessary.

Usage

Console:

chcss file.html
cat file.html | chcss

In Python:

>>> import chcss

See the source and documentation for more information.

Configuration

See chcss.toml for an example [tool.chcss] section that may be copied into a pyproject.toml file. The same entries may be used in a chcss entry in package.json for JavaScript/TypeScript projects.

Parsing Grammar

Basic Specification:

namespace-function((-component)+(-element(-modifier)*)?)?

Author

Jeremy A Gray

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

chcss-0.0.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

chcss-0.0.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file chcss-0.0.1.tar.gz.

File metadata

  • Download URL: chcss-0.0.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for chcss-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cbd1554b96d37b9e8490b18ca8e507bc288110cb6cce824907d407930e8565e1
MD5 4ebb60b31ffe973b75c32f25cbd448c9
BLAKE2b-256 7becab3396a3aaf76ecc2218cb7bf6ba613e8e16a2dd9ad9a646d3ad00e6863d

See more details on using hashes here.

File details

Details for the file chcss-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: chcss-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for chcss-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53b70132888cbc17d3cfa54f6b5179a481cb83924e7a3b293626506d50dff339
MD5 b8c4b25e83627a3cd198e7042ba238cf
BLAKE2b-256 45e33c87167dbdba3014d9e9628726d33f410e2783f702b1fe62d8c00379e454

See more details on using hashes here.

Supported by

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