Skip to content

Commit 485a461

Browse files
authored
Merge pull request #1135 from DanPurdy/feature/sasslintrc
Add sasslintrc support
2 parents 3b83d6f + d977a2f commit 485a461

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm install sass-lint --save-dev
2121

2222
## Configuring
2323

24-
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.
24+
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.
2525

2626
For example:
2727
```javascript
@@ -32,7 +32,7 @@ For example:
3232
}
3333
```
3434

35-
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).
35+
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).
3636

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

@@ -48,7 +48,6 @@ The following are options that you can use to config the Sass Linter.
4848
* [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
4949
* [output-file](https://github.com/sasstools/sass-lint/tree/master/docs/options/output-file.md) - Choose to write the linters output to a file
5050

51-
5251
#### Files
5352

5453
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.

lib/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ module.exports = function (options, configPath) {
5252
}
5353
else {
5454
configPath = confHelpers.findFile(false, '.sass-lint.yml');
55+
56+
if (!configPath) {
57+
configPath = confHelpers.findFile(false, '.sasslintrc');
58+
}
5559
}
5660
}
5761
else if (!pathIsAbsolute(configPath)) {

tests/cli.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,47 @@ describe('cli', function () {
239239
});
240240
});
241241

242+
// Test default config files
243+
244+
it('should return JSON from .sass-lint.yml', function (done) {
245+
var command = 'node ../../../bin/sass-lint ../../cli/cli.scss --verbose';
246+
247+
exec(command, { cwd: path.join(__dirname, 'yml', '.sass-lint.yml') }, function (err, stdout) {
248+
249+
if (err) {
250+
return done(err);
251+
}
252+
else {
253+
try {
254+
JSON.parse(stdout);
255+
return done();
256+
}
257+
catch (e) {
258+
return done(new Error('Not JSON'));
259+
}
260+
}
261+
});
262+
});
263+
264+
it('should return JSON from .sasslintrc', function (done) {
265+
var command = 'node ../../../bin/sass-lint ../../cli/cli.scss -c ".sasslintrc" --verbose';
266+
267+
exec(command, { cwd: path.join(__dirname, 'yml', '.sasslintrc') }, function (err, stdout) {
268+
if (err) {
269+
return done(err);
270+
}
271+
else {
272+
try {
273+
JSON.parse(stdout);
274+
return done();
275+
}
276+
catch (e) {
277+
return done(new Error('Not JSON'));
278+
}
279+
}
280+
});
281+
});
282+
242283
// Test custom config path
243284

244285
it('should return JSON from a custom config', function (done) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
options:
2+
formatter: json
3+
cache-config: false
4+
merge-default-rules: false
5+
files:
6+
include: '**/*.s+(a|c)ss'
7+
rules:
8+
no-color-keywords: 1

tests/yml/.sasslintrc/.sasslintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"options": {
3+
"formatter": "json",
4+
"cache-config": false,
5+
"merge-default-rules": false
6+
},
7+
"files": {
8+
"include": "**/*.s+(a|c)ss"
9+
},
10+
"rules": {
11+
"no-color-keywords": 1
12+
}
13+
}

0 commit comments

Comments
 (0)