Skip to content

class-pattern

Reports a class name that does not match the option pattern, a regex that by default means kebab-case (foo-bar). Each class of a class attribute is checked on its own.

Class names are looked up by name in stylesheets and scripts; one naming style makes them predictable to write and to search for. A class in another style is often a typo that no stylesheet ever matches.

To fix, rename the class here and in the stylesheet, or change the pattern.

Reported
<!DOCTYPE html>
<title>x</title>
<p id="fooBar" class="ok fooBar x_y"></p>
<p id="foo-bar"></p>
...
<input name="fooBar">
...
angular:
lint:
rules:
class-pattern:
level: warn # off (default), warn, error
options:
pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
html:
lint:
rules:
class-pattern:
level: warn # off (default), warn, error
options:
pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
svelte:
lint:
rules:
class-pattern:
level: warn # off (default), warn, error
options:
pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
vue:
lint:
rules:
class-pattern:
level: warn # off (default), warn, error
options:
pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
Option Type Default Description
pattern string "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" The regex the value must match.

Suppress one line with sudsy-disable-next-line class-pattern in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
html-validate class-pattern full