Skip to content

Commit

Permalink
chore: fix eslint violations reported by typescript-eslint 4.0.x
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Sep 3, 2020
1 parent 70845d2 commit 5910843
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('example-passport-login acceptance test', () => {
*/
before(() => MockTestOauth2SocialApp.startMock());
after(MockTestOauth2SocialApp.stopMock);

before(async function setupApplication(this: Mocha.Context) {
this.timeout(6000);
server = await startApplication(oauth2Providers);
Expand Down
1 change: 1 addition & 0 deletions examples/todo/src/__tests__/acceptance/todo.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('TodoApplication', () => {
after(() => app.stop());

let available = true;

before(async function (this: Mocha.Context) {
this.timeout(30 * 1000);
const service = await app.get<Geocoder>('services.Geocoder');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import {
bind,
Component,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config,
ContextTags,
CoreBindings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/* eslint-disable @typescript-eslint/no-unused-vars */
import {config, Constructor, Context, inject, JSONObject} from '@loopback/core';
import {
api,
Expand Down
1 change: 0 additions & 1 deletion extensions/health/src/health.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
bind,
BindingScope,
Component,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config,
ContextTags,
CoreBindings,
Expand Down
1 change: 0 additions & 1 deletion extensions/metrics/src/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Application,
bind,
Component,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config,
ContextTags,
CoreBindings,
Expand Down
7 changes: 0 additions & 7 deletions fixtures/mock-oauth2-provider/src/mock-oauth2-social-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ app.use(bodyParser.text({type: 'text/html'}));
// create application/x-www-form-urlencoded parser
const urlencodedParser = bodyParser.urlencoded({extended: false});

interface JWT {
payload: {
jti: string;
client_id: string;
};
}

/**
* data structure for an app registration, also holds issued tokens for an app
*/
Expand Down
1 change: 0 additions & 1 deletion packages/authorization/src/authorize-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
asGlobalInterceptor,
bind,
BindingAddress,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config,
Context,
Interceptor,
Expand Down
8 changes: 3 additions & 5 deletions packages/context/src/binding-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {generateUniqueId} from './unique-id';

export type BindingAddress<T = unknown> = string | BindingKey<T>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export class BindingKey<ValueType> {
static readonly PROPERTY_SEPARATOR = '#';

Expand All @@ -25,16 +26,13 @@ export class BindingKey<ValueType> {
* is allowed to contain propertyPath as encoded via `BindingKey#toString()`
* @param propertyPath - Optional path to a deep property of the bound value.
*/
public static create<ValueType>(
key: string,
propertyPath?: string,
): BindingKey<ValueType> {
public static create<V>(key: string, propertyPath?: string): BindingKey<V> {
// TODO(bajtos) allow chaining of propertyPaths, e.g.
// BindingKey.create('config#rest', 'port')
// should create {key: 'config', path: 'rest.port'}
if (propertyPath) {
BindingKey.validate(key);
return new BindingKey<ValueType>(key, propertyPath);
return new BindingKey<V>(key, propertyPath);
}

return BindingKey.parseKeyWithPath(key);
Expand Down
8 changes: 4 additions & 4 deletions packages/context/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ export class Binding<T = BoundValue> extends EventEmitter {
* easy to read.
* @param key - Binding key
*/
static bind<T = unknown>(key: BindingAddress<T>): Binding<T> {
static bind<V = unknown>(key: BindingAddress<V>): Binding<V> {
return new Binding(key);
}

Expand All @@ -868,13 +868,13 @@ export class Binding<T = BoundValue> extends EventEmitter {
* .to({port: 3000});
* ```
*
* @typeParam T Generic type for the configuration value (not the binding to
* @typeParam V Generic type for the configuration value (not the binding to
* be configured)
*
* @param key - Key for the binding to be configured
*/
static configure<T = unknown>(key: BindingAddress): Binding<T> {
return new Binding(BindingKey.buildKeyForConfig<T>(key)).tag({
static configure<V = unknown>(key: BindingAddress): Binding<V> {
return new Binding(BindingKey.buildKeyForConfig<V>(key)).tag({
[ContextTags.CONFIGURATION_FOR]: key.toString(),
});
}
Expand Down
12 changes: 6 additions & 6 deletions packages/context/src/context-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class ContextView<T = unknown>
*/
on(
eventName: 'bind',
listener: <T>(event: ContextViewEvent<T>) => void,
listener: <V>(event: ContextViewEvent<V>) => void,
): this;

/**
Expand All @@ -262,7 +262,7 @@ export class ContextView<T = unknown>
*/
on(
eventName: 'unbind',
listener: <T>(event: ContextViewEvent<T> & {cachedValue?: T}) => void,
listener: <V>(event: ContextViewEvent<V> & {cachedValue?: V}) => void,
): this;

/**
Expand All @@ -282,7 +282,7 @@ export class ContextView<T = unknown>
* @param listener The listener function to call when the event is emitted.
*/
// eslint-disable-next-line @typescript-eslint/unified-signatures
on(eventName: 'refresh', listener: <T>(result: T[]) => void): this;
on(eventName: 'refresh', listener: <V>(result: V[]) => void): this;

/**
* The "close" event is emitted when the view is closed (stopped observing
Expand Down Expand Up @@ -311,7 +311,7 @@ export class ContextView<T = unknown>
*/
once(
eventName: 'bind',
listener: <T>(event: ContextViewEvent<T>) => void,
listener: <V>(event: ContextViewEvent<V>) => void,
): this;

/**
Expand All @@ -322,7 +322,7 @@ export class ContextView<T = unknown>
*/
once(
eventName: 'unbind',
listener: <T>(event: ContextViewEvent<T> & {cachedValue?: T}) => void,
listener: <V>(event: ContextViewEvent<V> & {cachedValue?: V}) => void,
): this;

/**
Expand All @@ -342,7 +342,7 @@ export class ContextView<T = unknown>
* @param listener The listener function to call when the event is emitted.
*/
// eslint-disable-next-line @typescript-eslint/unified-signatures
once(eventName: 'refresh', listener: <T>(result: T[]) => void): this;
once(eventName: 'refresh', listener: <V>(result: V[]) => void): this;

/**
* The "close" event is emitted when the view is closed (stopped observing
Expand Down
3 changes: 2 additions & 1 deletion packages/context/src/interception-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export type AsValueOrPromise<T> = T extends Promise<unknown>
*/
export type AsInterceptedFunction<T> = T extends (
...args: InvocationArgs
) => infer R
) => // eslint-disable-next-line @typescript-eslint/no-unused-vars
infer R
? (...args: InvocationArgs) => AsValueOrPromise<R>
: T;

Expand Down
4 changes: 2 additions & 2 deletions packages/context/src/value-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function getDeepProperty<OUT = BoundValue, IN = BoundValue>(
*/
export function resolveMap<T, V>(
map: MapObject<T>,
resolver: (val: T, key: string, map: MapObject<T>) => ValueOrPromise<V>,
resolver: (val: T, key: string, values: MapObject<T>) => ValueOrPromise<V>,
): ValueOrPromise<MapObject<V>> {
const result: MapObject<V> = {};
let asyncResolvers: PromiseLike<void>[] | undefined = undefined;
Expand Down Expand Up @@ -156,7 +156,7 @@ export function resolveMap<T, V>(
*/
export function resolveList<T, V>(
list: T[],
resolver: (val: T, index: number, list: T[]) => ValueOrPromise<V>,
resolver: (val: T, index: number, values: T[]) => ValueOrPromise<V>,
): ValueOrPromise<V[]> {
const result: V[] = new Array<V>(list.length);
let asyncResolvers: PromiseLike<void>[] | undefined = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ describe('Express middleware registry', () => {
});

it('registers a LoopBack middleware provider with config injection', async () => {
type SpyConfig = {headerName: string};
type TestSpyConfig = {headerName: string};
class SpyMiddlewareProviderWithConfig implements Provider<Middleware> {
@config()
private options: SpyConfig;
private options: TestSpyConfig;
value(): Middleware {
return async ({request, response}, next) => {
response.set(
Expand Down
8 changes: 2 additions & 6 deletions packages/express/src/middleware-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ export function registerExpressMiddlewareInterceptor<CFG>(
middlewareConfig,
options,
);
const binding = createMiddlewareInterceptorBinding<CFG>(
providerClass,
options,
);
const binding = createMiddlewareInterceptorBinding(providerClass, options);
ctx.add(binding);
return binding;
}
Expand All @@ -400,9 +397,8 @@ export function registerExpressMiddlewareInterceptor<CFG>(
* @param middlewareProviderClass - Middleware provider class
* @param options - Options to create middlewareFactory interceptor binding
*
* @typeParam CFG - Configuration type
*/
export function createMiddlewareInterceptorBinding<CFG>(
export function createMiddlewareInterceptorBinding(
middlewareProviderClass: Constructor<Provider<Interceptor>>,
options: MiddlewareInterceptorBindingOptions = {},
) {
Expand Down
50 changes: 25 additions & 25 deletions packages/metadata/src/decorator-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ export class DecoratorFactory<
* @param options - Options for the decorator
*/
protected static _createDecorator<
T,
M extends T | MetadataMap<T> | MetadataMap<T[]>,
D extends DecoratorType
>(key: MetadataKey<T, D>, spec: T, options?: DecoratorOptions): D {
const inst = new this<T, M, D>(key.toString(), spec, options);
S,
MT extends S | MetadataMap<S> | MetadataMap<S[]>,
DT extends DecoratorType
>(key: MetadataKey<S, DT>, spec: S, options?: DecoratorOptions): DT {
const inst = new this<S, MT, DT>(key.toString(), spec, options);
return inst.create();
}

Expand Down Expand Up @@ -422,12 +422,12 @@ export class ClassDecoratorFactory<T> extends DecoratorFactory<
* @param spec - Metadata object from the decorator function
* @param options - Options for the decorator
*/
static createDecorator<T>(
key: MetadataKey<T, ClassDecorator>,
spec: T,
static createDecorator<S>(
key: MetadataKey<S, ClassDecorator>,
spec: S,
options?: DecoratorOptions,
) {
return super._createDecorator<T, T, ClassDecorator>(key, spec, options);
return super._createDecorator<S, S, ClassDecorator>(key, spec, options);
}
}

Expand Down Expand Up @@ -483,12 +483,12 @@ export class PropertyDecoratorFactory<T> extends DecoratorFactory<
* @param spec - Metadata object from the decorator function
* @param options - Options for the decorator
*/
static createDecorator<T>(
key: MetadataKey<T, PropertyDecorator>,
spec: T,
static createDecorator<S>(
key: MetadataKey<S, PropertyDecorator>,
spec: S,
options?: DecoratorOptions,
) {
return super._createDecorator<T, MetadataMap<T>, PropertyDecorator>(
return super._createDecorator<S, MetadataMap<S>, PropertyDecorator>(
key,
spec,
options,
Expand Down Expand Up @@ -549,12 +549,12 @@ export class MethodDecoratorFactory<T> extends DecoratorFactory<
* @param spec - Metadata object from the decorator function
* @param options - Options for the decorator
*/
static createDecorator<T>(
key: MetadataKey<T, MethodDecorator>,
spec: T,
static createDecorator<S>(
key: MetadataKey<S, MethodDecorator>,
spec: S,
options?: DecoratorOptions,
) {
return super._createDecorator<T, MetadataMap<T>, MethodDecorator>(
return super._createDecorator<S, MetadataMap<S>, MethodDecorator>(
key,
spec,
options,
Expand Down Expand Up @@ -642,12 +642,12 @@ export class ParameterDecoratorFactory<T> extends DecoratorFactory<
* @param spec - Metadata object from the decorator function
* @param options - Options for the decorator
*/
static createDecorator<T>(
key: MetadataKey<T, ParameterDecorator>,
spec: T,
static createDecorator<S>(
key: MetadataKey<S, ParameterDecorator>,
spec: S,
options?: DecoratorOptions,
) {
return super._createDecorator<T, MetadataMap<T[]>, ParameterDecorator>(
return super._createDecorator<S, MetadataMap<S[]>, ParameterDecorator>(
key,
spec,
options,
Expand Down Expand Up @@ -777,12 +777,12 @@ export class MethodParameterDecoratorFactory<T> extends DecoratorFactory<
* @param spec - Metadata object from the decorator function
* @param options - Options for the decorator
*/
static createDecorator<T>(
key: MetadataKey<T, MethodDecorator>,
spec: T,
static createDecorator<S>(
key: MetadataKey<S, MethodDecorator>,
spec: S,
options?: DecoratorOptions,
) {
return super._createDecorator<T, MetadataMap<T[]>, MethodDecorator>(
return super._createDecorator<S, MetadataMap<S[]>, MethodDecorator>(
key,
spec,
options,
Expand Down
9 changes: 5 additions & 4 deletions packages/metadata/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type DecoratorType =
* @typeParam T - Type of the metadata value
* @typeParam D - Type of the decorator
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export class MetadataAccessor<T, D extends DecoratorType = DecoratorType> {
private constructor(public readonly key: string) {}

Expand All @@ -27,11 +28,11 @@ export class MetadataAccessor<T, D extends DecoratorType = DecoratorType> {
/**
* Create a strongly-typed metadata accessor
* @param key - The metadata key
* @typeParam T - Type of the metadata value
* @typeParam D - Type of the decorator
* @typeParam V - Type of the metadata value
* @typeParam DT - Type of the decorator
*/
static create<T, D extends DecoratorType>(key: string) {
return new MetadataAccessor<T, D>(key);
static create<V, DT extends DecoratorType>(key: string) {
return new MetadataAccessor<V, DT>(key);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/openapi-v3/src/controller-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ function processSchemaExtensions(
* You cannot provide BOTH a defnintion AND one of these keywords.
*/
/* istanbul ignore else */
const hasOwn = (prop: string) => schema?.hasOwnProperty(prop);
const hasOwn = (prop: string) =>
schema != null && Object.prototype.hasOwnProperty.call(schema, prop);

if (SCHEMA_ARR_KEYS.some(k => hasOwn(k))) {
SCHEMA_ARR_KEYS.forEach((k: MixKey) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/openapi-v3/src/decorators/response.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ interface ResponseWithContent extends ResponseObject {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isResponseObject(c: any): c is ResponseWithContent {
return !!c?.hasOwnProperty('content') && !!c.content;
return (
c != null &&
Object.prototype.hasOwnProperty.call(c, 'content') &&
c.content != null
);
}

function buildDecoratorReducer(
Expand Down
Loading

0 comments on commit 5910843

Please sign in to comment.