Skip to content

Commit

Permalink
style: use eslint and remove tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 11, 2019
1 parent ddca098 commit 49fd215
Show file tree
Hide file tree
Showing 40 changed files with 154 additions and 155 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": [
"plugin:adonis/typescriptPackage"
],
"rules": {
"max-len": ["error", {
"code": 120,
"comments": 120,
"ignoreUrls": true,
"ignoreTemplateLiterals": true
}],
"@typescript-eslint/explicit-function-return-type": ["off"],
"@typescript-eslint/require-await": ["off"]
}
}
8 changes: 4 additions & 4 deletions adonis-typings/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ declare module '@ioc:Adonis/Lucid/Database' {
from: SelectTable<DatabaseQueryBuilderContract & ExcutableQueryBuilderContract<any>>,

/**
* Same as `insertQuery()`, but also selects the table for the query. The `table`
* method doesn't allow defining the return type and one must use `insertQuery`
* to define that.
* Same as `insertQuery()`, but also selects the table for the query.
* The `table` method doesn't allow defining the return type and
* one must use `insertQuery` to define that.
*/
table: Table<InsertQueryBuilderContract & ExcutableQueryBuilderContract<any>>,

Expand Down Expand Up @@ -431,7 +431,7 @@ declare module '@ioc:Adonis/Lucid/Database' {
/**
* The shape of a connection within the connection manager
*/
type ConnectionManagerConnectionNode = {
export type ConnectionManagerConnectionNode = {
name: string,
config: ConnectionConfigContract,
connection?: ConnectionContract,
Expand Down
16 changes: 8 additions & 8 deletions adonis-typings/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ declare module '@ioc:Adonis/Lucid/Model' {
* List of available relations
*/
export type AvailableRelations = 'hasOne' |
'hasMany' |
'belongsTo' |
'manyToMany' |
'hasManyThrough'
'hasMany' |
'belongsTo' |
'manyToMany' |
'hasManyThrough'

/**
* List of events for which a model will trigger hooks
Expand Down Expand Up @@ -270,10 +270,10 @@ declare module '@ioc:Adonis/Lucid/Model' {
* A union of relation relations query builders
*/
type RelationQueryBuilderContract<T extends any = ModelContract> = BelongsToQueryBuilderContract<T> |
HasOneQueryBuilderContract<T> |
HasManyQueryBuilderContract<T> |
ManyToManyQueryBuilderContract<T> |
HasManyThroughQueryBuilderContract<T>
HasOneQueryBuilderContract<T> |
HasManyQueryBuilderContract<T> |
ManyToManyQueryBuilderContract<T> |
HasManyThroughQueryBuilderContract<T>

/**
* Shae of has belongs to query builder contract
Expand Down
2 changes: 1 addition & 1 deletion commands/MakeMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class MakeMigration extends BaseCommand {
return this.prompt.choice('Select the migrations folder', directories, { name: 'folder' })
}

public async handle () {
public async handle (): Promise<void> {
const connection = this._db.getRawConnection(this.connection || this._db.primaryConnectionName)

/**
Expand Down
2 changes: 1 addition & 1 deletion commands/Migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class Migrate extends MigrationsBase {
/**
* Handle command
*/
public async handle () {
public async handle (): Promise<void> {
const connection = this._db.getRawConnection(this.connection || this._db.primaryConnectionName)

/**
Expand Down
2 changes: 1 addition & 1 deletion commands/MigrationsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default abstract class MigrationsBase extends BaseCommand {
/**
* Runs the migrations using the migrator
*/
protected async $runMigrations (migrator: MigratorContract) {
protected async $runMigrations (migrator: MigratorContract): Promise<void> {
/**
* A set of files processed and emitted using event emitter.
*/
Expand Down
2 changes: 1 addition & 1 deletion commands/Rollback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Migrate extends MigrationsBase {
/**
* Handle command
*/
public async handle () {
public async handle (): Promise<void> {
const connection = this._db.getRawConnection(this.connection || this._db.primaryConnectionName)

/**
Expand Down
21 changes: 9 additions & 12 deletions commands/Status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,21 @@ export default class Status extends BaseCommand {
/**
* Colorizes the status string
*/
private _colorizeStatus (status: MigrationListNode['status']) {
if (status === 'pending') {
return this.colors.yellow('pending')
}

if (status === 'migrated') {
return this.colors.green('completed')
}

if (status === 'corrupt') {
return this.colors.red('corrupt')
private _colorizeStatus (status: MigrationListNode['status']): string {
switch (status) {
case 'pending':
return this.colors.yellow('pending')
case 'migrated':
return this.colors.green('completed')
case 'corrupt':
return this.colors.red('corrupt')
}
}

/**
* Handle command
*/
public async handle () {
public async handle (): Promise<void> {
const connection = this._db.getRawConnection(this.connection || this._db.primaryConnectionName)

/**
Expand Down
2 changes: 1 addition & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class User extends BaseModel {
public profile: Profile
}

User.$before('save', async (user) => {
User.$before('save', (user) => {
user.username
})

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test:pg": "DB=pg node japaFile.js",
"test:docker": "npm run test:sqlite && npm run test:mysql && npm run test:pg",
"test": "docker-compose -f docker-compose.yml -f docker-compose-test.yml build && docker-compose -f docker-compose.yml -f docker-compose-test.yml run --rm test",
"lint": "tslint --project tsconfig.json",
"lint": "eslint . --ext=.ts",
"clean": "del build",
"compile": "npm run lint && npm run clean && tsc && npm run copy:files",
"copy:files": "copyfiles \"templates/**/*.txt\" build",
Expand Down Expand Up @@ -72,6 +72,8 @@
"del-cli": "^3.0.0",
"doctoc": "^1.4.0",
"dotenv": "^8.2.0",
"eslint": "^6.7.2",
"eslint-plugin-adonis": "^1.0.2",
"husky": "^3.1.0",
"japa": "^3.0.1",
"mrm": "^2.0.1",
Expand All @@ -81,8 +83,6 @@
"reflect-metadata": "^0.1.13",
"sqlite3": "^4.1.1",
"ts-node": "^8.5.4",
"tslint": "^5.20.1",
"tslint-eslint-rules": "^5.4.0",
"typescript": "^3.7.3"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions providers/DatabaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class DatabaseServiceProvider {
/**
* Register database binding
*/
public register () {
public register (): void {
this.$container.singleton('Adonis/Lucid/Database', () => {
const config = this.$container.use('Adonis/Core/Config').get('database', {})
const Logger = this.$container.use('Adonis/Core/Logger')
Expand Down Expand Up @@ -64,7 +64,7 @@ export default class DatabaseServiceProvider {
})
}

public boot () {
public boot (): void {
this.$container.with(['Adonis/Core/HealthCheck', 'Adonis/Lucid/Database'], (HealthCheck) => {
HealthCheck.addChecker('lucid', 'Adonis/Lucid/Database')
})
Expand Down
20 changes: 11 additions & 9 deletions src/Connection/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import { Exception } from '@poppinss/utils'
import { LoggerContract } from '@ioc:Adonis/Core/Logger'

import {
ReportNode,
ConnectionContract,
ConnectionConfigContract,
ConnectionManagerContract,
ConnectionManagerConnectionNode,
} from '@ioc:Adonis/Lucid/Database'

import { Connection } from './index'
Expand All @@ -42,7 +44,7 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
/**
* Monitors a given connection by listening for lifecycle events
*/
private _monitorConnection (connection: ConnectionContract) {
private _monitorConnection (connection: ConnectionContract): void {
/**
* Listens for disconnect to set the connection state and cleanup
* memory
Expand Down Expand Up @@ -186,7 +188,7 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
/**
* Returns the connection node for a given named connection
*/
public get (connectionName: string) {
public get (connectionName: string): ConnectionManagerConnectionNode | undefined {
return this.connections.get(connectionName)
}

Expand All @@ -195,15 +197,15 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
* a given named connection. This method doesn't tell if
* connection is connected or not.
*/
public has (connectionName: string) {
public has (connectionName: string): boolean {
return this.connections.has(connectionName)
}

/**
* Returns a boolean telling if connection has been established
* with the database or not
*/
public isConnected (connectionName: string) {
public isConnected (connectionName: string): boolean {
if (!this.has(connectionName)) {
return false
}
Expand All @@ -216,7 +218,7 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
* Closes a given connection and can optionally release it from the
* tracking list
*/
public async close (connectionName: string, release: boolean = false) {
public async close (connectionName: string, release: boolean = false): Promise<void> {
if (this.isConnected(connectionName)) {
await this.get(connectionName)!.connection!.disconnect()
}
Expand All @@ -229,15 +231,15 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
/**
* Close all tracked connections
*/
public async closeAll (release: boolean = false) {
public async closeAll (release: boolean = false): Promise<void> {
await Promise.all(Array.from(this.connections.keys()).map((name) => this.close(name, release)))
}

/**
* Release a connection. This will disconnect the connection
* and will delete it from internal list
*/
public async release (connectionName: string) {
public async release (connectionName: string): Promise<void> {
if (this.isConnected(connectionName)) {
await this.close(connectionName, true)
} else {
Expand All @@ -248,15 +250,15 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
/**
* Returns the report for all the connections marked for healthChecks.
*/
public async report () {
public async report (): Promise<{ health: { healthy: boolean, message: string }, meta: ReportNode[] }> {
const reports = await Promise.all(
Array.from(this.connections.keys())
.filter((one) => this.get(one)!.config.healthCheck)
.map((one) => {
this.connect(one)
return this.get(one)!.connection!.getReport()
}),
)
)

const healthy = !reports.find((report) => !!report.error)

Expand Down
6 changes: 3 additions & 3 deletions src/Connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Connection extends EventEmitter implements ConnectionContract {
* Validates the config to ensure that read/write replicas are defined
* properly.
*/
private _validateConfig () {
private _validateConfig (): void {
if (this.config.replicas) {
if (!this.config.replicas.read || !this.config.replicas.write) {
throw new Exception(
Expand All @@ -92,7 +92,7 @@ export class Connection extends EventEmitter implements ConnectionContract {
/**
* Cleanup references
*/
private _cleanup () {
private _cleanup (): void {
this.client = undefined
this.readClient = undefined
this._readReplicas = []
Expand All @@ -104,7 +104,7 @@ export class Connection extends EventEmitter implements ConnectionContract {
* For the same of simplicity, we get rid of both read and write
* clients, when anyone of them disconnects.
*/
private _monitorPoolResources () {
private _monitorPoolResources (): void {
/**
* Pool has destroyed and hence we must cleanup resources
* as well.
Expand Down
2 changes: 1 addition & 1 deletion src/Database/QueryBuilder/Chainable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ export abstract class Chainable implements ChainableContract {
return this.havingExists(value)
}

/**
/**
* Adding `having not exists` clause
*/
public havingNotExists (value: any): this {
Expand Down
8 changes: 4 additions & 4 deletions src/Dialects/Mssql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class MssqlDialect implements DialectContract {
public readonly name = 'mssql'
public supportsAdvisoryLocks = false

public async getAdvisoryLock (): Promise<boolean> {
throw new Error(`Support for advisory locks is not implemented for mssql. Create a PR to add the feature`)
public getAdvisoryLock (): Promise<boolean> {
throw new Error('Support for advisory locks is not implemented for mssql. Create a PR to add the feature')
}

public async releaseAdvisoryLock (): Promise<boolean> {
throw new Error(`Support for advisory locks is not implemented for mssql. Create a PR to add the feature`)
public releaseAdvisoryLock (): Promise<boolean> {
throw new Error('Support for advisory locks is not implemented for mssql. Create a PR to add the feature')
}
}
8 changes: 4 additions & 4 deletions src/Dialects/Oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class OracleDialect implements DialectContract {
public readonly name = 'oracledb'
public supportsAdvisoryLocks = false

public async getAdvisoryLock (): Promise<boolean> {
throw new Error(`Support for advisory locks is not implemented for oracledb. Create a PR to add the feature`)
public getAdvisoryLock (): Promise<boolean> {
throw new Error('Support for advisory locks is not implemented for oracledb. Create a PR to add the feature')
}

public async releaseAdvisoryLock (): Promise<boolean> {
throw new Error(`Support for advisory locks is not implemented for oracledb. Create a PR to add the feature`)
public releaseAdvisoryLock (): Promise<boolean> {
throw new Error('Support for advisory locks is not implemented for oracledb. Create a PR to add the feature')
}
}
8 changes: 4 additions & 4 deletions src/Dialects/Redshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export class RedshiftDialect implements DialectContract {
* Redshift doesn't support advisory locks. Learn more:
* https://tableplus.com/blog/2018/10/redshift-vs-postgres-database-comparison.html
*/
public async getAdvisoryLock (): Promise<boolean> {
throw new Error(`Redshift doesn't support advisory locks`)
public getAdvisoryLock (): Promise<boolean> {
throw new Error('Redshift doesn\'t support advisory locks')
}

/**
* Redshift doesn't support advisory locks. Learn more:
* https://tableplus.com/blog/2018/10/redshift-vs-postgres-database-comparison.html
*/
public async releaseAdvisoryLock (): Promise<boolean> {
throw new Error(`Redshift doesn't support advisory locks`)
public releaseAdvisoryLock (): Promise<boolean> {
throw new Error('Redshift doesn\'t support advisory locks')
}
}
8 changes: 4 additions & 4 deletions src/Dialects/Sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export class SqliteDialect implements DialectContract {
* Attempts to add advisory lock to the database and
* returns it's status.
*/
public async getAdvisoryLock (): Promise<boolean> {
throw new Error(`Sqlite doesn't support advisory locks`)
public getAdvisoryLock (): Promise<boolean> {
throw new Error('Sqlite doesn\'t support advisory locks')
}

/**
* Releases the advisory lock
*/
public async releaseAdvisoryLock (): Promise<boolean> {
throw new Error(`Sqlite doesn't support advisory locks`)
public releaseAdvisoryLock (): Promise<boolean> {
throw new Error('Sqlite doesn\'t support advisory locks')
}
}
Loading

0 comments on commit 49fd215

Please sign in to comment.