Skip to content

Commit

Permalink
🎨 Skip all front matter
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy committed Oct 21, 2016
1 parent b7bcb3a commit 8361446
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"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",
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 8361446

Please sign in to comment.