[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
102 lines (74 loc) · 2.91 KB

configuration.md

File metadata and controls

102 lines (74 loc) · 2.91 KB

Configuring lesshint

Start by creating a .lesshintrc file in your project root and add your settings to it. It will be automatically loaded and merged with the default values. If no .lesshintrc file is found in the current working directory, lesshint will traverse up the directory structure looking for one, stopping once it finds one or reaches the root directory.

In the .lesshintrc file, each option is specified by its own JSON object, for example:

{
    "fileExtensions": [".less", ".css"],

    "excludedFiles": ["vendor.less"],

    "spaceAfterPropertyColon": {
        "enabled": true,
        "style": "one_space" // Comments are allowed
    },

    "emptyRule": true, // If there are no options for a rule, you can simply enable it by setting it to true

    "importantRule": false // To disable a rule completely, set it to false
}

Now, take a look at the available linter options.

Inline configuration

It's possible to configure rules using inline comments in your .less files. This needs to be on the first line of your .less file. For example:

// lesshint spaceBeforeBrace: false
.foo{ // This line won't be reported
    color: red;
}

It's also possible to disable rules on a single line using a trailing comment:

.bar {
    color:red; // lesshint spaceAfterPropertyColon: false
}

If you wish to enable a rule that's disabled in your .lesshintrc you need to specify all the other options for it too. For example:

.lesshintrc:

{
    "emptyRule": false,
    "spaceAfterPropertyName": false
}

file.less

// lesshint spaceAfterPropertyName: { enabled: true, style: "one_space" }, emptyRule: true
.foo {
    color : red; // Won't report the extra space before ":"
}

.bar { // But this empty rule will be reported

}

The inline configuration options format is a less strict form of JSON. Keys doesn't need any quotes but string values need double quotes.

Other available options

fileExtensions

Array of file extensions to check. Either an array of extensions or "*" to allow all files. For example:

"fileExtensions": [".less", ".css"] // Allow ".less" and ".css" files. Can be passed with or without a dot.

"fileExtensions": "*" // Allow all files

excludedFiles

Array of minimatch glob patterns or a file to exclude. For example:

"excludedFiles": ["vendor/*.less"] // Ignore all files in "vendor/"

"excludedFiles": ["vendor.less"] // Ignore a file named "vendor.less"

linters

It's also possible to define your own linters to add to the built-in list. These can be the linters themselves or require paths relative to your current working directory. Note that any custom linters will need to be enabled before they can be used. For example:

"linters": [
    "/path/to/sample-linter.js"
]

"sample": {
    "enabled": true
},

"otherSample": {
    "enabled": true
}