Skip to content

Commit

Permalink
Lint entire app tree to include .scss/.sass files in pod-style dirs
Browse files Browse the repository at this point in the history
Changes the tree passed to broccoli-sass-lint from `this.app.trees.styles` to `this.app.trees.app`. The latter is a superset of the former, and results in including .scss/.sass files that are colocated with their components in app/components subdirectories.
  • Loading branch information
lukemelia committed Apr 3, 2017
1 parent 6a01686 commit a433f93
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
var formattedResults, mergedTrees, results;

if (type === 'app') {
mergedTrees = mergeTrees([this.app.trees.styles]);
mergedTrees = mergeTrees([this.app.trees.app]);

return new SassLinter(mergedTrees, this.sassLintOptions);
} else {
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/components/example-component/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Component.extend({
});
9 changes: 9 additions & 0 deletions tests/dummy/app/components/example-component/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SHould throw linting errors
.funkytown {
color: blue; // To test if the styles are still compiled
@extend %huh;
}

#should-also-allowed-by-sass-lint-test-config-yml {
color: green;
}
1 change: 1 addition & 0 deletions tests/dummy/app/components/example-component/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am an <span class="funkytown">example</span> component
61 changes: 40 additions & 21 deletions tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function buildAndLint(sourcePath) {
}
},
trees: {
styles: sourcePath, // Directory to lint
app: sourcePath, // Directory to lint
},
});

Expand All @@ -45,34 +45,53 @@ describe('ember-cli-sass-lint', function() {
}
});

it('The linter should run', function() {
return buildAndLint('tests/dummy').then(function() {
var firstError = errors[0];
var messageIdStrings;
it('The linter should run and lint a file in the app/styles dir', function() {
return buildAndLint('tests/dummy').then(function() {
var appCssError = errors.filter((error) => { return error.filePath === 'app/styles/app.scss' })[0];
var messageIdStrings;

assert.ok(!!firstError,
'The linting should occur');
assert.ok(!!appCssError,
'The app.scss file should be linted');

assert.equal(firstError.filePath, 'app/styles/app.scss',
'The app.scss file should be linted');
assert.ok(appCssError.messages.length > 1,
'Errors for app.scss should be logged');

assert.ok(firstError.messages.length > 1,
'Errors for app.scss should be logged');
/* Create a string of error ID's we can easily test */

/* Create a string of error ID's we can easily test */
messageIdStrings = appCssError.messages.reduce(function(previousValue, currentValue) {
return previousValue + ' ' + currentValue.ruleId;
}, '');

messageIdStrings = firstError.messages.reduce(function(previousValue, currentValue) {
return previousValue + ' ' + currentValue.ruleId;
}, '');
assert.include(messageIdStrings, 'no-color-keywords',
'Should respect default rules not specified in project\'s sass-lint.yml');

assert.include(messageIdStrings, 'no-color-keywords',
'Should respect default rules not specified in project\'s sass-lint.yml');
assert.notInclude(messageIdStrings, 'no-ids',
'Should respect non-default rules specified in project\'s sass-lint.yml');
});
});

it('The linter should run and lint a file in the app/components dir', function() {
return buildAndLint('tests/dummy').then(function() {
var componentCssError = errors.filter((error) => { return error.filePath === 'app/components/example-component/style.scss' })[0];
var messageIdStrings;

assert.ok(!!componentCssError,
'The app/components/example-component/style.scss file should be linted');

assert.ok(componentCssError.messages.length > 1,
'Errors for app/components/example-component/style.scss should be logged');

/* Create a string of error ID's we can easily test */

assert.notInclude(messageIdStrings, 'no-ids',
'Should respect non-default rules specified in project\'s sass-lint.yml');
messageIdStrings = componentCssError.messages.reduce(function(previousValue, currentValue) {
return previousValue + ' ' + currentValue.ruleId;
}, '');

assert.include(messageIdStrings, 'no-color-keywords',
'Should respect default rules not specified in project\'s sass-lint.yml');

assert.notInclude(messageIdStrings, 'no-ids',
'Should respect non-default rules specified in project\'s sass-lint.yml');
});
});
});
});

0 comments on commit a433f93

Please sign in to comment.