[CORL-678] Transition to eslint (#2634)

* chore: setup eslint

* chore: tslint checks with types & check for import order

* chore: complete eslint transition

* fix: tests

* fix: linting after rebase, faster lint for lint-staged

* chore: remove line

* fix: lint rules

* feat: add a11y linter and fix errors

* fix: tests
This commit is contained in:
Vinh
2019-10-15 22:56:38 +00:00
committed by Wyatt Johnson
parent b0e0ba6633
commit 3bfcc509d2
569 changed files with 2592 additions and 1925 deletions
+19 -19
View File
@@ -275,6 +275,20 @@ export async function createActions(
export type CommentActionConnectionInput = ConnectionInput<CommentAction>;
async function retrieveConnection(
input: CommentActionConnectionInput,
query: Query<CommentAction>
): Promise<Readonly<Connection<Readonly<CommentAction>>>> {
// Apply the pagination arguments to the query.
query.orderBy({ createdAt: -1 });
if (input.after) {
query.where({ createdAt: { $lt: input.after as Date } });
}
// Return a connection.
return resolveConnection(query, input, action => action.createdAt);
}
export async function retrieveCommentActionConnection(
mongo: Db,
tenantID: string,
@@ -291,20 +305,6 @@ export async function retrieveCommentActionConnection(
return retrieveConnection(input, query);
}
async function retrieveConnection(
input: CommentActionConnectionInput,
query: Query<CommentAction>
): Promise<Readonly<Connection<Readonly<CommentAction>>>> {
// Apply the pagination arguments to the query.
query.orderBy({ createdAt: -1 });
if (input.after) {
query.where({ createdAt: { $lt: input.after as Date } });
}
// Return a connection.
return resolveConnection(query, input, action => action.createdAt);
}
export async function retrieveUserAction(
mongo: Db,
tenantID: string,
@@ -330,7 +330,7 @@ export async function retrieveManyUserActionPresence(
userID: string | null,
commentIDs: string[]
): Promise<GQLActionPresence[]> {
const cursor = await collection(mongo).find(
const cursor = collection(mongo).find(
{
tenantID,
userID,
@@ -505,10 +505,10 @@ interface DecodedActionCountKey {
* actionType and reason.
*/
function decodeActionCountKey(key: string): DecodedActionCountKey | null {
let actionType: string = "";
let reason: string = "";
let actionType = "";
let reason = "";
if (key.indexOf(ACTION_COUNT_JOIN_CHAR) >= 0) {
if (key.includes(ACTION_COUNT_JOIN_CHAR)) {
const keys = key.split(ACTION_COUNT_JOIN_CHAR);
if (keys.length !== 2) {
throw new Error(
@@ -651,7 +651,7 @@ function incrementActionCounts(
actionCounts: ActionCounts,
actionType: ACTION_TYPE,
reason: GQLCOMMENT_FLAG_REASON | undefined,
count: number = 1
count = 1
) {
switch (actionType) {
case ACTION_TYPE.REACTION:
@@ -93,7 +93,7 @@ export async function retrieveCommentModerationActions(
tenantID: string,
filter: CommentModerationActionFilter
) {
const result = await collection(mongo).find({
const result = collection(mongo).find({
tenantID,
...filter,
});
+3 -3
View File
@@ -376,7 +376,7 @@ export async function retrieveManyComments(
tenantID: string,
ids: string[]
) {
const cursor = await collection(mongo).find({
const cursor = collection(mongo).find({
id: {
$in: ids,
},
@@ -941,7 +941,7 @@ export async function retrieveStoryCommentTagCounts(
const startTime = performanceNow();
// Load the counts from the database for this particular tag query.
const cursor = await collection<{
const cursor = collection<{
_id: { tag: GQLTAG; storyID: string };
total: number;
}>(mongo).aggregate([
@@ -994,7 +994,7 @@ export async function retrieveManyRecentStatusCounts(
authorIDs: string[]
) {
// Get all the statuses for the given date stamp.
const cursor = await collection<{
const cursor = collection<{
_id: {
status: GQLCOMMENT_STATUS;
authorID: string;
+1 -1
View File
@@ -84,7 +84,7 @@ export default class Query<T> {
"executing query"
);
let cursor = await this.collection.find(this.filter);
let cursor = this.collection.find(this.filter);
if (this.limit) {
// Apply a limit if it exists.
@@ -89,7 +89,7 @@ export async function failMigration(mongo: Db, id: number, now = new Date()) {
}
export async function retrieveAllMigrationRecords(mongo: Db) {
const cursor = await collection(mongo)
const cursor = collection(mongo)
.find({})
.sort({ id: 1 });
return cursor.toArray();
+1 -1
View File
@@ -61,7 +61,7 @@ export async function primeQueries(
}
export async function getQueries(mongo: Db, ids: string[]) {
const cursor = await collection(mongo).find({ id: { $in: ids } });
const cursor = collection(mongo).find({ id: { $in: ids } });
const queries = await cursor.toArray();
return ids.map(id => queries.find(query => query.id === id) || null);
}
@@ -66,7 +66,7 @@ export async function recalculateSharedModerationQueueQueueCounts(
await redis.del(key, freshKey);
// Fetch all the moderation queue counts.
const queueResults = await collection<{
const queueResults = collection<{
_id: string;
total: number;
}>(mongo).aggregate([
@@ -142,7 +142,7 @@ export async function recalculateSharedModerationQueueTotalCounts(
await redis.del(key, freshKey);
// Fetch all the totals for the moderation queues.
const totalResults = await collection<{
const totalResults = collection<{
total: number;
}>(mongo).aggregate([
{
@@ -197,7 +197,7 @@ export async function recalculateSharedStatusCommentCounts(
await redis.del(key, freshKey);
// Fetch all the comments of each status.
const statusResults = await collection<{
const statusResults = collection<{
_id: string;
total: number;
}>(mongo).aggregate([
@@ -271,7 +271,7 @@ export async function recalculateSharedActionCommentCounts(
await redis.del(key, freshKey);
// Fetch all the comments of each status.
const actionResults = await collection<{
const actionResults = collection<{
_id: string;
total: number;
}>(mongo).aggregate([
+2 -2
View File
@@ -258,7 +258,7 @@ export async function retrieveManyStories(
tenantID: string,
ids: string[]
) {
const cursor = await collection(mongo).find({
const cursor = collection(mongo).find({
id: { $in: ids },
tenantID,
});
@@ -273,7 +273,7 @@ export async function retrieveManyStoriesByURL(
tenantID: string,
urls: string[]
) {
const cursor = await collection(mongo).find({
const cursor = collection(mongo).find({
url: { $in: urls },
tenantID,
});
+2 -2
View File
@@ -212,7 +212,7 @@ export async function retrieveTenant(mongo: Db, id: string) {
}
export async function retrieveManyTenants(mongo: Db, ids: string[]) {
const cursor = await collection(mongo).find({
const cursor = collection(mongo).find({
id: {
$in: ids,
},
@@ -227,7 +227,7 @@ export async function retrieveManyTenantsByDomain(
mongo: Db,
domains: string[]
) {
const cursor = await collection(mongo).find({
const cursor = collection(mongo).find({
domain: {
$in: domains,
},
+7 -3
View File
@@ -523,11 +523,12 @@ async function findOrCreateUserInput(
// Mutate the profiles to ensure we mask handle any secrets.
switch (profile.type) {
case "local":
case "local": {
// Hash the user's password with bcrypt.
const password = await hashPassword(profile.password);
defaults.profiles.push({ ...profile, password });
break;
}
default:
// Push the profile onto the User.
defaults.profiles.push(profile);
@@ -626,7 +627,7 @@ export async function retrieveManyUsers(
tenantID: string,
ids: string[]
) {
const cursor = await collection(mongo).find({
const cursor = collection(mongo).find({
tenantID,
id: {
$in: ids,
@@ -1098,7 +1099,7 @@ export async function updateUserEmail(
return result.value;
} catch (err) {
if (err instanceof MongoError && err.code === 11000) {
throw new DuplicateEmailError(email!);
throw new DuplicateEmailError(email);
}
throw err;
}
@@ -1420,6 +1421,7 @@ export async function premodUser(
/**
* removeUserPremod will lift a user premod requirement
*
* @param mongo the mongo database handle
* @param tenantID the Tenant's ID where the User exists
* @param id the ID of the user having their ban lifted
@@ -2354,6 +2356,7 @@ export async function retrieveUserScheduledForDeletion(
/**
* createModeratorNote will add a note to a users account
*
* @param mongo the database to put the notification digests into
* @param tenantID the ID of the Tenant that this User exists on
* @param id the ID of the User who is the subject of the note
@@ -2397,6 +2400,7 @@ export async function createModeratorNote(
/**
* deleteModeratorNote will remove a note from a user profile
*
* @param mongo the database to put the notification digests into
* @param tenantID the ID of the Tenant that this User exists on
* @param userID the ID of the user