Skip to content

Commit c46e702

Browse files
committed
fix: address linter errors and enable all usual checks for the codebase
Signed-off-by: Denis Golovin <[email protected]>
1 parent 73e345a commit c46e702

19 files changed

+379
-259
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"sourceType": "module",
2121
"warnOnUnsupportedTypeScriptVersion": false,
2222
"project": [
23-
"tsconfig.json"
23+
"tsconfig.json",
24+
"tests/tsconfig.json"
2425
]
2526
},
2627
"overrides": [

.github/workflows/pr-check.yaml

+60-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,68 @@ name: pr-check
2020
on: [pull_request]
2121

2222
jobs:
23-
pr-check-job:
23+
24+
build:
25+
name: Build
26+
needs: test
2427
strategy:
2528
matrix:
2629
target: [windows-2022, macos-14, ubuntu-20.04]
30+
fail-fast: true
2731
uses: redhat-developer/podman-desktop-redhat-account-ext/.github/workflows/build.yaml@main
2832
with:
29-
runs-on: ${{ matrix.target }}
33+
runs-on: ${{ matrix.target }}
34+
35+
test:
36+
name: Test
37+
runs-on: ${{ matrix.target }}
38+
strategy:
39+
matrix:
40+
target: [windows-2022, macos-14, ubuntu-22.04]
41+
fail-fast: true
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: actions/setup-node@v4
46+
with:
47+
node-version: 20
48+
49+
- name: Get yarn cache directory path (Windows)
50+
if: ${{ matrix.target=='windows-2022' }}
51+
id: yarn-cache-dir-path-windows
52+
run: echo "dir=$(yarn cache dir)" >> ${env:GITHUB_OUTPUT}
53+
54+
- name: Get yarn cache directory path (mac/Linux)
55+
if: ${{ matrix.target=='ubuntu-22.04'}}
56+
id: yarn-cache-dir-path-unix
57+
run: echo "dir=$(yarn cache dir)" >> ${GITHUB_OUTPUT}
58+
59+
- uses: actions/cache@v4
60+
if: ${{ matrix.target=='windows-2022' }}
61+
id: yarn-cache-windows
62+
with:
63+
path: ${{ steps.yarn-cache-dir-path-windows.outputs.dir }}
64+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
65+
restore-keys: |
66+
${{ runner.target }}-yarn-
67+
68+
- uses: actions/cache@v4
69+
if: ${{ matrix.target=='ubuntu-22.04'}}
70+
id: yarn-cache-unix
71+
with:
72+
path: ${{ steps.yarn-cache-dir-path-unix.outputs.dir }}
73+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
74+
restore-keys: |
75+
${{ runner.os }}-yarn-
76+
77+
- name: Execute yarn
78+
run: yarn --frozen-lockfile --network-timeout 180000
79+
80+
- name: Run linter
81+
run: yarn lint:check
82+
83+
- name: Run formatter
84+
run: yarn format:check
85+
86+
- name: Run unit tests
87+
run: yarn test

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"scripts": {
3535
"build": "rollup --bundleConfigAsCjs --config rollup.config.js --compact --environment BUILD:production && node ./scripts/build.js",
3636
"watch": "rollup --bundleConfigAsCjs --config rollup.config.js -w",
37-
"format:check": "prettier --cache --check \"{src,types,scripts}/**/*.{ts,js}\"",
37+
"format:check": "prettier --end-of-line auto --cache --check \"{src,types,scripts}/**/*.{ts,js}\"",
3838
"format:fix": "prettier --cache --write \"{src,types,scripts}/**/*.{ts,js}\"",
3939
"lint:clean": "rimraf .eslintcache",
4040
"lint:fix": "node --max-old-space-size=6144 node_modules/eslint/bin/eslint.js --cache . --fix --ext js,ts",

src/authentication-server.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import * as fs from 'fs';
20-
import * as http from 'http';
21-
import * as path from 'path';
22-
import * as url from 'url';
23-
import { ServerConfig, AuthConfig } from './configuration';
19+
import * as fs from 'node:fs';
20+
import * as http from 'node:http';
21+
import * as path from 'node:path';
22+
import * as url from 'node:url';
23+
24+
import type { AuthConfig, ServerConfig } from './configuration';
2425

2526
interface Deferred<T> {
2627
resolve: (result: T | Promise<T>) => void;
27-
reject: (reason: any) => void;
28+
reject: (reason: unknown) => void;
2829
}
2930

3031
export type RedirectResult =
3132
| { req: http.IncomingMessage; res: http.ServerResponse }
32-
| { err: any; res: http.ServerResponse };
33+
| { err: unknown; res: http.ServerResponse };
3334

34-
export function createServer(config: AuthConfig, nonce: string) {
35+
export function createServer(
36+
config: AuthConfig,
37+
nonce: string,
38+
): {
39+
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
40+
redirectPromise: Promise<RedirectResult>;
41+
callbackPromise: Promise<RedirectResult>;
42+
} {
3543
let deferredRedirect: Deferred<RedirectResult>;
3644
const redirectPromise = new Promise<RedirectResult>((resolve, reject) => (deferredRedirect = { resolve, reject }));
3745

@@ -76,7 +84,7 @@ export function createServer(config: AuthConfig, nonce: string) {
7684
export async function startServer(config: ServerConfig, server: http.Server): Promise<string> {
7785
let portTimer: NodeJS.Timeout;
7886

79-
function cancelPortTimer() {
87+
function cancelPortTimer(): void {
8088
clearTimeout(portTimer);
8189
}
8290

@@ -87,6 +95,7 @@ export async function startServer(config: ServerConfig, server: http.Server): Pr
8795

8896
server.on('listening', () => {
8997
const address = server.address();
98+
// eslint-disable-next-line no-null/no-null
9099
if (typeof address === 'undefined' || address === null) {
91100
reject(new Error('adress is null or undefined'));
92101
} else if (typeof address === 'string') {
@@ -111,7 +120,7 @@ export async function startServer(config: ServerConfig, server: http.Server): Pr
111120
return port;
112121
}
113122

114-
function sendFile(res: http.ServerResponse, filepath: string, contentType: string) {
123+
function sendFile(res: http.ServerResponse, filepath: string, contentType: string): void {
115124
fs.stat(filepath, (err, stats) => {
116125
if (err) {
117126
console.error(err);

src/authentication-service.spec.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19+
import type { ExtensionContext } from '@podman-desktop/api';
20+
import { authentication } from '@podman-desktop/api';
21+
import type { BaseClient, TokenSet } from 'openid-client';
22+
import { Issuer } from 'openid-client';
1923
import { beforeEach, expect, test, vi } from 'vitest';
20-
import { RedHatAuthenticationService, convertToSession } from './authentication-service';
21-
import { AuthenticationProvider, ExtensionContext, authentication } from '@podman-desktop/api';
22-
import { TokenSet, Issuer, BaseClient } from 'openid-client';
24+
25+
import { convertToSession, RedHatAuthenticationService } from './authentication-service';
2326
import { getAuthConfig } from './configuration';
2427

2528
vi.mock('@podman-desktop/api', async () => {
@@ -70,11 +73,11 @@ test('An authentication token is converted to a session', () => {
7073
});
7174

7275
test('Authentication service loads tokens form secret storage during initialization', async () => {
73-
vi.spyOn(Issuer, 'discover').mockImplementation(async (url: string) => {
76+
vi.spyOn(Issuer, 'discover').mockImplementation(async () => {
7477
return {
7578
Client: vi.fn().mockImplementation(() => {
7679
return {
77-
refresh: vi.fn().mockImplementation((refreshToken: string): TokenSet => {
80+
refresh: vi.fn().mockImplementation((): TokenSet => {
7881
return {
7982
claims: vi.fn().mockImplementation(() => {
8083
return {
@@ -98,9 +101,7 @@ test('Authentication service loads tokens form secret storage during initializat
98101
} as unknown as Issuer<BaseClient>;
99102
});
100103

101-
let provider: AuthenticationProvider;
102-
vi.mocked(authentication.registerAuthenticationProvider).mockImplementation((_id, _label, ssoProvider) => {
103-
provider = ssoProvider;
104+
vi.mocked(authentication.registerAuthenticationProvider).mockImplementation((_id, _label, _ssoProvider) => {
104105
return {
105106
dispose: vi.fn(),
106107
};

0 commit comments

Comments
 (0)