Giter Club home page Giter Club logo

lesshint's Introduction

lesshint

npm Build Status Build status Coverage Status Dependency Status devDependency Status

lesshint is a tool to aid you in writing clean and consistent Less.

Requirements

Node.js 0.10 (or later) or io.js 1.0 (or later).

Installation

Run the following command from the command line (add -g to install globally):

npm install lesshint

Configuration

lesshint is customizable and we highly recommend you to look at the available options to tailor it to your needs.

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.

Each option is then specified by it's own JSON object, for example:

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

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

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

Inline configuration

Since 1.4.0 it's possible to configure rules using inline comments in your .less files. 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 any other options too. But rules without options can be enabled by just setting it to true. 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 {

}

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

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"

CLI usage

Run lesshint from the command-line by passing one or more files/directories to recursively scan.

lesshint src/less/ lib/style.less
Available Flags Description
-c/--config Specify the configuration file to use (will be merged with defaults).
-e/--exclude A minimatch glob pattern or a file to exclude form being linted.
-r/--reporter The reporter to use. See "Reporters" below for possible values.
-V/--version Show version.

Exit status codes

Depending on the linter results and options supplied, the exit status code returned by the CLI will differ.

Exit status code Description
0 Everything is alright, no linting errors found.
1 One or more linting errors with a severity of warning was found.
2 One or more linting errors with a severity of error was found (since 1.3.0).
66 No files to lint were supplied.
70 An unknown error occurred within lesshint, possibly a bug. Please file an issue!
78 Something is wrong with the config file, most likely invalid JSON.

These codes were chosen with regards to the preferable exit codes.

Reporters

As of 0.8.0 the ability to specify custom reporters has been added. These can do anything from just printing something to the terminal to generate custom reports.

There are three ways to load a reporter.

  1. Pass the name of a core reporter. See below for a complete listing.
  2. Pass the name of a Node module. If lesshint is installed globally only globally installed reporters are available (the normal Node module loading rules apply).
  3. Pass a absolute or relative path to a custom reporter anywhere on the disk. Relative paths will be resolved against process.cwd().

Core reporters

  • stylish - Colored print of all errors to the console.

Writing your own reporter

In it's simplest form, a reporter is just a function accepting some input. The most basic reporter possible:

module.exports = {
    report: function (errors) {
        console.log(errors.length ? 'Errors found' : 'No errors');
    }
};

// Old usage, deprecated as of 1.2.0:
module.exports = function (errors) {
    console.log(errors.length ? 'Errors found' : 'No errors');
};

The reporter will be passed an array of objects representing each error:

{
    column: 5,
    file: 'file.less',
    fullPath: 'path/to/file.less',
    line: 1,
    linter: 'spaceBeforeBrace',
    message: 'Opening curly brace should be preceded by one space.',
    severity: 'warning',
    source: '.foo{'
}

It's then up to the reporter to do something with the errors. No returns or anything is needed. lesshint will handle everything like exit codes etc.

Take a look at the default reporter for more information.

lesshint's People

Contributors

abhishekdev avatar aodev avatar c7pt7in avatar citguy avatar fiftyfactorauthentication avatar jcalvor avatar jwilsson avatar kaiyoma avatar kokarn avatar miloszsobczak avatar monoblaine avatar rmbl avatar shellscape avatar srogers202 avatar thybzi avatar wareczek avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.