Add jscs style check, fix violations found
This commit is contained in:
parent
83723379a2
commit
5b5071864b
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"preset": "google",
|
||||||
|
"requireCurlyBraces": [
|
||||||
|
"do",
|
||||||
|
"try",
|
||||||
|
"catch"
|
||||||
|
],
|
||||||
|
"disallowSpacesInsideObjectBrackets": null,
|
||||||
|
"requireSpaceAfterLineComment": true,
|
||||||
|
"maximumLineLength": {
|
||||||
|
"value": 80,
|
||||||
|
"allowRegex": true
|
||||||
|
},
|
||||||
|
"validateJSDoc": {
|
||||||
|
"checkParamNames": false,
|
||||||
|
"checkRedundantParams": false,
|
||||||
|
"requireParamTypes": true
|
||||||
|
},
|
||||||
|
"excludeFiles": [
|
||||||
|
"node_modules/**",
|
||||||
|
"coverage/**",
|
||||||
|
"test/sandbox/**"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"node": true,
|
"node": true,
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"camelcase" : true,
|
|
||||||
"eqnull" : true,
|
"eqnull" : true,
|
||||||
"indent": 2,
|
"indent": 2,
|
||||||
"undef": true,
|
"undef": true,
|
||||||
|
|
2
index.js
2
index.js
|
@ -136,7 +136,7 @@ exports.compileToBrowserify = function(options, bundler) {
|
||||||
addInstructionsToBrowserify(compile(options), bundler);
|
addInstructionsToBrowserify(compile(options), bundler);
|
||||||
};
|
};
|
||||||
|
|
||||||
//-- undocumented low-level API --//
|
/*-- undocumented low-level API --*/
|
||||||
|
|
||||||
exports.ConfigLoader = ConfigLoader;
|
exports.ConfigLoader = ConfigLoader;
|
||||||
exports.compile = compile;
|
exports.compile = compile;
|
||||||
|
|
|
@ -22,7 +22,7 @@ var Module = require('module');
|
||||||
module.exports = function compile(options) {
|
module.exports = function compile(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if(typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = { appRootDir: options };
|
options = { appRootDir: options };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ module.exports = function compile(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function assertIsValidConfig(name, config) {
|
function assertIsValidConfig(name, config) {
|
||||||
if(config) {
|
if (config) {
|
||||||
assert(typeof config === 'object',
|
assert(typeof config === 'object',
|
||||||
name + ' config must be a valid JSON object');
|
name + ' config must be a valid JSON object');
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ function findScripts(dir) {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
path.join(require.resolve(filepath));
|
path.join(require.resolve(filepath));
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
debug('Skipping directory %s - %s', filepath, err.code || err);
|
debug('Skipping directory %s - %s', filepath, err.code || err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ function findScripts(dir) {
|
||||||
function tryReadDir() {
|
function tryReadDir() {
|
||||||
try {
|
try {
|
||||||
return fs.readdirSync.apply(fs, arguments);
|
return fs.readdirSync.apply(fs, arguments);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,9 @@ function loadModelDefinition(rootDir, jsonFile, allFiles) {
|
||||||
var basename = path.basename(jsonFile, path.extname(jsonFile));
|
var basename = path.basename(jsonFile, path.extname(jsonFile));
|
||||||
|
|
||||||
// find a matching file with a supported extension like `.js` or `.coffee`
|
// find a matching file with a supported extension like `.js` or `.coffee`
|
||||||
var base, ext, validFileType;
|
var base;
|
||||||
|
var ext;
|
||||||
|
var validFileType;
|
||||||
var sourceFile = allFiles
|
var sourceFile = allFiles
|
||||||
.filter(function(f) {
|
.filter(function(f) {
|
||||||
ext = path.extname(f);
|
ext = path.extname(f);
|
||||||
|
|
|
@ -103,7 +103,7 @@ function loadConfigFiles(files) {
|
||||||
*/
|
*/
|
||||||
function mergeConfigurations(configObjects, mergeFn) {
|
function mergeConfigurations(configObjects, mergeFn) {
|
||||||
var result = configObjects.shift() || {};
|
var result = configObjects.shift() || {};
|
||||||
while(configObjects.length) {
|
while (configObjects.length) {
|
||||||
var next = configObjects.shift();
|
var next = configObjects.shift();
|
||||||
mergeFn(result, next, next._filename);
|
mergeFn(result, next, next._filename);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ function mergeArrays(target, config, keyPrefix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use for(;;) to iterate over undefined items, for(in) would skip them.
|
// Use for(;;) to iterate over undefined items, for(in) would skip them.
|
||||||
for (var ix=0; ix < target.length; ix++) {
|
for (var ix = 0; ix < target.length; ix++) {
|
||||||
var fullKey = keyPrefix + '[' + ix + ']';
|
var fullKey = keyPrefix + '[' + ix + ']';
|
||||||
var err = mergeSingleItemOrProperty(target, config, ix, fullKey);
|
var err = mergeSingleItemOrProperty(target, config, ix, fullKey);
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
|
@ -189,15 +189,15 @@ function hasCompatibleType(origValue, newValue) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to read a config file with .json extension
|
* Try to read a config file with .json extension
|
||||||
* @param cwd Dirname of the file
|
* @param {string} cwd Dirname of the file
|
||||||
* @param fileName Name of the file without extension
|
* @param {string} fileName Name of the file without extension
|
||||||
* @returns {Object|undefined} Content of the file, undefined if not found.
|
* @returns {Object|undefined} Content of the file, undefined if not found.
|
||||||
*/
|
*/
|
||||||
function tryReadJsonConfig(cwd, fileName) {
|
function tryReadJsonConfig(cwd, fileName) {
|
||||||
try {
|
try {
|
||||||
return require(path.join(cwd, fileName + '.json'));
|
return require(path.join(cwd, fileName + '.json'));
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
if(e.code !== 'MODULE_NOT_FOUND') {
|
if (e.code !== 'MODULE_NOT_FOUND') {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,10 @@ function patchAppLoopback(app) {
|
||||||
// patch the app object to make loopback-boot work with older versions too
|
// patch the app object to make loopback-boot work with older versions too
|
||||||
try {
|
try {
|
||||||
app.loopback = require('loopback');
|
app.loopback = require('loopback');
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
if (err.code === 'MODULE_NOT_FOUND') {
|
if (err.code === 'MODULE_NOT_FOUND') {
|
||||||
console.error(
|
console.error(
|
||||||
'When using loopback-boot with loopback <1.9, '+
|
'When using loopback-boot with loopback <1.9, ' +
|
||||||
'the loopback module must be available for `require(\'loopback\')`.');
|
'the loopback module must be available for `require(\'loopback\')`.');
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -69,7 +69,7 @@ function assertLoopBackVersion(app) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setHost(app, instructions) {
|
function setHost(app, instructions) {
|
||||||
//jshint camelcase:false
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||||
var host =
|
var host =
|
||||||
process.env.npm_config_host ||
|
process.env.npm_config_host ||
|
||||||
process.env.OPENSHIFT_SLS_IP ||
|
process.env.OPENSHIFT_SLS_IP ||
|
||||||
|
@ -79,14 +79,14 @@ function setHost(app, instructions) {
|
||||||
process.env.npm_package_config_host ||
|
process.env.npm_package_config_host ||
|
||||||
app.get('host');
|
app.get('host');
|
||||||
|
|
||||||
if(host !== undefined) {
|
if (host !== undefined) {
|
||||||
assert(typeof host === 'string', 'app.host must be a string');
|
assert(typeof host === 'string', 'app.host must be a string');
|
||||||
app.set('host', host);
|
app.set('host', host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPort(app, instructions) {
|
function setPort(app, instructions) {
|
||||||
//jshint camelcase:false
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||||
var port = _.find([
|
var port = _.find([
|
||||||
process.env.npm_config_port,
|
process.env.npm_config_port,
|
||||||
process.env.OPENSHIFT_SLS_PORT,
|
process.env.OPENSHIFT_SLS_PORT,
|
||||||
|
@ -98,7 +98,7 @@ function setPort(app, instructions) {
|
||||||
3000
|
3000
|
||||||
], _.isFinite);
|
], _.isFinite);
|
||||||
|
|
||||||
if(port !== undefined) {
|
if (port !== undefined) {
|
||||||
var portType = typeof port;
|
var portType = typeof port;
|
||||||
assert(portType === 'string' || portType === 'number',
|
assert(portType === 'string' || portType === 'number',
|
||||||
'app.port must be a string or number');
|
'app.port must be a string or number');
|
||||||
|
@ -122,9 +122,9 @@ function setApiRoot(app, instructions) {
|
||||||
|
|
||||||
function applyAppConfig(app, instructions) {
|
function applyAppConfig(app, instructions) {
|
||||||
var appConfig = instructions.config;
|
var appConfig = instructions.config;
|
||||||
for(var configKey in appConfig) {
|
for (var configKey in appConfig) {
|
||||||
var cur = app.get(configKey);
|
var cur = app.get(configKey);
|
||||||
if(cur === undefined || cur === null) {
|
if (cur === undefined || cur === null) {
|
||||||
app.set(configKey, appConfig[configKey]);
|
app.set(configKey, appConfig[configKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ function isBuiltinLoopBackModel(app, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function forEachKeyedObject(obj, fn) {
|
function forEachKeyedObject(obj, fn) {
|
||||||
if(typeof obj !== 'object') return;
|
if (typeof obj !== 'object') return;
|
||||||
|
|
||||||
Object.keys(obj).forEach(function(key) {
|
Object.keys(obj).forEach(function(key) {
|
||||||
fn(key, obj[key]);
|
fn(key, obj[key]);
|
||||||
|
@ -240,8 +240,8 @@ function runScripts(app, list, callback) {
|
||||||
function tryRequire(modulePath) {
|
function tryRequire(modulePath) {
|
||||||
try {
|
try {
|
||||||
return require.apply(this, arguments);
|
return require.apply(this, arguments);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
if(e.code === 'MODULE_NOT_FOUND') {
|
if (e.code === 'MODULE_NOT_FOUND') {
|
||||||
debug('Warning: cannot require %s - module not found.', modulePath);
|
debug('Warning: cannot require %s - module not found.', modulePath);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"browser": "browser.js",
|
"browser": "browser.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "jshint .",
|
"pretest": "jscs . && jshint .",
|
||||||
"test": "mocha"
|
"test": "mocha"
|
||||||
},
|
},
|
||||||
"license": {
|
"license": {
|
||||||
|
@ -37,6 +37,7 @@
|
||||||
"coffee-script": "^1.8.0",
|
"coffee-script": "^1.8.0",
|
||||||
"coffeeify": "^0.7.0",
|
"coffeeify": "^0.7.0",
|
||||||
"fs-extra": "^0.12.0",
|
"fs-extra": "^0.12.0",
|
||||||
|
"jscs": "^1.7.3",
|
||||||
"jshint": "^2.5.6",
|
"jshint": "^2.5.6",
|
||||||
"loopback": "^2.5.0",
|
"loopback": "^2.5.0",
|
||||||
"mocha": "^1.19.0",
|
"mocha": "^1.19.0",
|
||||||
|
|
|
@ -76,7 +76,7 @@ describe('browser support', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function browserifyTestApp(appDir, strategy, next) {
|
function browserifyTestApp(appDir, strategy, next) {
|
||||||
//set default args
|
// set default args
|
||||||
if (((typeof strategy) === 'function') && !next) {
|
if (((typeof strategy) === 'function') && !next) {
|
||||||
next = strategy;
|
next = strategy;
|
||||||
strategy = undefined;
|
strategy = undefined;
|
||||||
|
|
|
@ -12,7 +12,10 @@ describe('compiler', function() {
|
||||||
beforeEach(appdir.init);
|
beforeEach(appdir.init);
|
||||||
|
|
||||||
describe('from options', function() {
|
describe('from options', function() {
|
||||||
var options, instructions, appConfig;
|
var options;
|
||||||
|
var instructions;
|
||||||
|
var appConfig;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
options = {
|
options = {
|
||||||
config: {
|
config: {
|
||||||
|
@ -256,7 +259,7 @@ describe('compiler', function() {
|
||||||
appdir.writeConfigFileSync('config.local.json', {
|
appdir.writeConfigFileSync('config.local.json', {
|
||||||
toplevel: [
|
toplevel: [
|
||||||
{
|
{
|
||||||
nested: [ 'value' ]
|
nested: ['value']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -337,7 +340,7 @@ describe('compiler', function() {
|
||||||
appConfigRootDir: path.resolve(appdir.PATH, 'custom')
|
appConfigRootDir: path.resolve(appdir.PATH, 'custom')
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(instructions.config).to.have.property('port');
|
expect(instructions.config).to.have.property('port');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports `dsRootDir` option', function() {
|
it('supports `dsRootDir` option', function() {
|
||||||
|
|
|
@ -171,7 +171,7 @@ describe('executor', function() {
|
||||||
};
|
};
|
||||||
builtinModel.definition.redefined = true;
|
builtinModel.definition.redefined = true;
|
||||||
|
|
||||||
boot.execute(app, someInstructions({ models: [ builtinModel ] }));
|
boot.execute(app, someInstructions({ models: [builtinModel] }));
|
||||||
|
|
||||||
expect(app.models.User.settings.redefined, 'redefined').to.not.equal(true);
|
expect(app.models.User.settings.redefined, 'redefined').to.not.equal(true);
|
||||||
});
|
});
|
||||||
|
@ -266,7 +266,7 @@ describe('executor', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prioritize sources', function() {
|
it('should prioritize sources', function() {
|
||||||
/*jshint camelcase:false */
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||||
process.env.npm_config_host = randomHost();
|
process.env.npm_config_host = randomHost();
|
||||||
process.env.OPENSHIFT_SLS_IP = randomHost();
|
process.env.OPENSHIFT_SLS_IP = randomHost();
|
||||||
process.env.OPENSHIFT_NODEJS_IP = randomHost();
|
process.env.OPENSHIFT_NODEJS_IP = randomHost();
|
||||||
|
@ -323,12 +323,11 @@ describe('executor', function() {
|
||||||
'module.exports = function(app) { app.fnCalled = true; };');
|
'module.exports = function(app) { app.fnCalled = true; };');
|
||||||
|
|
||||||
delete app.fnCalled;
|
delete app.fnCalled;
|
||||||
boot.execute(app, someInstructions({ files: { boot: [ file ] } }));
|
boot.execute(app, someInstructions({ files: { boot: [file] } }));
|
||||||
expect(app.fnCalled, 'exported fn was called').to.be.true();
|
expect(app.fnCalled, 'exported fn was called').to.be.true();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function assertValidDataSource(dataSource) {
|
function assertValidDataSource(dataSource) {
|
||||||
// has methods
|
// has methods
|
||||||
assert.isFunc(dataSource, 'createModel');
|
assert.isFunc(dataSource, 'createModel');
|
||||||
|
@ -340,7 +339,7 @@ function assertValidDataSource(dataSource) {
|
||||||
assert.isFunc(dataSource, 'operations');
|
assert.isFunc(dataSource, 'operations');
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.isFunc = function (obj, name) {
|
assert.isFunc = function(obj, name) {
|
||||||
assert(obj, 'cannot assert function ' + name +
|
assert(obj, 'cannot assert function ' + name +
|
||||||
' on object that does not exist');
|
' on object that does not exist');
|
||||||
assert(typeof obj[name] === 'function', name + ' is not a function');
|
assert(typeof obj[name] === 'function', name + ' is not a function');
|
||||||
|
|
|
@ -2,4 +2,3 @@ process.bootFlags.push('barSyncLoaded');
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
process.bootFlags.push('barSyncExecuted');
|
process.bootFlags.push('barSyncExecuted');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue