npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-lesslint

v5.0.0

Published

Grunt task for validating LESS files with CSS Lint

Downloads

3,541

Readme

LESS Lint Grunt plugin

Build Status Dependency Status devDependency Status

Lint your LESS files using CSS Lint from Grunt.

This plugin compiles your LESS files, runs the generated CSS through CSS Lint, and outputs the offending LESS line for any CSS Lint errors found.

Installing

npm install grunt-lesslint

Building

  • Clone the repository
  • Run npm install
  • Run grunt to compile the CoffeeScript code
  • Run grunt test to run the specs

Configuring

Add the following to your Gruntfile.coffee:

grunt.initConfig
  lesslint:
    src: ['src/**/*.less']

grunt.loadNpmTasks('grunt-lesslint')

Then run grunt lesslint to lint all the .less files under src/.

By default the plugin uses the less and csslint config settings to configure the LESS parser and the CSS Lint validator.

CSS Lint

You can configure the CSS Lint validator, such as for disabling certain rules or loading a .csslintrc file, by adding a csslint option value:

lesslint:
  src: ['less/*.less']
  options:
    csslint:
      'known-properties': false
      csslintrc: '.csslintrc'

Allow lint warnings without failing the grunt task

The failOnWarning configuration option is now available to allow any failing lint rules set to "warn" to not fail the grunt task.

To maintain backwards-compatibility:

  • This option's value is defaulted to failOnWarning: true, which will continue to fail the grunt task on any failed rule. When using the default option, the following example output shows the task failure due to failed lint rules configured as "warnings":
      >> 58 lint issues in 167 files (0 errors, 58 warnings)
      Warning: Task "lesslint" failed. Use --force to continue.
  • Setting failOnError: false will act as a complete override for both settings: don't fail grunt task if EITHER lint rule warning(s) or error(s) are found. Example Config:
      lesslint:
        src: ['less/*.less']
        options:
          csslint:
            'known-properties': true
            csslintrc: '.csslintrc'
          failOnError: false

By setting failOnWarning: false, any failing rule configured to "warn" will no longer fail the grunt task:

lesslint:
  src: ['less/*.less']
  options:
    csslint:
      'known-properties': true
      csslintrc: '.csslintrc'
    failOnWarning: false

This example's task output shows the task completing without failure, even when there are failed lint rules configured as "warnings":

>> 58 lint issues in 167 files (0 errors, 58 warnings)
Done, without errors.

Notes:

The new task summary output is borrowed from equivalent output used by eslint:

✖ 31 problems (0 errors, 31 warnings)

This option is meant to afford large projects the recourse of a staged adoption strategy of specific CSS rules. New rules may be activated to trigger a warning notification across teams without breaking the build and deployment. Once existing infractions are addressed, those rules would then be configured from "warning" setting to "error", to finalize their enforcement (by blocking any subsequent build attempts).

LESS

You can configure the LESS parser, such as for adding include paths, by adding a less option value:

lesslint:
  src: ['less/*.less']
  options:
    less:
      paths: ['includes']

Linting imports

By default, this plugin does not include any lint errors from imported files in the output.

You can enable this by adding an imports configuration option:

lesslint:
  src: ['src/**/*.less']
  options:
    imports: ['imports/**/*.less']

Generating reports

This plugin provides the same output formatter options as the CSS Lint plugin and can be configured similarly:

lesslint:
  options:
    formatters: [
      id: 'csslint-xml'
      dest: 'report/lesslint.xml'
    ]

Using custom rules

It is possible to create and use your own custom rules. To create rules, please refer to the official CSSLint guidelines. The only addition is that each custom rule file must import CSSLint using CSSLint = require('grunt-lesslint').CSSLint.

You can enable your custom rules by adding a customRules configuration option:

lesslint:
  options:
    customRules: ['lint-rules/less/**/*.coffee']

Example output

> grunt lesslint
Running "lesslint" (lesslint) task
static/editor.less (1)
Values of 0 shouldn't have units specified. You don't need to specify units when a value is 0. (zero-units)
>> 14: line-height: 0px;

>> 1 linting error in 56 files.

Breaking changes

  • In v3.0.0 options is no longer passed to the LESS compiler. options.less is passed instead, as described by the documentation.
  • In v2.0.0 the LESS compiler was updated to v2.5.3