Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sasslintrc support #1135

Merged
merged 5 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install sass-lint --save-dev

## Configuring

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 project's `package.json` file.
Sass-lint can be configured from a `.sass-lint.yml` or `.sasslintrc` file in your project. The `.sasslintrc` file can be in either JSON format or YAML. Both formats are interchangeable easily using tools such as [json2yaml](https://www.json2yaml.com/). If you don't either file 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 project's `package.json` file with the `sasslintConfig` option.

For example:
```javascript
Expand All @@ -32,7 +32,7 @@ For example:
}
```

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).
Use the [Sample Config (YAML)](https://github.com/sasstools/sass-lint/tree/master/docs/sass-lint.yml) or [Sample Config (JSON)](https://github.com/sasstools/sass-lint/tree/master/docs/sasslintrc) as a guide to create your own 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)

Expand All @@ -48,7 +48,6 @@ The following are options that you can use to config the Sass Linter.
* [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 contains two properties, `include` and `ignore`. Both can be set to either a [glob](https://github.com/isaacs/node-glob) or an array of glob strings/file paths depending on your projects' needs and setup.
Expand Down
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ module.exports = function (options, configPath) {
}
else {
configPath = confHelpers.findFile(false, '.sass-lint.yml');

if (!configPath) {
configPath = confHelpers.findFile(false, '.sasslintrc');
}
}
}
else if (!pathIsAbsolute(configPath)) {
Expand Down
41 changes: 41 additions & 0 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,47 @@ describe('cli', function () {
});
});

// Test default config files

it('should return JSON from .sass-lint.yml', function (done) {
var command = 'node ../../../bin/sass-lint ../../cli/cli.scss --verbose';

exec(command, { cwd: path.join(__dirname, 'yml', '.sass-lint.yml') }, function (err, stdout) {

if (err) {
return done(err);
}
else {
try {
JSON.parse(stdout);
return done();
}
catch (e) {
return done(new Error('Not JSON'));
}
}
});
});

it('should return JSON from .sasslintrc', function (done) {
var command = 'node ../../../bin/sass-lint ../../cli/cli.scss -c ".sasslintrc" --verbose';

exec(command, { cwd: path.join(__dirname, 'yml', '.sasslintrc') }, function (err, stdout) {
if (err) {
return done(err);
}
else {
try {
JSON.parse(stdout);
return done();
}
catch (e) {
return done(new Error('Not JSON'));
}
}
});
});

// Test custom config path

it('should return JSON from a custom config', function (done) {
Expand Down
8 changes: 8 additions & 0 deletions tests/yml/.sass-lint.yml/.sass-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
options:
formatter: json
cache-config: false
merge-default-rules: false
files:
include: '**/*.s+(a|c)ss'
rules:
no-color-keywords: 1
13 changes: 13 additions & 0 deletions tests/yml/.sasslintrc/.sasslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"options": {
"formatter": "json",
"cache-config": false,
"merge-default-rules": false
},
"files": {
"include": "**/*.s+(a|c)ss"
},
"rules": {
"no-color-keywords": 1
}
}