Skip to content

Commit

Permalink
feat(grunt): enforce code style with JSCS
Browse files Browse the repository at this point in the history
Based on AngularJS’s .jscsrc rules.

Updated .js files to follow rules.

Closes #30
  • Loading branch information
seriema committed Sep 13, 2015
1 parent 5cecae0 commit 1d8799c
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 69 deletions.
52 changes: 52 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"disallowKeywords": ["with"],
"disallowKeywordsOnNewLine": ["else"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineStrings": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInCallExpression": true,
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInsideArrayBrackets": {
"allExcept": [ "[", "]", "{", "}" ]
},
"requireSpaceBeforeKeywords": [
"else",
"while",
"catch"
],
"disallowSpacesInsideParentheses": true,
"requireTrailingComma": {
"ignoreSingleLine": true,
"ignoreSingleValue": true
},
"disallowTrailingWhitespace": true,
"requireCommaBeforeLineBreak": true,
"requireLineFeedAtFileEnd": true,
"requireSpaceAfterBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
"requireSpaceBeforeBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpacesInForStatement": true,
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"validateLineBreaks": "LF"
}
51 changes: 33 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ module.exports = function (grunt) {
version: require('./bower.json').version,
app: require('./bower.json').appPath,
dist: 'dist',
test: 'test',
},

bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: ['yeoman'],
files: [ 'package.json', 'bower.json' ],
updateConfigs: [ 'yeoman' ],
commit: true,
commitMessage: 'chore(release): release v%VERSION%. See CHANGELOG.md',
commitFiles: ['-a'], // '-a' for all files
commitFiles: [ '-a' ], // '-a' for all files
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
Expand All @@ -56,18 +57,18 @@ module.exports = function (grunt) {
// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
tasks: ['newer:jshint:all', 'karma:default'],
files: [ '<%= yeoman.app %>/scripts/{,*/}*.js' ],
tasks: [ 'newer:jshint:all', 'karma:default' ],
options: {
livereload: true,
},
},
jsTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['newer:jshint:test', 'karma:default'],
files: [ 'test/spec/{,*/}*.js' ],
tasks: [ 'newer:jshint:test', 'karma:default' ],
},
gruntfile: {
files: ['Gruntfile.js'],
files: [ 'Gruntfile.js' ],
},
livereload: {
options: {
Expand Down Expand Up @@ -120,8 +121,21 @@ module.exports = function (grunt) {
options: {
jshintrc: 'test/.jshintrc',
},
src: ['test/spec/{,*/}*.js'],
}
src: [ 'test/spec/{,*/}*.js' ],
},
},

// Check code style guidelines
jscs: {
src: [
'<%= yeoman.app %>/scripts/**/*.js',
'<%= yeoman.test %>/spec/**/*.js',
'*.js',
],
options: {
config: '.jscsrc',
verbose: true,
},
},

// Empties folders to start fresh
Expand All @@ -144,15 +158,15 @@ module.exports = function (grunt) {
singleQuotes: true,
},
dist: {
src: ['<%= yeoman.dist %>/angular-apimock.js'],
src: [ '<%= yeoman.dist %>/angular-apimock.js' ],
dest: '<%= yeoman.dist %>/angular-apimock.js',
},
},

// Replace Google CDN references
cdnify: {
dist: {
html: ['<%= yeoman.dist %>/*.html'],
html: [ '<%= yeoman.dist %>/*.html' ],
},
},

