Skip to content

Commit

Permalink
Merge branch 'develop' into max-warnings
Browse files Browse the repository at this point in the history
  # Conflicts:
  #	tests/cli.js
  • Loading branch information
house9 committed Apr 5, 2016
2 parents f55d3a9 + db4db51 commit 07b6e69
Show file tree
Hide file tree
Showing 51 changed files with 1,279 additions and 1,371 deletions.
14 changes: 6 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rules:
no-caller: 2
no-console: 0
no-delete-var: 2
no-empty-label: 2
no-labels: 2
no-eval: 2
no-extend-native: 2
no-extra-bind: 2
Expand All @@ -64,7 +64,6 @@ rules:
no-invalid-this: 2
no-iterator: 2
no-label-var: 2
no-labels: 2
no-lone-blocks: 2
no-loop-func: 2
no-mixed-spaces-and-tabs:
Expand Down Expand Up @@ -110,15 +109,16 @@ rules:
- 2
- before: false
after: true
space-after-keywords:
- 2
- always
keyword-spacing:
- 2
-
before: true
after: true
space-before-blocks: 2
space-before-function-paren:
- 2
- always
space-infix-ops: 2
space-return-throw-case: 2
space-unary-ops:
- 2
- words: true
Expand All @@ -144,11 +144,9 @@ rules:

# Previously on by default in node environment
no-catch-shadow: 0
no-console: 0
no-mixed-requires: 2
no-new-require: 2
no-path-concat: 2
no-process-exit: 2
handle-callback-err:
- 2
- err
98 changes: 95 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,61 @@

A Node-only Sass linter for both `sass` and `scss` syntax!

---

