Skip to content

Commit

Permalink
Update for lint config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zajrik committed Jan 8, 2021
1 parent 30529ee commit ca765f6
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 45 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
"@types/node": "^8.0.19",
"@types/node-json-db": "0.0.1",
"@types/sequelize": "^4.0.68",
"@typescript-eslint/eslint-plugin": "^2.4.0",
"@typescript-eslint/parser": "^2.4.0",
"cross-env": "^5.1.3",
"del": "^6.0.0",
"eslint": "^6.5.1",
Expand Down
28 changes: 16 additions & 12 deletions src/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export class Client extends Discord.Client
public readonly tsNode: boolean;

// Internals
public readonly _middleware: MiddlewareFunction[];
public readonly _customResolvers: ResolverConstructor[];
public readonly middleware: MiddlewareFunction[];
public readonly customResolvers: ResolverConstructor[];

// eslint-disable-next-line complexity
public constructor(options: YAMDBFOptions, clientOptions?: ClientOptions)
Expand Down Expand Up @@ -245,7 +245,7 @@ export class Client extends Discord.Client
this.plugins = new PluginLoader(this, this._plugins);

// Middleware function storage for the client instance
this._middleware = [];
this.middleware = [];

/**
* Client-specific storage. Also contains a `guilds` Collection property containing
Expand All @@ -267,8 +267,8 @@ export class Client extends Discord.Client
* @type {ResolverLoader}
*/
this.resolvers = new ResolverLoader(this);
this._customResolvers = options.customResolvers ?? [];
this.resolvers._loadResolvers();
this.customResolvers = options.customResolvers ?? [];
this.resolvers.loadResolvers();

/**
* Whether or not compact mode is enabled
Expand Down Expand Up @@ -335,6 +335,7 @@ export class Client extends Discord.Client
// #region Event handlers

// @ts-ignore - Handled via ListenerUtil
// eslint-disable-next-line @typescript-eslint/naming-convention
@once('ready') private async __onReadyEvent(): Promise<void>
{
// Set default owner (OAuth Application owner) if none exists
Expand All @@ -359,14 +360,15 @@ export class Client extends Discord.Client
this.user!.setActivity(this.statusText);
}

// eslint-disable-next-line @typescript-eslint/naming-convention
@once('continue') private async __onContinueEvent(): Promise<void>
{
await this._guildStorageLoader.init();
await this._guildStorageLoader.loadStorages();
await this._guildStorageLoader.cleanGuilds();

this._logger.info('Loading plugins...');
await this.plugins._loadPlugins();
await this.plugins.loadPlugins();

if (!this.passive)
{
Expand All @@ -376,11 +378,11 @@ export class Client extends Discord.Client
this._commandLoader.loadCommandsFrom(this.commandsDir);
}

this.commands._checkDuplicateAliases();
this.commands._checkReservedCommandNames();
this.commands.checkDuplicateAliases();
this.commands.checkReservedCommandNames();

this._logger.info('Initializing commands...');
const initSuccess: boolean = await this.commands._initCommands();
const initSuccess: boolean = await this.commands.initCommands();
this._logger.info(`Commands initialized${initSuccess ? '' : ' with errors'}.`);

Lang.loadCommandLocalizations();
Expand Down Expand Up @@ -413,6 +415,7 @@ export class Client extends Discord.Client
}

// @ts-ignore - Handled via ListenerUtil
// eslint-disable-next-line @typescript-eslint/naming-convention
@on('guildCreate') private async __onGuildCreateEvent(guild: Guild): Promise<void>
{
if (this.storage.guilds.has(guild.id))
Expand All @@ -426,6 +429,7 @@ export class Client extends Discord.Client
}

// @ts-ignore - Handled via ListenerUtil
// eslint-disable-next-line @typescript-eslint/naming-convention
@on('guildDelete') private __onGuildDeleteEvent(guild: Guild): void
{
if (this.storage.guilds.has(guild.id))
Expand Down Expand Up @@ -596,15 +600,15 @@ export class Client extends Discord.Client
*/
public use(func: MiddlewareFunction): this
{
this._middleware.push(func);
this.middleware.push(func);
return this;
}

