Giter Club home page Giter Club logo

lesshint's Introduction

lesshint

npm Build Status Build status Coverage Status

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

Installation

Node.js 6 (or later) is required.

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

npm install lesshint

Configuration

For information on how to configure lesshint and other available options, see the user guide.

Since lesshint is highly customizable we recommend you to also take a look at the available rule options to tailor it to your needs.

CLI usage

Run lesshint from the command-line by passing one or more files/directories to recursively scan. Quote the glob patterns for optimal cross-platform results.

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 globby glob pattern or a file to exclude from being linted.
-l/--linters Paths to custom linters to add to the built-in list. See "Linters" below for more information.
-r/--reporter The reporter to use. See "Reporters" below for more information.
-V/--version Show the version.
-x/--max-warnings Number of warnings to allow before exiting with a non-zero code. Omit it to always exit with zero code.

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 or only linting errors with a severity of warning were found.
1 One or more linting errors with a severity of error were found. Or when --max-warnings flag is set and the number of linting errors with a severity of warning found is greater than the given value.
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.

Complementary tools

Linters

In addition to the linters included with lesshint, it's also possible to include custom ones. For example to check something team or project specific.

For more information on using custom linters, see the user guide.

Reporters

Reporters are small modules that can be used to perform actions with the lint results, for example printing something to the terminal or generate custom reports.

For more information on using reporters, see the user guide.

Developer resources

lesshint's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lesshint's Issues

