Skip to content

Commit

Permalink
fix(config): update lint to naming-convention rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jul 30, 2020
1 parent 062007d commit 64e1e64
Show file tree
Hide file tree
Showing 35 changed files with 106 additions and 19 deletions.
58 changes: 55 additions & 3 deletions config/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
}
}
],
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility": [
Expand All @@ -61,7 +60,6 @@
"SwitchCase": 1
}
],
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/member-delimiter-style": [
"error",
{
Expand Down Expand Up @@ -89,6 +87,60 @@
]
}
],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": [
"camelCase"
],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid"
},
{
"selector": "variable",
"format": [
"camelCase",
"UPPER_CASE"
],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid"
},
{
"selector": "typeLike",
"format": [
"PascalCase"
],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid"
},
{
"selector": "interface",
"format": [
"PascalCase"
],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid"
},
{
"selector": "function",
"format": [
"camelCase",
"PascalCase"
],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid"
},
{
"selector": "enumMember",
"format": [
"PascalCase",
"UPPER_CASE"
],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid"
}
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
Expand Down Expand Up @@ -386,4 +438,4 @@
}
]
}
}
}
4 changes: 2 additions & 2 deletions src/controller/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Listener } from '../listener';
import { Locale, TranslateOptions } from '../locale';
import { ServiceModule } from '../module/ServiceModule';
import { ServiceDefinition } from '../Service';
import { applyTransforms, extractBody, Transform, TransformData } from '../transform';
import { applyTransforms, extractBody, Transform, TransformData, TransformInput } from '../transform';
import { TYPE_JSON, TYPE_TEXT } from '../utils/Mime';

export type HandlerMethod = (this: BaseController<ControllerData>, cmd: Command, ctx: Context) => Promise<void>;
Expand Down Expand Up @@ -144,7 +144,7 @@ export abstract class BaseController<TData extends ControllerData> extends BotSe
return false;
}

