Skip to content

Commit

Permalink
added maxBuffer and did some tidying up
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmednuaman committed Aug 14, 2014
1 parent 1482055 commit 1487560
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 84 deletions.
91 changes: 33 additions & 58 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch",
"case",
"default"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireMultipleVarDecl": true,
"requireBlocksOnNewline": true,
"disallowPaddingNewlinesInBlocks": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?",
"=",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
Expand All @@ -50,13 +38,15 @@
"<",
"<="
],
"disallowLeftStickedOperators": [
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"?",
"=",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
Expand All @@ -66,14 +56,13 @@
"<",
"<="
],
"requireRightStickedOperators": ["!"],
"disallowRightStickedOperators": [
"requireSpaceAfterBinaryOperators": [
"?",
"=",
"+",
"-",
"/",
"*",
":",
"=",
"==",
"===",
"!=",
Expand All @@ -83,36 +72,22 @@
"<",
"<="
],
"requireLeftStickedOperators": [","],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": ["with"],
"disallowMultipleLineBreaks": true,
"validateQuoteMarks": "'",
"validateIndentation": 2,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": ["else"],
"maximumLineLength": 120,
"requireCapitalizedConstructors": true,
"safeContextKeyword": ["that"],
"disallowYodaConditions": true,
"excludeFiles": ["node_modules/**"]
}
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
},
"requireSpaceAfterLineComment": true
}
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function (grunt) {
},
files: [{
src: [
'test/fixtures/fail.scss',
'test/fixtures/fail.scss'
]
}]
}
Expand All @@ -57,7 +57,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-internal');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-jscs-checker');
grunt.loadNpmTasks('grunt-jscs');

grunt.registerTask('test', ['jscs', 'jshint', 'nodeunit']);

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ Emits a Grunt event on scss-lint error called `scss-lint-error`.

Set `force` to `true` to report scss-lint errors but not fail the task.

#### maxBuffer

- Type: `Number` or `Boolean`
- Default: `300 * 1024`

