Skip to content

Commit

Permalink
Convert codebase to ES6 (#1126)
Browse files Browse the repository at this point in the history
* Convert all code (server and client) to ES6:
  * Manually fix a few var → let/const situations
  * Remove [`use strict`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) using https://github.com/5to6/5to6-codemod and enable `no-strict` rule
  * Convert `var` → `const`/`let` (using `eslint --fix` and a few manual fixes)
  * Other things that `eslint --fix` can do
* Reorganise testutils to server and client subfolders for easier linting via separate server & client side overrides
* Update Eslint config:
  *  Lint everything as es6
  * Refactor to be more specific for each override section; each section has their own globals instead of keeping them together for the whole app
  * Separate client-side and server-side, as well tests and app files.
  *  Use `eslint:recommended` as a base; remove rules in our custom set which would be duplicate with recommended.
  * Add `one-var` linter rule since we're already touching all these lines. This should make e.g. automatically replacing require→import easier later on.
   * Removed all redundant Eslint disabled rules
  • Loading branch information
simison authored Dec 4, 2019
1 parent 5f7cc35 commit 84d34ce
Show file tree
Hide file tree
Showing 352 changed files with 3,017 additions and 3,823 deletions.
371 changes: 181 additions & 190 deletions .eslintrc.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions bin/admin/trshell.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

// Ensuring that we're in the right directory
process.chdir(__dirname);
process.chdir('../../');
Expand Down
2 changes: 1 addition & 1 deletion bin/db-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (process.env.NODE_ENV === 'production') {
}

// Use mongoose configuration
var mongooseService = require('../config/lib/mongoose.js');
const mongooseService = require('../config/lib/mongoose.js');

mongooseService.connect(function (db) {
mongooseService.dropDatabase(db, function () {
Expand Down
37 changes: 18 additions & 19 deletions bin/db-maintenance/archive-done-agenda-jobs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
'use strict';

/**
* Archive done Agenda jobs from `agendaJobs` collection by moving them
Expand All @@ -16,23 +15,23 @@
* npm run agenda-maintenance -- reverse
*/

var MongoClient = require('mongodb').MongoClient,
path = require('path'),
chalk = require('chalk'),
async = require('async'),
config = require(path.resolve('./config/config'));
const MongoClient = require('mongodb').MongoClient;
const path = require('path');
const chalk = require('chalk');
const async = require('async');
const config = require(path.resolve('./config/config'));

var dbConnection,
sourceCollection,
targetCollection,
filter = { nextRunAt: null, lockedAt: null },
total;
let dbConnection;
let sourceCollection;
let targetCollection;
const filter = { nextRunAt: null, lockedAt: null };
let total;

var isReverse = process.argv[2] === 'reverse';
const isReverse = process.argv[2] === 'reverse';

// By default from live to achived, but if requested "reverse" do Archived → back to live
var sourceCollectionName = isReverse ? 'agendaJobsArchived' : 'agendaJobs';
var targetCollectionName = isReverse ? 'agendaJobs' : 'agendaJobsArchived';
const sourceCollectionName = isReverse ? 'agendaJobsArchived' : 'agendaJobs';
const targetCollectionName = isReverse ? 'agendaJobs' : 'agendaJobsArchived';

if (isReverse) {
console.log(chalk.red('🚨 Reverse action! Movind docs from archive back to live.'));
Expand Down Expand Up @@ -150,12 +149,12 @@ async.waterfall([
//
// settings how often the progress will be printed to console
// every PROGRESS_INTERVAL %
var PROGRESS_INTERVAL = 0.1; // percent
var keepGoing = true;
var progress = 1; // progress counter
const PROGRESS_INTERVAL = 0.1; // percent
let keepGoing = true;
let progress = 1; // progress counter

// this is the test for async.doWhilst
var testKeepGoing = function () {
const testKeepGoing = function () {
return keepGoing;
};

Expand All @@ -170,7 +169,7 @@ async.waterfall([
// showing the progress sometimes
if (progress % Math.ceil(total / 100 * PROGRESS_INTERVAL) === 0) {
// update the progress instead of logging to newline
var progressPercent = (progress / total * 100).toFixed(1);
const progressPercent = (progress / total * 100).toFixed(1);
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(
Expand Down
2 changes: 1 addition & 1 deletion bin/db-maintenance/ensure-indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (process.argv[2]) {
predefinedModel = process.argv[2];
} else {
console.log('Ensuring indexes for all Mongo collections');
};
}

mongooseService.connect(async (connection) => {
await mongooseService.loadModels();
Expand Down
32 changes: 17 additions & 15 deletions bin/fillTestData/Messages.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

/**
* Required dependencies
*/
const _ = require('lodash'),
path = require('path'),
mongooseService = require(path.resolve('./config/lib/mongoose')),
chalk = require('chalk'),
yargs = require('yargs'),
faker = require('faker'),
mongoose = require('mongoose'),
config = require(path.resolve('./config/config'));
const _ = require('lodash');
const path = require('path');
const mongooseService = require(path.resolve('./config/lib/mongoose'));
const chalk = require('chalk');
const yargs = require('yargs');
const faker = require('faker');
const mongoose = require('mongoose');
const config = require(path.resolve('./config/config'));


/**
Expand Down Expand Up @@ -115,6 +113,8 @@ function seedThreads() {
* successfully been added.
*/
function addThreads(initialThreadCount) {
// @TODO: valid lint issue that should be fixed
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
let threadsSaved = 0;

Expand All @@ -132,7 +132,7 @@ function seedThreads() {
}

// Get the users
let users = await User.find();
const users = await User.find();

// If we don't have enough users in the database
if (users.length < 2) {
Expand All @@ -144,13 +144,15 @@ function seedThreads() {
while (index < numThreads) {
const messageCount = random(maxMessages) + 1;
let messageIndex = messageCount;
let to,
from;
let to;
let from;

// Add messages until we reach the total
while (messageIndex > 0) {
// @TODO: valid lint issue that should be fixed
// eslint-disable-next-line no-inner-declarations
function addMessage(depth, userTo, userFrom) {
let message = new Message();
const message = new Message();

message.created = addDays(Date.now(), -depth + 1);
message.content = faker.lorem.sentences();
Expand Down Expand Up @@ -193,7 +195,7 @@ function seedThreads() {

// Add thread for the most recent message
if (depth === 1) {
let messageThread = new Thread;
const messageThread = new Thread;

// seed the message thread data
seedThread(messageThread, message);
Expand Down
20 changes: 9 additions & 11 deletions bin/fillTestData/Tribes.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

/**
* Required dependencies
*/
const _ = require('lodash'),
path = require('path'),
mongooseService = require(path.resolve('./config/lib/mongoose')),
chalk = require('chalk'),
yargs = require('yargs'),
faker = require('faker'),
mongoose = require('mongoose'),
config = require(path.resolve('./config/config'));
const _ = require('lodash');
const path = require('path');
const mongooseService = require(path.resolve('./config/lib/mongoose'));
const chalk = require('chalk');
const yargs = require('yargs');
const faker = require('faker');
const mongoose = require('mongoose');
const config = require(path.resolve('./config/config'));

/**
* Configure the script usage using yargs to obtain parameters and enforce usage.
Expand Down Expand Up @@ -155,7 +153,7 @@ function seedTribes() {

// Add tribes until we reach the total
while (index < max) {
let tribe = new Tribe();
const tribe = new Tribe();

// seed the tribe data
seedTribe(tribe, initialTribeCount + index);
Expand Down
36 changes: 17 additions & 19 deletions bin/fillTestData/Users.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict';

/**
* Required dependencies
*/
const _ = require('lodash'),
path = require('path'),
mongooseService = require(path.resolve('./config/lib/mongoose')),
chalk = require('chalk'),
yargs = require('yargs'),
faker = require('faker'),
moment = require('moment'),
mongoose = require('mongoose'),
config = require(path.resolve('./config/config')),
cities = require(path.resolve('./bin/fillTestData/data/Cities.json'));
const _ = require('lodash');
const path = require('path');
const mongooseService = require(path.resolve('./config/lib/mongoose'));
const chalk = require('chalk');
const yargs = require('yargs');
const faker = require('faker');
const moment = require('moment');
const mongoose = require('mongoose');
const config = require(path.resolve('./config/config'));
const cities = require(path.resolve('./bin/fillTestData/data/Cities.json'));

require(path.resolve('./modules/offers/server/models/offer.server.model'));

Expand Down Expand Up @@ -50,8 +48,8 @@ const argv = yargs.usage('$0 <numberOfUsers>', 'Seed database with number of tri
/**
* Globals
*/
let savedUsers = 0,
savedOffers = 0;
let savedUsers = 0;
let savedOffers = 0;
const Offer = mongoose.model('Offer');


Expand Down Expand Up @@ -108,7 +106,7 @@ function printSummary(countExisting, countSaved) {
* @param {function} callback
*/
function addOffer(userID, maxUsers, initialUserCount, limit, callback) {
let offer = new Offer();
const offer = new Offer();

const city = cities[random(cities.length)];
const lat = city.lat + randomizeLocation();
Expand Down Expand Up @@ -223,7 +221,7 @@ function addUsers() {

while (index < max) {
(function addNextUser(){
let user = new User();
const user = new User();
let admin;

// Check if this is an admin user
Expand Down Expand Up @@ -255,7 +253,7 @@ function addUsers() {
// non admin user
user.email = index + faker.internet.email();
user.password = faker.internet.password();
user.username = index + user.displayName.toLowerCase().replace(/\'/g, '').replace(/\s/g, '');
user.username = index + user.displayName.toLowerCase().replace(/'/g, '').replace(/\s/g, '');
}

// Add the user to tribes
Expand All @@ -271,7 +269,7 @@ function addUsers() {

// Add the tribes using the random indecies
for (let j = 0; j < userNumTribes; j++) {
let rand = randomTribes[j];
const rand = randomTribes[j];
user.member.push({ tribe: tribes[rand]._id, since: Date.now() });
tribes[rand].count += 1;
}
Expand Down Expand Up @@ -360,6 +358,6 @@ function addUsers() {
}
});
});
}; // addUsers()
} // addUsers()

addUsers();
2 changes: 0 additions & 2 deletions config/assets/default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

module.exports = {
client: {
lib: {
Expand Down
8 changes: 3 additions & 5 deletions config/assets/development.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var _ = require('lodash'),
path = require('path'),
defaultAssets = require(path.resolve('./config/assets/default'));
const _ = require('lodash');
const path = require('path');
const defaultAssets = require(path.resolve('./config/assets/default'));

module.exports = {
// Override any default asset blocks here or add new blocks
Expand Down
8 changes: 3 additions & 5 deletions config/assets/production.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var _ = require('lodash'),
path = require('path'),
defaultAssets = require(path.resolve('./config/assets/default'));
const _ = require('lodash');
const path = require('path');
const defaultAssets = require(path.resolve('./config/assets/default'));

module.exports = {
// Override any default asset blocks here or add new blocks
Expand Down
10 changes: 4 additions & 6 deletions config/assets/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var _ = require('lodash'),
path = require('path'),
defaultAssets = require(path.resolve('./config/assets/default'));
const _ = require('lodash');
const path = require('path');
const defaultAssets = require(path.resolve('./config/assets/default'));

module.exports = {
// Override any default asset blocks here or add new blocks
Expand All @@ -11,7 +9,7 @@ module.exports = {
uibModuleTemplates: defaultAssets.client.lib.uibModuleTemplates,
css: defaultAssets.client.lib.css,
js: _.union(defaultAssets.client.lib.js, [
'testutils/angulartics-null.testutil.js'
'testutils/client/angulartics-null.testutil.js'
]),
less: defaultAssets.client.lib.less,
tests: defaultAssets.client.lib.tests
Expand Down
Loading

0 comments on commit 84d34ce

Please sign in to comment.