Available options/default value for zeroUnit

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. keep_unit
  2. no_unit (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for spaceBetweenParens

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space (default)
  2. one_space

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for stringQuotes

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. double
  2. single (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for singleLinePerSelector

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for trailingSemicolon

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need an option to allow missing semicolons on the last property?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for singleLinePerProperty

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for attributeQuotes

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. double
  2. single (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for finalNewline

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for urlFormat

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. absolute
  2. relative (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for spaceBeforeBrace

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space
  2. one_space (default)
  3. new_line

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Lint stops after each file

When running into an linting error the linter will stop after every file that has an error.

Shouldn't it lint all files or is this by design?

urlFormat and urlQuotes linters broken?

Tried with this code

div {
    background-image: url( 'http://placekitten.com/g/1200/600' );
}

The only error I get is this

test.less: line 2, col 23, urlQuotes: URLs should enclosed in quotes.

Shouldn't I get an error that the format is incorrect and no error on the quotes?

Try to add reasoning to defaults

It would be good for educational purposes to see what the reasoning behind each default is.
Also it will probably spark discussion further down the line which is always a good thing.

Available options/default value for idSelector

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for hexNotation

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. lowercase (default)
  2. uppercase

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for spaceAfterComma

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space
  2. one_space (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for importantRule

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for duplicateProperty

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Forking and contributing

We've decided to move forward with forking lesshint and contributing to it, but wanted to get on the same page with how you guys are using branches.

It appears from the request to PR to the 0.8.1 branch, that you're developing off of separate branches before pushing to master. So that's our first question - Why? Typically branches like that are used for features and then PR'd to master. Or a branch is marked as 'development' and used by primary maintainers/contributors to do out-of-track-next-major-version work. But PRs from forks are almost always made to master.

It also looks like you're creating a branch to work on a patch release, which is not something we've seen done before. We've seen minor and major branches before, but never for a patch release (as following semver, patch releases are for bugfixes only and should follow the primary track).

We follow semver pretty closely in our org, and for ease of use and org-wide contribution, it'd be great to get on the same page. I'm certainly not suggesting that you adopt any of our practices, merely requesting some discussion around adopting some more widely accepted standards in this area.

False positive with "singleLinePerProperty"

singleLineProperty is returning a false positive for inline comments.

Valid CSS

.foo {
  background-color: #000;
  color: #000; // black on black
}

Shouldn't error

test.less: line 3, col 5, singleLinePerProperty: Each property should be on it's own line.

Please add support for inline comments

Available options/default value for comment

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
Regexp for allowed comments.

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for spaceAfterPropertyColon

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space
  2. one_space (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for emptyRule

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

More tests needed

The linters are pretty good but the core methods need some more.

Especially lib/lesshint.js and lib/config-loader.js.

Add ability to disable linting for a single line

Other linters/hinters have the ability to ignore linting on a single line via a trailing comment. It would be very useful to have this ability. An example...

My team discourages the use of !important but there are edge cases where it needs to be used. As such, it would be useful to enable importantRule globally, but apply something like // lesshint ignore:line that would ignore linting for a specific line, so that I can allow !important in edge cases (bonus points if we can just ignore the single rule via // lesshint ignore:importantRule).

Warnings vs Errors

Given the discussion around #43 errors being swallowed, I'd like to raise the question of warnings vs errors. jshint plops every result into an 'errors' object, but has a code on every result that differentiates error from warning. In jshint's case, it has W for warning, I for info, and E for error. I'm not suggesting lesshint follow suit, as I've never been incredibly keen on using single letters for error codes, but it would be a great addition to the project to differentiate.

Consider this lesshint gulp reporter: https://github.com/sagikazarmark/gulp-lesshint-stylish, which is transforming the results and marking everything back from lesshint as a warning.

Ideally everything that lesshint is returning as a result at this moment, sans parse error support, should be a warning. Once parse error support is added, those results should be errors. I'm not sure if info has any use here.

Available options/default value for spaceAfterPropertyValue

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space (default)
  2. one_space

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for hexLength

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. long (default)
  2. short

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for qualifyingElement

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. allowWithId (default false)
  2. allowWithClass (default false)
  3. allowWithAttribute (default false)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for spaceBeforeComma

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space (default)
  2. one_space

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for borderZero

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. none
  2. zero (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for propertyUnits

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
global: [] Array of allowed units (currently all CSS units)
properties: {} Object with unit overrides for specific properties

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for leadingZero

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. exclude_zero
  2. include_zero (default)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

When lesshint encounters erroneous data, it reports no errors

I ran lesshint against this silly tidbit:

.myclass {
  border: none;
  cursor pointer
}

And it produced no output, no errors using default settings. It should have at the least reported on the border: none; line, and should have reported an error in the syntax at cursor pointer. When I change that line to cursor: pointer all is well and I get the error about using 0.

It would appear parsing errors, or syntax errors, are being swallowed.

Available options/default value for trailingZero

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. exclude_zero (default)
  2. include_zero

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Lesshint outputs wrong line number

Following test was done in v0.7.0

h1 {
  width: 100px;
  height: 100px;
  color: #00f;
  background: #000;
  top:10px;
  left: 1000px;
}

This example Less/CSS file only has the rule finalNewline disabled and it reports the following errors:
test.less: line 7, col 10, hexLength: #00f should be written in the long-form format.
test.less: line 9, col 15, hexLength: #000 should be written in the long-form format.
test.less: line 11, col 7, spaceAfterPropertyColon: Colon after property name should be followed by one space.

As you can see the errors are not correctly guiding me to the correct line number.

Thanks

Available options/default value for spaceAfterPropertyName

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:

  1. no_space (default)
  2. one_space

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for importPath

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
exclude: array of files to exclude
filenameExtension: true/false (default false)
leadingUnderscore: true/false (default false)

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Add validateIndentation

My team uses 4 spaces per indentation. It would be nice to have a linter to check that indentation is correct. Something along the lines of the following (with suggested defaults):

validateIndentation

syntax

"validateIndentation": {
  "enabled": true,
  "style": "spaces",
  "quantity": 4
}

options

style (string)

  • spaces (default)
  • tabs

quantity (integer) number of spaces/tabs per indentation

  • 2 (default)
  • user defined value

Available options/default value for urlQuotes

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

Available options/default value for trailingWhitespace

Do we need any more options? Are we satisfied with the current default value? Any other thoughts?

Current options:
None, do we need any options or is it enough with enabled: true/false?

Please cast a vote for one of the options or post your other thoughts or suggestions for options.

False Positive with "spaceBeforeComma"

spaceBeforeComma returns a false positive with the following LESS file

@var: (4 / 2);

test.less: line 1, col 9, spaceBeforeComma: Commas should not be preceded by any space.

Yet, returns no errors with the following LESS file

@var: (4/ 2);

Please update to allow space before LESS operators.

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.