Skip to main content

A linter & autoformatter for consistent HTML code, or else.

Project description

Cutesy 🥰

Python 3.6+ Build Status

A cute little HTML linter, until y̵ou ma̴k̵e i̴͌ͅt̴̖̀ a̵̤̤͕̰͐̅͘͘n̶̦̣͙̑̌̆̄ǵ̷̗̗̀͝r̷̭̈́͂͘ẙ̶͔̟̞̊̈…̴̢͘

Cutesy checks HTML documents for consistency and best practices. It’s opinionated. It includes a set of rules, most of which can be fixed automatically.

Cutesy expects HTML5 files, with UTF-8 encoding.

Cutesy works with templating languages, such as Django Template Language or Ruby's ERB. These are handled during the "preprocessing" step. Because of this, Cutesy takes dynamic template tags into account for certain types of formatting (such as indentation) & some rules (such as balancing HTML tags).

Preprocessing is (or will be) supported for these templating languages:

  • Django
  • Jinja
  • ERB
  • Handlebars
  • EJS
  • Mustache
  • Nunjucks
  • Smarty
  • Liquid

Benefits

  • Catch accidental errors.
  • Enforce best practices.
  • Code without worrying about formatting. Cutesy formats automatically.
  • Improve code readability.
  • Small diffs for easier code review.

Examples

Cutesy ensures that HTML documents contain consistent whitespace, follow best practices, and adhere to common conventions. In --fix mode, Cutesy turns this:

    <!doctype html>
<html>
                    <head>
    <title>Test Page</title>
   </head>
<body>
            <h1>Hello     world! </h1>


            {% if condition1 %}
                            <p>I love           cookies.</p>
                          {% endif %}



                <div     class='someDiv'
                       id="theDiv"   ></div    >
                    </body>
</html>

…into this:

<!doctype html>
<html>
<head>
    <title>Test Page</title>
</head>
<body>
    <h1>Hello world! </h1>

    {% if condition1 %}
        <p>I love cookies.</p>
    {% endif %}

    <div id="theDiv" class="someDiv"></div>
</body>
</html>

See the full list of rules for more information.

Installation

Cutesy is written in Python. Install via PyPI:

pip install cutesy

Usage

Minimal usage:

cutesy some_file.html

Lint multiple files using a glob pattern:

cutesy "*.html"
cutesy "path/to/templates/**/*.html"
# etc…

Fix files automatically (recommended):

cutesy "*.html" --fix

Cutesy can check HTML fragments, or whole HTML documents. By default, Cutesy ignores files specifying a non-HTML5 doctype (anything other than <!doctype html>).

To assume (and enforce) that all matching files are HTML5, use the --check-doctype flag:

cutesy "*.html" --fix --check-doctype

To lint files written in a template language, such as the Django Template Language:

cutesy "*.html" --fix --preprocessor django

Other options:

  • --code: Process the code passed in as a string.
  • --quiet: Don't print individual problems.
  • --return-zero: Always exit with 0, even if unfixed problems remain.
  • --version: Show the version and exit.
  • --help: Show the CLI help and exit.

Testing, etc.

Install development requirements (Requires Python >= 3.8):

make install

Sort imports:

make format

Lint:

make lint

Test:

make test

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

cutesy-1.0b1.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

cutesy-1.0b1-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file cutesy-1.0b1.tar.gz.

File metadata

  • Download URL: cutesy-1.0b1.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for cutesy-1.0b1.tar.gz
Algorithm Hash digest
SHA256 37ee340655f536b9e403ac0bf0079f9e94d6b21fca31ca27c14a04ba8a19c881
MD5 6f6142ee5e8fcab675d1cfc4a977b375
BLAKE2b-256 3a20cc30a24193ee2154c880e55820c67d5b6ac81c3c4906e6fac91819a83b94

See more details on using hashes here.

File details

Details for the file cutesy-1.0b1-py3-none-any.whl.

File metadata

  • Download URL: cutesy-1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for cutesy-1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c40eb004a21b5baa7da190a1a0090c536d396dc0f6edfc1cceff60c1f8d87e2
MD5 98700fe42affc891dc099bf131768cc5
BLAKE2b-256 92291d4301b8f551c1d9bce8a99fe945afe974576f174dd49651ad55f06471e5

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