protected async transformJSON(cmd: Command, data: object, ctx?: Context): Promise<void> {
protected async transformJSON(cmd: Command, data: TransformInput, ctx?: Context): Promise<void> {
this.logger.debug({ data }, 'transforming json body');

const result = await applyTransforms(this.transforms, cmd, TYPE_JSON, data);
Expand Down
4 changes: 3 additions & 1 deletion src/controller/CommandController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { makeDict } from '@apextoaster/js-utils';

import { CheckRBAC, Controller, ControllerData, Handler } from '.';
import { Command, CommandOptions, CommandVerb } from '../entity/Command';
import { Context } from '../entity/Context';
Expand All @@ -19,7 +21,7 @@ export class CommandController extends BaseController<CommandControllerData> imp
@Handler(NOUN_COMMAND, CommandVerb.Create)
@CheckRBAC()
public async createCommand(cmd: Command, ctx: Context): Promise<void> {
const data = await applyTransforms(this.transforms, cmd, TYPE_JSON, cmd.data);
const data = await applyTransforms(this.transforms, cmd, TYPE_JSON, makeDict(cmd.data));
this.logger.debug({ data }, 'creating next command');
const next = new Command({
context: ctx,
Expand Down
1 change: 1 addition & 0 deletions src/controller/SearchController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SearchController extends BaseController<SearchControllerData> imple
const requestUrl = this.url.render({ data });
this.logger.debug({ requestUrl }, 'searching at url');

/* eslint-disable-next-line @typescript-eslint/ban-types */
const response: object = await this.request.create({
json: true,
method: this.data.request.method,
Expand Down
2 changes: 2 additions & 0 deletions src/controller/WeatherController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Context } from '../entity/Context';
import { RequestFactory } from '../utils/Request';
import { BaseController, BaseControllerOptions } from './BaseController';

/* eslint-disable @typescript-eslint/naming-convention */

export interface WeatherControllerData extends ControllerData {
api: {
key: string;
Expand Down
2 changes: 2 additions & 0 deletions src/controller/github/PullController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Context } from '../../entity/Context';
import { GithubClient, GithubClientData } from '../../utils/github';
import { BaseController, BaseControllerOptions, ErrorReplyType } from '../BaseController';

/* eslint-disable @typescript-eslint/naming-convention */

export const NOUN_PULL_REQUEST = 'github-pull-request';

export interface GithubPullControllerData extends ControllerData {
Expand Down
1 change: 1 addition & 0 deletions src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface HandlerOptions {
rbac?: RBACOptions;
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
export function getHandlerOptions(target: Function): HandlerOptions | undefined {
if (!Reflect.hasMetadata(SYMBOL_HANDLER, target)) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/endpoint/GitlabEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { TemplateScope } from '../utils/Template';
import { BaseEndpointOptions, STATUS_NOTFOUND, STATUS_SUCCESS } from './BaseEndpoint';
import { HookEndpoint, HookEndpointData } from './HookEndpoint';

/* eslint-disable @typescript-eslint/no-explicit-any, camelcase */
/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any, camelcase */

export interface GitlabBaseWebhook {
object_kind: string;
}
Expand Down
1 change: 1 addition & 0 deletions src/entity/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Command extends BaseCommand implements CommandOptions {
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
const result: Dict<unknown> = {
data: Array.from(this.data),
Expand Down
1 change: 1 addition & 0 deletions src/entity/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class Context extends BaseEntity implements ContextOptions, ContextRoute
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
return {
channel: this.channel,
Expand Down
3 changes: 2 additions & 1 deletion src/entity/Fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class Fragment extends BaseCommand implements FragmentOptions {
}
}

public toJSON() {
/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
return {
data: this.data,
id: this.id,
Expand Down
1 change: 1 addition & 0 deletions src/entity/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Message extends LabelEntity implements MessageEntityOptions {
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
const context = doesExist(this.context) ? this.context.toJSON() : {};
return {
Expand Down
1 change: 1 addition & 0 deletions src/entity/Tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Tick extends BaseEntity {
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
return {
createdAt: this.createdAt,
Expand Down
1 change: 1 addition & 0 deletions src/entity/auth/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class Token extends DataEntity<Array<string>> implements TokenOptions {
});
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
return {
audience: this.audience,
Expand Down
1 change: 1 addition & 0 deletions src/entity/auth/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class User extends BaseEntity implements UserOptions {
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public toJSON(): object {
return {
id: this.id,
Expand Down
1 change: 1 addition & 0 deletions src/entity/base/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ export abstract class BaseCommand extends DataEntity<CommandValue> {
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public abstract toJSON(): object;
}
1 change: 1 addition & 0 deletions src/entity/base/BaseEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export abstract class BaseEntity implements BaseEntityOptions {
}
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public abstract toJSON(): object;

public toString(): string {
Expand Down
1 change: 1 addition & 0 deletions src/entity/base/DataEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ export abstract class DataEntity<TVal> extends LabelEntity {
return getOrDefault(this.data, key, defaultValue);
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public abstract toJSON(): object;
}
1 change: 1 addition & 0 deletions src/entity/base/LabelEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export abstract class LabelEntity extends BaseEntity {
this.labelStr = JSON.stringify(Array.from(this.labels));
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public abstract toJSON(): object;
}
1 change: 1 addition & 0 deletions src/listener/ExpressListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class ExpressListener extends SessionListener<ExpressListenerData> implem
return [];
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public traceRequest(req: Request, res: Response, next: Function) {
this.logger.debug({ req, res }, 'handling request');
this.requestCounter.inc({
Expand Down
1 change: 1 addition & 0 deletions src/module/EntityModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class EntityModule extends Module {
}

@Provides(INJECT_ENTITIES)
/* eslint-disable-next-line @typescript-eslint/ban-types */
public async createEntities(): Promise<Array<Function>> {
return [
Command,
Expand Down
2 changes: 2 additions & 0 deletions src/schema/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { ServiceModule } from '../../module/ServiceModule';
import { GRAPH_OUTPUT_SERVICE, ServiceMetadata } from '../../Service';
import { Storage } from '../../storage';

/* eslint-disable @typescript-eslint/naming-convention */

const GRAPH_INPUT_COMMAND_LIST = new GraphQLList(GRAPH_INPUT_COMMAND);
const GRAPH_INPUT_MESSAGE_LIST = new GraphQLList(GRAPH_INPUT_MESSAGE);
const GRAPH_OUTPUT_COMMAND_LIST = new GraphQLList(GRAPH_OUTPUT_COMMAND);
Expand Down
8 changes: 5 additions & 3 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Ajv from 'ajv';
import { SCHEMA_KEYWORD_REGEXP } from './keyword/Regexp';
import * as SCHEMA_GLOBAL from './schema.yml';

export type SchemaDef = Record<string, unknown>;

export interface SchemaResult {
errors: Array<string>;
valid: boolean;
Expand All @@ -22,9 +24,9 @@ export class Schema {

protected compiler: Ajv.Ajv;

private readonly children: Map<string, object>;
private readonly children: Map<string, SchemaDef>;

constructor(schema: object = SCHEMA_GLOBAL) {
constructor(schema: SchemaDef = SCHEMA_GLOBAL) {
this.children = new Map();
this.compiler = new Ajv({
allErrors: true,
Expand All @@ -40,7 +42,7 @@ export class Schema {
this.addSchema('isolex', schema);
}

public addSchema(name: string, schema: object) {
public addSchema(name: string, schema: SchemaDef) {
if (!this.children.has(name)) {
this.children.set(name, schema);
this.compiler.addSchema(schema, name);
Expand Down
2 changes: 2 additions & 0 deletions src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { INJECT_ENTITIES } from '../module/EntityModule';
import { INJECT_MIGRATIONS } from '../module/MigrationModule';
import { ServiceLifecycle } from '../Service';

/* eslint-disable @typescript-eslint/ban-types */

export const INJECT_STORAGE_LOGGER = Symbol('inject-storage-logger');

export interface StorageData extends BaseServiceData {
Expand Down
1 change: 1 addition & 0 deletions src/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Service, ServiceDefinition } from '../Service';
import { TemplateScope } from '../utils/Template';

// @TODO: fix these good
/* eslint-disable-next-line @typescript-eslint/ban-types */
export type TransformInput = object;
export type TransformOutput = TemplateScope;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createServiceCounter(registry: Registry, config: Partial<Counter
});
}

export function incrementServiceCounter(svc: Service, counter: StringCounter, data: object) {
export function incrementServiceCounter(svc: Service, counter: StringCounter, data: Record<string, string | undefined>) {
counter.inc({
...data,
serviceId: svc.id,
Expand Down
1 change: 1 addition & 0 deletions src/utils/TemplateCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class TemplateCompiler {
return parts.join('');
}

/* eslint-disable-next-line @typescript-eslint/ban-types */
public formatJSON(value: object): hbs.SafeString {
return new Handlebars.SafeString(JSON.stringify(value));
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { INJECT_LOGGER, INJECT_REQUEST } from '../../BaseService';
import { classLogger } from '../../logger';
import { RequestFactory, RequestOptions } from '../Request';

/* eslint-disable camelcase */
/* eslint-disable camelcase, @typescript-eslint/naming-convention */

export interface GroupOptions {
group: string;
}
Expand Down
2 changes: 1 addition & 1 deletion test/controller/TestEchoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('echo controller', async () => {
const msg = 'hello world';
module.bind('test-transform').toInstance(ineeda<Transform>({
check: () => Promise.resolve(true),
transform: (c: Command, type: string, data: object) => Promise.resolve({
transform: (c: Command, type: string, data: Record<string, unknown>) => Promise.resolve({
body: [msg],
}),
}));
Expand Down
3 changes: 2 additions & 1 deletion test/controller/github/TestCommitController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { Transform } from '../../../src/transform';
import { GithubClient } from '../../../src/utils/github';
import { createService, createServiceContainer } from '../../helpers/container';

/* eslint-disable @typescript-eslint/no-explicit-any, camelcase */
/* eslint-disable @typescript-eslint/naming-convention,@typescript-eslint/no-explicit-any, camelcase */

const TEST_TRANSFORM = 'test-transform';

interface ClientResponse<T> {
Expand Down
2 changes: 2 additions & 0 deletions test/endpoint/TestGitlabEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { GitlabEndpoint, GitlabEndpointData } from '../../src/endpoint/GitlabEnd
import { CommandVerb } from '../../src/entity/Command';
import { createEndpoint } from '../helpers/request';

/* eslint-disable @typescript-eslint/naming-convention */

const TEST_DATA: GitlabEndpointData = {
defaultCommand: {
data: {},
Expand Down
2 changes: 1 addition & 1 deletion test/entity/base/TestBaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseCommand } from '../../../src/entity/base/BaseCommand';
import { CommandVerb } from '../../../src/entity/Command';

class TestCommand extends BaseCommand {
public toJSON(): object {
public toJSON() {
return {};
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/entity/base/TestDataEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestEntity extends DataEntity<string> {
this.labelStr = str;
}

public toJSON(): object {
public toJSON() {
return {};
}
}
Expand Down
Loading

0 comments on commit 64e1e64

Please sign in to comment.