/**
* Reload custom commands. Used internally by the `reload` command
* @private
*/
public _reloadCustomCommands(): number
public reloadCustomCommands(): number
{
if (!this.commandsDir)
throw new Error('Client is missing `commandsDir`, cannot reload Commands');
Expand All @@ -616,7 +620,7 @@ export class Client extends Discord.Client
* Reload Events from all registered event source directories
* @private
*/
public _reloadEvents(): number
public reloadEvents(): number
{
return this.eventLoader.loadFromSources();
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/PluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class PluginLoader
* Called internally by the YAMDBF Client at startup
* @private
*/
public async _loadPlugins(): Promise<void>
public async loadPlugins(): Promise<void>
{
await this._provider.init();
this._logger.debug('Plugin storage provider initialized.');
Expand Down
18 changes: 9 additions & 9 deletions src/command/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export abstract class Command<T extends Client = Client>
public lockTimeout!: number;

// Internals
public readonly _middleware: MiddlewareFunction[];
public _classloc!: string;
public _initialized: boolean;
public readonly middleware: MiddlewareFunction[];
public classloc!: string;
public initialized: boolean;

public constructor(info?: CommandInfo)
{
Expand Down Expand Up @@ -196,9 +196,9 @@ export abstract class Command<T extends Client = Client>
*/

// Middleware function storage for the Command instance
this._middleware = [];
this.middleware = [];

this._initialized = false;
this.initialized = false;

if (info) Object.assign(this, info);
}
Expand Down Expand Up @@ -237,7 +237,7 @@ export abstract class Command<T extends Client = Client>
* Called internally by the command loader
* @private
*/
public _register(client: T): void
public register(client: T): void
{
this.client = client;

Expand All @@ -254,11 +254,11 @@ export abstract class Command<T extends Client = Client>
if (typeof this.ownerOnly === 'undefined') this.ownerOnly = false;
if (typeof this.external === 'undefined') this.external = false;
if (typeof this._disabled === 'undefined') this._disabled = false;
if (typeof this._classloc === 'undefined') this._classloc = '<External Command>';
if (typeof this.classloc === 'undefined') this.classloc = '<External Command>';
if (typeof this.lockTimeout === 'undefined') this.lockTimeout = 30e3;

// Make necessary asserts
if (!this.name) throw new Error(`A command is missing a name:\n${this._classloc}`);
if (!this.name) throw new Error(`A command is missing a name:\n${this.classloc}`);
if (!this.desc) throw new Error(`A description must be provided for Command: ${this.name}`);
if (!this.usage) throw new Error(`Usage information must be provided for Command: ${this.name}`);
if (this.aliases && !Array.isArray(this.aliases))
Expand Down Expand Up @@ -349,7 +349,7 @@ export abstract class Command<T extends Client = Client>
*/
public use(func: MiddlewareFunction): this
{
this._middleware.push(func);
this.middleware.push(func);
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions src/command/CommandDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export function localizable(target: Command, key: string, descriptor: PropertyDe
* Set an arbitrary value to an arbitrary key on a command class
* @private
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function _setMetaData(key: string, value: any): ClassDecorator
{
return function<T extends Function>(target: T): T
Expand All @@ -165,6 +166,7 @@ function _setMetaData(key: string, value: any): ClassDecorator
* Set a boolean flag metadata on a command class
* @private
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function _setFlagMetaData<T extends Function>(target: T, flag: string): T
{
Object.defineProperty(target.prototype, flag, {
Expand Down
2 changes: 1 addition & 1 deletion src/command/CommandDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class CommandDispatcher

let commandResult!: CommandResult;
let middlewarePassed: boolean = true;
const middleware: MiddlewareFunction[] = this._client._middleware.concat(command!._middleware);
const middleware: MiddlewareFunction[] = this._client.middleware.concat(command!.middleware);

// Function to send middleware result, utilizing compact mode if enabled
const sendMiddlewareResult: (result: string, options?: MessageOptions) => Promise<any> =
Expand Down
5 changes: 3 additions & 2 deletions src/command/CommandLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class CommandLoader
continue;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
for (const CommandClass of commandClasses)
{
const commandInstance: Command = new CommandClass();
Expand All @@ -82,14 +83,14 @@ export class CommandLoader
continue;

this._logger.info(`Loaded command: ${commandInstance.name}`);
commandInstance._classloc = file;
commandInstance.classloc = file;
loadedCommands.push(commandInstance);
}
}

// Register all of the loaded commands
for (const command of loadedCommands)
this._commands._registerInternal(command);
this._commands.registerInternal(command);

return loadedCommands.length;
}
Expand Down
16 changes: 8 additions & 8 deletions src/command/CommandRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class CommandRegistry<
public registerExternal(command: Command<any>): void
{
this._logger.info(`External command loaded: ${command.name}`);
this._registerInternal(command as V, true);
this.registerInternal(command as V, true);
}

/**
Expand All @@ -85,7 +85,7 @@ export class CommandRegistry<
* `registerExternal()` instead
* @private
*/
public _registerInternal(command: V, external: boolean = false): void
public registerInternal(command: V, external: boolean = false): void
{
if (this.has(command.name as K))
{
Expand All @@ -97,15 +97,15 @@ export class CommandRegistry<
this.delete(command.name as K);
}
this.set(command.name as K, command);
command._register(this._client);
command.register(this._client);
if (external) command.external = true;
}

/**
* Check for duplicate aliases, erroring on any. Used internally
* @private
*/
public _checkDuplicateAliases(): void
public checkDuplicateAliases(): void
{
for (const command of this.values())
for (const alias of command.aliases)
Expand Down Expand Up @@ -133,7 +133,7 @@ export class CommandRegistry<
* Check for commands with reserved names. Used internally
* @private
*/
public _checkReservedCommandNames(): void
public checkReservedCommandNames(): void
{
const reserved: string[] = this._reserved.map(r => typeof r !== 'string' ? r() : r);
for (const name of reserved)
Expand All @@ -151,17 +151,17 @@ export class CommandRegistry<
* This is an internal method and should not be used
* @private
*/
public async _initCommands(): Promise<boolean>
public async initCommands(): Promise<boolean>
{
let success: boolean = true;
for (const command of this.values())
{
if (command._initialized) continue;
if (command.initialized) continue;
try
{
// eslint-disable-next-line no-await-in-loop, @typescript-eslint/await-thenable
await command.init();
command._initialized = true;
command.initialized = true;
}
catch (err)
{
Expand Down
6 changes: 3 additions & 3 deletions src/command/base/Reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export default class extends Command
const commandStart: number = Util.now();

const disabled: string[] = this.client.commands.filter(c => c.disabled).map(c => c.name);
const reloaded: number = this.client._reloadCustomCommands();
const reloaded: number = this.client.reloadCustomCommands();

this._logger.log('Re-initializing reloaded commands...');
this.client.commands._initCommands();
this.client.commands.initCommands();

const toDisable: Collection<string, Command> =
this.client.commands.filter(c => disabled.includes(c.name));
Expand All @@ -47,7 +47,7 @@ export default class extends Command

// Reload events
const eventStart: number = Util.now();
const eventNumber: string = this.client._reloadEvents().toString();
const eventNumber: string = this.client.reloadEvents().toString();
const eventEnd: number = Util.now();

const commandTime: string = (commandEnd - commandStart).toFixed(3);
Expand Down
4 changes: 2 additions & 2 deletions src/command/resolvers/ResolverLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export class ResolverLoader
* Used internally
* @private
*/
public _loadResolvers(): void
public loadResolvers(): void
{
for (const resolver of this._base.concat(this._client._customResolvers))
for (const resolver of this._base.concat(this._client.customResolvers))
{
// eslint-disable-next-line new-cap
const newResolver: Resolver = new resolver(this._client);
Expand Down
2 changes: 1 addition & 1 deletion src/event/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class Event<T extends Client = Client>
* Receive the client instance and save it
* @private
*/
public _register(client: T): void
public register(client: T): void
{
/**
* The YAMDBF Client instance
Expand Down
3 changes: 2 additions & 1 deletion src/event/EventLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class EventLoader
continue;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
for (const EventClass of eventClasses)
{
const eventInstance: Event = new EventClass();
Expand All @@ -127,7 +128,7 @@ export class EventLoader
// Register all of the loaded events
for (const event of loadedEvents)
{
event._register(this._client);
event.register(this._client);
this._registry.register(event);
}

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ import { GuildStorage } from './storage/GuildStorage';
import { Client } from './client/Client';

// Add a getter for GuildStorage to the base Guild class
Structures.extend('Guild', Guild =>
class extends Guild
Structures.extend('Guild', guild =>
class extends guild
{
public get storage(): GuildStorage
{
Expand Down
4 changes: 3 additions & 1 deletion src/storage/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export class Database
Database._instance = this;
this._url = url;

// Lazy load sequelize
const packages: string[] = ['sequelize-typescript', 'sequelize'];

// Lazy load sequelize
// eslint-disable-next-line @typescript-eslint/naming-convention
const Seq: typeof Sequelize.Sequelize = Util.lazyLoad<typeof Sequelize>(...packages).Sequelize;

const logging: (...args: any[]) => void =
Expand Down
1 change: 1 addition & 0 deletions src/storage/Providers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { SequelizeProvider, Dialect } from './SequelizeProvider';
import { JSONProvider } from './JSONProvider';
import { StorageProviderConstructor } from '../types/StorageProviderConstructor';
Expand Down
Loading

0 comments on commit ca765f6

Please sign in to comment.