Skip to content

fix lint errors #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.ebextensions
.elasticbeanstalk
coverage
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
"mocha": true
},
"rules": {
"no-param-reassign": 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to use the default settings with eslint-config-airbnb base. Please don't modify the lint rules.

"global-require": 0,
"func-names": 0,
"no-mixed-operators": 0,
"consistent-return": 0,
"no-unused-expressions": 0,
"newline-per-chained-call": 0,
"no-underscore-dangle": 0,
"import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this to
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "**/*.spec.js"]}],

"max-len": ["error", {
"code": 120,
"ignoreComments": true,
"ignoreTrailingComments": true,
"tabWidth": 2
}],
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
Expand Down
56 changes: 28 additions & 28 deletions config/sample.local.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// force using test.json for unit tests

var config
let config;
if (process.env.NODE_ENV === 'test') {
config = require('./test.json')
config = require('./test.json');
} else {
config = {
"authSecret": "secret",
"logLevel": "debug",
"captureLogs": "false",
"logentriesToken": "",
"rabbitmqURL": "amqp://dockerhost:5672",
"fileServiceEndpoint": "https://api.topcoder-dev.com/v3/files/",
"topicServiceEndpoint": "https://api.topcoder-dev.com/v4/topics/",
"directProjectServiceEndpoint": "https://api.topcoder-dev.com/v3/direct",
"userServiceUrl": "https://api.topcoder-dev.com/v3/users",
"connectProjectsUrl": "https://connect.topcoder-dev.com/projects/",
"salesforceLead" : {
"webToLeadUrl": 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
"orgId": "00D2C0000000dO6",
"projectNameFieldId": "title",
"projectDescFieldId": "description",
"projectLinkFieldId": "URL",
"projectIdFieldId" : "00N2C000000Vxxx"
},
"dbConfig": {
"masterUrl": "postgres://coder:mysecretpassword@dockerhost:5432/projectsdb",
"maxPoolSize": 50,
"minPoolSize": 4,
"idleTimeout": 1000
}
}
authSecret: 'secret',
logLevel: 'debug',
captureLogs: 'false',
logentriesToken: '',
rabbitmqURL: 'amqp://dockerhost:5672',
fileServiceEndpoint: 'https://api.topcoder-dev.com/v3/files/',
topicServiceEndpoint: 'https://api.topcoder-dev.com/v4/topics/',
directProjectServiceEndpoint: 'https://api.topcoder-dev.com/v3/direct',
userServiceUrl: 'https://api.topcoder-dev.com/v3/users',
connectProjectsUrl: 'https://connect.topcoder-dev.com/projects/',
salesforceLead: {
webToLeadUrl: 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
orgId: '00D2C0000000dO6',
projectNameFieldId: 'title',
projectDescFieldId: 'description',
projectLinkFieldId: 'URL',
projectIdFieldId: '00N2C000000Vxxx',
},
dbConfig: {
masterUrl: 'postgres://coder:mysecretpassword@dockerhost:5432/projectsdb',
maxPoolSize: 50,
minPoolSize: 4,
idleTimeout: 1000,
},
};
}
module.exports = config
module.exports = config;
16 changes: 8 additions & 8 deletions migrations/sync.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict'

/**
* Sync the database models to db tables.
*/

import winston from 'winston';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using bunyan not winston


/**
* Make sure we are in development mode
* @type {String}
*/
// process.env.NODE_ENV = 'development'

require('./dist/models').default.sequelize.sync({ force: true })
require('../dist/models').default.sequelize.sync({ force: true })
.then(() => {
console.log('Database synced successfully')
process.exit()
winston.info('Database synced successfully');
process.exit();
}).catch((err) => {
console.error('Error syncing database', err)
process.exit(1)
})
winston.error('Error syncing database', err);
process.exit(1);
});
16 changes: 8 additions & 8 deletions newrelic.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'


/**
* New Relic agent configuration.
*
* See lib/config.defaults.js in the agent distribution for a more complete
* description of configuration variables and their potential values.
*/
var appName = "tc-projects-service"
let appName = 'tc-projects-service';
if (process.env.NODE_ENV === 'development') {
appName += "-dev"
appName += '-dev';
} else if (process.env.NODE_ENV === 'qa') {
appName += "-qa"
appName += '-qa';
} else {
appName += '-prod'
appName += '-prod';
}

