Skip to content

Commit

Permalink
Whitespace. Linting. Jerkery.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceejbot committed Aug 22, 2015
1 parent 018a5df commit faea91a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 95 deletions.
58 changes: 58 additions & 0 deletions .jscsrc
@@ -0,0 +1,58 @@
{
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowEmptyBlocks": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireBlocksOnNewline": 1,
"requireCommaBeforeLineBreak": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"requireSpacesInForStatement": true,
"requireSpaceBetweenArguments": true,
"requireCurlyBraces": [
"do"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof"
],
"safeContextKeyword": "self",
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"validateIndentation": "\t",
"requireSemicolons": true
}
57 changes: 6 additions & 51 deletions .jshintrc
@@ -1,39 +1,26 @@
{
// == Enforcing Options ===============================================
//
// These options tell JSHint to be more strict towards your code. Use
// them if you want to allow only a safe subset of JavaScript, very
// useful when your codebase is shared with a big number of developers
// with different skill levels.

"bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.).
"curly" : false, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"eqeqeq" : false, // Require triple equals i.e. `===`.
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : false, // Prohibit variable use before definition.
"newcap" : false, // Require capitalization of all constructor functions e.g. `new F()`.
"newcap" : false, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : false, // Prohibit use of constructors for side-effects.
"nonew" : false, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`.
"regexp" : false, // Prohibit `.` and `[^...]` in regular expressions.
"undef" : true, // Require all non-global variables be declared before they are used.
"strict" : false, // Require `use strict` pragma in every file.
"trailing" : false, // Prohibit trailing whitespaces.

// == Relaxing Options ================================================
//
// These options allow you to suppress certain types of warnings. Use
// them only if you are absolutely positive that you know what you are
// doing.

"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : true, // Tolerate use of `== null`.
"es5" : true, // Allow EcmaScript 5 syntax.
"esnext" : false, // Allow ES.next specific features such as `const` and `let`.
"eqnull" : false, // Tolerate use of `== null`.
"esnext" : true, // Allow ES.next specific features such as `const` and `let`.
"evil" : false, // Tolerate use of `eval`.
"expr" : true, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
Expand All @@ -54,46 +41,14 @@
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.

// == Environments ====================================================
//
// These options pre-define global variables that are exposed by
// popular JavaScript libraries and runtime environments—such as
// browser or node.js.

"browser" : false, // Standard browser globals e.g. `window`, `document`.
"couch" : false, // Enable globals exposed by CouchDB.
"devel" : false, // Allow development statements e.g. `console.log();`.
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
"jquery" : false, // Enable globals exposed by jQuery JavaScript library.
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
"node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.

// == JSLint Legacy ===================================================
//
// These options are legacy from JSLint. Aside from bug fixes they will
// not be improved in any way and might be removed at any point.

"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : false, // Check against strict whitespace and indentation rules.

// == Undocumented Options ============================================
//
// While I've found these options in [example1][2] and [example2][3]
// they are not described in the [JSHint Options documentation][4].
//
// [4]: http://www.jshint.com/options/

"maxerr" : 100, // Maximum errors before stopping.
"predef" : [ // Extra globals.
//"exampleVar",
//"anotherCoolGlobal",
//"iLoveDouglas"
],
"es5": false
"indent" : 4 // Specify indentation spacing
}
2 changes: 1 addition & 1 deletion lib/persistence.js
Expand Up @@ -233,7 +233,7 @@ persist.plugins =
return;

var body = attach.body;
var payload = body == null ? '' : (Buffer.isBuffer(body) ? body : new Buffer(body)).toString('base64');
var payload = body === null ? '' : (Buffer.isBuffer(body) ? body : new Buffer(body)).toString('base64');

attach.stub = false;
attach.data = payload;
Expand Down
10 changes: 5 additions & 5 deletions lib/polyclay.js
Expand Up @@ -154,11 +154,11 @@ PolyClay.Model.prototype.valid = function()
var props = this.__properties;
var types = this.__types;
this.errors = {};
for (i=0, len=props.length; i<len; i++)
for (i = 0, len = props.length; i < len; i++)
{
p = props[i];
var val = this.__attributes[p];
if (val != null && !PolyClay.validate[types[p]](val))
if (val !== null && !PolyClay.validate[types[p]](val))
{
this.errors[p] = 'invalid data';
valid = false;
Expand Down Expand Up @@ -205,12 +205,12 @@ PolyClay.Model.addProperty = function(obj, propname, type)
var setterFunc = function(newval)
{
var type = this.__types[propname];
if (newval == null)
if (newval === null)
newval = (type === 'string') ? '' : null;
else
{
if (!PolyClay.validate[type](newval))
throw(new Error(propname+': type of '+newval+' not '+type));
throw(new Error(propname + ': type of ' + newval + ' not ' + type));

if ((type === 'date') && !_.isDate(newval))
newval = new Date(newval);
Expand All @@ -219,7 +219,7 @@ PolyClay.Model.addProperty = function(obj, propname, type)
this.__attributesPrev[propname] = this.__attributes[propname];
this.__attributes[propname] = newval;
this.__dirty = true;
this.emit('change', newval);
this.emit('change', newval);
this.emit('change.' + propname, newval);
};

Expand Down
49 changes: 25 additions & 24 deletions package.json
@@ -1,19 +1,8 @@
{
"name": "polyclay",
"version": "1.7.1",
"description": "a schema-enforcing model class for node with optional key-value store persistence",
"version": "1.7.1",
"author": "C J Silverio <ceejceej@gmail.com>",
"contributors": [
"C J Silverio <ceejceej@gmail.com>",
"Kit Cambridge <kitcambridge@me.com>"
],
"license": "MIT",
"readmeFilename": "README.md",
"main": "index.js",
"scripts": {
"test": "mocha --check-leaks --ui exports --require blanket -R mocoverage",
"test-cov": "mocha --require blanket -R travis-cov test/test-*.js"
},
"config": {
"blanket": {
"pattern": "lib",
Expand All @@ -28,10 +17,10 @@
"threshold": 80
}
},
"repository": {
"type": "git",
"url": "git://github.com/ceejbot/polyclay.git"
},
"contributors": [
"C J Silverio <ceejceej@gmail.com>",
"Kit Cambridge <kitcambridge@me.com>"
],
"dependencies": {
"lodash": "~3.10.1",
"p-promise": "~0.5.0"
Expand All @@ -44,14 +33,26 @@
"travis-cov": "~0.2.5"
},
"keywords": [
"odm",
"model",
"mapper",
"schema",
"couchdb",
"cassandra",
"couch",
"redis",
"couchdb",
"levelup",
"cassandra"
]
"mapper",
"model",
"odm",
"redis",
"schema"
],
"license": "MIT",
"main": "index.js",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git://github.com/ceejbot/polyclay.git"
},
"scripts": {
"lint": "jshint lib/*.js test/*.js index.js && jscs lib index.js",
"test": "mocha --check-leaks --ui exports --require blanket -R mocoverage",
"test-cov": "mocha --require blanket -R travis-cov test/test-*.js"
}
}
22 changes: 8 additions & 14 deletions test/test-02-persistence.js
Expand Up @@ -126,7 +126,7 @@ describe('persistence layer', function()
{
properties:
{
'id': 'string'
id: 'string'
}
});
polyclay.persist(Ephemeral, 'id');
Expand All @@ -150,10 +150,7 @@ describe('persistence layer', function()
{
var Ephemeral = polyclay.Model.buildClass(
{
properties:
{
'id': 'string'
}
properties: { id: 'string' }
});
polyclay.persist(Ephemeral, 'id');

Expand All @@ -173,10 +170,7 @@ describe('persistence layer', function()
{
var Ephemeral = polyclay.Model.buildClass(
{
properties:
{
'key': 'string'
}
properties: { key: 'string' }
});
polyclay.persist(Ephemeral);

Expand Down Expand Up @@ -272,7 +266,7 @@ describe('persistence layer', function()
obj.key = '1';

var gotEvent = false;
obj.on('before-save', function() { gotEvent = true; })
obj.on('before-save', function() { gotEvent = true; });

obj.save()
.then(function()
Expand All @@ -288,7 +282,7 @@ describe('persistence layer', function()
obj.key = '2';

var gotEvent = false;
obj.on('after-save', function() { gotEvent = true; })
obj.on('after-save', function() { gotEvent = true; });

obj.save().then(function()
{
Expand All @@ -306,7 +300,7 @@ describe('persistence layer', function()
.then(function(r)
{
obj = r;
obj.on('before-destroy', function() { gotEvent = true; })
obj.on('before-destroy', function() { gotEvent = true; });
return obj.destroy();
}).then(function(ok)
{
Expand Down Expand Up @@ -435,7 +429,7 @@ describe('persistence layer', function()
demand(obj.propertyType('nonexistent')).not.exist();
});

it('clearDirty() wipes the dirty bit');
it('clearDirty() wipes the dirty bit on all attachments');
it('clearDirty() wipes the dirty bit');
it('clearDirty() wipes the dirty bit on all attachments');

});

0 comments on commit faea91a

Please sign in to comment.