Skip to content

Commit 4a699bf

Browse files
Ritesh Sangwanparthshah
Ritesh Sangwan
authored andcommitted
fix lint errors (#46)
1 parent 87f0527 commit 4a699bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+300
-258
lines changed

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
.ebextensions
4+
.elasticbeanstalk
5+
coverage

.eslintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
"mocha": true
99
},
1010
"rules": {
11+
"no-param-reassign": 0,
12+
"global-require": 0,
13+
"func-names": 0,
14+
"no-mixed-operators": 0,
15+
"consistent-return": 0,
16+
"no-unused-expressions": 0,
17+
"newline-per-chained-call": 0,
18+
"no-underscore-dangle": 0,
19+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}],
20+
"max-len": ["error", {
21+
"code": 120,
22+
"ignoreComments": true,
23+
"ignoreTrailingComments": true,
24+
"tabWidth": 2
25+
}],
1126
"valid-jsdoc": ["error", {
1227
"requireReturn": true,
1328
"requireReturnType": true,

config/sample.local.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
// force using test.json for unit tests
22

3-
var config
3+
let config;
44
if (process.env.NODE_ENV === 'test') {
5-
config = require('./test.json')
5+
config = require('./test.json');
66
} else {
77
config = {
8-
"authSecret": "secret",
9-
"logLevel": "debug",
10-
"captureLogs": "false",
11-
"logentriesToken": "",
12-
"rabbitmqURL": "amqp://dockerhost:5672",
13-
"fileServiceEndpoint": "https://api.topcoder-dev.com/v3/files/",
14-
"topicServiceEndpoint": "https://api.topcoder-dev.com/v4/topics/",
15-
"directProjectServiceEndpoint": "https://api.topcoder-dev.com/v3/direct",
16-
"userServiceUrl": "https://api.topcoder-dev.com/v3/users",
17-
"connectProjectsUrl": "https://connect.topcoder-dev.com/projects/",
18-
"salesforceLead" : {
19-
"webToLeadUrl": 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
20-
"orgId": "00D2C0000000dO6",
21-
"projectNameFieldId": "title",
22-
"projectDescFieldId": "description",
23-
"projectLinkFieldId": "URL",
24-
"projectIdFieldId" : "00N2C000000Vxxx"
25-
},
26-
"dbConfig": {
27-
"masterUrl": "postgres://coder:mysecretpassword@dockerhost:5432/projectsdb",
28-
"maxPoolSize": 50,
29-
"minPoolSize": 4,
30-
"idleTimeout": 1000
31-
}
32-
}
8+
authSecret: 'secret',
9+
logLevel: 'debug',
10+
captureLogs: 'false',
11+
logentriesToken: '',
12+
rabbitmqURL: 'amqp://dockerhost:5672',
13+
fileServiceEndpoint: 'https://api.topcoder-dev.com/v3/files/',
14+
topicServiceEndpoint: 'https://api.topcoder-dev.com/v4/topics/',
15+
directProjectServiceEndpoint: 'https://api.topcoder-dev.com/v3/direct',
16+
userServiceUrl: 'https://api.topcoder-dev.com/v3/users',
17+
connectProjectsUrl: 'https://connect.topcoder-dev.com/projects/',
18+
salesforceLead: {
19+
webToLeadUrl: 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
20+
orgId: '00D2C0000000dO6',
21+
projectNameFieldId: 'title',
22+
projectDescFieldId: 'description',
23+
projectLinkFieldId: 'URL',
24+
projectIdFieldId: '00N2C000000Vxxx',
25+
},
26+
dbConfig: {
27+
masterUrl: 'postgres://coder:mysecretpassword@dockerhost:5432/projectsdb',
28+
maxPoolSize: 50,
29+
minPoolSize: 4,
30+
idleTimeout: 1000,
31+
},
32+
};
3333
}
34-
module.exports = config
34+
module.exports = config;

migrations/sync.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
'use strict'
2-
31
/**
42
* Sync the database models to db tables.
53
*/
64

5+
import winston from 'winston';
6+
77
/**
88
* Make sure we are in development mode
99
* @type {String}
1010
*/
1111
// process.env.NODE_ENV = 'development'
1212

13-
require('./dist/models').default.sequelize.sync({ force: true })
13+
require('../dist/models').default.sequelize.sync({ force: true })
1414
.then(() => {
15-
console.log('Database synced successfully')
16-
process.exit()
15+
winston.info('Database synced successfully');
16+
process.exit();
1717
}).catch((err) => {
18-
console.error('Error syncing database', err)
19-
process.exit(1)
20-
})
18+
winston.error('Error syncing database', err);
19+
process.exit(1);
20+
});

