Skip to content

Commit

Permalink
Small codestyle changes + renamed tests file
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Nov 24, 2015
1 parent 073d9f6 commit 84d9a39
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 46 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ Thumbs.db
*.log
*.pid
*.seed
*.sublime-project
*.sublime-workspace
*.sublime-*
6 changes: 2 additions & 4 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@
//"requirePaddingNewLineAfterVariableDeclaration": true,
//"requirePaddingNewLinesAfterBlocks": true,
"requirePaddingNewlinesBeforeKeywords":
["do", "case", "try", "void", "while"],
["do", "case", "try", "void", "while", "function"],
//"requirePaddingNewLinesInObjects": true,
"requireParenthesesAroundIIFE": true,
"requireQuotedKeysInObjects": true,
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterKeywords":
["do", "for", "if", "else", "switch", "case", "try", "catch", "void", "while", "with", "return", "typeof"],
"requireSpaceAfterLineComment":
{ "allExcept": ["#", "=",
"------------------------------------------------------------------------------", "//////////////////////////////////////////////////////////////////////////////"] },
{ "allExcept": ["#", "="] },
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
Expand Down
17 changes: 6 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* gulp-scss-lint-stylish | lib/index.js
* file version: 0.00.007
*/
'use strict';

Expand All @@ -11,7 +10,7 @@ var TextTable = require('text-table');

var IS_WIN32 = (process.platform === 'win32');

////////////////////////////////////////////////////////////////////////////////
// // // // // // // // // // // // // // // // // // // // // // // // // // //

function colorize($str, $color1, $color2)
{
Expand Down Expand Up @@ -47,7 +46,7 @@ function pluralize($str, $count)
return $str;
}

//------------------------------------------------------------------------------
// -----------------------------------------------------------------------------

/**
* @param {object} $file - Vinyl object with scsslint key in it.
Expand All @@ -60,8 +59,6 @@ var GulpScssLintStylish = function($file)
var $errorCount = 0;
var $warningCount = 0;
var $log = [];
var $issue;
var $reason;

// no output needed on success or empty report
if (_.isUndefined($report) || _.isEmpty($report) ||
Expand All @@ -73,8 +70,8 @@ var GulpScssLintStylish = function($file)
// loop through all issues in the report
for (var $i = 0, $iL = $report.issues.length; $i < $iL; $i++)
{
$issue = $report.issues[$i];
$reason = $issue.reason;
var $issue = $report.issues[$i];
var $reason = $issue.reason;

if ($issue.severity === 'error')
{
Expand All @@ -95,8 +92,7 @@ var GulpScssLintStylish = function($file)
}

// this is actually a with columns wich are passed to TextTable
$log.push(
[
$log.push([
'',
Chalk.gray('line ' + $issue.line),
Chalk.gray('col ' + $issue.column),
Expand All @@ -107,8 +103,7 @@ var GulpScssLintStylish = function($file)
// at the end of the output log, display the amount of warnings/errors
if ($log.length >= 1)
{
$result =
[
$result = [
Chalk.underline($file.path),
TextTable($log) + '\n'
];
Expand Down
48 changes: 19 additions & 29 deletions test/main.js → test/index_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* gulp-scss-lint-stylish | test/main.js
* file version: 0.00.008
* gulp-scss-lint-stylish | test/index_tests.js
*/
'use strict';

Expand All @@ -14,7 +13,7 @@ var LogInterceptor = require('log-interceptor');
var LogSymbols = require('log-symbols');
var StripAnsi = GulpUtil.colors.stripColor;

////////////////////////////////////////////////////////////////////////////////
// // // // // // // // // // // // // // // // // // // // // // // // // // //

/**
* Returns a fixture file wich can be piped to gulp-scss-lint.
Expand All @@ -25,8 +24,7 @@ var StripAnsi = GulpUtil.colors.stripColor;
function getFixtureFile($file)
{
$file = Path.resolve(__dirname, './fixtures/' + $file);
$file = new GulpUtil.File(
{
$file = new GulpUtil.File({
'cwd': Path.dirname(Path.dirname($file)),
'base': Path.dirname($file),
'path': $file,
Expand Down Expand Up @@ -81,11 +79,9 @@ function streamTest($file, $done, $expected)
function stylishResult($severity, $amount)
{
var $result;
var $data =
{
var $data = {
'path': __filename,
'scsslint':
{
'scsslint': {
'success': false,
'issues': []
}
Expand All @@ -94,8 +90,7 @@ function stylishResult($severity, $amount)
// prepare test data
for (var $i = 1; $i <= $amount; $i++)
{
$data.scsslint.issues.push(
{
$data.scsslint.issues.push({
'linter': 'TestCase',
'reason': 'Forced ' + $severity + ' test',
'severity': $severity,
Expand All @@ -121,28 +116,26 @@ describe('gulp-scss-lint', function()
this.timeout(5000);

// no errors or warnings, scss is valid
it('should display nothing', function($done)
it('display nothing', function($done)
{
streamTest('success.scss', $done, []);
});

// warning in scss file
it('should display stylish warning', function($done)
it('display stylish warning', function($done)
{
streamTest('warning.scss', $done,
[
streamTest('warning.scss', $done, [
' line 1 col 1 IdSelector: Avoid using id selectors\n',
' ' + StripAnsi(LogSymbols.warning) + ' 1 warning\n'
]);
});

// error in scss file
it('should display stylish error', function($done)
it('display stylish error', function($done)
{
var $error = 'Invalid CSS after "}": expected "}", was ""';

streamTest('error.scss', $done,
[
streamTest('error.scss', $done, [
' line 5 col 1 Syntax Error: ' + $error + '\n',
' ' + StripAnsi(LogSymbols.error) + ' 1 error\n'
]);
Expand All @@ -151,28 +144,26 @@ describe('gulp-scss-lint', function()

describe('GulpScssLintStylish()', function()
{
it('should return on non existing report', function()
it('return on non existing report', function()
{
Assert.equal(false, GulpScssLintStylish({ }));
});

it('should return on empty report', function()
it('return on empty report', function()
{
Assert.equal(false, GulpScssLintStylish({ 'scsslint': {} }));
});

it('should return on successful report', function()
it('return on successful report', function()
{
Assert.equal(false, GulpScssLintStylish(
{
Assert.equal(false, GulpScssLintStylish({
'scsslint': { 'success': true }
}));
});

it('should return a stylish error', function()
it('return a stylish error', function()
{
Assert.deepEqual(stylishResult('error', 1),
[
Assert.deepEqual(stylishResult('error', 1), [
'',
__filename,
' line 1 col 1 TestCase: Forced error test',
Expand All @@ -182,10 +173,9 @@ describe('GulpScssLintStylish()', function()
].join('\n'));
});

it('should return two stylish warnings', function()
it('return two stylish warnings', function()
{
Assert.deepEqual(stylishResult('warning', 2),
[
Assert.deepEqual(stylishResult('warning', 2), [
'',
__filename,
' line 1 col 1 TestCase: Forced warning test',
Expand Down

0 comments on commit 84d9a39

Please sign in to comment.