Skip to content

Commit

Permalink
fix: adapt to new eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Jan 17, 2025
1 parent 511b6ee commit 2f950e5
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export class AccessTokenEvents {
addAccessTokenExpired(cb: AccessTokenCallback): () => void;
addAccessTokenExpiring(cb: AccessTokenCallback): () => void;
// (undocumented)
load(container: User): Promise<void>;
load(container: User): void;
// (undocumented)
protected readonly _logger: Logger;
removeAccessTokenExpired(cb: AccessTokenCallback): void;
removeAccessTokenExpiring(cb: AccessTokenCallback): void;
// (undocumented)
unload(): Promise<void>;
unload(): void;
}

// @public (undocumented)
Expand Down
10 changes: 5 additions & 5 deletions jest-environment-jsdom.cjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
"use strict";

const { TextEncoder, TextDecoder } = require('util');
const { default: $JSDOMEnvironment, TestEnvironment } = require('jest-environment-jsdom');
const { TextEncoder, TextDecoder } = require("util");
const { default: $JSDOMEnvironment, TestEnvironment } = require("jest-environment-jsdom");
const crypto = require("crypto");

Object.defineProperty(exports, '__esModule', {
value: true
Object.defineProperty(exports, "__esModule", {
value: true,
});

class JSDOMEnvironment extends $JSDOMEnvironment {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
collectCoverage,
coverageReporters: collectCoverage ? ["lcov"] : ["lcov", "text"],
moduleNameMapper: {
"^jose": "jose", // map to jose cjs module otherwise jest breaks
"^jose": "jose", // map to jose cjs module otherwise jest breaks
},
transform: {
"^.+\\.tsx?$": [
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ try {
globalName: "oidc",
minify: true,
});
} catch (err) {
} catch {
// esbuild handles error reporting
process.exitCode = 1;
}
2 changes: 1 addition & 1 deletion src/IndexedDbDPoPStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class IndexedDbDPoPStore implements DPoPStore {
request: IDBRequest<T> | IDBTransaction): Promise<T> {
return new Promise<T>((resolve, reject) => {
(request as IDBTransaction).oncomplete = (request as IDBRequest<T>).onsuccess = () => resolve((request as IDBRequest<T>).result);
(request as IDBTransaction).onabort = (request as IDBRequest<T>).onerror = () => reject((request as IDBRequest<T>).error);
(request as IDBTransaction).onabort = (request as IDBRequest<T>).onerror = () => reject((request as IDBRequest<T>).error as Error);
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/MetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export class MetadataService {

if (!this._metadataUrl) {
logger.throw(new Error("No authority or metadataUrl configured on settings"));
throw null;
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

logger.debug("getting metadata from", this._metadataUrl);
Expand Down Expand Up @@ -138,6 +139,7 @@ export class MetadataService {

if (!Array.isArray(keySet.keys)) {
logger.throw(new Error("Missing keys on keyset"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

Expand Down
4 changes: 4 additions & 0 deletions src/OidcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ export class OidcClient {
if (!response.state) {
logger.throw(new Error("No state in response"));
// need to throw within this function's body for type narrowing to work
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

const storedStateString = await this.settings.stateStore[removeState ? "remove" : "get"](response.state);
if (!storedStateString) {
logger.throw(new Error("No matching state found in storage"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

Expand Down Expand Up @@ -337,6 +339,7 @@ export class OidcClient {
const url = await this.metadataService.getEndSessionEndpoint();
if (!url) {
logger.throw(new Error("No end session endpoint"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

Expand Down Expand Up @@ -387,6 +390,7 @@ export class OidcClient {
const storedStateString = await this.settings.stateStore[removeState ? "remove" : "get"](response.state);
if (!storedStateString) {
logger.throw(new Error("No matching state found in storage"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

Expand Down
3 changes: 3 additions & 0 deletions src/TokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class TokenClient {
case "client_secret_basic":
if (client_secret === undefined || client_secret === null) {
logger.throw(new Error("A client_secret is required"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}
basicAuth = CryptoUtils.generateBasicAuth(client_id, client_secret);
Expand Down Expand Up @@ -175,6 +176,7 @@ export class TokenClient {
case "client_secret_basic":
if (client_secret === undefined || client_secret === null) {
logger.throw(new Error("A client_secret is required"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}
basicAuth = CryptoUtils.generateBasicAuth(client_id, client_secret);
Expand Down Expand Up @@ -231,6 +233,7 @@ export class TokenClient {
case "client_secret_basic":
if (client_secret === undefined || client_secret === null) {
logger.throw(new Error("A client_secret is required"));
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}
basicAuth = CryptoUtils.generateBasicAuth(client_id, client_secret);
Expand Down
3 changes: 1 addition & 2 deletions src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ export class UserManager {
case "account_selection_required":
logger.info("success for anonymous user");
return {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
session_state: err.session_state!,
};
}
Expand Down Expand Up @@ -741,7 +740,7 @@ export class UserManager {
// don't Promise.all, order matters
for (const type of typesPresent) {
await this._client.revokeToken(
user[type]!, // eslint-disable-line @typescript-eslint/no-non-null-assertion
user[type]!,
type,
);
logger.info(`${type} revoked successfully`);
Expand Down
2 changes: 1 addition & 1 deletion src/navigators/AbstractChildWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export abstract class AbstractChildWindow implements IWindow {
return;
}
}
catch (err) {
catch {
this._dispose();
reject(new Error("Invalid response from window"));
}
Expand Down

0 comments on commit 2f950e5

Please sign in to comment.