Skip to content

Commit

Permalink
Replace JSHint with ESLint and JSCS
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Nov 11, 2015
1 parent 07fc61c commit 219f66e
Show file tree
Hide file tree
Showing 51 changed files with 1,483 additions and 1,412 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
tmp/
45 changes: 45 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"extends": "eslint:recommended",
"root": true,
"rules": {
"curly": [2, "multi-line"],
"no-console": 0,
"no-path-concat": 2,
"handle-callback-err": 2,
"no-use-before-define": [2, "nofunc"],
"no-shadow-restricted-names": 2,
"block-scoped-var": 2,
"dot-notation": 2,
"eqeqeq": [2, "allow-null"],
"no-else-return": 1,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new-wrappers": 2,
"no-redeclare": 2,
"no-return-assign": 2,
"no-throw-literal": 2,
"no-unused-expressions": [2, {
"allowShortCircuit": true,
"allowTernary": true
}],
"no-useless-call": 2,
"no-useless-concat": 2,
"no-with": 2,
"radix": 2,
"no-self-compare": 2,
"no-unused-vars": [2, {
"vars": "all",
"args": "none"
}],
"strict": [2, "global"]
},
"env": {
"node": true
}
}
85 changes: 85 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"excludeFiles": ["node_modules/**", "coverage/**", "tmp/**"],
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"requireSemicolons": true,
"disallowEmptyBlocks": true,
"disallowKeywordsOnNewLine": ["else"],
"disallowKeywords": ["with"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,
"disallowMultipleVarDecl": "exceptUndefined",
"disallowNewlineBeforeBlockStatements": true,
"disallowOperatorBeforeLineBreak": ["."],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforeComma": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeSemicolon": true,
"disallowSpacesInCallExpression": true,
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideParenthesizedExpression": {
"allExcept": [ "{", "}" ]
},
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"requireBlocksOnNewline": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"for",
"while",
"do",
"try",
"catch"
],
"requireDotNotation": true,
"requireLineBreakAfterVariableAssignment": true,
"requireLineFeedAtFileEnd": true,
"requirePaddingNewLinesAfterBlocks": true,
"requirePaddingNewLinesAfterUseStrict": true,
"requireParenthesesAroundIIFE": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof"
],
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"validateNewlineAfterArrayElements": true,
"validateParameterSeparator": ", ",
"disallowMultipleSpaces": true
}
14 changes: 0 additions & 14 deletions .jshintrc

This file was deleted.

8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ cache:
node_js:
- "0.10"
- "0.12"
- iojs
- "4"
- "5"

script:
- npm test
- npm run eslint
- npm run jscs
- npm run test-cov

after_script:
- npm install coveralls
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
47 changes: 0 additions & 47 deletions gulpfile.js

This file was deleted.

43 changes: 22 additions & 21 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var extend = util.extend;
* @constructor
* @module warehouse
*/
function Database(options){
function Database(options) {
/**
* Database options.
*
Expand All @@ -30,8 +30,9 @@ function Database(options){
*/
this.options = extend({
version: 0,
onUpgrade: function(){},
onDowngrade: function(){}
onUpgrade: function() {},

onDowngrade: function() {}
}, options);

/**
Expand All @@ -51,7 +52,7 @@ function Database(options){
* @constructor
* @private
*/
var _Model = this.Model = function(name, schema){
var _Model = this.Model = function(name, schema) {
Model.call(this, name, schema);
};

Expand All @@ -67,8 +68,8 @@ function Database(options){
* @param {Schema|Object} [schema]
* @return {Model}
*/
Database.prototype.model = function(name, schema){
if (this._models[name]){
Database.prototype.model = function(name, schema) {
if (this._models[name]) {
return this._models[name];
}

Expand All @@ -83,20 +84,20 @@ Database.prototype.model = function(name, schema){
* @param {Function} [callback]
* @return {Promise}
*/
Database.prototype.load = function(callback){
Database.prototype.load = function(callback) {
var path = this.options.path;
var self = this;

if (!path) throw new WarehouseError('options.path is required');

return new Promise(function(resolve, reject){
return new Promise(function(resolve, reject) {
var src = fs.createReadStream(path, {encoding: 'utf8'});
var oldVersion = 0;

var stream = JSONStream.parse([true, true], function(value, keys){
var stream = JSONStream.parse([true, true], function(value, keys) {
switch (keys.shift()){
case 'meta':
if (keys.shift() === 'version'){
if (keys.shift() === 'version') {
oldVersion = value;
}

Expand All @@ -111,15 +112,15 @@ Database.prototype.load = function(callback){
src
.pipe(stream)
.on('error', reject)
.on('end', function(){
.on('end', function() {
resolve(oldVersion);
});
}).then(function(oldVersion){
}).then(function(oldVersion) {
var newVersion = self.options.version;

if (newVersion > oldVersion){
if (newVersion > oldVersion) {
return self.options.onUpgrade(oldVersion, newVersion);
} else if (newVersion < oldVersion){
} else if (newVersion < oldVersion) {
return self.options.onDowngrade(oldVersion, newVersion);
}
}).nodeify(callback);
Expand All @@ -132,13 +133,13 @@ Database.prototype.load = function(callback){
* @param {Function} callback
* @return {Promise}
*/
Database.prototype.save = function(callback){
Database.prototype.save = function(callback) {
var path = this.options.path;
var self = this;

if (!path) throw new WarehouseError('options.path is required');

return new Promise(function(resolve, reject){
return new Promise(function(resolve, reject) {
var stream = fs.createWriteStream(path);

// Start
Expand All @@ -151,13 +152,13 @@ Database.prototype.save = function(callback){
}) + ',');

// Export models
var models = self._models,
keys = Object.keys(models),
model, key;
var models = self._models;
var keys = Object.keys(models);
var model, key;

stream.write('"models":{');

for (var i = 0, len = keys.length; i < len; i++){
for (var i = 0, len = keys.length; i < len; i++) {
key = keys[i];
model = models[key];

Expand Down Expand Up @@ -201,4 +202,4 @@ Database.SchemaType = Database.prototype.SchemaType = SchemaType;
*/
Database.version = pkg.version;

module.exports = Database;
module.exports = Database;
Loading

0 comments on commit 219f66e

Please sign in to comment.