### Example pyproject.toml Configuration
Source: https://www.curlylint.org/docs/configuration
This example shows how to configure Curlylint's include and exclude patterns, as well as specific rules like indentation and language.
```toml
[tool.curlylint]
include = "\\.(html|jinja)$"
exclude = "''"
(
(/(
\.eggs # exclude a few common directories in the root of the project
| \.git
| \.venv
)/
| webpack-stats.html # also separately exclude a file named webpack-stats.html in the root of the project
)
''"
[tool.curlylint.rules]
indent = 4
html_has_lang = "en-GB"
```
--------------------------------
### Install Curlylint
Source: https://www.curlylint.org/docs
Install Curlylint using pip. This command installs the package and its dependencies.
```bash
pip install curlylint
```
--------------------------------
### Verify Curlylint Installation
Source: https://www.curlylint.org/docs
Check if Curlylint is installed correctly by running the version and help commands.
```bash
curlylint --version
```
```bash
curlylint --help
```
--------------------------------
### Lint HTML Template Directory
Source: https://www.curlylint.org/docs
Start linting by providing the path to your HTML template directory.
```bash
curlylint template-directory/
```
--------------------------------
### Allow as_p Rendering (Shell)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
CLI example demonstrating the use of `form.as_p` when the `django_forms_rendering` rule is configured to allow it.
```html
{{ form.as_p }}
```
--------------------------------
### Valid HTML with No Tabindex or Tabindex -1 (CLI Example)
Source: https://www.curlylint.org/docs/rules/tabindex_no_positive
Valid HTML examples demonstrating adherence to the `tabindex_no_positive` rule, shown in the context of a CLI command. This includes elements without `tabindex`, `tabindex="0"`, and `tabindex="-1"`.
```html
ARIA button
I can receive focus via JS
```
--------------------------------
### Allow as_p Rendering (TOML)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Example demonstrating the allowed use of `form.as_p` when the `django_forms_rendering` rule is configured to permit it.
```html
{{ form.as_p }}
```
--------------------------------
### Disallow as_p Rendering (Shell)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
CLI example showing `form.as_p` usage, which violates the `django_forms_rendering` rule when set to `true` (and not explicitly allowed).
```html
{{ form.as_p }}
```
--------------------------------
### Valid Input without Autofocus (Command Line)
Source: https://www.curlylint.org/docs/rules/no_autofocus
This command-line example demonstrates a valid input element that adheres to the no_autofocus rule, as it lacks the autofocus attribute.
```html
```
--------------------------------
### Disallow as_table Rendering (Shell)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
CLI example showing `form.as_table` usage, which violates the `django_forms_rendering` rule when set to `true`.
```html
{{ form.as_table }}
```
--------------------------------
### Disallow as_p Rendering (TOML)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Example of using `form.as_p`, which is disallowed when `django_forms_rendering` is set to `true` (and not explicitly allowed).
```html
{{ form.as_p }}
```
--------------------------------
### Disallow as_ul Rendering (Shell)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
CLI example showing `form.as_ul` usage, which violates the `django_forms_rendering` rule when set to `true`.
```html
{{ form.as_ul }}
```
--------------------------------
### Disallow as_table Rendering (TOML)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Example of using `form.as_table`, which is disallowed when `django_forms_rendering` is set to `true`.
```html
{{ form.as_table }}
```
--------------------------------
### Valid ARIA Role Usage (TOML)
Source: https://www.curlylint.org/docs/rules/aria_role
Examples of valid ARIA role usage with TOML configuration. This demonstrates correct implementation when the rule is enabled globally or with a specific list.
```html
```
--------------------------------
### Disallow as_ul Rendering (TOML)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Example of using `form.as_ul`, which is disallowed when `django_forms_rendering` is set to `true`.
```html
{{ form.as_ul }}
```
--------------------------------
### Manually Render Form Field (Shell)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
CLI example showing manual form field rendering, which is compliant with the `django_forms_rendering` rule when set to `true`.
```html
{{ form.username }}
```
--------------------------------
### Valid ARIA Role Usage (Shell)
Source: https://www.curlylint.org/docs/rules/aria_role
Examples of valid ARIA role usage with shell commands. These snippets show how to apply the rule with different configurations for correct ARIA role implementation.
```html
```
--------------------------------
### Valid Viewport Meta Tags (CLI)
Source: https://www.curlylint.org/docs/rules/meta_viewport
Examples of valid viewport meta tags that adhere to accessibility standards, as configured by the meta_viewport rule via CLI.
```html
```
--------------------------------
### Invalid Input with Autofocus (Command Line)
Source: https://www.curlylint.org/docs/rules/no_autofocus
This command-line example shows an invalid input element with the autofocus attribute, violating the no_autofocus rule.
```html
```
--------------------------------
### Valid HTML with lang Attribute (TOML)
Source: https://www.curlylint.org/docs/rules/html_has_lang
Examples of valid HTML structures when the 'html_has_lang' rule is configured via TOML. These demonstrate correct usage for presence, specific language, and multiple language options.
```HTML
```
--------------------------------
### Invalid Image Tags Missing Alt Attribute
Source: https://www.curlylint.org/docs/rules/image_alt
Shows examples of `` tags that violate the rule by omitting the `alt` attribute.
```HTML
```
```HTML
```
--------------------------------
### Valid Viewport Meta Tags (TOML)
Source: https://www.curlylint.org/docs/rules/meta_viewport
Examples of valid viewport meta tags that adhere to accessibility standards, as configured by the meta_viewport rule in TOML.
```html
```
--------------------------------
### Valid HTML with lang Attribute (Shell)
Source: https://www.curlylint.org/docs/rules/html_has_lang
Examples of valid HTML structures when the 'html_has_lang' rule is configured via shell commands. These demonstrate correct usage for presence, specific language, and multiple language options.
```HTML
```
--------------------------------
### Manually Render Form Field (TOML)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Example of manually rendering a single form field, which is considered good practice and allowed when the rule is configured to disallow convenience methods.
```html
{{ form.username }}
```
--------------------------------
### Configure Curlylint with Custom File Matching
Source: https://www.curlylint.org/docs/reference/integrations
Override the default file matching behavior for Curlylint in pre-commit hooks by using the `files` setting to specify a custom regex pattern. This example matches `.html` and `.sls` files.
```yaml
- id: curlylint
files: \.(html|sls)$
```
--------------------------------
### Invalid Viewport Meta Tags (CLI)
Source: https://www.curlylint.org/docs/rules/meta_viewport
Examples of invalid viewport meta tags that violate accessibility standards, flagged by the meta_viewport rule via CLI.
```html
```
--------------------------------
### Invalid HTML with Positive Tabindex (TOML)
Source: https://www.curlylint.org/docs/rules/tabindex_no_positive
Example of invalid HTML that violates the `tabindex_no_positive` rule due to a positive `tabindex` value. This configuration is set in TOML.
```html
```
--------------------------------
### Invalid Viewport Meta Tags (TOML)
Source: https://www.curlylint.org/docs/rules/meta_viewport
Examples of invalid viewport meta tags that violate accessibility standards, flagged by the meta_viewport rule in TOML.
```html
```
--------------------------------
### Invalid ARIA Role Usage (Shell)
Source: https://www.curlylint.org/docs/rules/aria_role
Examples of invalid ARIA role usage with shell commands. These demonstrate incorrect role assignments that would be flagged by the linter.
```html
```
--------------------------------
### Invalid HTML with Positive Tabindex (CLI)
Source: https://www.curlylint.org/docs/rules/tabindex_no_positive
Example of invalid HTML that violates the `tabindex_no_positive` rule due to a positive `tabindex` value. This is shown in the context of a CLI command.
```html
```
--------------------------------
### Invalid ARIA Role Usage (TOML)
Source: https://www.curlylint.org/docs/rules/aria_role
Examples of invalid ARIA role usage with TOML configuration. This highlights common mistakes like using non-existent roles or roles not present in the allowed list.
```html
```
--------------------------------
### Valid HTML with No Tabindex or Tabindex -1
Source: https://www.curlylint.org/docs/rules/tabindex_no_positive
Examples of valid HTML that adhere to the `tabindex_no_positive` rule. This includes elements without a `tabindex` attribute, elements with `tabindex="0"` (though not recommended for general use), and elements with `tabindex="-1"` for programmatic focus.
```html
ARIA button
I can receive focus via JS
```
--------------------------------
### Invalid HTML Missing or Incorrect lang Attribute (TOML)
Source: https://www.curlylint.org/docs/rules/html_has_lang
Examples of invalid HTML structures that violate the 'html_has_lang' rule when configured via TOML. These show cases where the 'lang' attribute is missing or uses an incorrect language tag.
```HTML
```
--------------------------------
### Invalid HTML Missing or Incorrect lang Attribute (Shell)
Source: https://www.curlylint.org/docs/rules/html_has_lang
Examples of invalid HTML structures that violate the 'html_has_lang' rule when configured via shell commands. These show cases where the 'lang' attribute is missing or uses an incorrect language tag.
```HTML
```
--------------------------------
### Print Configuration
Source: https://www.curlylint.org/docs/command-line-usage
Displays the configuration applied to a specific file and then exits.
```bash
curlylint --print-config some-file.html
```
--------------------------------
### Configure Rules with JSON Values
Source: https://www.curlylint.org/docs/command-line-usage
Specifies rules and their configurations using JSON values. Multiple rules can be configured by repeating the flag.
```bash
curlylint --rule 'indent: 2' --rule 'html_has_lang: true' template-directory/
```
```bash
curlylint --rule 'html_has_lang: "en"' template-directory/
```
```bash
curlylint --rule 'html_has_lang: ["en", "en-US"]' template-directory/
```
--------------------------------
### Show Version
Source: https://www.curlylint.org/docs/command-line-usage
Displays the current version of Curlylint and exits the program.
```bash
curlylint --version
```
--------------------------------
### Specify Output Format
Source: https://www.curlylint.org/docs/command-line-usage
Sets the output format for linting results. Available formats are stylish, compact, and json.
```bash
curlylint --format json some-file.html
```
--------------------------------
### Specify Configuration File
Source: https://www.curlylint.org/docs/command-line-usage
Instructs Curlylint to read its configuration from a specified TOML file.
```bash
curlylint --config test_pyproject.toml template-directory/
```
--------------------------------
### Enable meta_viewport Rule via CLI
Source: https://www.curlylint.org/docs/rules/meta_viewport
Enable the meta_viewport rule using the curlylint CLI command with the specified rule.
```shell
curlylint --rule 'meta_viewport: true' .
```
--------------------------------
### Configure Indentation with CLI
Source: https://www.curlylint.org/docs/rules/indent
Configure indentation using the command line. Use 'tab' for tab characters or a number for spaces.
```Shell
# Use tabs.
curlylint --rule 'indent: "tab"' .
# Use a given number of spaces.
curlylint --rule 'indent: 4' .
```
--------------------------------
### Read from Standard Input
Source: https://www.curlylint.org/docs/command-line-usage
Pipes template content to Curlylint for processing. The path is specified as '-'.
```bash
cat some-file.html | curlylint -
```
--------------------------------
### Configure Indentation with TOML
Source: https://www.curlylint.org/docs/rules/indent
Configure indentation using TOML. Use 'tab' for tab characters or a number for spaces.
```TOML
# Use tabs.
indent = "tab"
# Use a given number of spaces.
indent = 4
```
--------------------------------
### Configure Django Forms Rendering Rule (Shell)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Configure the django_forms_rendering rule using the Curlylint CLI. Use `true` to disable all convenience methods or a string like `"as_p"` to allow specific ones.
```shell
# Forms cannot be rendered with as_table, as_ul, or as_p
curlylint --rule 'django_forms_rendering: true' .
# Allows as_p
curlylint --rule 'django_forms_rendering: "as_p"' .
```
--------------------------------
### Enable image_alt Rule via Shell Command
Source: https://www.curlylint.org/docs/rules/image_alt
Activate the `image_alt` rule directly from the command line using the `--rule` flag.
```Shell
# The `alt` attribute must be present.
curlylint --rule 'image_alt: true' .
```
--------------------------------
### Enable Verbose Mode
Source: https://www.curlylint.org/docs/command-line-usage
Activates verbose mode for detailed troubleshooting of configuration and linting processes.
```bash
curlylint --verbose template-directory/
```
--------------------------------
### Enable All Rules via Command Line
Source: https://www.curlylint.org/docs/rules/all
This command-line invocation enables all rules in Curlylint using individual `--rule` flags. It's a way to apply all checks without a configuration file.
```shell
curlylint --rule 'aria_role: true' --rule 'django_forms_rendering: true' --rule 'html_has_lang: true' --rule 'image_alt: true' --rule 'indent: "tab"' --rule 'meta_viewport: true' --rule 'no_autofocus: true' --rule 'tabindex_no_positive: true' .
```
--------------------------------
### Provide Stdin Filepath
Source: https://www.curlylint.org/docs/command-line-usage
Specifies a virtual file path for content read from standard input, used for linting and reporting.
```bash
cat some-file.html | curlylint - --stdin-filepath some-file.html
```
--------------------------------
### Variable Interpolation in Templates
Source: https://www.curlylint.org/docs/template-languages
Demonstrates the use of double curly braces for variable interpolation in template languages.
```html
{{ pretty_cool_variable }}
```
--------------------------------
### Enable Rule via CLI
Source: https://www.curlylint.org/docs/rules/tabindex_no_positive
Enable the `tabindex_no_positive` rule using the `curlylint` command-line interface by specifying the rule and its value.
```shell
# Avoid positive `tabindex` values, change the order of elements on the page instead.
curlylint --rule 'tabindex_no_positive: true' .
```
--------------------------------
### Enable All Rules in TOML Configuration
Source: https://www.curlylint.org/docs/rules/all
This TOML configuration enables all rules in Curlylint. Each rule is set to its default or a common configuration. Use this to test all functionalities at once.
```toml
[tool.curlylint.rules]
# All role attributes must be valid.
# See https://www.curlylint.org/docs/rules/aria_role.
aria_role = true
# Forms cannot be rendered with as_table, as_ul, or as_p
# See https://www.curlylint.org/docs/rules/django_forms_rendering.
django_forms_rendering = true
# The `lang` attribute must be present.
# See https://www.curlylint.org/docs/rules/html_has_lang.
html_has_lang = true
# The `alt` attribute must be present.
# See https://www.curlylint.org/docs/rules/image_alt.
image_alt = true
# Use tabs.
# See https://www.curlylint.org/docs/rules/indent.
indent = "tab"
# `user-scalable=no` must not be used, and `maximum-scale` should be 2 or above.
# See https://www.curlylint.org/docs/rules/meta_viewport.
meta_viewport = true
# The `autofocus` attribute must not be used.
# See https://www.curlylint.org/docs/rules/no_autofocus.
no_autofocus = true
# Avoid positive `tabindex` values, change the order of elements on the page instead.
# See https://www.curlylint.org/docs/rules/tabindex_no_positive.
tabindex_no_positive = true
```
--------------------------------
### Include Files with Custom Extension
Source: https://www.curlylint.org/docs/command-line-usage
Includes files matching a specific regular expression during recursive searches, overriding the default.
```bash
curlylint --parse-only --include .njk nunjucks-templates/
```
--------------------------------
### Configure Curlylint with Pre-commit
Source: https://www.curlylint.org/docs/reference/integrations
Add this configuration to your `.pre-commit-config.yaml` file to integrate Curlylint into your git pre-commit hooks. Ensure you specify a valid revision for the `rev` field.
```yaml
repo: https://github.com/thibaudcolas/curlylint
rev: "" # select a tag / sha to point at
hooks:
- id: curlylint
```
--------------------------------
### Valid Image Tags with Alt Attribute
Source: https://www.curlylint.org/docs/rules/image_alt
Demonstrates correct usage of `` tags with a present `alt` attribute, including meaningful text and an empty string for decorative images.
```HTML
```
```HTML
```
--------------------------------
### Special Blocks or Tags in Templates
Source: https://www.curlylint.org/docs/template-languages
Shows how to use curly braces with percent signs for special blocks or tags in template languages.
```html
{% my_special_tag %}
```
--------------------------------
### Enable Rule in Configuration
Source: https://www.curlylint.org/docs/rules/tabindex_no_positive
Enable the `tabindex_no_positive` rule by setting it to `true` in your TOML configuration file.
```toml
# Avoid positive `tabindex` values, change the order of elements on the page instead.
tabindex_no_positive = true
```
--------------------------------
### Enable meta_viewport Rule in TOML
Source: https://www.curlylint.org/docs/rules/meta_viewport
Enable the meta_viewport rule by setting it to true in your TOML configuration file.
```toml
# `user-scalable=no` must not be used, and `maximum-scale` should be 2 or above.
meta_viewport = true
```
--------------------------------
### Enable image_alt Rule in TOML
Source: https://www.curlylint.org/docs/rules/image_alt
Configure the `image_alt` rule to be active by setting it to `true` in your TOML configuration file.
```TOML
# The `alt` attribute must be present.
image_alt = true
```
--------------------------------
### Configure Django Forms Rendering Rule (TOML)
Source: https://www.curlylint.org/docs/rules/django_forms_rendering
Configure the django_forms_rendering rule in TOML format. Set to `true` to disallow all convenience rendering methods, or specify allowed methods like `"as_p"`.
```toml
# Forms cannot be rendered with as_table, as_ul, or as_p
django_forms_rendering = true
# Allows as_p
django_forms_rendering = "as_p"
```
--------------------------------
### Enable no_autofocus Rule via Command Line
Source: https://www.curlylint.org/docs/rules/no_autofocus
Enforce the no_autofocus rule directly from the command line using the curlylint command with the rule specified.
```shell
# The `autofocus` attribute must not be used.
curlylint --rule 'no_autofocus: true' .
```
--------------------------------
### Configure ARIA Role Validation (TOML)
Source: https://www.curlylint.org/docs/rules/aria_role
Configure the aria-role rule in TOML format. It can be set to true to enforce any valid role or to a list of allowed roles.
```toml
aria_role = true
aria_role = [ "search", "presentation", "alert",]
```
--------------------------------
### Filters in Template Variable Interpolation
Source: https://www.curlylint.org/docs/template-languages
Illustrates the use of pipes within double curly braces to apply filters to variables in template languages.
```html
{{ pretty_cool_list|length }}
```
--------------------------------
### Specify Custom Template Tags
Source: https://www.curlylint.org/docs/command-line-usage
Defines additional sets of template tags, particularly for tags that wrap other markup. The input must be a JSON-formatted list of lists.
```bash
curlylint --template-tags '[["cache", "endcache"]]' template-directory/
```
--------------------------------
### Lint Specific HTML Files
Source: https://www.curlylint.org/docs
Lint one or more specific HTML files by listing them after the curlylint command.
```bash
curlylint some-file.html some-other-file.html
```
--------------------------------
### Configure ARIA Role Validation (Shell)
Source: https://www.curlylint.org/docs/rules/aria_role
Configure the aria-role rule using shell commands. This allows enabling the rule or specifying a custom list of allowed roles.
```shell
curlylint --rule 'aria_role: true' .
curlylint --rule 'aria_role: [ "search", "presentation", "alert"]' .
```
--------------------------------
### Configure html_has_lang Rule via Shell
Source: https://www.curlylint.org/docs/rules/html_has_lang
Configure the 'html_has_lang' rule using shell commands. This snippet demonstrates enabling the rule, enforcing a specific language, or allowing multiple language options.
```Shell
# The `lang` attribute must be present.
curlylint --rule 'html_has_lang: true' .
# The `lang` attribute must match the configured language tag.
curlylint --rule 'html_has_lang: "en-US"' .
# The `lang` attribute must match one of the configured language tags.
curlylint --rule 'html_has_lang: ["en", "en-US"]' .
```
--------------------------------
### Configure html_has_lang Rule in TOML
Source: https://www.curlylint.org/docs/rules/html_has_lang
Configure the 'html_has_lang' rule using TOML. This snippet shows how to enable the rule, enforce a specific language, or allow a list of languages.
```TOML
# The `lang` attribute must be present.
html_has_lang = true
# The `lang` attribute must match the configured language tag.
html_has_lang = "en-US"
# The `lang` attribute must match one of the configured language tags.
html_has_lang = [ "en", "en-US",]
```
--------------------------------
### Parse Only Mode
Source: https://www.curlylint.org/docs/command-line-usage
Checks only for syntax errors without performing linting.
```bash
curlylint --parse-only template-directory/
```
--------------------------------
### Valid Input without Autofocus (TOML)
Source: https://www.curlylint.org/docs/rules/no_autofocus
This TOML configuration shows a valid input element that does not use the autofocus attribute, satisfying the no_autofocus rule.
```html
```
--------------------------------
### Invalid Input with Autofocus (TOML)
Source: https://www.curlylint.org/docs/rules/no_autofocus
This TOML configuration highlights an invalid input element that uses the autofocus attribute, which will be flagged by the no_autofocus rule.
```html
```
--------------------------------
### Enable Quiet Mode
Source: https://www.curlylint.org/docs/command-line-usage
Suppresses non-error messages to stderr. Errors are still shown unless redirected.
```bash
curlylint --quiet template-directory/
```
```bash
curlylint --quiet template-directory/ 2>/dev/null
```
--------------------------------
### Enable no_autofocus Rule in TOML
Source: https://www.curlylint.org/docs/rules/no_autofocus
Configure the no_autofocus rule to be enforced by setting it to true in your TOML configuration file.
```toml
# The `autofocus` attribute must not be used.
no_autofocus = true
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.