Skip to content

Commit

Permalink
Merge pull request #588 from DanPurdy/feature/fix-assertion-config-error
Browse files Browse the repository at this point in the history
Fix assertion config error - Gonzales-3.2
  • Loading branch information
bgriffith committed Mar 29, 2016
2 parents 981c564 + d920464 commit 924dd16
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ sassLint.lintFiles = function (files, options, configPath) {
}
else {
files = this.getConfig(options, configPath).files;

if (typeof files === 'string') {
files = glob.sync(files);
}
Expand Down
24 changes: 11 additions & 13 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,27 @@ var loadDefaults = function loadDefaults () {

var findFile = function findFile (configPath, filename) {
var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
dirname,
parentDirname;
dirname = null,
parentDirname = null;

configPath = configPath || path.join(process.cwd(), filename);

if (fs.existsSync(configPath)) {
if (configPath && fs.existsSync(configPath)) {
dirname = path.dirname(configPath);
parentDirname = path.dirname(dirname);
return fs.realpathSync(configPath);
}

dirname = path.dirname(configPath);
parentDirname = path.dirname(dirname);

if (dirname === HOME || dirname === parentDirname) {
if (dirname === null || dirname === HOME || dirname === parentDirname) {
return null;
}

configPath = path.join(parentDirname, filename);

return findFile(configPath, filename);
};

module.exports = function (options, configPath) {
var meta,
var meta = null,
metaPath,
configMerge = false,
configMergeExists = false,
Expand Down Expand Up @@ -70,10 +68,11 @@ module.exports = function (options, configPath) {

if (!configPath) {
metaPath = findFile(false, 'package.json');
meta = require(metaPath);

if (meta.sasslintConfig) {
if (metaPath) {
meta = require(metaPath);
}

if (meta && meta.sasslintConfig) {
configPath = path.resolve(path.dirname(metaPath), meta.sasslintConfig);
}
else {
Expand All @@ -90,7 +89,6 @@ module.exports = function (options, configPath) {
config.rules = config.rules ? config.rules : {};
}
}

// check to see if user config contains an options property and whether property has a property called merge-default-rules
configMergeExists = (config.options && typeof config.options['merge-default-rules'] !== 'undefined');

Expand Down
50 changes: 31 additions & 19 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ var assert = require('assert'),
should = require('should'),
fs = require('fs-extra'),
path = require('path'),
childProcess = require('child_process');
exec = require('child_process').exec;


describe('cli', function () {
it('should return help instructions', function (done) {
var command = 'sass-lint -h';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {
if (err) {
return done(err);
}
Expand All @@ -23,7 +23,7 @@ describe('cli', function () {
it('should return a version', function (done) {
var command = 'sass-lint -V';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {
if (err) {
return done(err);
}
Expand All @@ -37,7 +37,7 @@ describe('cli', function () {
it('CLI format option should output JSON', function (done) {
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format json';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

if (err) {
return done(err);
Expand All @@ -58,7 +58,7 @@ describe('cli', function () {
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format json --output tests/cli-output.json',
outputFile = path.resolve(process.cwd(), 'tests/cli-output.json');

childProcess.exec(command, function (err) {
exec(command, function (err) {

if (err) {
return done(err);
Expand All @@ -81,7 +81,7 @@ describe('cli', function () {
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format json --output tests/cli-output.json',
outputFile = path.resolve(process.cwd(), 'tests/cli-output.json');

childProcess.exec(command, function (err) {
exec(command, function (err) {

if (err) {
return done(err);
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('cli', function () {
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format JSON --output tests/cli-output.json',
outputFile = path.resolve(process.cwd(), 'tests/cli-output.json');

childProcess.exec(command, function (err) {
exec(command, function (err) {

if (err) {
return done(err);
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('cli', function () {
it('should return JSON from a custom config', function (done) {
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --verbose';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

if (err) {
return done(err);
Expand All @@ -170,7 +170,7 @@ describe('cli', function () {
it('output should return no errors/warnings', function (done) {
var command = 'sass-lint -c tests/yml/.json-lint.yml tests/sass/cli.scss --verbose';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

var result = 0;

Expand All @@ -192,7 +192,7 @@ describe('cli', function () {
it('should return a warning', function (done) {
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --verbose';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

var result = '';

Expand Down Expand Up @@ -222,7 +222,7 @@ describe('cli', function () {
var command = 'sass-lint -c tests/yml/.stylish-errors.yml tests/sass/cli.scss --verbose',
expectedOutputLength = 155;

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

if (err) {
return done(err);
Expand All @@ -244,7 +244,7 @@ describe('cli', function () {

var command = 'sass-lint -i \'**/*.s+(a|c)ss\'';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

if (err) {
return done(err);
Expand All @@ -267,7 +267,7 @@ describe('cli', function () {

var command = 'sass-lint -i \'**/*.scss, **/*.sass \'';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

if (err) {
return done(err);
Expand All @@ -290,7 +290,7 @@ describe('cli', function () {

var command = 'sass-lint --syntax scss tests/sass/cli.txt --verbose';

childProcess.exec(command, function (err, stdout) {
exec(command, function (err, stdout) {

var result = 0;

Expand All @@ -311,7 +311,7 @@ describe('cli', function () {
it('should exit with exit code 1 when quiet', function (done) {
var command = 'sass-lint -c tests/yml/.error-output.yml tests/sass/cli-error.scss --verbose --no-exit';

childProcess.exec(command, function (err) {
exec(command, function (err) {
if (err.code === 1) {
return done();
}
Expand All @@ -320,13 +320,25 @@ describe('cli', function () {
});
});

it('should not exit with an error if no config is specified', function (done) {
var command = 'sass-lint tests/sass/cli-clean.scss --verbose --no-exit';

exec(command, function (err) {
if (!err) {
return done();
}

return done(new Error('Exited with error code 1'));
});
});

/**
* We disabled eslints handle callback err rule here as we are deliberately throwing errors that we don't care about
*/
it('parse errors should report as a lint error', function (done) {
var command = 'sass-lint --config tests/yml/.stylish-output.yml tests/sass/parse.scss --verbose --no-exit --format json';

childProcess.exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
var result = JSON.parse(stdout)[0];

assert.equal(1, result.errorCount);
Expand All @@ -337,7 +349,7 @@ describe('cli', function () {
it('parse errors should report as severity 2', function (done) {
var command = 'sass-lint --config tests/yml/.stylish-output.yml tests/sass/parse.scss --verbose --no-exit --format json';

childProcess.exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
var result = JSON.parse(stdout)[0],
messages = result.messages[0],
severity = 2;
Expand All @@ -350,7 +362,7 @@ describe('cli', function () {
it('parse errors should report the correct message', function (done) {
var command = 'sass-lint --config tests/yml/.stylish-output.yml tests/sass/parse.scss --verbose --no-exit --format json';

childProcess.exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
var result = JSON.parse(stdout)[0],
message = result.messages[0].message,
expected = 'Please check validity of the block starting from line #5';
Expand All @@ -363,7 +375,7 @@ describe('cli', function () {
it('parse errors rule Id should be \'Fatal\'', function (done) {
var command = 'sass-lint --config tests/yml/.stylish-output.yml tests/sass/parse.scss --verbose --no-exit --format json';

childProcess.exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
exec(command, function (err, stdout) { // eslint-disable-line handle-callback-err
var result = JSON.parse(stdout)[0],
messages = result.messages[0],
ruleId = 'Fatal';
Expand Down
5 changes: 5 additions & 0 deletions tests/sass/cli-clean.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$red: #f00;

.cli {
color: $red;
}

0 comments on commit 924dd16

Please sign in to comment.