Skip to content

Commit

Permalink
chore: add linter for async method Async suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman committed Jun 14, 2024
1 parent 59fc778 commit 2dc67cf
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 93 deletions.
55 changes: 0 additions & 55 deletions .eslintrc

This file was deleted.

47 changes: 47 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = {
root: true,
extends: ['universe/node', 'universe/shared/typescript-analysis'],
plugins: ['eslint-plugin-tsdoc'],
rules: {
'no-restricted-imports': ['error', { paths: ['.', '..', '../..'] }],
'tsdoc/syntax': 'warn',
'no-console': 'warn',
'handle-callback-err': 'off',
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.d.ts'],
parserOptions: {
project: './tsconfig.json',
},
rules: {
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: true,
},
],
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'enumMember',
format: ['UPPER_CASE'],
},
// async functions must have names ending with 'Async'
{
selector: ['function', 'classMethod', 'typeMethod', 'memberLike'],
format: ['camelCase'],
modifiers: ['async'],
suffix: ['Async'],
},
],
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': ['error'],
},
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BatchedRedis implements IRedis {
);
}

// eslint-disable-next-line @typescript-eslint/naming-convention
async mget(...args: string[]): Promise<(string | null)[]> {
return await this.mgetBatcher.batchAsync(args);
}
Expand All @@ -52,6 +53,7 @@ class BatchedRedis implements IRedis {
return this.redis.multi();
}

