Skip to content

Commit

Permalink
Upgrade versions of prettier and eslint
Browse files Browse the repository at this point in the history
Some newer syntax of typescript were not readable by the current formatter
(like `export * as something...`). All eslint and prettier packages are
upgraded to their latest version.

`yarn format` is run on the code, some of the rules have changed and the
files formatted.

Also remove the `eslint --fix .` from the `format` script, as it is
included in prettier-eslint.
  • Loading branch information
tahini committed Dec 7, 2022
1 parent 431b75c commit 28d0b1e
Show file tree
Hide file tree
Showing 151 changed files with 1,520 additions and 1,891 deletions.
10 changes: 5 additions & 5 deletions packages/chaire-lib-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test:sequential": "cross-env NODE_ENV=test jest --config=jest.sequential.config.js --runInBand",
"test:ui": "echo 'no tests to run for this workspace'",
"lint": "eslint .",
"format": "prettier-eslint $PWD/'src/**/*.{ts,tsx}' --write && eslint --fix ."
"format": "prettier-eslint $PWD/'src/**/*.{ts,tsx}' --write"
},
"dependencies": {
"@casl/ability": "^5.4.3",
Expand Down Expand Up @@ -103,18 +103,18 @@
"@types/stream-chain": "^2.0.1",
"@types/stream-json": "^1.7.1",
"@types/validator": "^13.6.6",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@typescript-eslint/eslint-plugin": "^5.45.1",
"@typescript-eslint/parser": "^5.45.1",
"cross-env": "^7.0.2",
"eslint": "^7.32.0",
"eslint": "^8.29.0",
"eslint-plugin-node": "^11.1.0",
"jest": "^27.3.1",
"jest-each": "^27.3.1",
"jest-fetch-mock": "^3.0.3",
"mock-knex": "^0.4.9",
"mock-spawn": "^0.2.6",
"nodemailer-mock": "^1.5.8",
"prettier-eslint-cli": "^5.0.1",
"prettier-eslint-cli": "^7.1.0",
"supertest": "^6.1.3",
"supertest-session": "^4.1.0",
"ts-jest": "^27.0.7"
Expand Down
2 changes: 1 addition & 1 deletion packages/chaire-lib-backend/src/api/auth.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const defaultFailureCallback = (err, _req: Request, res: Response, _next) => {
});
};

