Skip to content

Commit

Permalink
turned off a few custom lint rules to be more in line with the airbnb…
Browse files Browse the repository at this point in the history
… standard
  • Loading branch information
stevengill committed Jul 23, 2020
1 parent 4654309 commit 88c033c
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 97 deletions.
92 changes: 46 additions & 46 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'airbnb-typescript/base',
/* TODO: Uncomment rule below once jsdoc comments are added.
env: {
es6: true,
node: true,
},
extends: [
'airbnb-typescript/base',
/* TODO: Uncomment rule below once jsdoc comments are added.
This matches the jsdoc rules in the TSLint config */
// "plugin:jsdoc/recommended",
'prettier',
'prettier/@typescript-eslint',
'./eslint-config-base', // the common settings in eslint-config-base
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.eslint.json',
},
plugins: ['@typescript-eslint'],
ignorePatterns: ["**/*.spec.ts", "src/test-helpers.ts"],
rules: {
// "plugin:jsdoc/recommended",
'prettier',
'prettier/@typescript-eslint',
'./eslint-config-base', // the common settings in eslint-config-base
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.eslint.json',
},
plugins: ['@typescript-eslint'],
ignorePatterns: ['**/*.spec.ts', 'src/test-helpers.ts'],
rules: {
/* Below are some of the new 'airbnb-typescript' rules that the project currently does not follow.
They've been disabled here since they raise errors in a few files. The best course
of action is likely to adopt these rules and make the quick (and mostly automated) fixes
needed in the repo to conform to these. ESLint and the airbnb-typecript config is more strict
than the original TSLint configuration that this project had. */
'import/first': ['off'],
'import/prefer-default-export': ['off'],
'import/newline-after-import': ['off'],
'import/no-cycle': ['off'],
'import/no-useless-path-segments': ['off'],
'import/order': ['off'],
'max-classes-per-file': ['off', 1],
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
'no-nested-ternary': 'off',
'no-restricted-globals': 'off',
'no-lonely-if': 'off',
'no-undef-init': 'off',
'no-multi-assign': 'off',
'prefer-object-spread': 'off',
'consistent-return': 'off',
'no-restricted-syntax': 'off',
'prefer-destructuring': 'off',
'import/first': ['off'],
'import/prefer-default-export': ['off'],
'max-classes-per-file': ['off', 1],
'import/no-cycle': ['off'],
'@typescript-eslint/no-use-before-define': 'off',
'no-nested-ternary': 'off',
'consistent-return': 'off',
// 'import/order': ['off'],
// 'import/newline-after-import': ['off'],
// 'import/no-useless-path-segments': ['off'],
// '@typescript-eslint/lines-between-class-members': 'off',
// 'no-restricted-globals': 'off',
// 'no-lonely-if': 'off',
// 'no-undef-init': 'off',
// 'no-multi-assign': 'off',
// 'prefer-object-spread': 'off',
// 'no-restricted-syntax': 'off',
// 'prefer-destructuring': 'off',

/* Some currently-enabled additional rules. Uncomment to disable. The project currently conforms to them
so there it's best to just keep these commented or delete them entirely */
// '@typescript-eslint/ban-types': 'off',
// '@typescript-eslint/no-empty-interface': 'off',
// '@typescript-eslint/no-unsafe-assign': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/no-unsafe-member-access': 'off',
// '@typescript-eslint/no-unsafe-return': 'off',
// '@typescript-eslint/no-unnecessary-type-assertion': 'off',
// '@typescript-eslint/no-non-null-assertion': 'off',
// '@typescript-eslint/no-unsafe-assignment': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/no-unsafe-member-access': 'off',
// '@typescript-eslint/no-unsafe-return': 'off',
// '@typescript-eslint/no-unnecessary-type-assertion': 'off',
// '@typescript-eslint/no-non-null-assertion': 'off',
// '@typescript-eslint/no-unsafe-assignment': 'off',
// '@typescript-eslint/no-unsafe-call': 'off',
// '@typescript-eslint/restrict-template-expressions': 'off',
// '@typescript-eslint/unbound-method': 'off',
// '@typescript-eslint/explicit-module-boundary-types': 'off',
// '@typescript-eslint/unbound-method': 'off',
// '@typescript-eslint/explicit-module-boundary-types': 'off',
// '@typescript-eslint/require-await': 'off',
},
},
};
63 changes: 30 additions & 33 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WebClient, ChatPostMessageArguments, addAppMetadata, WebClientOptions }
import { Logger, LogLevel, ConsoleLogger } from '@slack/logger';
import axios, { AxiosInstance } from 'axios';
import ExpressReceiver, { ExpressReceiverOptions } from './ExpressReceiver';
import packageJson from '../package.json';
import {
ignoreSelf as ignoreSelfMiddleware,
onlyActions,
Expand Down Expand Up @@ -46,8 +47,8 @@ import {
} from './types';
import { IncomingEventType, getTypeAndConversation, assertNever } from './helpers';
import { CodedError, asCodedError, AppInitializationError, MultipleListenerError } from './errors';
// eslint-disable-next-line import/order
import allSettled = require('promise.allsettled'); // eslint-disable-line @typescript-eslint/no-require-imports
const packageJson = require('../package.json'); // eslint-disable-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires

/** App initialization options */
export interface AppOptions {
Expand Down Expand Up @@ -122,6 +123,7 @@ export interface ErrorHandler {

class WebClientPool {
private pool: { [token: string]: WebClient } = {};

public getOrCreate(token: string, clientOptions: WebClientOptions): WebClient {
const cachedClient = this.pool[token];
if (typeof cachedClient !== 'undefined') {
Expand Down Expand Up @@ -208,44 +210,38 @@ export default class App {
// the public WebClient instance (app.client) - this one doesn't have a token
this.client = new WebClient(undefined, this.clientOptions);

this.axios = axios.create(
Object.assign(
{
httpAgent: agent,
httpsAgent: agent,
},
clientTls,
),
);
this.axios = axios.create({
httpAgent: agent,
httpsAgent: agent,
...clientTls,
});

this.middleware = [];
this.listeners = [];

// Check for required arguments of ExpressReceiver
if (receiver !== undefined) {
this.receiver = receiver;
} else {
} else if (signingSecret === undefined) {
// No custom receiver
if (signingSecret === undefined) {
throw new AppInitializationError(
'Signing secret not found, so could not initialize the default receiver. Set a signing secret or use a ' +
'custom receiver.',
);
} else {
// Create default ExpressReceiver
this.receiver = new ExpressReceiver({
signingSecret,
endpoints,
processBeforeResponse,
clientId,
clientSecret,
stateSecret,
installationStore,
installerOptions,
scopes,
logger: this.logger,
});
}
throw new AppInitializationError(
'Signing secret not found, so could not initialize the default receiver. Set a signing secret or use a ' +
'custom receiver.',
);
} else {
// Create default ExpressReceiver
this.receiver = new ExpressReceiver({
signingSecret,
endpoints,
processBeforeResponse,
clientId,
clientSecret,
stateSecret,
installationStore,
installerOptions,
scopes,
logger: this.logger,
});
}

let usingOauth = false;
Expand Down Expand Up @@ -611,11 +607,12 @@ export default class App {
}

// Get the client arg
let client = this.client;
let { client } = this;
const token = selectToken(context);
if (token !== undefined) {
let pool = this.clients[source.teamId];
if (pool === undefined) {
// eslint-disable-next-line no-multi-assign
pool = this.clients[source.teamId] = new WebClientPool();
}
client = pool.getOrCreate(token, this.clientOptions);
Expand Down Expand Up @@ -783,7 +780,7 @@ function singleTeamAuthorization(
});

return async () => {
return Object.assign({ botToken: authorization.botToken }, await identifiers);
return { botToken: authorization.botToken, ...(await identifiers) };
};
}

Expand Down
18 changes: 12 additions & 6 deletions src/ExpressReceiver.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility, @typescript-eslint/strict-boolean-expressions */

import { AnyMiddlewareArgs, Receiver, ReceiverEvent } from './types';
import { createServer, Server } from 'http';
import express, { Request, Response, Application, RequestHandler, Router } from 'express';
import rawBody from 'raw-body';
import querystring from 'querystring';
import crypto from 'crypto';
import tsscmp from 'tsscmp';
import App from './App';
import { ReceiverAuthenticityError, ReceiverMultipleAckError } from './errors';
import { Logger, ConsoleLogger } from '@slack/logger';
import { InstallProvider, StateStore, InstallationStore, CallbackOptions } from '@slack/oauth';
import App from './App';
import { ReceiverAuthenticityError, ReceiverMultipleAckError } from './errors';
import { AnyMiddlewareArgs, Receiver, ReceiverEvent } from './types';

// TODO: we throw away the key names for endpoints, so maybe we should use this interface. is it better for migrations?
// if that's the reason, let's document that with a comment.
Expand Down Expand Up @@ -50,10 +50,15 @@ export default class ExpressReceiver implements Receiver {
public app: Application;

private server: Server;

private bolt: App | undefined;

private logger: Logger;

private processBeforeResponse: boolean;

public router: Router;

public installer: InstallProvider | undefined = undefined;

constructor({
Expand Down Expand Up @@ -83,9 +88,9 @@ export default class ExpressReceiver implements Receiver {
this.logger = logger;
const endpointList = typeof endpoints === 'string' ? [endpoints] : Object.values(endpoints);
this.router = Router();
for (const endpoint of endpointList) {
endpointList.forEach((endpoint) => {
this.router.post(endpoint, ...expressMiddleware);
}
});

if (
clientId !== undefined &&
Expand Down Expand Up @@ -143,7 +148,7 @@ export default class ExpressReceiver implements Receiver {
// tslint:disable-next-line: align
}, 3001);

let storedResponse = undefined;
let storedResponse;
const event: ReceiverEvent = {
body: req.body,
ack: async (response): Promise<void> => {
Expand Down Expand Up @@ -300,6 +305,7 @@ function verifyRequestSignature(
}

const ts = Number(requestTimestamp);
// eslint-disable-next-line no-restricted-globals
if (isNaN(ts)) {
throw new ReceiverAuthenticityError('Slack request signing verification failed. Timestamp is invalid.');
}
Expand Down
2 changes: 2 additions & 0 deletions src/conversation-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ export interface ConversationStore<ConversationState = any> {
*/
export class MemoryStore<ConversationState = any> implements ConversationStore<ConversationState> {
private state: Map<string, { value: ConversationState; expiresAt?: number }> = new Map();

public set(conversationId: string, value: ConversationState, expiresAt?: number): Promise<void> {
return new Promise((resolve) => {
this.state.set(conversationId, { value, expiresAt });
resolve();
});
}

public get(conversationId: string): Promise<ConversationState> {
return new Promise((resolve, reject) => {
const entry = this.state.get(conversationId);
Expand Down
4 changes: 4 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class AppInitializationError extends Error implements CodedError {

export class AuthorizationError extends Error implements CodedError {
public code = ErrorCode.AuthorizationError;

public original: Error;

constructor(message: string, original: Error) {
Expand All @@ -46,6 +47,7 @@ export class AuthorizationError extends Error implements CodedError {

export class ContextMissingPropertyError extends Error implements CodedError {
public code = ErrorCode.ContextMissingPropertyError;

public missingProperty: string;

constructor(missingProperty: string, message: string) {
Expand All @@ -68,6 +70,7 @@ export class ReceiverAuthenticityError extends Error implements CodedError {

export class MultipleListenerError extends Error implements CodedError {
public code = ErrorCode.MultipleListenerError;

public originals: Error[];

constructor(originals: Error[]) {
Expand All @@ -81,6 +84,7 @@ export class MultipleListenerError extends Error implements CodedError {

export class UnknownError extends Error implements CodedError {
public code = ErrorCode.UnknownError;

public original: Error;

constructor(original: Error) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const packageJson = require('../package.json'); // eslint-disable-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
import pleaseUpgradeNode from 'please-upgrade-node';
import packageJson from '../package.json';

pleaseUpgradeNode(packageJson);

Expand Down
8 changes: 3 additions & 5 deletions src/middleware/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,10 @@ export function matchConstraints(

if (isViewBody(body)) {
callbackId = body['view']['callback_id'];
} else if (isCallbackIdentifiedBody(body)) {
callbackId = body['callback_id'];
} else {
if (isCallbackIdentifiedBody(body)) {
callbackId = body['callback_id'];
} else {
return;
}
return;
}

if (typeof constraints.callback_id === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Middleware, AnyMiddlewareArgs, Context } from '../types';
import { WebClient } from '@slack/web-api';
import { Logger } from '@slack/logger';
import { Middleware, AnyMiddlewareArgs, Context } from '../types';

export async function processMiddleware(
middleware: Middleware<AnyMiddlewareArgs>[],
Expand Down
2 changes: 1 addition & 1 deletion src/types/events/base-events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StringIndexed } from '../helpers';
import { MessageAttachment, KnownBlock, Block, View } from '@slack/types';
import { StringIndexed } from '../helpers';

/**
* All known event types in Slack's Events API
Expand Down
4 changes: 2 additions & 2 deletions src/types/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { WebClient } from '@slack/web-api';
import { Logger } from '@slack/logger';
import { StringIndexed } from './helpers';
import { SlackEventMiddlewareArgs } from './events';
import { SlackActionMiddlewareArgs } from './actions';
import { SlackCommandMiddlewareArgs } from './command';
import { SlackOptionsMiddlewareArgs } from './options';
import { SlackShortcutMiddlewareArgs } from './shortcuts';
import { SlackViewMiddlewareArgs } from './view';
import { WebClient } from '@slack/web-api';
import { Logger } from '@slack/logger';

// TODO: rename this to AnyListenerArgs, and all the constituent types
export type AnyMiddlewareArgs =
Expand Down
2 changes: 1 addition & 1 deletion src/types/receiver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import App from '../App';
import { AckFn } from '../types';
import { AckFn } from './index';
import { StringIndexed } from './helpers';

export interface ReceiverEvent {
Expand Down
Loading

0 comments on commit 88c033c

Please sign in to comment.