Skip to content

Commit

Permalink
Merge branch 'develop' into feature/patch-space-before-colon
Browse files Browse the repository at this point in the history
  • Loading branch information
bgriffith authored Oct 24, 2016
2 parents c8f2e6c + c53043e commit 8f91e3c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ For further information you can visit our CLI documentation linked below.
---
## Front matter
Certain static site generators such as [Jekyll](http://jekyllrb.com/docs/frontmatter/) include the YAML front matter block at the top of their scss file. Sass-lint by default checks a file for this block and attempts to parse your Sass without this front matter. You can see an example of a front matter block below.
```scss
---
# Only the main Sass file needs front matter (the dashes are enough)
---
.test {
color: red;
}
```

---

## 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).
Expand Down
8 changes: 7 additions & 1 deletion lib/groot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
//////////////////////////////
'use strict';

var gonzales = require('gonzales-pe');
var gonzales = require('gonzales-pe'),
fm = require('front-matter');

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

// Run `.toString()` to allow Buffers to be passed in
text = text.toString();

// if we're skipping front matter do it here, fall back to just our text in case it fails
if (fm.test(text)) {
text = fm(text).body || text;
}

try {
tree = gonzales.parse(text, {
'syntax': syntax
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
"dependencies": {
"commander": "^2.8.1",
"eslint": "^2.7.0",
"front-matter": "2.1.0",
"fs-extra": "^0.30.0",
"glob": "^7.0.0",
"globule": "^1.0.0",
"gonzales-pe": "3.4.4",
"gonzales-pe": "3.4.7",
"js-yaml": "^3.5.4",
"lodash.capitalize": "^4.1.0",
"lodash.kebabcase": "^4.0.0",
Expand Down
12 changes: 12 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ describe('sass lint', function () {
});
});

// ==============================================================================
// Parse files with YAML front matter
// ==============================================================================

it('should parse a file with front matter correctly and without parse error', function (done) {
lintFile('front-matter/front-matter.scss', function (data) {
assert.equal(0, data.errorCount);
assert.equal(2, data.warningCount);
done();
});
});

// ==============================================================================
// Parse Errors should return as lint errors
// ==============================================================================
Expand Down
7 changes: 7 additions & 0 deletions tests/sass/front-matter/front-matter.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# Only the main Sass file needs front matter (the dashes are enough)
---

.test {
color: red;
}

0 comments on commit 8f91e3c

Please sign in to comment.