Skip to content

Commit

Permalink
correct a bunch of eslint issues (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo authored and shriramshankar committed Nov 5, 2016
1 parent 517b715 commit 2292ba3
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 88 deletions.
5 changes: 3 additions & 2 deletions api/v1/apiErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ apiErrors.create({
name: 'SubjectValidationError',
parent: apiErrors.ValidationError,
fields: [],
defaultMessage: 'You are not allowed to set the subject\'s absolutePath attribute' +
'directly--it is generated based on the subject\'s name and parent.',
defaultMessage: 'You are not allowed to set the subject\'s absolutePath ' +
'attribute directly--it is generated based on the subject\'s name and ' +
'parent.',
});

// ----------------------------------------------------------------------------
Expand Down
38 changes: 8 additions & 30 deletions api/v1/controllers/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,52 +123,30 @@ module.exports = {
logAPI(req, helper.modelName, o);
}

return res.status(httpStatus.OK).json(u.responsify(o, helper, req.method));
return res.status(httpStatus.OK)
.json(u.responsify(o, helper, req.method));
})
.catch((err) => u.handleError(next, err, helper.modelName));
},

/**
* POST /samples/upsert/bulk
*
* Upserts multiple samples. Response will contain the number of successful
* upserts, the number of failed upserts, and an array of errors for the
* failed upserts.
* Upserts multiple samples. Returns "OK" without waiting for the upserts to
* happen.
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
* @returns {ServerResponse} - The response object indicating merely that the
* bulk upsert request has been received.
*/
bulkUpsertSample(req, res, next) {
// UNPROMISIFY THIS FUNCTION TO RETURN THE RESPONSE IMMEDIATELY!

/*
const retval = {
successCount: 0,
failureCount: 0,
errors: [],
};
*/

bulkUpsertSample(req, res /* , next */) {
helper.model.bulkUpsertByName(req.swagger.params.queryBody.value);
if (helper.loggingEnabled) {
logAPI(req, helper.modelName);
}

return res.status(httpStatus.OK).json({ 'status': 'OK' });

/*
.each((o) => {
if (util.isError(o)) {
retval.failureCount++;
retval.errors.push(o);
} else {
retval.successCount++;
}
})
.then((o) => res.status(200).json(retval)) // TODO add apiLinks!
.catch((err) => u.handleError(next, err, helper.modelName));
*/
return res.status(httpStatus.OK).json({ status: 'OK' });
},

/**
Expand Down
6 changes: 3 additions & 3 deletions api/v1/controllers/subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = {
*/
patchSubject(req, res, next) {
if (req.body.absolutePath) {
throw new apiErrors.SubjectValidationError;
throw new apiErrors.SubjectValidationError();
}

doPatch(req, res, next, helper);
Expand All @@ -144,7 +144,7 @@ module.exports = {
*/
postSubject(req, res, next) {
if (req.body.absolutePath) {
throw new apiErrors.SubjectValidationError;
throw new apiErrors.SubjectValidationError();
}

doPost(req, res, next, helper);
Expand Down Expand Up @@ -187,7 +187,7 @@ module.exports = {
*/
putSubject(req, res, next) {
if (req.body.absolutePath) {
throw new apiErrors.SubjectValidationError;
throw new apiErrors.SubjectValidationError();
}

doPut(req, res, next, helper);
Expand Down
7 changes: 4 additions & 3 deletions api/v1/helpers/nouns/subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ function applyTagFilters(keys, filterBy) {
if (!filters[filterBy].includes || !filters[filterBy].excludes) {
return true;
}

// When tags are not present, no filters are applied to it.
if (keys.length === 0) {
if (!keys.length) {
return false;
}

let isPartOfInFilter = false;
let isPartOfNotInFilter = false;

// check if the elements of keys are part of the "includes" filter
for (let i = 0; i < keys.length; i++) {

if (filters[filterBy].includes.has(keys[i].toLowerCase())) {
isPartOfInFilter = true;
break;
Expand All @@ -131,7 +132,6 @@ function applyTagFilters(keys, filterBy) {

// check if the elements of keys are part of the "excludes" filter
for (let i = 0; i < keys.length; i++) {

if (filters[filterBy].excludes.has(keys[i].toLowerCase())) {
isPartOfNotInFilter = true;
break;
Expand Down Expand Up @@ -184,6 +184,7 @@ function applyFilters(key, filterBy) {
!filters[filterBy].excludes.has(key.toLowerCase())) {
return true;
}

// If the entity is present in the includes filter clause return true.
if (filters[filterBy].includes.has(key.toLowerCase())) {
return true;
Expand Down
12 changes: 6 additions & 6 deletions api/v1/helpers/verbs/findUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ function toSequelizeWhere(filter, props) {

const values = [];

// if tag filter is enabled and key is "tags", then create a contains
// clause and add it to where clause,
// like, { where : { '$contains': ['tag1', 'tag2'] } }
/*
* If tag filter is enabled and key is "tags", then create a "contains"
* clause and add it to where clause, e.g.
* { where : { '$contains': ['tag1', 'tag2'] } }
*/
if (props.tagFilterName && key === props.tagFilterName) {
const tagArr = filter[key];
values.push(toWhereClause(tagArr, props));
Expand Down Expand Up @@ -131,11 +133,9 @@ function toSequelizeWhere(filter, props) {
* a Sequelize "order" array of arrays.
*
* @param {Array|String} sortOrder - The sort order to transform
* @param {String} modelName - The DB model name, used to disambiguate field
* names
* @returns {Array} a Sequelize "order" array of arrays
*/
function toSequelizeOrder(sortOrder, modelName) {
function toSequelizeOrder(sortOrder) {
if (sortOrder) {
const sortOrderArray = Array.isArray(sortOrder) ?
sortOrder : [sortOrder];
Expand Down
21 changes: 11 additions & 10 deletions api/v1/helpers/verbs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ const constants = require('../../constants');
const commonDbUtil = require('../../../../db/helpers/common');

/**
* This functions adds the association scope name to the as the to all
* This function adds the association scope name to the as the to all
* the elements of the associaton array
* @param {Array} assocArry - The array of association objects that are
* to be created
* @param {Module} props - The module containing the properties of the
*
* @param {Array} associations - The array of association objects that are
* to be created
* @param {Object} props - The module containing the properties of the
* resource type to post
*/
function addAssociationScope(assocArry, props) {
assocArry.map((o) =>
o.associatedModelName = props.modelName
);
function addAssociationScope(associations, props) {
associations.map((o) => {
o.associatedModelName = props.modelName;
});
} // addAssociationScope

/**
Expand Down Expand Up @@ -433,12 +434,12 @@ function cleanAndStripNulls(obj) {

// if undefined, parentAbsolutePath needs to be set to empty string,
// to pass swagger's schema validation
if (key == 'parentAbsolutePath' && !o[key]) {
if (key === 'parentAbsolutePath' && !o[key]) {
o[key] = '';
} else if (o[key] === undefined || o[key] === null) {
delete o[key];
} else if (Array.isArray(o[key])) {
o[key] = o[key].map((i) => cleanAndStripNulls(i));
o[key] = o[key].map((j) => cleanAndStripNulls(j));
} else if (typeof o[key] === 'object') {
o[key] = cleanAndStripNulls(o[key]);
}
Expand Down
3 changes: 1 addition & 2 deletions clock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*
* Main module to start the clock process. To just start the clock process,
* use "npm run start-clock". To start both the web and the clock process
* locally, use "heroku local"
* locally, use "heroku local".
*/
const featureToggles = require('feature-toggles');
const conf = require('../config');
const env = conf.environment[conf.nodeEnv];

const dbSample = require('../db/index').Sample;

if (featureToggles.isFeatureEnabled('enableClockDyno')) {
Expand Down
17 changes: 13 additions & 4 deletions db/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
/**
* ./db/utils.js
*
* Provides utility functions to parse the DB URL and to determine
* whether or not the db is in a Heroku Private Space.
*
* Provides utility functions to parse the DB URL and initialize the admin
* user and profile.
*/
const url = require('url');
const conf = require('../config');
const env = conf.environment[conf.nodeEnv];
const DB_URL = env.dbUrl;

// create dbconfig object from DB URL
/**
* Create a dbconfig object from the DB URL.
*
* @returns {Object} - dbconfig
*/
function dbConfigObjectFromDbURL() {
const u = url.parse(DB_URL);
const auth = u.auth.split(':');
Expand All @@ -31,6 +34,12 @@ function dbConfigObjectFromDbURL() {
};
} // dbConfigObjectFromDbURL

/**
* Initialize Admin User and Profile.
*
* @param {Object} seq - Sequelize
* @returns {Promise}
*/
function initializeAdminUserAndProfile(seq) {
var pid;
return seq.models.Profile.upsert(conf.db.adminProfile)
Expand Down
9 changes: 8 additions & 1 deletion passportconfig.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/**
* Copyright (c) 2016, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* ./passport.js
* Passport strategies
*/

const LocalStrategy = require('passport-local').Strategy;
const User = require('./db/index').User;
const Profile = require('./db/index').Profile;
Expand Down
4 changes: 2 additions & 2 deletions pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const redis = require('redis');
const conf = require('./config');
const env = conf.environment[conf.nodeEnv];

const pub = redis.createClient(env.redisUrl);;
const sub = redis.createClient(env.redisUrl);;
const pub = redis.createClient(env.redisUrl);
const sub = redis.createClient(env.redisUrl);

sub.subscribe(conf.redis.channelName);

Expand Down
3 changes: 1 addition & 2 deletions utils/loggingUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*
* Utility for Audit logs
*/

'use strict' // eslint-disable-line strict
'use strict'; // eslint-disable-line strict
const winston = require('winston');

/**
Expand Down
50 changes: 27 additions & 23 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

'use strict';

const pe = process.env; // eslint-disable-line no-process-env
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
Expand All @@ -16,44 +15,49 @@ module.exports = {
devtool: 'eval-source-map',
entry: [
'webpack-hot-middleware/client?reload=true',
path.join(__dirname, 'view/perspective/app.js')
path.join(__dirname, 'view/perspective/app.js'),
],
output: {
path: path.join(__dirname, '/public/perspective/'),
filename: 'app.js',
publicPath: '/perspective'
publicPath: '/perspective',
},
plugins: [
new HtmlWebpackPlugin({
template: 'view/perspective/perspective.pug',
inject: 'body',
filename: 'index.html',
googleAnalytics: {
trackingId: process.env.GOOGLE_ANALYTICS_ID || 'N/A',
pageViewOnLoad: true
trackingId: pe.GOOGLE_ANALYTICS_ID || 'N/A',
pageViewOnLoad: true,
},
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
"presets": ["react", "es2015", "stage-0", "react-hmre"]
}
}, {
test: /\.json?$/,
loader: 'json'
}, {
test: /\.css$/,
loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
}]
}
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-0', 'react-hmre'],
},
},
{
test: /\.json?$/,
loader: 'json',
},
{
test: /\.css$/,
loader:
'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]',
},
],
},
};

0 comments on commit 2292ba3

Please sign in to comment.