exports.config = {
Expand All @@ -30,6 +30,6 @@ exports.config = {
* issues with the agent, 'info' and higher will impose the least overhead on
* production applications.
*/
level: 'info'
}
}
level: 'info',
},
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"build": "babel src -d dist --presets es2015",
"sync": "node migrations/sync.js",
"lint": "./node_modules/.bin/eslint src",
"lint": "./node_modules/.bin/eslint .",
"lint:fix": "./node_modules/.bin/eslint . --fix || true",
"prestart": "npm run -s build",
"start": "node dist",
"start:dev": "NODE_ENV=local PORT=8001 nodemon -w src --exec \"babel-node src --presets es2015\" | ./node_modules/.bin/bunyan",
Expand Down Expand Up @@ -47,7 +48,8 @@
"pg": "^4.5.5",
"pg-native": "^1.10.0",
"sequelize": "^3.23.0",
"tc-core-library-js": "^1.0.8"
"tc-core-library-js": "^1.0.8",
"winston": "^2.3.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove winston dependency

},
"devDependencies": {
"babel-cli": "^6.9.0",
Expand Down
4 changes: 1 addition & 3 deletions src/events/projects/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import config from 'config';
import querystring from 'querystring';
import util from '../../util';


/**
* Creates a lead in salesforce for the connect project.
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


import models from './models';

// include newrelic
if (process.env.NODE_ENV !== 'test' && process.env.NODE_ENV !== 'local') {
require('newrelic');
Expand All @@ -11,6 +9,7 @@ const app = require('./app');

/**
* Handle server shutdown gracefully
* @return {Void} This function returns void
*/
function gracefulShutdown() {
app.services.pubsub.disconnect()
Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/checkRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* @version 1.0
*/
import config from 'config';

const util = require('tc-core-library-js').util(config);

module.exports = function (roleName) {
return function (req, res, next) {
if (!req.authUser || !Array.isArray(req.authUser.roles) || req.authUser.roles.indexOf(roleName) == -1) {
if (!req.authUser || !Array.isArray(req.authUser.roles) || req.authUser.roles.indexOf(roleName) === -1) {
return res.status(403)
.json(util.wrapErrorResponse(req.id, 403, 'You are not allowed to perform this action.'));
}
Expand Down
5 changes: 4 additions & 1 deletion src/mocks/addBillingAccount.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable max-len */
import winston from 'winston';

const http = require('https');

const options = {
Expand All @@ -23,7 +26,7 @@ const req = http.request(options, (res) => {

res.on('end', () => {
const body = Buffer.concat(chunks);
console.log(body.toString());
winston.info(body.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use winston logger

});
});
req.write('{\n "billingAccountId": 123456789\n}');
Expand Down
5 changes: 4 additions & 1 deletion src/mocks/addCopilot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable max-len */
import winston from 'winston';

const http = require('https');

const options = {
Expand All @@ -23,7 +26,7 @@ const req = http.request(options, (res) => {

res.on('end', () => {
const body = Buffer.concat(chunks);
console.log(body.toString());
winston.info(body.toString());
});
});
req.write('{\n "copilotUserId": 123456789\n}');
Expand Down
5 changes: 4 additions & 1 deletion src/mocks/createProject.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable max-len */
import winston from 'winston';

const http = require('https');

const options = {
Expand All @@ -23,7 +26,7 @@ const req = http.request(options, (res) => {

res.on('end', () => {
const body = Buffer.concat(chunks);
console.log(body.toString());
winston.info(body.toString());
});
});

Expand Down
57 changes: 30 additions & 27 deletions src/mocks/direct.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@


import express from 'express';
import express, { Router } from 'express';
import _ from 'lodash';
import bodyParser from 'body-parser';
import config from 'config';
import coreLib from 'tc-core-library-js';
import expressRequestId from 'express-request-id';
import Router from 'express';
import https from 'https';
import path from 'path';
import fs from 'fs';
config.version = 'v3';

const util = require('tc-core-library-js').util(config);
const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator;

config.version = 'v3';

const app = express();
app.use(bodyParser.urlencoded({
extended: false,
Expand All @@ -33,10 +36,9 @@ app.use(coreLib.middleware.logger(null, logger));
app.logger = logger;

const router = Router();
const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator;
router.all('/v3/direct/projects*', jwtAuth());

let projectId = 2;
const projectId = 2;
const projects = {
1: {
projectName: 'test direct project1',
Expand All @@ -55,55 +57,56 @@ router.route('/v3/direct/projects')
})
.post((req, res) => {
app.logger.info({ body: req.body }, 'create direct project');
const newId = projectId++;
const newId = projectId + 1;
req.body.id = newId;
projects[newId] = req.body;
res.json(util.wrapResponse(req.id, { projectId: newId }));
});

router.route('/v3/direct/projects/:projectId(\\d+)/billingaccount')
.post((req, res) => {
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'add billingaccount to Project');
if (projects[projectId]) {
projects[projectId] = _.merge(projects[projectId], req.body);
res.json(util.wrapResponse(req.id, { billingAccountName: `mock account name for ${req.body.billingAccountId}` }));
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'add billingaccount to Project');
if (projects[pId]) {
projects[pId] = _.merge(projects[pId], req.body);
res.json(util.wrapResponse(req.id, { billingAccountName: 'mock account name for ' +
`${req.body.billingAccountId}` }));
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
}
});


router.route('/v3/direct/projects/:projectId(\\d+)/copilot')
.post((req, res) => {
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'add copilot to Project');
if (projects[projectId]) {
projects[projectId] = _.merge(projects[projectId], req.body);
res.json(util.wrapResponse(req.id, { copilotProjectId: projectId }));
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'add copilot to Project');
if (projects[pId]) {
projects[pId] = _.merge(projects[pId], req.body);
res.json(util.wrapResponse(req.id, { copilotProjectId: pId }));
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
}
})
.delete((req, res) => {
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'remove copilot from Project');
if (projects[projectId]) {
projects[projectId] = _.omit(projects[projectId], 'copilotUserId');
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'remove copilot from Project');
if (projects[pId]) {
projects[pId] = _.omit(projects[pId], 'copilotUserId');
res.json(util.wrapResponse(req.id, true));
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
}
});

router.route('/v3/direct/projects/:projectId(\\d+)/permissions')
.post((req, res) => {
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'add permissions to Project');
if (projects[projectId]) {
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'add permissions to Project');
if (projects[pId]) {
res.json();
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
}
});

Expand Down
Loading