Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Add jscs code validation. Fix code warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmalov committed Oct 13, 2014
1 parent b005c8b commit 55f9f24
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 125 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
npm-debug.log
tmp
test/tmp.sqlite
*.log
logs
test/.tmp
coverage
.idea
86 changes: 86 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"function",
"typeof"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"requireBlocksOnNewline": 1,
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"disallowSpaceBeforeBinaryOperators": [
","
],
"requireSpaceBeforeBinaryOperators": [
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"validateIndentation": 2,
"disallowMixedSpacesAndTabs": "smart",
"disallowTrailingWhitespace": true,
"disallowKeywordsOnNewLine": [ "else" ],
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"disallowNewlineBeforeBlockStatements": true,
"requireDotNotation": null,
"disallowYodaConditions": true,
"excludeFiles": [
"node_modules/**",
"**/node_modules/**"
]
}
16 changes: 2 additions & 14 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"browser": true,
"node": true,

"strict": true,
Expand All @@ -11,19 +10,8 @@
"indent": 2,
"trailing": true,
"quotmark": "single",
"camelcase": "We have to set this to false in order to support the use of snake case for database table fields",
"camelcase": false,
"camelcase": true,
"newcap": true,
"curly": true,
"eqeqeq": true,
"predef": [
"require",
"define",
"before",
"after",
"describe",
"it",
"beforeEach",
"afterEach"
]
"eqeqeq": true
}
70 changes: 32 additions & 38 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,66 @@
'use strict';

module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);

var files = {
lib: ['lib/**/*.js', 'tasks/**/*.js'],
test: ['test/**/*.js'],
specs: ['test/**/.spec.js']
};

// Project configuration.
grunt.initConfig({
jshint: {
options: { jshintrc: true },
lib: files.lib,
test: files.test
},

jscs: {
options: {
jshintrc: '.jshintrc',
ignores: [
'*.min.js',
'node_modules/**/*',
'public/bower_components/**/*',
'dist/**/*',
'coverage/**/*'
]
config: '.jscsrc'
},
all: [
'*.js',
'**/*.js'
]

lib: files.lib,
test: files.test
},

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp', 'test/tmp.sqlite', 'test/tmp.sqlite-journal'],
test: ['test/.tmp']
},

mochaTest: {
options: {
reporter: 'spec',
ui: 'bdd',
require: ['./test']
},

specs: files.specs
},

// Configuration to be run (and then tested).
sequelize: {
options:{
dialect: 'sqlite',
storage: 'test/tmp.sqlite',
storage: 'test/.tmp/db-test.sqlite',
logging: false,
migrationsPath: __dirname + '/test/migrations'
}
},

mochaTest: {
test: {
options: {
reporter: 'dot',
},
src: ['test/**.js']
}
},
}

});

// Actually load this plugin's task(s).
grunt.loadTasks('tasks');

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mocha-test');


grunt.registerTask('mocha', ['mochaTest']);
grunt.registerTask('test', ['clean', 'mocha']);
grunt.registerTask('lint', ['jshint']);
grunt.registerTask('test', ['clean', 'mochaTest']);
grunt.registerTask('validate', ['jshint', 'jscs']);

if(process.env.TEST_CMD) {
grunt.registerTask('travis', process.env.TEST_CMD);
}

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
grunt.registerTask('default', ['validate', 'test']);

};
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@
},
"scripts": {
"test": "grunt test",
"coverage": "rm -rf coverage && ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec && ./node_modules/.bin/istanbul report --root ./coverage --dir ./coverage lcov",
"coveralls": "rm -rf coverage && ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec && ./node_modules/.bin/istanbul report --root ./coverage --dir ./coverage lcovonly && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage"
"coverage": "rm -rf coverage && istanbul cover _mocha --report lcov",
"coveralls": "rm -rf coverage && istanbul cover _mocha --report lcovonly cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"devDependencies": {
"chai": "^1.9.2",
"coveralls": "~2.3.0",
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-mocha-test": "~0.7.0",
"istanbul": "~0.1.45",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-jscs": "^0.7.1",
"grunt-mocha-test": "^0.12.1",
"istanbul": "^0.3.2",
"load-grunt-tasks": "^0.6.0",
"lodash": "^2.4.1",
"mocha": "~1.14.0",
"pg": "~2.8.2",
"random-string": "~0.1.1",
"sqlite3": "~2.1.19"
"mocha": "^1.21.5",
"random-string": "^0.1.1",
"sqlite3": "^3.0.2",
"time-grunt": "^1.0.0"
},
"peerDependencies": {
"grunt": "~0.4.1",
Expand Down
2 changes: 1 addition & 1 deletion tasks/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports = function (grunt) {
grunt.log.writeln('Syncing database ' + options.database + '...');

var models = [];
var fileArray = fs
fs
.readdirSync(options.modelsDir)
.filter(function (file) {
return (file.indexOf('.') !== 0) && (file !== 'index.js');
Expand Down
28 changes: 28 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"node": true,

"strict": true,
"undef": true,
"unused": true,
"latedef": true,
"immed": true,
"noarg": true,
"indent": 2,
"trailing": true,
"quotmark": "single",
"camelcase": true,
"newcap": true,
"curly": true,
"eqeqeq": true,
"expr": true,
"predef": [
"define",
"before",
"after",
"describe",
"it",
"beforeEach",
"afterEach",
"expect"
]
}
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var chai = require('chai');

global.expect = chai.expect;
4 changes: 2 additions & 2 deletions test/migrations/20131121163607-inital-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
'use strict';

module.exports = {
up: function(migration, DataTypes, done) {
up: function (migration, DataTypes, done) {

migration.createTable('users', {
name: DataTypes.STRING
}).complete(done);

},
down: function(migration, DataTypes, done) {
down: function (migration, DataTypes, done) {

migration.dropTable('nameOfTheExistingTable').complete(done);

Expand Down
4 changes: 2 additions & 2 deletions test/migrations/20131121163655-add-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
'use strict';

module.exports = {
up: function(migration, DataTypes, done) {
up: function (migration, DataTypes, done) {

migration.addColumn('users', 'admin', DataTypes.BOOLEAN).complete(done);

},
down: function(migration, DataTypes, done) {
down: function (migration, DataTypes, done) {

migration.removeColumn('users', 'admin').complete(done);

Expand Down
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--reporter spec
--ui bdd
--recursive
--require ./test
Loading

0 comments on commit 55f9f24

Please sign in to comment.