Skip to content

Commit

Permalink
Merge master into doc-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilsson committed Feb 3, 2017
2 parents 92942c8 + a91aabb commit f00f6f0
Show file tree
Hide file tree
Showing 99 changed files with 2,966 additions and 2,529 deletions.
78 changes: 42 additions & 36 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
{
"extends": "eslint:recommended",
"ecmaVersion": 2015,
"env": {
"es6": true,
"mocha": true,
"node": true
},
"rules": {
"array-bracket-spacing": 2,
"brace-style": 2,
"camelcase": 2,
"comma-dangle": 0,
"comma-spacing": 2,
"comma-style": 2,
"computed-property-spacing": 2,
"curly": 2,
"dot-location": [2, "property"],
"dot-notation": 2,
"eol-last": 2,
"eqeqeq": 2,
"guard-for-in": 2,
"indent": [2, 4, {
"array-bracket-spacing": "error",
"arrow-body-style": ["error", "always"],
"arrow-parens": "error",
"brace-style": "error",
"camelcase": "error",
"comma-dangle": "off",
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"curly": "error",
"dot-location": ["error", "property"],
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": "error",
"guard-for-in": "error",
"indent": ["error", 4, {
"SwitchCase": 1,
"VariableDeclarator": 0
}],
"key-spacing": 2,
"keyword-spacing": [2, {
"key-spacing": "error",
"keyword-spacing": ["error", {
"after": true,
"before": true
}],
"newline-after-var": 2,
"no-caller": 2,
"no-console": 2,
"no-else-return": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-lonely-if": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-trailing-spaces": 2,
"one-var": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": 2,
"space-before-blocks": 2,
"space-before-function-paren": 2,
"space-in-parens": 2,
"space-unary-ops": [2, {
"no-bitwise": "error",
"no-caller": "error",
"no-console": "error",
"no-const-assign": "error",
"no-else-return": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-lonely-if": "error",
"no-loop-func": "error",
"no-multi-spaces": "error",
"no-trailing-spaces": "error",
"no-var": "error",
"prefer-const": "error",
"quotes": ["error", "single", "avoid-escape"],
"semi": "error",
"space-before-blocks": "error",
"space-before-function-paren": "error",
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": ["error", {
"nonwords": false,
"words": true
}],
"strict": [2, "global"],
"vars-on-top": 2,
"yoda": 2
"strict": ["error", "global"],
"template-curly-spacing": ["error", "always"],
"yoda": "error"
}
}
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
Please include as much information as possible about your issue/request.
Not all headers below are relevant for all issues, if something's irrelevant, just remove it.
-->

**Which version of `lesshint` are you using?**

**How are you running `lesshint`? CLI, Node.js API, Grunt/Gulp plugin?**

**What's your `.lesshintrc` configuration?**

```js
// Code here
```

**If you're reporting a bug, please show us some code that's failing.**

```less
// Code here
```

**What did you expect to happen?**

**What's the actual result?**

**Would you be interested in submitting a PR for this issue?**
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
If you're submitting a PR for a new feature, please open an issue about it first so we can discuss it.
If you're submitting a PR for something else, for example a documentation fix, go right ahead!
-->

**Which issue, if any, does this resolve?**

**Is there anything in this PR that needs extra explaining or should something specific be focused on?**
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ sudo: false

language: node_js
node_js:
- "0.12"
- "iojs-v1"
- "iojs-v2"
- "iojs-v3"
- "4"
- "5"
- "6"
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Changelog
## 2.4.0 (2016-12-14)
* Added a `allowSingleLineRules` option to `singleLinePerProperty`. ([52879a7](https://github.com/lesshint/lesshint/commit/52879a7acfe4bba6d532a8a231b338616a5ce42c))
* Added a `position` field to results. ([6292387](https://github.com/lesshint/lesshint/commit/62923873b287ed1a347532eac233e8347a5213af))
* Test console spies are now restored before doing assertions. ([00f2f1d](https://github.com/lesshint/lesshint/commit/00f2f1d8b16740b83e6456676ed16193b942c66c))
* Added issue and PR templates. ([33f767d](https://github.com/lesshint/lesshint/commit/33f767de2ef3119024088cfecf8ec95f4c927e2e))
* Fixed a "there's"/"there are" typo in the README. ([31e5eb3](https://github.com/lesshint/lesshint/commit/31e5eb3043c1f0b2d61b9b3c7347fd008d8d04ee))

## 2.3.0 (2016-11-29)
* Added a `-x`/`--max-warnings` CLI flag. ([21e184d](https://github.com/lesshint/lesshint/commit/21e184d1006317bd60e7b5b98b2d52edfe0fc90c))
* Added a JSON reporter. ([a69bdee](https://github.com/lesshint/lesshint/commit/a69bdee9d48502bf1fa266c583d06d7129dfe8f8))
* Reporters can now also be objects and not just file paths. ([376940c](https://github.com/lesshint/lesshint/commit/376940c0923bcd6b72138518a8dc6694639d662f))
* Fixed a "is"/"are" typo in the README. ([282fdea](https://github.com/lesshint/lesshint/commit/282fdea03ad8cc0f4a88e4d96e6ecadb539beef5))

## 2.2.1 (2016-10-30)
* Fixed a `newlineAfterBlock` regression from `2.2.0`. ([117a2b5](https://github.com/lesshint/lesshint/commit/117a2b55bd44f508a334f1b7b540afc44702bd61))

Expand Down
170 changes: 170 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,179 @@ npm install lesshint
```

## Configuration
<<<<<<< HEAD
For information on how to configure `lesshint` and other available options, see the [user guide](/docs/user-guide/configuration.md).

Since `lesshint` is highly customizable we recommend you to also take a look at the [available rule options](/lib/linters/README.md) to tailor it to your needs.
=======
`lesshint` is customizable and we highly recommend you to look at the [available options](lib/linters/README.md) 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 its own JSON object, for example:

```js
{
"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
}
```

### Setting custom configuration path

```js
var path = require('path');
var fs = require('fs');
var LessHint = require('lesshint');
var lesshint = new LessHint();

var lesshintConfigPath = path.resolve('my-custom-path/.lesshintrc');
var lesshintConfig = JSON.parse(fs.readFileSync(lesshintConfigurePath, 'utf8'));

lesshint.configure(lesshintConfiguration);
```

### Inline configuration
It's also possible to configure rules using inline comments in your `.less` files. For example:

```less
// 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:

```less
.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`:
```json
{
"emptyRule": false,
"spaceAfterPropertyName": false
}
```

`file.less`
```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:

```js
"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](https://github.com/isaacs/minimatch) or a file to exclude. For example:

```js
"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. For example:

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

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

"otherSample": {
"enabled": true
}
```


## Custom linters
Since `2.0.0` it's possible to create your own linters when needed for something team/project specfic or something that's out of scope for `lesshint`.

To work properly, all linters are required to expose a few things.
* `name` - The name of the linter. While we don't enforce namespaces, we recommend it to prevent naming collisions.
* `nodeTypes` - An array of [PostCSS node types](http://api.postcss.org/postcss.html) that the linter wants to check.
* `lint` - The main lint method which will be called with the following arguments.
* `config` - The config object for this linter.
* `node` - The current node to lint.

If the linter doesn't find any errors or doesn't need/want to check the passed node for some reason it should return `undefined`. If it finds something it should return an array of result objects which looks like this:

```js
{
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{'
}
```

If a linter doesn't set a value for a property, `lesshint` will set it. Most of the time, you'll only want to set `column`, `line`, and `message` while leaving the rest to `lesshint`.

A simple linter example:
```js
module.exports = {
name: 'my-namespace/my-super-awesome-linter',
nodeTypes: ['decl'],
lint: function (config, node) {
var results = [];

if (true) { // Nothing to lint, return early
return;
}

// Check some things...

// Return the results
return results;
}
};
```

We highly recommend the following resources which are all included with `lesshint`.
* [postcss](http://api.postcss.org/postcss.html) - Main PostCSS docs.
* [postcss-less](https://github.com/webschik/postcss-less) - PostCSS Less plugin docs.
* [postcss-selector-parser](https://github.com/postcss/postcss-selector-parser) - PostCSS plugin for working with selectors.
* [postcss-values-parser](https://github.com/lesshint/postcss-values-parser) - PostCSS plugin for working with values.
>>>>>>> master
## CLI usage
Run `lesshint` from the command-line by passing one or more files/directories to recursively scan.
Expand Down
4 changes: 0 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ version: "{build}"

environment:
matrix:
- nodejs_version: "0.12"
- nodejs_version: "1"
- nodejs_version: "2"
- nodejs_version: "3"
- nodejs_version: "4"
- nodejs_version: "5"
- nodejs_version: "6"
Expand Down
17 changes: 13 additions & 4 deletions bin/lesshint
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env node

var cli = require('../lib/cli');
const program = require('commander');
const cli = require('../lib/cli');

/**
* Command line interface for lesshint.
Expand All @@ -9,8 +10,6 @@ var cli = require('../lib/cli');
* lesshint file1 dir1
*/

var program = require('commander');

program
.version(require('../package.json').version)
.usage('[options] <file ...>')
Expand All @@ -22,4 +21,14 @@ program
.option('-x, --max-warnings [int]', 'Number of warnings to trigger nonzero exit code, defaults to 0')
.parse(process.argv);

cli(program);
const output = function (result) {
if (result.message) {
console.error(result.message);
}

process.exitCode = result.status;
};

cli(program)
.then(output)
.catch(output);

0 comments on commit f00f6f0

Please sign in to comment.