export default function(app: express.Express) {
export default function (app: express.Express) {
app.get(
'/googlelogin',
passport.authenticate('google', { scope: 'https://www.googleapis.com/auth/userinfo.email' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EventEmitter } from 'events';
import allPreferences from 'chaire-lib-common/lib/config/Preferences';
import preferencesQueries from '../models/db/preferences.db.queries';

export default function(socket: EventEmitter, userId: number) {
export default function (socket: EventEmitter, userId: number) {
socket.on('preferences.read', async (callback) => {
try {
const preferences = await preferencesQueries.read(userId);
Expand Down
2 changes: 1 addition & 1 deletion packages/chaire-lib-backend/src/api/trRouting.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ router.get('/summary', async (req, res) => {
}
});

export default function(app: express.Express) {
export default function (app: express.Express) {
app.use('/trRouting', router);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ObjectImporter =
type: 'importOnly';
};

export default function(
export default function (
socket: SocketIO.Socket,
absoluteUserDir: string,
importerByObjectName: { [object: string]: ObjectImporter },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const sendEmailIfRequired = async (
done(null, false, { message: 'UnconfirmedUser' });
};

export default function(passport: PassportStatic) {
export default function (passport: PassportStatic) {
passport.use(
'local-login',
new LocalStrategy.Strategy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface newUserParams {
confirmationToken?: string;
}

export const saveNewUser = async function(params: newUserParams): Promise<UserModel | null> {
export const saveNewUser = async function (params: newUserParams): Promise<UserModel | null> {
const userPassword = params.password;
const user = new UserModel({
username: params.username || null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getOrCreateUserWithEmail = async (destination: string): Promise<UserModel>
}
};

export default function(passport: PassportStatic) {
export default function (passport: PassportStatic) {
// TODO Manage the language
const magicLogin = new MagicLoginStrategy({
// Used to encrypt the authentication token. Needs to be long, unique and (duh) secret.
Expand Down
2 changes: 1 addition & 1 deletion packages/chaire-lib-backend/src/config/knexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (
)
throw 'database is not set';

export const onUpdateTrigger = function(table: string) {
export const onUpdateTrigger = function (table: string) {
return `
CREATE TRIGGER ${table}_updated_at
BEFORE UPDATE ON ${table}
Expand Down
33 changes: 10 additions & 23 deletions packages/chaire-lib-backend/src/models/db/default.db.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import TrError from 'chaire-lib-common/lib/utils/TrError';

// TODO Move these to a generic class, so we can use identical types for U and T in generic methods.

const stringifyDataSourceIds = function(dataSourceIds: string[]): string[] {
const stringifyDataSourceIds = function (dataSourceIds: string[]): string[] {
if (dataSourceIds && !Array.isArray(dataSourceIds)) {
dataSourceIds = [dataSourceIds];
}
Expand All @@ -32,9 +32,7 @@ const exists = async (knex: Knex, tableName: string, id: string): Promise<boolea
);
}
try {
const rows = await knex(tableName)
.count('*')
.where('id', id);
const rows = await knex(tableName).count('*').where('id', id);

const count = rows.length > 0 ? rows[0].count : 0;
if (count) {
Expand Down Expand Up @@ -65,9 +63,7 @@ const create = async <T extends GenericAttributes, U>(
try {
const _newObject = parser ? parser(newObject) : newObject;

const returningArray = await knex(tableName)
.insert(_newObject)
.returning(returning);
const returningArray = await knex(tableName).insert(_newObject).returning(returning);
return returningArray[0];
} catch (error) {
throw new TrError(
Expand Down Expand Up @@ -126,9 +122,7 @@ const read = async <T extends GenericAttributes, U>(
'DatabaseCannotReadBecauseIdIsMissingOrInvalid'
);
}
const rows = await knex(tableName)
.select(knex.raw(query))
.where('id', id);
const rows = await knex(tableName).select(knex.raw(query)).where('id', id);

if (rows.length !== 1) {
throw new TrError(
Expand All @@ -137,7 +131,7 @@ const read = async <T extends GenericAttributes, U>(
'DatabaseCannotReadBecauseObjectDoesNotExist'
);
} else {
const _newObject = parser ? parser((rows[0] as unknown) as U) : (rows[0] as T);
const _newObject = parser ? parser(rows[0] as unknown as U) : (rows[0] as T);
return _newObject;
}
} catch (error) {
Expand Down Expand Up @@ -167,10 +161,7 @@ const update = async <T extends GenericAttributes, U>(
}
const _attributes = parser ? parser(attributes) : attributes;

const returningArray = await knex(tableName)
.update(_attributes)
.where('id', id)
.returning(returning);
const returningArray = await knex(tableName).update(_attributes).where('id', id).returning(returning);
return returningArray[0];
} catch (error) {
throw new TrError(
Expand Down Expand Up @@ -223,9 +214,7 @@ const deleteRecord = async (knex: Knex, tableName: string, id: string) => {
'ObjectCannotDeleteBecauseIdIsMissingOrInvalid'
);
}
await knex(tableName)
.where('id', id)
.del();
await knex(tableName).where('id', id).del();
return id;
} catch (error) {
throw new TrError(
Expand All @@ -236,7 +225,7 @@ const deleteRecord = async (knex: Knex, tableName: string, id: string) => {
}
};

const deleteMultiple = function(knex: Knex, tableName: string, ids: string[]): Promise<string[]> {
const deleteMultiple = function (knex: Knex, tableName: string, ids: string[]): Promise<string[]> {
return new Promise((resolve, reject) => {
return knex(tableName)
.whereIn('id', ids)
Expand All @@ -259,9 +248,7 @@ const deleteMultiple = function(knex: Knex, tableName: string, ids: string[]): P

const deleteForDataSourceId = async (knex: Knex, tableName: string, dataSourceId: string): Promise<string> => {
try {
await knex(tableName)
.where('data_source_id', dataSourceId)
.del();
await knex(tableName).where('data_source_id', dataSourceId).del();
return dataSourceId;
} catch (error) {
throw new TrError(
Expand All @@ -286,7 +273,7 @@ const truncate = async (knex: Knex, tableName: string): Promise<string> => {
}
};

const destroy = function(
const destroy = function (
knex: Knex,
callback: () => void = () => {
/* nothing to do */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ export async function up(knex: Knex): Promise<unknown> {
}
await knex.schema.createTable('users', (table: Knex.TableBuilder) => {
table.increments();
table
.uuid('uuid')
.notNullable()
.defaultTo(knex.raw('gen_random_uuid()'));
table
.string('username')
.unique()
.index();
table.uuid('uuid').notNullable().defaultTo(knex.raw('gen_random_uuid()'));
table.string('username').unique().index();
table.text('password');
table.string('generated_password');
table
.string('email')
.unique()
.index();
table.string('email').unique().index();
table.string('first_name');
table.string('last_name');
table.boolean('is_valid').index();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const read = async (userId: number) => {
}

try {
const rows = await knex('users')
.select('preferences')
.where('id', userId);
const rows = await knex('users').select('preferences').where('id', userId);
if (rows.length !== 1) {
throw new TrError(
`Cannot find user with id ${userId} in database`,
Expand Down Expand Up @@ -57,10 +55,7 @@ const update = async (userId: number, valuesByPath: { [pref: string]: unknown })
for (const path in valuesByPath) {
_set(preferences, path, valuesByPath[path]);
}
const idArray = await knex('users')
.update({ preferences })
.where('id', userId)
.returning('id');
const idArray = await knex('users').update({ preferences }).where('id', userId).returning('id');
return idArray[0];
} catch (error) {
if (TrError.isTrError(error)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const createSocketIoFile = (

return new SocketIOFile(socket, {
uploadDir: allOptions.uploadDirs,
rename: function(filename, fileInfo) {
rename: function (filename, fileInfo) {
console.log('file info', fileInfo);
// TODO Type of data is wrong, it is any[], not an object as assumed here
if (fileInfo.data && (fileInfo.data as any).filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

// TODO Type those functions

const writePackedMessageToStream = function(writeStream, message) {
const writePackedMessageToStream = function (writeStream, message) {
const arrayBuffer = message.toPackedArrayBuffer();
// Because streams can't handle ArrayBuffers
const buffer = Buffer.from(arrayBuffer);
writeStream.write(buffer);
};

const readToEndOfStream = function(readStream) {
const readToEndOfStream = function (readStream) {
return new Promise((resolve, reject) => {
let result = new Uint8Array();
readStream.on('close', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param {(number | null | undefined)} value The value to convert
* @return {*} {number} The original value or -1 if it was null
*/
const nullToMinusOne = function(value: number | null | undefined): number {
const nullToMinusOne = function (value: number | null | undefined): number {
if (value === null || value === undefined) {
return -1;
}
Expand All @@ -24,7 +24,7 @@ const nullToMinusOne = function(value: number | null | undefined): number {
* @return {*} {number | undefined)} The original value or undefined if the
* value was -1
*/
const minusOneToUndefined = function(value: number): number | undefined {
const minusOneToUndefined = function (value: number): number | undefined {
if (value === -1) {
return undefined;
}
Expand All @@ -37,7 +37,7 @@ const minusOneToUndefined = function(value: number): number | undefined {
* @param {( boolean | null | undefined)} value The value to convert
* @return {*} {number} 1 for true, 0 for false or -1 for any other value
*/
const boolToInt8 = function(value: boolean | null | undefined): number {
const boolToInt8 = function (value: boolean | null | undefined): number {
if (value === true) {
return 1;
} else if (value === false) {
Expand All @@ -53,7 +53,7 @@ const boolToInt8 = function(value: boolean | null | undefined): number {
* @return {*} {(boolean | undefined)} true if 1, false if 0 or undefined for
* any other value
*/
const int8ToBool = function(value: number): boolean | undefined {
const int8ToBool = function (value: number): boolean | undefined {
if (value === 1) {
return true;
} else if (value === 0) {
Expand All @@ -70,7 +70,7 @@ const int8ToBool = function(value: number): boolean | undefined {
* @return {*} {(string | undefined)} undefined if str is the 'none' string,
* the original value otherwise
*/
const noneStringToUndefined = function(str: string): string | undefined {
const noneStringToUndefined = function (str: string): string | undefined {
if (str === 'none') {
return undefined;
}
Expand All @@ -86,7 +86,7 @@ const LAT_LON_PRECISION_FACTOR = 1000000;
* @param {[number, number]} coordinates The coordinates to round
* @return {*} {[number, number]} Rounded coordinates
*/
const roundLonLatCoordinates = function(coordinates: [number, number]): [number, number] {
const roundLonLatCoordinates = function (coordinates: [number, number]): [number, number] {
// precise to approximately 10 cm
return [roundLonLatCoordinate(coordinates[0]), roundLonLatCoordinate(coordinates[1])];
};
Expand All @@ -98,7 +98,7 @@ const roundLonLatCoordinates = function(coordinates: [number, number]): [number,
* @param {number} coordinate The coordinate to round
* @return {*} {number}
*/
const roundLonLatCoordinate = function(coordinate: number): number {
const roundLonLatCoordinate = function (coordinate: number): number {
return intCoordinateToLatLon(latLonCoordinateToInt(coordinate));
};

Expand All @@ -110,7 +110,7 @@ const roundLonLatCoordinate = function(coordinate: number): number {
* @param {number} coordinate The coordinate to transform to integer
* @return {*} {number}
*/
const latLonCoordinateToInt = function(coordinate: number): number {
const latLonCoordinateToInt = function (coordinate: number): number {
return Math.round(coordinate * LAT_LON_PRECISION_FACTOR);
};

Expand All @@ -121,7 +121,7 @@ const latLonCoordinateToInt = function(coordinate: number): number {
* @param {number} intCoordinate The integer to convert back to lat/lon
* @return {*} {number}
*/
const intCoordinateToLatLon = function(intCoordinate: number): number {
const intCoordinateToLatLon = function (intCoordinate: number): number {
return intCoordinate / LAT_LON_PRECISION_FACTOR;
};

Expand Down
Loading

0 comments on commit 28d0b1e

Please sign in to comment.