// eslint-disable-next-line @typescript-eslint/naming-convention
async del(...args: string[]): Promise<void> {
await this.redis.del(...args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ describe('postgres entity integration', () => {
});

beforeEach(async () => {
await PostgresTestEntity.createOrTruncatePostgresTable(knexInstance);
await PostgresTestEntity.createOrTruncatePostgresTableAsync(knexInstance);
});

afterAll(async () => {
await PostgresTestEntity.dropPostgresTable(knexInstance);
await PostgresTestEntity.dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe(PostgresEntityQueryContextProvider, () => {
});

beforeEach(async () => {
await PostgresUniqueTestEntity.createOrTruncatePostgresTable(knexInstance);
await PostgresUniqueTestEntity.createOrTruncatePostgresTableAsync(knexInstance);
});

afterAll(async () => {
await PostgresUniqueTestEntity.dropPostgresTable(knexInstance);
await PostgresUniqueTestEntity.dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('postgres entity integration', () => {
});

beforeEach(async () => {
await InvalidTestEntity.createOrTruncatePostgresTable(knexInstance);
await InvalidTestEntity.createOrTruncatePostgresTableAsync(knexInstance);
});

afterAll(async () => {
await InvalidTestEntity.dropPostgresTable(knexInstance);
await InvalidTestEntity.dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ describe('postgres errors', () => {
});

beforeEach(async () => {
await ErrorsTestEntity.createOrTruncatePostgresTable(knexInstance);
await ErrorsTestEntity.createOrTruncatePostgresTableAsync(knexInstance);
});

afterAll(async () => {
await ErrorsTestEntity.dropPostgresTable(knexInstance);
await ErrorsTestEntity.dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ErrorsTestEntity extends Entity<
};
}

public static async createOrTruncatePostgresTable(knex: Knex): Promise<void> {
public static async createOrTruncatePostgresTableAsync(knex: Knex): Promise<void> {
await knex.raw('CREATE EXTENSION IF NOT EXISTS "btree_gist"'); // for gist exclusion on varchar

const tableName = 'postgres_test_entities';
Expand Down Expand Up @@ -89,7 +89,7 @@ export default class ErrorsTestEntity extends Entity<
await knex(foreignTableName).delete();
}

public static async dropPostgresTable(knex: Knex): Promise<void> {
public static async dropPostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (hasTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class InvalidTestEntity extends Entity<
};
}

public static async createOrTruncatePostgresTable(knex: Knex): Promise<void> {
public static async createOrTruncatePostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (!hasTable) {
Expand All @@ -46,7 +46,7 @@ export default class InvalidTestEntity extends Entity<
await knex.into(tableName).truncate();
}

public static async dropPostgresTable(knex: Knex): Promise<void> {
public static async dropPostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (hasTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class PostgresTestEntity extends Entity<
};
}

public static async createOrTruncatePostgresTable(knex: Knex): Promise<void> {
public static async createOrTruncatePostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (!hasTable) {
Expand All @@ -70,7 +70,7 @@ export default class PostgresTestEntity extends Entity<
await knex.into(tableName).truncate();
}

public static async dropPostgresTable(knex: Knex): Promise<void> {
public static async dropPostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (hasTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class PostgresTriggerTestEntity extends Entity<
};
}

public static async createOrTruncatePostgresTable(knex: Knex): Promise<void> {
public static async createOrTruncatePostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (!hasTable) {
Expand All @@ -61,7 +61,7 @@ export default class PostgresTriggerTestEntity extends Entity<
await knex.into(tableName).truncate();
}

public static async dropPostgresTable(knex: Knex): Promise<void> {
public static async dropPostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (hasTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class PostgresUniqueTestEntity extends Entity<
};
}

public static async createOrTruncatePostgresTable(knex: Knex): Promise<void> {
public static async createOrTruncatePostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (!hasTable) {
Expand All @@ -46,7 +46,7 @@ export default class PostgresUniqueTestEntity extends Entity<
await knex.into(tableName).truncate();
}

public static async dropPostgresTable(knex: Knex): Promise<void> {
public static async dropPostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (hasTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class PostgresValidatorTestEntity extends Entity<
};
}

public static async createOrTruncatePostgresTable(knex: Knex): Promise<void> {
public static async createOrTruncatePostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (!hasTable) {
Expand All @@ -50,7 +50,7 @@ export default class PostgresValidatorTestEntity extends Entity<
await knex.into(tableName).truncate();
}

public static async dropPostgresTable(knex: Knex): Promise<void> {
public static async dropPostgresTableAsync(knex: Knex): Promise<void> {
const tableName = 'postgres_test_entities';
const hasTable = await knex.schema.hasTable(tableName);
if (hasTable) {
Expand Down
4 changes: 2 additions & 2 deletions packages/entity-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import createAppAsync from './app';

async function main(): Promise<void> {
async function mainAsync(): Promise<void> {
const app = await createAppAsync();
app.listen(3000);
}

main();
mainAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const testEntityConfiguration = new EntityConfiguration<TestFields>({
cacheAdapterFlavor: 'redis',
});

async function createOrTruncatePostgresTables(knex: Knex): Promise<void> {
async function createOrTruncatePostgresTablesAsync(knex: Knex): Promise<void> {
await knex.schema.createTable('testentities', (table) => {
table.uuid('id').defaultTo(knex.raw('gen_random_uuid()')).primary();
table.string('other_string').notNullable();
Expand All @@ -87,7 +87,7 @@ async function createOrTruncatePostgresTables(knex: Knex): Promise<void> {
await knex.into('testentities').truncate();
}

async function dropPostgresTable(knex: Knex): Promise<void> {
async function dropPostgresTableAsync(knex: Knex): Promise<void> {
if (await knex.schema.hasTable('testentities')) {
await knex.schema.dropTable('testentities');
}
Expand Down Expand Up @@ -125,12 +125,12 @@ describe('Entity cache inconsistency', () => {
});

beforeEach(async () => {
await createOrTruncatePostgresTables(knexInstance);
await createOrTruncatePostgresTablesAsync(knexInstance);
await redisClient.flushdb();
});

afterAll(async () => {
await dropPostgresTable(knexInstance);
await dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
redisClient.disconnect();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ChildEntity from './entities/ChildEntity';
import ParentEntity from './entities/ParentEntity';
import { createFullIntegrationTestEntityCompanionProvider } from '../testfixtures/createFullIntegrationTestEntityCompanionProvider';

async function createOrTruncatePostgresTables(knex: Knex): Promise<void> {
async function createOrTruncatePostgresTablesAsync(knex: Knex): Promise<void> {
await knex.schema.createTable('parents', (table) => {
table.uuid('id').defaultTo(knex.raw('gen_random_uuid()')).primary();
});
Expand All @@ -22,7 +22,7 @@ async function createOrTruncatePostgresTables(knex: Knex): Promise<void> {
await knex.into('children').truncate();
}

async function dropPostgresTable(knex: Knex): Promise<void> {
async function dropPostgresTableAsync(knex: Knex): Promise<void> {
if (await knex.schema.hasTable('children')) {
await knex.schema.dropTable('children');
}
Expand Down Expand Up @@ -63,12 +63,12 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
});

beforeEach(async () => {
await createOrTruncatePostgresTables(knexInstance);
await createOrTruncatePostgresTablesAsync(knexInstance);
await redisClient.flushdb();
});

afterAll(async () => {
await dropPostgresTable(knexInstance);
await dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
redisClient.disconnect();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ const testEntityConfiguration = new EntityConfiguration<TestFields>({
cacheAdapterFlavor: 'redis',
});

async function createOrTruncatePostgresTables(knex: Knex): Promise<void> {
async function createOrTruncatePostgresTablesAsync(knex: Knex): Promise<void> {
await knex.schema.createTable('testentities', (table) => {
table.uuid('id').defaultTo(knex.raw('gen_random_uuid()')).primary();
});
await knex.into('testentities').truncate();
}

async function dropPostgresTable(knex: Knex): Promise<void> {
async function dropPostgresTableAsync(knex: Knex): Promise<void> {
if (await knex.schema.hasTable('testentities')) {
await knex.schema.dropTable('testentities');
}
Expand Down Expand Up @@ -114,12 +114,12 @@ describe('Entity integrity', () => {
});

beforeEach(async () => {
await createOrTruncatePostgresTables(knexInstance);
await createOrTruncatePostgresTablesAsync(knexInstance);
await redisClient.flushdb();
});

afterAll(async () => {
await dropPostgresTable(knexInstance);
await dropPostgresTableAsync(knexInstance);
await knexInstance.destroy();
redisClient.disconnect();
});
Expand Down
Loading

0 comments on commit 2dc67cf

Please sign in to comment.