Set `maxBuffer` for the `child_process.exec` process, [if you're linting a lot of files and you're recieving no output](https://github.com/ahmednuaman/grunt-scss-lint/issues/63) then you can try and increase this value. Setting it to `false`, `0`, `NaN` or `Infinite` will not return any `stdout` or `stderr` and the task will think that everything's fine.

### Usage Examples

#### Example config
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
},
"dependencies": {
"lodash": "2.4.1",
"xmlbuilder": "2.2.1",
"chalk": "0.4.0"
"xmlbuilder": "2.4.3",
"chalk": "0.5.1"
},
"devDependencies": {
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-nodeunit": "0.4.1",
"grunt-contrib-internal": "0.4.10",
"grunt-jscs-checker": "0.4.1",
"grunt-jscs": "0.6.2",
"grunt": ">=0.4.5"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions tasks/lib/scss-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.init = function (grunt) {
return;
}

results = (results.length !== 0) ? results.split("\n") : [];
results = (results.length !== 0) ? results.split('\n') : [];

xml = xmlBuilder.create('testsuites');

Expand Down Expand Up @@ -62,7 +62,7 @@ exports.init = function (grunt) {
matches;

results = chalk.stripColor(results);
results = (results.length !== 0) ? results.split("\n") : [];
results = results.length !== 0 ? results.split('\n') : [];

_.forEach(results, function (result) {
if (result === '') {
Expand Down Expand Up @@ -150,7 +150,7 @@ exports.init = function (grunt) {
}

child = exec(args.join(' '), {
maxBuffer: 300 * 1024,
maxBuffer: options.maxBuffer,
cwd: process.cwd(),
env: env
}, function (err, results, code) {
Expand Down
3 changes: 2 additions & 1 deletion tasks/scss-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = function (grunt) {
bundleExec: false,
colorizeOutput: true,
compact: false,
force: false
force: false,
maxBuffer: 300 * 1024
});

grunt.verbose.writeflags(opts, 'scss-lint options');
Expand Down
47 changes: 30 additions & 17 deletions test/scss-lint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var path = require('path'),
fixtures = path.join(__dirname, 'fixtures'),
reporterOutFile = path.join(__dirname, 'output.xml'),
escapeRe = function (str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
},
defaultOptions;

Expand All @@ -25,7 +25,7 @@ exports.scsslint = {
test.expect(5);
var files = path.join(fixtures, 'fail.scss');
scsslint.lint(files, defaultOptions, function (results) {
results = results.split("\n");
results = results.split('\n');
test.ok(
results[0].indexOf('Class `Button` in selector should be written in all lowercase as `button`') !== -1,
'Should report bad case.'
Expand Down Expand Up @@ -64,9 +64,9 @@ exports.scsslint = {
stdout = [],
testOptions;

testOptions = _.assign({}, defaultOptions, {
force: true
});
testOptions = _.assign({}, defaultOptions, {
force: true
});

grunt.log.muted = false;

Expand All @@ -78,7 +78,6 @@ exports.scsslint = {
});

scsslint.lint(files, testOptions, function (results) {

grunt.option('debug', undefined);
hooker.unhook(process.stdout, 'write');
grunt.log.muted = muted;
Expand Down Expand Up @@ -110,6 +109,7 @@ exports.scsslint = {
});

grunt.option('debug', true);

scsslint.lint(files, defaultOptions, function () {
grunt.option('debug', undefined);
hooker.unhook(process.stdout, 'write');
Expand Down Expand Up @@ -186,7 +186,7 @@ exports.scsslint = {
scsslint.lint(files, testOptions, function (results) {
var report = grunt.file.read(reporterOutFile);

results = results.split("\n");
results = results.split('\n');

test.ok(report.indexOf(results[0]) !== -1,
'Should write the errors out to a report');
Expand All @@ -206,7 +206,6 @@ exports.scsslint = {
});

scsslint.lint(files, testOptions, function (results) {

var report = grunt.file.read(reporterOutFile);

test.ok(report.indexOf('errors="0"') !== -1,
Expand All @@ -228,7 +227,7 @@ exports.scsslint = {
scsslint.lint(file, testOptions, function (results) {
var styles = chalk.styles;

results = results.split("\n")[0];
results = results.split('\n')[0];

test.ok(
results.indexOf(styles.cyan.open + file) !== -1,
Expand Down Expand Up @@ -257,8 +256,7 @@ exports.scsslint = {
});

scsslint.lint([file1, file2], testOptions, function (results) {

results = results.split("\n");
results = results.split('\n');

test.ok(
results[1].indexOf(file1) !== -1,
Expand Down Expand Up @@ -298,7 +296,7 @@ exports.scsslint = {

scsslint.lint([file1, file2], testOptions, function (results) {
var styles = chalk.styles;
results = results.split("\n");
results = results.split('\n');

test.ok(
results[1].indexOf(styles.bold.open + file1) !== -1,
Expand Down Expand Up @@ -382,34 +380,49 @@ exports.scsslint = {
});

scsslint.lint(file1, testOptions, function (results) {
results = results.split("\n");
results = results.split('\n');
test.ok(results.length === 4);
test.done();
});
},

exitCodeOnFailure: function (test) {
test.expect(1);
grunt.util.spawn({grunt: true, args: ["scsslint"]}, function (error, result, code) {
grunt.util.spawn({grunt: true, args: ['scsslint']}, function (error, result, code) {
test.notEqual(code, 0);
test.done();
});
},

exitCodeAndOutputOnMissingRuby: function (test) {
test.expect(2);
grunt.util.spawn({grunt: true, args: ["scsslint"], opts: {env: {PATH: "."}}}, function (error, result, code) {
grunt.util.spawn({grunt: true, args: ['scsslint'], opts: {env: {PATH: '.'}}}, function (error, result, code) {
test.notEqual(code, 0);
test.ok(result.stdout.match("Please make sure you have ruby installed"));
test.ok(result.stdout.match('Please make sure you have ruby installed'));
test.done();
});
},

exitCodeOnSuccess: function (test) {
test.expect(1);
grunt.util.spawn({grunt: true, args: ["scsslint:success"]}, function (error, result, code) {
grunt.util.spawn({grunt: true, args: ['scsslint:success']}, function (error, result, code) {
test.equal(code, 0);
test.done();
});
},

maxBuffer: function (test) {
test.expect(1);
var files = path.join(fixtures, 'fail.scss'),
testOptions;

testOptions = _.assign({}, defaultOptions, {
maxBuffer: false
});

scsslint.lint(files, testOptions, function (results) {
test.ok(!results, 'There should be no lint errors');
test.done();
});
}
};

0 comments on commit 1487560

Please sign in to comment.