## Install
You can get `sass-lint` from [NPM](https://www.npmjs.com/package/sass-lint)

```
npm install sass-lint --save-dev
```

---

## Configuring

Use the [Sample Config](docs/sass-lint.yml) as a guide to create your `.sass-lint.yml` in the root of where you are running Sass Lint from. The default configuration can be found [here](https://github.com/sasstools/sass-lint/blob/master/lib/config/sass-lint.yml).
Sass-lint can be configured from a `.sass-lint.yml` file in your project. If you don't have one in the root of your project or you would like all your projects to follow a standard config file then you can specify the path to one in your projects `package.json` file.

For example:
```javascript
{
"name": "my-project",
"version": "1.0.0",
"sasslintConfig": "PATH/TO/YOUR/CONFIG/FILE"
}
```

Use the [Sample Config](https://github.com/sasstools/sass-lint/tree/master/docs/sass-lint.yml) as a guide to create your own `.sass-lint.yml` config file. The default configuration can be found [here](https://github.com/sasstools/sass-lint/blob/master/lib/config/sass-lint.yml).

### [Configuration Documentation](https://github.com/sasstools/sass-lint/tree/master/docs/options)

*Migrating from SCSS-Lint*: If you already have a config for SCSS-Lint, you can instantly convert it to the equivalent Sass Lint config at [sasstools.github.io/make-sass-lint-config](http://sasstools.github.io/make-sass-lint-config/).

### Options

The following are options that you can use to config the Sass Linter.

* [cache-config](https://github.com/sasstools/sass-lint/tree/master/docs/options/cache-config.md) - Allows you to cache your config for a small speed boost when not changing the contents of your config file
* [config-file](https://github.com/sasstools/sass-lint/tree/master/docs/options/config-file.md) - Specify another config file to load
* [formatter](https://github.com/sasstools/sass-lint/tree/master/docs/options/formatter.md) - Choose the format for any warnings/errors to be displayed
* [merge-default-rules](https://github.com/sasstools/sass-lint/tree/master/docs/options/merge-default-rules.md) - Allows you to merge your rules with the default config file included with sass-lint
* [output-file](https://github.com/sasstools/sass-lint/tree/master/docs/options/output-file.md) - Choose to write the linters output to a file


#### Files

The `files` option can either be set to a [glob](https://github.com/isaacs/node-glob) or it can be set to an object, where the key `include` is set to the glob you want to include, and `ignore` set to either a glob string or an array of glob strings that you would like to ignore.

```yml
files:
include: 'sass/**/*.s+(a|c)ss'
ignore:
- 'sass/vendor/**/*.*'
```

#### Rules

For all [rules](docs/rules), setting their severity to `0` turns it off, setting to `1` sets it as a warning (something that should not be committed in), and setting to `2` set it to an error (something that should not be written). If a rule is set to just a severity, it will use the default configuration (where available).
For all [rules](https://github.com/sasstools/sass-lint/tree/master/docs/rules), setting their severity to `0` turns it off, setting to `1` sets it as a warning (something that should not be committed in), and setting to `2` sets it to an error (something that should not be written). If a rule is set to just a severity, it will use the default configuration (where available).

If you want to configure options, set the rule to an array, where the first item in the array is the severity, and the second item in the array is an object including the options you would like to set.

Expand All @@ -37,14 +69,74 @@ indentation:
size: 2
```

### [Rules Documentation](https://github.com/sasstools/sass-lint/tree/master/docs/rules)

---

## CLI

Sass Lint [`v1.1.0`](https://github.com/sasstools/sass-lint/releases/tag/v1.1.0) introduced the ability to run Sass Lint through a command line interface. See the [CLI Docs](docs/cli) for full documentation on how to use the CLI.
Sass Lint [`v1.1.0`](https://github.com/sasstools/sass-lint/releases/tag/v1.1.0) introduced the ability to run Sass Lint through a command line interface. See the [CLI Docs](https://github.com/sasstools/sass-lint/tree/master/docs/cli) for full documentation on how to use the CLI.

There are small differences which are useful to understand over other CLI tools you may have encountered with other linters.

By default any rule set to severity: `2` in your config will throw an error which will stop the CLI on the first error it encounters. If you wish to see a list of errors and not have the CLI exit then you'll need to use the `-q` or `--no-exit` flag.

Warnings or any rule set to severity: `1` in your config by default will not be reported by the CLI tool unless you use verbose flag `-v` or `--verbose`.

With this in mind if you would like to have the CLI show both warnings and errors then at the very least your starting point to use the cli should be the following command.
`sass-lint -v -q`

### CLI Examples

#### Specify a config

Below is an example of the command being used to load a config `-c app/config/.sass-lint.yml` file show errors and warnings on the command line and target a glob pattern `**/*.scss` being used.

```
sass-lint -c app/config/.sass-lint.yml '**/*.scss' -v -q
```

or with long form flags

```
sass-lint --config app/config/.sass-lint.yml '**/*.scss' --verbose --no-exit
```

#### Ignore files/patterns
To add a list of files to ignore `tests/**/*.scss, dist/other.scss` into the mix you could do the following:
```
sass-lint -c app/config/.sass-lint.yml '**/*.scss' -v -q -i 'tests/**/*.scss'
```
or with long form flags
```
sass-lint --config app/config/.sass-lint.yml '**/*.scss' --verbose --no-exit --ignore 'tests/**/*.scss, dist/other.scss'
```


> Notice that glob patterns need to be wrapped in quotation or single quote marks in order to be passed to sass-lint correctly and if you want to ignore multiple paths you also need to wrap it in quotation marks and seperate each pattern/fil with a comma and a space `, `.
This will be revisited and updated in `sass-lint` v2.0.0

For further information you can visit our CLI documentation linked below.

### [CLI Documentation](https://github.com/sasstools/sass-lint/tree/master/docs/cli)

---

## Contributions

We welcome all contributions to this project but please do read our [contribution guidelines](https://github.com/sasstools/sass-lint/blob/master/CONTRIBUTING.md) first, especially before opening a pull request. It would also be good to read our [code of conduct](https://github.com/sasstools/sass-lint/blob/master/CODE_OF_CONDUCT.md).

Please don't feel hurt or embarrassed if you find your issues/PR's that don't follow these guidelines closed as it can be a very time consuming process managing the quantity of issues and PR's we receive. If you have any questions just ask!

---

## Creating Rules

Our AST is [Gonzales-PE](https://github.com/tonyganch/gonzales-pe/tree/dev). Each rule will be passed the full AST which they can traverse as they please. There are many different [node types](https://github.com/tonyganch/gonzales-pe/blob/dev/docs/node-types.md) that may be traversed, and an extensive [API for working with nodes](https://github.com/tonyganch/gonzales-pe/tree/dev#api). The file of the rule must have the same name as the name of the rule. All of the available rules are in our [rules directory](https://github.com/sasstools/sass-lint/tree/develop/lib/rules). Default options will be merged in with user config.

---

## Task Runner Integration

* [Gulp](https://www.npmjs.com/package/gulp-sass-lint)
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/variable-for-property.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Variable For Property

Rule `variable-for-property` will enforce the use of variables for the values of specified properties. There are no properties by default.
Rule `variable-for-property` will enforce the use of variables for the values of specified properties.
There are no properties by default, except for reserved words listed below which are always whitelisted:
* inherit
* initial
* transparent
* none
* currentColor

## Options

Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ sassLint.lintFiles = function (files, options, configPath) {
}
else {
files = this.getConfig(options, configPath).files;

if (typeof files === 'string') {
files = glob.sync(files);
}
Expand Down
24 changes: 11 additions & 13 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,27 @@ var loadDefaults = function loadDefaults () {

var findFile = function findFile (configPath, filename) {
var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
dirname,
parentDirname;
dirname = null,
parentDirname = null;

configPath = configPath || path.join(process.cwd(), filename);

if (fs.existsSync(configPath)) {
if (configPath && fs.existsSync(configPath)) {
dirname = path.dirname(configPath);
parentDirname = path.dirname(dirname);
return fs.realpathSync(configPath);
}

dirname = path.dirname(configPath);
parentDirname = path.dirname(dirname);

if (dirname === HOME || dirname === parentDirname) {
if (dirname === null || dirname === HOME || dirname === parentDirname) {
return null;
}

configPath = path.join(parentDirname, filename);

return findFile(configPath, filename);
};

module.exports = function (options, configPath) {
var meta,
var meta = null,
metaPath,
configMerge = false,
configMergeExists = false,
Expand Down Expand Up @@ -70,10 +68,11 @@ module.exports = function (options, configPath) {

if (!configPath) {
metaPath = findFile(false, 'package.json');
meta = require(metaPath);

if (meta.sasslintConfig) {
if (metaPath) {
meta = require(metaPath);
}

if (meta && meta.sasslintConfig) {
configPath = path.resolve(path.dirname(metaPath), meta.sasslintConfig);
}
else {
Expand All @@ -90,7 +89,6 @@ module.exports = function (options, configPath) {
config.rules = config.rules ? config.rules : {};
}
}

// check to see if user config contains an options property and whether property has a property called merge-default-rules
configMergeExists = (config.options && typeof config.options['merge-default-rules'] !== 'undefined');

Expand Down
2 changes: 1 addition & 1 deletion lib/groot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//////////////////////////////
'use strict';

var gonzales = require('gonzales-pe');
var gonzales = require('gonzales-pe-sl');

module.exports = function (text, syntax, filename) {
var tree;
Expand Down
Loading

0 comments on commit 07b6e69

Please sign in to comment.