- attributeQuotes
- borderZero
- comment
- decimalZero
- depthLevel
- duplicateProperty
- emptyRule
- finalNewline
- hexLength
- hexNotation
- hexValidation
- idSelector
- importantRule
- importPath
- propertyOrdering
- propertyUnits
- qualifyingElement
- selectorNaming
- singleLinePerProperty
- singleLinePerSelector
- spaceAfterPropertyColon
- spaceAfterPropertyName
- spaceAfterPropertyValue
- spaceAroundComma
- spaceAroundOperator
- spaceBeforeBrace
- spaceBetweenParens
- stringQuotes
- trailingSemicolon
- trailingWhitespace
- urlFormat
- urlQuotes
- zeroUnit
In addition to the linter specific options outlined below, each linter also accepts these options:
Option | Default value | Description |
---|---|---|
enabled |
true |
Turn the linter on/off completely. It's also possible to disable a linter by setting the whole property to false . |
severity |
"warning" |
Set the severity level for a linter, possible values are "warning" and "error" . This will affect CLI exit codes and will be reported together with other lint results (since 1.3.0 ). |
All values in attribute selectors should be enclosed in quotes. Since some values require quotes it's better for consistency to always quote the values.
input[type=text] {
color: red;
}
input[type='text'] {
color: red;
}
input[type="text"] {
color: red;
}
Prefer 0
over none
in border declarations.
Option | Description |
---|---|
style |
none , zero (default) |
.foo {
border: none;
}
.foo {
border: 0;
}
Prefer single-line comments (//
) over multi-line (/* ... */
) since they're not rendered in the final CSS.
This linter is disabled by default.
Option | Description |
---|---|
allowed |
A regexp to match allowed comments. The default is ^! allowing comments starting with a bang, i.e. /*! Copyright... */ . |
/* Will get rendered */
// Won't get rendered
/*! Will get rendered, but it's OK */
Floating point numbers should be written with a leading/trailing zero.
Option | Description |
---|---|
leading |
Floating point numbers must be written with a leading zero (default). |
trailing |
Floating point numbers must be written with a trailing zero. |
both |
Floating point numbers must be written with a leading and trailing zero. |
none |
Floating point numbers must not be written with a leading or trailing zero. |
.foo {
font-size: .5em; // leading, both
font-size: 1em; // trailing, both
font-size: 1.0em; // none
}
.foo {
font-size: 0.5em; // leading, both
font-size: 1.0em; // trailing, both
font-size: .5em; // none
}
Sets the depth of nested styles in every parent style.
Option | Description |
---|---|
depth |
From 1-'n' levels of Depth, 3 (default). |
.foo {
margin-right: 0;
.foo-2 {
color: red;
.foo-3 {
width: 100%;
.foo-4 {
height: 100%;
}
}
}
}
.foo {
margin-right: 0;
.foo-2 {
color: red;
.foo-3 {
width: 100%;
}
}
}
There shouldn't be any duplicate properties since this is usually an error, causing unexpected bugs.
However, sometimes, there might be valid reasons such as a fallback for older browsers.
In those cases, it's best to set the exclude
option to stop lesshint
from reporting those properties.
Option | Description |
---|---|
exclude |
Array of properties to exclude, for example background-color when used with a fallback. |
.foo {
color: red;
color: blue;
}
.foo {
color: red;
}
There shouldn't be any empty rules present.
.foo {
}
.foo {
color: red;
}
All files should end with a empty line to help create better diffs since the last line will always be untouched and therefore not marked as changed.
.foo {
color: red;
}
.foo {
color: red;
}
...
Prefer longhand hex color declarations over short hand ones to be consistent with colors that can't be written using shorthand notation.
Option | Description |
---|---|
style |
long (default), short |
.foo {
color: #000000;
}
.foo {
color: #000;
}
Hex color declarations should be written in lowercase to aid readability.
Option | Description |
---|---|
style |
lowercase (default), uppercase |
.foo {
color: #abcdef;
}
.foo {
color: #ABCDEF;
}
Check if hex color declarations are valid.
.foo {
color: #ab;
}
.foo {
color: #abc;
}
Disallow the usage of ID selectors. ID selectors should be avoided since they introduce unnecessarily specific selectors which can't be easily overridden.
Option | Description |
---|---|
exclude |
Array of IDs to exclude (with or without # ). |
#foo {
color: red;
}
.foo {
color: red;
}
Disallow the usage of !important
.
The use of !important
is often due to a lack of understanding of CSS specificity.
.foo {
color: red !important;
}
.foo {
color: red;
}
Imported files should not include a leading underscore or the filename extension.
The filename extension isn't required and underscores should be reserved for usage with config-files, such as _vars.less
.
Option | Description |
---|---|
filenameExtension |
false (default), true |
leadingUnderscore |
false (default), true |
exclude |
Array of files to exclude |
@import 'foo.less';
@import '_bar';
@import 'foo';
@import 'bar';
Make sure properties are sorted in a particular order.
Option | Description |
---|---|
style |
alpha (default) |
Specify which units are allowed for property values.
By default all properties can have any value.
The global
option can be used to specify global units that are allowed
and the properties
option can be used to fine tune units for each property.
Note: Shorthands are not supported by the properties
option. For example, to specify units for margin
, all margin-* properties must be specified.
Option | Description |
---|---|
valid |
Allowed units (by default all units are allowed) |
invalid |
Units not allowed under any circumstances. Overrides all other options. |
properties |
Object with property names and allowed units (empty by default) |
"propertyUnits": {
"valid": ["rem", "vw"], // These units are allowed for all properties
"invalid": ["pt"], // The 'pt' unit is not allowed under any circumstances
"properties": {
"line-height": [] // No units are allowed for line-height
}
}
.foo {
font-size: 1.5rem; // Allowed
line-height: 30px; // Not allowed
}
Selectors should not include a qualifying element since this will just add unnecessary specificity.
Option | Description |
---|---|
allowWithAttribute |
false (default), true |
allowWithClass |
false (default), true |
allowWithId |
false (default), true |
div[foo='bar'] {
color: red;
}
div.foo {
color: red;
}
div#foo {
color: red;
}
[foo='bar'] {
color: red;
}
.foo {
color: red;
}
#foo {
color: red;
}
Option | Description |
---|---|
disallowUppercase |
true (default), boolean |
disallowUnderscore |
true (default), boolean |
disallowDash |
false (default), boolean |
exclude |
string array |
var options = {
disallowUppercase: true,
disallowUnderscore: true,
exclude: ['fooExcluded']
}
.foo-bar {
}
.fooExcluded {
}
.fooBar {
}
.foo_bar {
}
Currently this option lets you approximate some naming conventions. Keep in mind that it's not foolproof.
Style | example | options to enable |
---|---|---|
train case | .btn-primary | disallowUppercase , disallowUnderscore |
snake case | .btn_primary | disallowUppercase , disallowDash |
camel case | .btnPrimary | disallowUnderscore , disallowDash |
Each property should be on its own line.
.foo {
color: red; margin-right: 10px;
}
.bar { color: red; }
.foo {
color: red;
margin-right: 10px;
}
.bar {
color: red;
}
Each selector should be on its own line.
Option | Description |
---|---|
style |
18f , none (default) |
The 18f
option refers to the 18F Style Guide.
.foo, .bar {
color: red;
}
// Style "18f"
.foobar, .baz {
color: red;
}
.foo,
.bar {
color: red;
}
// Style "18f"
.foo, .bar {
color: red;
}
Each colon in property declarations should be followed by a space to aid readability.
Option | Description |
---|---|
style |
no_space , one_space (default) |
.foo {
margin:0;
}
.foo {
margin: 0;
}
The colon in property declarations shouldn't be preceded by any space.
Option | Description |
---|---|
style |
no_space (default), one_space |
.foo {
margin: 0;
}
.foo {
margin : 0;
}
The semicolon in property declarations shouldn't be preceded by any space.
Option | Description |
---|---|
style |
no_space (default), one_space |
.foo {
margin: 0;
}
.foo {
margin: 0 ;
}
Defines how commas in functions, mixins, etc. should be formatted by a space to aid readability.
Option | Description |
---|---|
allowNewline |
false (default), boolean |
style |
after (default), before , both , none |
.foo {
color: rgb(255, 255, 255);
}
.foo {
color: rgb(255 ,255 ,255);
}
.foo {
color: rgb(255 , 255 , 255);
}
.foo {
color: rgb(255,255,255);
}
.foo {
font:
14px,
Roboto,
#000;
}
Defines how operators (+
, -
, *
, /
, and =
) should be formatted by a space to aid readability.
Option | Description |
---|---|
style |
both (default), none |
.foo {
height: calc(10px + 10px);
}
.foo {
height: calc(10px+10px);
}
A space should be present before opening braces to aid readability.
Option | Description |
---|---|
style |
no_space , one_space (default), new_line |
.foo{
color: red;
}
.foo {
color: red;
}
.foo
{
color: red;
}
There shouldn't be any space before or after parentheses.
Option | Description |
---|---|
style |
no_space (default), one_space |
.foo {
color: rgb(255, 255, 255);
}
.foo {
color: rgb( 255, 255, 255 );
}
All strings should use single quotes since they are often easier to type since the Shift
key doesn't need to be pressed.
Option | Description |
---|---|
style |
double , single (default) |
.foo {
content: "Hello world";
}
.foo {
content: 'Hello world';
}
All property declarations should end with a semicolon. Semicolons are optional after the last property in a ruleset but it's a good habit to always add them since one doesn't need to think about it when adding new properties afterwards.
.foo {
color: red
}
.foo {
color: red;
}
There should't be any trailing whitespace since this will mess up diffs etc.
All URLs should be relative. Using relative URLs increases portability and is recommended by the CSS spec.
Option | Description |
---|---|
style |
absolute , relative (default) |
.foo {
background-image: url('http://example.com/img/image.jpg');
}
.foo {
background-image: url('img/image.jpg');
}
All URLs should be enclosed in quotes. Using quotes around URLs allows them to be treated as strings, making escaping of characters easier. The CSS spec also recommends the use of quotes.
.foo {
background-image: url(img/image.jpg);
}
.foo {
background-image: url('img/image.jpg');
}
Zero values should include a unit for consistency with other values.
Option | Description |
---|---|
style |
no_unit , keep_unit (default) |
units |
string array additional units to enforce. |
exclude |
string array additional properties to exclude. |
.foo {
margin-right: 0;
}
.foo {
margin-right: 0px;
}
Note: This rule doesn't apply to angles or time units since they always require a unit.
Most of these rules are based on @mdos code guide.