newrelic.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
'use strict'
1+
22

33
/**
44
* New Relic agent configuration.
55
*
66
* See lib/config.defaults.js in the agent distribution for a more complete
77
* description of configuration variables and their potential values.
88
*/
9-
var appName = "tc-projects-service"
9+
let appName = 'tc-projects-service';
1010
if (process.env.NODE_ENV === 'development') {
11-
appName += "-dev"
11+
appName += '-dev';
1212
} else if (process.env.NODE_ENV === 'qa') {
13-
appName += "-qa"
13+
appName += '-qa';
1414
} else {
15-
appName += '-prod'
15+
appName += '-prod';
1616
}
1717

1818
exports.config = {
@@ -30,6 +30,6 @@ exports.config = {
3030
* issues with the agent, 'info' and higher will impose the least overhead on
3131
* production applications.
3232
*/
33-
level: 'info'
34-
}
35-
}
33+
level: 'info',
34+
},
35+
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"scripts": {
1010
"build": "babel src -d dist --presets es2015",
1111
"sync": "node migrations/sync.js",
12-
"lint": "./node_modules/.bin/eslint src",
12+
"lint": "./node_modules/.bin/eslint .",
13+
"lint:fix": "./node_modules/.bin/eslint . --fix || true",
1314
"prestart": "npm run -s build",
1415
"start": "node dist",
1516
"start:dev": "NODE_ENV=local PORT=8001 nodemon -w src --exec \"babel-node src --presets es2015\" | ./node_modules/.bin/bunyan",
@@ -47,7 +48,8 @@
4748
"pg": "^4.5.5",
4849
"pg-native": "^1.10.0",
4950
"sequelize": "^3.23.0",
50-
"tc-core-library-js": "^1.0.8"
51+
"tc-core-library-js": "^1.0.8",
52+
"winston": "^2.3.1"
5153
},
5254
"devDependencies": {
5355
"babel-cli": "^6.9.0",

src/events/projects/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import config from 'config';
2-
import querystring from 'querystring';
3-
import util from '../../util';
1+
42

53
/**
64
* Creates a lead in salesforce for the connect project.

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

22

3-
import models from './models';
4-
53
// include newrelic
64
if (process.env.NODE_ENV !== 'test' && process.env.NODE_ENV !== 'local') {
75
require('newrelic');
@@ -11,6 +9,7 @@ const app = require('./app');
119

1210
/**
1311
* Handle server shutdown gracefully
12+
* @return {Void} This function returns void
1413
*/
1514
function gracefulShutdown() {
1615
app.services.pubsub.disconnect()

src/middlewares/checkRole.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
* @version 1.0
88
*/
99
import config from 'config';
10+
1011
const util = require('tc-core-library-js').util(config);
1112

1213
module.exports = function (roleName) {
1314
return function (req, res, next) {
14-
if (!req.authUser || !Array.isArray(req.authUser.roles) || req.authUser.roles.indexOf(roleName) == -1) {
15+
if (!req.authUser || !Array.isArray(req.authUser.roles) || req.authUser.roles.indexOf(roleName) === -1) {
1516
return res.status(403)
1617
.json(util.wrapErrorResponse(req.id, 403, 'You are not allowed to perform this action.'));
1718
}

src/mocks/addBillingAccount.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable max-len */
2+
import winston from 'winston';
3+
14
const http = require('https');
25

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

2427
res.on('end', () => {
2528
const body = Buffer.concat(chunks);
26-
console.log(body.toString());
29+
winston.info(body.toString());
2730
});
2831
});
2932
req.write('{\n "billingAccountId": 123456789\n}');

src/mocks/addCopilot.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable max-len */
2+
import winston from 'winston';
3+
14
const http = require('https');
25

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

2427
res.on('end', () => {
2528
const body = Buffer.concat(chunks);
26-
console.log(body.toString());
29+
winston.info(body.toString());
2730
});
2831
});
2932
req.write('{\n "copilotUserId": 123456789\n}');

src/mocks/createProject.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable max-len */
2+
import winston from 'winston';
3+
14
const http = require('https');
25

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

2427
res.on('end', () => {
2528
const body = Buffer.concat(chunks);
26-
console.log(body.toString());
29+
winston.info(body.toString());
2730
});
2831
});
2932

