Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix Master: cli output fix #213

Merged
merged 1 commit into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions bin/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ var configPath,
configOptions = {};

var detectPattern = function (pattern) {
var detects,
formatted;
var detects;

detects = lint.lintFiles(pattern, configOptions, configPath);
formatted = lint.format(detects, configOptions, configPath);


if (program.verbose) {
lint.outputResults(formatted, configOptions, configPath);
lint.outputResults(detects, configOptions, configPath);
}


if (program.exit) {
lint.failOnError(detects);
}
Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var slConfig = require('./lib/config'),
slRules = require('./lib/rules'),
glob = require('glob'),
path = require('path'),
jsonFormatter = require('eslint/lib/formatters/json'),
fs = require('fs-extra');


Expand All @@ -20,7 +21,8 @@ sassLint.getConfig = function (config, configPath) {

sassLint.resultCount = function (results) {
var flagCount = 0,
jsonResults = JSON.parse(results);
jsonResults = JSON.parse(jsonFormatter(results));


for (var i = 0; i < jsonResults.length; i++) {
flagCount += (jsonResults[i].warningCount + jsonResults[i].errorCount);
Expand Down Expand Up @@ -108,17 +110,20 @@ sassLint.outputResults = function (results, options, configPath) {
var config = this.getConfig(options, configPath);

if (this.resultCount(results)) {

var formatted = this.format(results, options, configPath);

if (config.options['output-file']) {
try {
fs.outputFileSync(path.resolve(process.cwd(), config.options['output-file']), results);
fs.outputFileSync(path.resolve(process.cwd(), config.options['output-file']), formatted);
console.log('Output successfully written to ' + path.resolve(process.cwd(), config.options['output-file']));
}
catch (e) {
console.log('Error: Output was unable to be written to ' + path.resolve(process.cwd(), config.options['output-file']));
}
}
else {
console.log(results);
console.log(formatted);
}
}
return results;
Expand Down
17 changes: 17 additions & 0 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,21 @@ describe('cli', function () {
}
});
});

it('should return a warning - stylish', function (done) {
var command = 'sass-lint -c tests/yml/.stylish-errors.yml tests/sass/cli.scss --verbose',
expectedOutputLength = 155;

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

if (err) {
return done(err);
}

else {
assert.equal(expectedOutputLength, stdout.length);
done();
}
});
});
});
3 changes: 1 addition & 2 deletions tests/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ describe('output', function () {
};

var outPath = path.resolve(process.cwd(), options.options['output-file']),
formatted = lint.format(results, options),
output = lint.outputResults(formatted, options);
output = lint.outputResults(results, options);

output = fs.readFileSync(outPath, 'utf-8');
fs.removeSync(outPath);
Expand Down
58 changes: 58 additions & 0 deletions tests/yml/.stylish-errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
options:
formatter: stylish
files:
include: '**/*.s+(a|c)ss'
rules:
# Extends
extends-before-mixins: 0
extends-before-declarations: 0
placeholder-in-extend: 0

# Mixins
mixins-before-declarations: 0

# Line Spacing
one-declaration-per-line: 0
empty-line-between-blocks: 0
single-line-per-selector: 0

# Disallows
no-debug: 0
no-duplicate-properties: 0
no-empty-rulesets: 0
no-extends: 0
no-ids: 0
no-important: 0
no-warn: 0
no-color-keywords: 1
no-invalid-hex: 0
no-css-comments: 0
no-color-literals: 0
no-vendor-prefix: 0

# Style Guide
border-zero: 0
clean-import-paths: 0
empty-args: 0
hex-length: 0
hex-notation: 0
indentation: 0
leading-zero: 0
nesting-depth: 0
property-sort-order: 0
quotes: 0
variable-for-property: 0
zero-unit: 0

# Inner Spacing
space-after-comma: 0
space-before-colon: 0
space-after-colon: 0
space-before-brace: 0
space-before-bang: 0
space-after-bang: 0
space-between-parens: 0

# Final Items
trailing-semicolon: 0
final-newline: 0