Expand Down Expand Up @@ -206,7 +220,7 @@ module.exports = function (grunt) {
// Default
},
sauce: {
browsers: ['SL_Chrome', 'SL_Firefox', 'SL_Safari', 'SL_iOS', 'SL_IE_8', 'SL_IE_9', 'SL_IE_10', 'SL_IE_11'],
browsers: [ 'SL_Chrome', 'SL_Firefox', 'SL_Safari', 'SL_iOS', 'SL_IE_8', 'SL_IE_9', 'SL_IE_10', 'SL_IE_11' ],
reporters: [ 'progress', 'saucelabs' ],
files: [{
src: [
Expand All @@ -219,7 +233,7 @@ module.exports = function (grunt) {
],
},
coverage: {
browsers: ['PhantomJS'],
browsers: [ 'PhantomJS' ],
reporters: [ 'dots', 'coverage' ],
coverageReporter: {
reporters: [
Expand Down Expand Up @@ -287,6 +301,7 @@ module.exports = function (grunt) {

grunt.registerTask('test', [
'jshint',
'jscs',
'connect:test',
'karma:coverage',
'karma:angular12',
Expand All @@ -310,10 +325,10 @@ module.exports = function (grunt) {
'nugetpush',
]);

grunt.registerTask('publish', ['publish:patch']);
grunt.registerTask('publish:patch', ['test', 'karma:sauce', 'bump-only:patch', '_publish']);
grunt.registerTask('publish:minor', ['test', 'karma:sauce', 'bump-only:minor', '_publish']);
grunt.registerTask('publish:major', ['test', 'karma:sauce', 'bump-only:major', '_publish']);
grunt.registerTask('publish', [ 'publish:patch' ]);
grunt.registerTask('publish:patch', [ 'test', 'karma:sauce', 'bump-only:patch', '_publish' ]);
grunt.registerTask('publish:minor', [ 'test', 'karma:sauce', 'bump-only:minor', '_publish' ]);
grunt.registerTask('publish:major', [ 'test', 'karma:sauce', 'bump-only:major', '_publish' ]);

grunt.registerTask('default', [
'test',
Expand Down
22 changes: 11 additions & 11 deletions app/scripts/angular-apimock.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ angular.module('apiMock', [])
}

if (angular.isArray(toSerialize)) {
angular.forEach(toSerialize, function(value, index) {
angular.forEach(toSerialize, function (value, index) {
serialize(value, prefix + '[' + (angular.isObject(value) ? index : '') + ']');
});
} else if (angular.isObject(toSerialize) && !angular.isDate(toSerialize)) {
forEachSorted(toSerialize, function(value, key) {
forEachSorted(toSerialize, function (value, key) {
serialize(value, prefix +
(topLevel ? '' : '[') +
key +
Expand All @@ -136,7 +136,7 @@ angular.module('apiMock', [])
var paramArray = paramString.split('&');

var result = {};
angular.forEach(paramArray, function(param) {
angular.forEach(paramArray, function (param) {
param = param.split('=');
result[param[0]] = param[1] || '';
});
Expand Down Expand Up @@ -179,7 +179,7 @@ angular.module('apiMock', [])
break;

case 'string':
switch(mockValue.toLowerCase()) {
switch (mockValue.toLowerCase()) {
case 'auto':
return { type: 'recover' };
case 'true':
Expand Down Expand Up @@ -207,8 +207,8 @@ angular.module('apiMock', [])
status: status,
headers: {
'Content-Type': 'text/html; charset=utf-8',
'Server': 'Angular ApiMock'
}
'Server': 'Angular ApiMock',
},
};
$log.info('apiMock: mocking HTTP status to ' + status);
return $q.reject(response);
Expand Down Expand Up @@ -257,7 +257,7 @@ angular.module('apiMock', [])
var params = angular.extend(req.params || {}, queryParamsFromUrl);

//test if there is already a trailing /
if (newPath[newPath.length-1] !== '/') {
if (newPath[newPath.length - 1] !== '/') {
newPath += '/';
}

Expand Down Expand Up @@ -363,7 +363,7 @@ angular.module('apiMock', [])
};
})

.service('httpInterceptor', function($injector, $q, $timeout, apiMock) {
.service('httpInterceptor', function ($injector, $q, $timeout, apiMock) {
/* The main service. Is jacked in as a interceptor on `$http` so it gets called
* on every http call. This allows us to do our magic. It uses the provider
* `apiMock` to determine if a mock should be done, then do the actual mocking.
Expand All @@ -379,8 +379,8 @@ angular.module('apiMock', [])
var deferred = $q.defer();

$timeout(
function() {
deferred.resolve( apiMock.onResponse(res) ); // TODO: Apparently, no tests break regardless what this resolves to. Fix the tests!
function () {
deferred.resolve(apiMock.onResponse(res)); // TODO: Apparently, no tests break regardless what this resolves to. Fix the tests!
},
apiMock.getDelay(),
true // Trigger a $digest.
Expand All @@ -402,7 +402,7 @@ angular.module('apiMock', [])
deferred.resolve(data);
});
} else {
deferred.reject( rej );
deferred.reject(rej);
}
},
apiMock.getDelay(),
Expand Down
8 changes: 4 additions & 4 deletions karma-e2e.conf.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html

module.exports = function(config) {
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',

// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],
frameworks: [ 'ng-scenario' ],

// list of files / patterns to load in the browser
files: [
Expand Down Expand Up @@ -37,12 +37,12 @@ module.exports = function(config) {
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Firefox'],
browsers: [ 'Firefox' ],


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
singleRun: false,

// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
Expand Down
32 changes: 16 additions & 16 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html

module.exports = function(config) {
var sourcePreprocessors = ['coverage'];
module.exports = function (config) {
var sourcePreprocessors = [ 'coverage' ];
function isDebug(argument) {
return argument === '--debug';
}
Expand All @@ -15,7 +15,7 @@ module.exports = function(config) {
basePath: '',

// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
frameworks: [ 'jasmine' ],

// reporter style
reporters: [ 'progress' ],
Expand All @@ -32,7 +32,7 @@ module.exports = function(config) {
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/scripts/**/*.js',
'test/spec/**/*.js'
'test/spec/**/*.js',
],

// list of files / patterns to exclude
Expand All @@ -58,48 +58,48 @@ module.exports = function(config) {
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
browsers: [ 'PhantomJS' ],

// Check out https://saucelabs.com/platforms for all browser/platform combos
captureTimeout: 120000,
customLaunchers: {
'SL_Chrome': {
base: 'SauceLabs',
browserName: 'chrome'
browserName: 'chrome',
},
'SL_Firefox': {
base: 'SauceLabs',
browserName: 'firefox'
browserName: 'firefox',
},
'SL_Safari': {
base: 'SauceLabs',
browserName: 'safari'
browserName: 'safari',
},
'SL_IE_8': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '8'
version: '8',
},
'SL_IE_9': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '9'
version: '9',
},
'SL_IE_10': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '10'
version: '10',
},
'SL_IE_11': {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
version: '11',
},
'SL_iOS': {
base: 'SauceLabs',
browserName: 'iphone'
}
browserName: 'iphone',
},
},

// SauceLabs config for local development.
Expand All @@ -111,7 +111,7 @@ module.exports = function(config) {

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
singleRun: false,
});

// Travis specific configs.
Expand All @@ -133,7 +133,7 @@ module.exports = function(config) {
// Debug logging into a file, that we print out at the end of the build.
config.loggers.push({
type: 'file',
filename: (process.env.LOGS_DIR || '') + '/karma.log'
filename: (process.env.LOGS_DIR || '') + '/karma.log',
});
}
};
Loading

0 comments on commit 1d8799c

Please sign in to comment.