src/mocks/direct.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11

22

3-
import express from 'express';
3+
import express, { Router } from 'express';
44
import _ from 'lodash';
55
import bodyParser from 'body-parser';
66
import config from 'config';
77
import coreLib from 'tc-core-library-js';
88
import expressRequestId from 'express-request-id';
9-
import Router from 'express';
109
import https from 'https';
1110
import path from 'path';
1211
import fs from 'fs';
13-
config.version = 'v3';
12+
1413
const util = require('tc-core-library-js').util(config);
14+
const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator;
15+
16+
config.version = 'v3';
17+
1518
const app = express();
1619
app.use(bodyParser.urlencoded({
1720
extended: false,
@@ -33,10 +36,9 @@ app.use(coreLib.middleware.logger(null, logger));
3336
app.logger = logger;
3437

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

39-
let projectId = 2;
41+
const projectId = 2;
4042
const projects = {
4143
1: {
4244
projectName: 'test direct project1',
@@ -55,55 +57,56 @@ router.route('/v3/direct/projects')
5557
})
5658
.post((req, res) => {
5759
app.logger.info({ body: req.body }, 'create direct project');
58-
const newId = projectId++;
60+
const newId = projectId + 1;
5961
req.body.id = newId;
6062
projects[newId] = req.body;
6163
res.json(util.wrapResponse(req.id, { projectId: newId }));
6264
});
6365

6466
router.route('/v3/direct/projects/:projectId(\\d+)/billingaccount')
6567
.post((req, res) => {
66-
const projectId = req.params.projectId;
67-
app.logger.info({ body: req.body, projectId }, 'add billingaccount to Project');
68-
if (projects[projectId]) {
69-
projects[projectId] = _.merge(projects[projectId], req.body);
70-
res.json(util.wrapResponse(req.id, { billingAccountName: `mock account name for ${req.body.billingAccountId}` }));
68+
const pId = req.params.projectId;
69+
app.logger.info({ body: req.body, pId }, 'add billingaccount to Project');
70+
if (projects[pId]) {
71+
projects[pId] = _.merge(projects[pId], req.body);
72+
res.json(util.wrapResponse(req.id, { billingAccountName: 'mock account name for ' +
73+
`${req.body.billingAccountId}` }));
7174
} else {
72-
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
75+
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
7376
}
7477
});
7578

7679

7780
router.route('/v3/direct/projects/:projectId(\\d+)/copilot')
7881
.post((req, res) => {
79-
const projectId = req.params.projectId;
80-
app.logger.info({ body: req.body, projectId }, 'add copilot to Project');
81-
if (projects[projectId]) {
82-
projects[projectId] = _.merge(projects[projectId], req.body);
83-
res.json(util.wrapResponse(req.id, { copilotProjectId: projectId }));
82+
const pId = req.params.projectId;
83+
app.logger.info({ body: req.body, pId }, 'add copilot to Project');
84+
if (projects[pId]) {
85+
projects[pId] = _.merge(projects[pId], req.body);
86+
res.json(util.wrapResponse(req.id, { copilotProjectId: pId }));
8487
} else {
85-
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
88+
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
8689
}
8790
})
8891
.delete((req, res) => {
89-
const projectId = req.params.projectId;
90-
app.logger.info({ body: req.body, projectId }, 'remove copilot from Project');
91-
if (projects[projectId]) {
92-
projects[projectId] = _.omit(projects[projectId], 'copilotUserId');
92+
const pId = req.params.projectId;
93+
app.logger.info({ body: req.body, pId }, 'remove copilot from Project');
94+
if (projects[pId]) {
95+
projects[pId] = _.omit(projects[pId], 'copilotUserId');
9396
res.json(util.wrapResponse(req.id, true));
9497
} else {
95-
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
98+
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
9699
}
97100
});
98101

99102
router.route('/v3/direct/projects/:projectId(\\d+)/permissions')
100103
.post((req, res) => {
101-
const projectId = req.params.projectId;
102-
app.logger.info({ body: req.body, projectId }, 'add permissions to Project');
103-
if (projects[projectId]) {
104+
const pId = req.params.projectId;
105+
app.logger.info({ body: req.body, pId }, 'add permissions to Project');
106+
if (projects[pId]) {
104107
res.json();
105108
} else {
106-
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
109+
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
107110
}
108111
});
109112

0 commit comments

Comments
 (0)