Skip to content

Commit 2878158

Browse files
committed
fix: resolve lint, typecheck, and prettier errors across packages
- Fix ExtractorLogLevel type in api-report config (use enum instead of string literals) - Remove unused imports in api-report integration tests - Add eslint-disable for intentionally unused type assertions in typecheck files - Apply prettier formatting fixes across all affected files
1 parent 6aac711 commit 2878158

14 files changed

Lines changed: 112 additions & 118 deletions

File tree

packages/davinci-client/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export * from './lib/collector.types.js';
2727
export type { FidoClient } from './lib/fido/fido.js';
2828

2929
// Node slice and reducer exports needed to resolve DavinciClient
30-
export { updateCollectorValues, nextCollectorValues, nodeCollectorReducer } from './lib/node.reducer.js';
30+
export {
31+
updateCollectorValues,
32+
nextCollectorValues,
33+
nodeCollectorReducer,
34+
} from './lib/node.reducer.js';
3135

3236
// Re-export the davinci function so DavinciClient type alias can be resolved
3337
export { davinci } from './lib/client.store.js';

packages/journey-client/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"@forgerock/sdk-utilities": "workspace:*",
3636
"@forgerock/storage": "workspace:*",
3737
"@reduxjs/toolkit": "catalog:",
38-
"tslib": "^2.3.0"
38+
"tslib": "^2.3.0",
39+
"vitest": "catalog:vitest",
40+
"vitest-canvas-mock": "catalog:vitest"
3941
},
4042
"devDependencies": {
4143
"@vitest/coverage-v8": "catalog:vitest",

packages/journey-client/src/__tests__/types-reexport.typecheck.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@ import type {
2525
// PolicyKey is a value (enum), verify it is available from main index
2626
import { PolicyKey } from '../index.js';
2727

28-
// Use each type to prevent unused import errors
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2929
type _TypeAssert = [
30-
Step, Callback, CallbackType, StepType, GenericError,
31-
PolicyRequirement, FailedPolicyRequirement, LogLevel, CustomLogger,
32-
RequestMiddleware, ActionTypes, NameValue, StepDetail, AuthResponse,
30+
Step,
31+
Callback,
32+
CallbackType,
33+
StepType,
34+
GenericError,
35+
PolicyRequirement,
36+
FailedPolicyRequirement,
37+
LogLevel,
38+
CustomLogger,
39+
RequestMiddleware,
40+
ActionTypes,
41+
NameValue,
42+
StepDetail,
43+
AuthResponse,
3344
FailureDetail,
3445
];
46+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3547
const _pk: typeof PolicyKey = PolicyKey;

packages/oidc-client/src/__tests__/types-reexport.typecheck.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ import type {
1616
ResponseType,
1717
} from '../types.js';
1818

19+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1920
type _Assert = [
20-
GenericError, GetAuthorizationUrlOptions, WellknownResponse, StorageConfig,
21-
ActionTypes, RequestMiddleware, CustomLogger, LogLevel, ResponseType,
21+
GenericError,
22+
GetAuthorizationUrlOptions,
23+
WellknownResponse,
24+
StorageConfig,
25+
ActionTypes,
26+
RequestMiddleware,
27+
CustomLogger,
28+
LogLevel,
29+
ResponseType,
2230
];

tools/api-report/src/config.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { buildReportFileName } from './config.js';
33

44
describe('buildReportFileName', () => {
55
it('should produce base name for root entry "."', () => {
6-
expect(buildReportFileName('@forgerock/journey-client', '.')).toBe(
7-
'journey-client.api.md',
8-
);
6+
expect(buildReportFileName('@forgerock/journey-client', '.')).toBe('journey-client.api.md');
97
});
108

119
it('should append subpath for sub-entries', () => {
@@ -21,8 +19,6 @@ describe('buildReportFileName', () => {
2119
});
2220

2321
it('should handle different scoped package names', () => {
24-
expect(buildReportFileName('@forgerock/oidc-client', '.')).toBe(
25-
'oidc-client.api.md',
26-
);
22+
expect(buildReportFileName('@forgerock/oidc-client', '.')).toBe('oidc-client.api.md');
2723
});
2824
});

tools/api-report/src/config.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { ExtractorConfig } from '@microsoft/api-extractor';
1+
import { ExtractorConfig, ExtractorLogLevel } from '@microsoft/api-extractor';
22
import { resolve } from 'node:path';
33
import type { EntryPoint } from './resolve-entries.js';
44

55
const WORKSPACE_ROOT = resolve(import.meta.dirname, '../../..');
66

7-
export function buildReportFileName(
8-
packageName: string,
9-
subpath: string,
10-
): string {
7+
export function buildReportFileName(packageName: string, subpath: string): string {
118
const baseName = packageName.replace(/^@forgerock\//, '');
129
const suffix = subpath === '.' ? '' : '.' + subpath.replace('./', '');
1310
return baseName + suffix + '.api.md';
@@ -39,8 +36,8 @@ export function buildExtractorConfig(options: ConfigOptions): ExtractorConfig {
3936
tsdocMetadata: { enabled: false },
4037
messages: {
4138
extractorMessageReporting: {
42-
'ae-forgotten-export': { logLevel: 'error' as const },
43-
'ae-missing-release-tag': { logLevel: 'none' as const },
39+
'ae-forgotten-export': { logLevel: ExtractorLogLevel.Error },
40+
'ae-missing-release-tag': { logLevel: ExtractorLogLevel.None },
4441
},
4542
},
4643
},

tools/api-report/src/fixer.spec.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111

1212
describe('parseForgottenExportMessage', () => {
1313
it('should extract symbol name from ae-forgotten-export message', () => {
14-
const text =
15-
'The symbol "GenericError" needs to be exported by the entry point index.d.ts';
14+
const text = 'The symbol "GenericError" needs to be exported by the entry point index.d.ts';
1615
const result = parseForgottenExportMessage(text);
1716
expect(result).toBe('GenericError');
1817
});
@@ -23,16 +22,14 @@ describe('parseForgottenExportMessage', () => {
2322
});
2423

2524
it('should handle symbols with underscores and numbers', () => {
26-
const text =
27-
'The symbol "OAuth2_Config3" needs to be exported by the entry point index.d.ts';
25+
const text = 'The symbol "OAuth2_Config3" needs to be exported by the entry point index.d.ts';
2826
expect(parseForgottenExportMessage(text)).toBe('OAuth2_Config3');
2927
});
3028
});
3129

3230
describe('resolveSourcePackage', () => {
3331
it('should resolve @forgerock scoped package from source path', () => {
34-
const sourcePath =
35-
'/workspace/packages/sdk-types/src/lib/error.types.ts';
32+
const sourcePath = '/workspace/packages/sdk-types/src/lib/error.types.ts';
3633
const result = resolveSourcePackage(sourcePath, '/workspace');
3734
expect(result).toBe('@forgerock/sdk-types');
3835
});
@@ -49,8 +46,7 @@ describe('resolveSourcePackage', () => {
4946
});
5047

5148
it('should fall back to directory name for sdk-effects when package.json unreadable', () => {
52-
const sourcePath =
53-
'/fake-workspace/packages/sdk-effects/logger/src/lib/logger.types.ts';
49+
const sourcePath = '/fake-workspace/packages/sdk-effects/logger/src/lib/logger.types.ts';
5450
const result = resolveSourcePackage(sourcePath, '/fake-workspace');
5551
expect(result).toBe('@forgerock/sdk-effects/logger');
5652
});
@@ -69,8 +65,7 @@ describe('resolveSourcePackage', () => {
6965
});
7066

7167
it('should handle dist paths within packages', () => {
72-
const sourcePath =
73-
'/workspace/packages/sdk-types/dist/src/lib/error.types.d.ts';
68+
const sourcePath = '/workspace/packages/sdk-types/dist/src/lib/error.types.d.ts';
7469
const result = resolveSourcePackage(sourcePath, '/workspace');
7570
expect(result).toBe('@forgerock/sdk-types');
7671
});
@@ -183,11 +178,11 @@ describe('buildReExportStatement', () => {
183178
describe('insertReExport', () => {
184179
it('should append to existing re-export block for same package', () => {
185180
const content = [
186-
"export type {",
187-
" Step,",
188-
" Callback,",
181+
'export type {',
182+
' Step,',
183+
' Callback,',
189184
"} from '@forgerock/sdk-types';",
190-
"",
185+
'',
191186
"export * from './lib/client.types.js';",
192187
].join('\n');
193188

@@ -202,7 +197,7 @@ describe('insertReExport', () => {
202197
it('should add new re-export statement when no existing block matches', () => {
203198
const content = [
204199
"export type { Step } from '@forgerock/sdk-types';",
205-
"",
200+
'',
206201
"export * from './lib/client.types.js';",
207202
].join('\n');
208203

@@ -213,9 +208,9 @@ describe('insertReExport', () => {
213208

214209
it('should not duplicate if symbol already exported', () => {
215210
const content = [
216-
"export type {",
217-
" Step,",
218-
" GenericError,",
211+
'export type {',
212+
' Step,',
213+
' GenericError,',
219214
"} from '@forgerock/sdk-types';",
220215
].join('\n');
221216

@@ -227,12 +222,12 @@ describe('insertReExport', () => {
227222

228223
it('should append to existing multi-line type block for same package', () => {
229224
const content = [
230-
"export type {",
231-
" Step,",
232-
" Callback,",
233-
" CallbackType,",
234-
" StepType,",
235-
" GenericError,",
225+
'export type {',
226+
' Step,',
227+
' Callback,',
228+
' CallbackType,',
229+
' StepType,',
230+
' GenericError,',
236231
"} from '@forgerock/sdk-types';",
237232
].join('\n');
238233

@@ -249,7 +244,7 @@ describe('insertReExport', () => {
249244
it('should handle value re-exports alongside type re-exports', () => {
250245
const content = [
251246
"export type { Step } from '@forgerock/sdk-types';",
252-
"",
247+
'',
253248
"export { callbackType } from '@forgerock/sdk-types';",
254249
].join('\n');
255250

tools/api-report/src/fixer.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ export function parseForgottenExportMessage(text: string): string | null {
1414
* Resolves which @forgerock/* package a source file belongs to.
1515
* Handles both workspace source paths and node_modules paths.
1616
*/
17-
export function resolveSourcePackage(
18-
sourceFilePath: string,
19-
workspaceRoot: string,
20-
): string | null {
17+
export function resolveSourcePackage(sourceFilePath: string, workspaceRoot: string): string | null {
2118
// Check node_modules path: ...node_modules/@forgerock/package-name/...
2219
const nodeModulesMatch = /@forgerock\/([^/]+)/.exec(sourceFilePath);
2320
if (nodeModulesMatch && sourceFilePath.includes('node_modules')) {
@@ -52,14 +49,13 @@ export function resolveSourcePackage(
5249
* Finds the module specifier for a symbol's import in a .d.ts file.
5350
* Given `import { ForgottenType } from '@forgerock/sdk-types'`, returns '@forgerock/sdk-types'.
5451
*/
55-
export function findImportModuleForSymbol(
56-
fileContent: string,
57-
symbolName: string,
58-
): string | null {
52+
export function findImportModuleForSymbol(fileContent: string, symbolName: string): string | null {
5953
// Match: import [type] { ..., symbolName, ... } from 'module'
6054
// Handle both single-line and multi-line imports, with optional 'type' keyword
6155
const regex = new RegExp(
62-
"import\\s+(?:type\\s+)?\\{[^}]*\\b" + escapeRegex(symbolName) + "\\b[^}]*\\}\\s*from\\s*['\"]([^'\"]+)['\"]",
56+
'import\\s+(?:type\\s+)?\\{[^}]*\\b' +
57+
escapeRegex(symbolName) +
58+
'\\b[^}]*\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]',
6359
's',
6460
);
6561
const match = regex.exec(fileContent);
@@ -71,10 +67,7 @@ export function findImportModuleForSymbol(
7167
* (class/enum/const/function) by scanning the source file content.
7268
* Defaults to 'type' when uncertain.
7369
*/
74-
export function determineExportKind(
75-
sourceContent: string,
76-
symbolName: string,
77-
): 'type' | 'value' {
70+
export function determineExportKind(sourceContent: string, symbolName: string): 'type' | 'value' {
7871
// Check for value patterns first (more specific)
7972
// Handle optional 'export' and 'declare' keywords in .d.ts files
8073
const valuePatterns = [
@@ -111,7 +104,7 @@ export function buildReExportStatement(
111104
kind: 'type' | 'value',
112105
): string {
113106
const keyword = kind === 'type' ? 'export type' : 'export';
114-
return keyword + " { " + symbolName + " } from '" + sourcePackage + "';";
107+
return keyword + ' { ' + symbolName + " } from '" + sourcePackage + "';";
115108
}
116109

117110
function escapeRegex(str: string): string {
@@ -131,12 +124,12 @@ export function insertReExport(
131124
kind: 'type' | 'value',
132125
): string {
133126
// Check if already exported (handle multi-line blocks where symbol and 'from' are on different lines)
134-
const hasSymbolInPackageBlock = new RegExp(
135-
'\\b' + escapeRegex(symbolName) + '\\b',
136-
);
127+
const hasSymbolInPackageBlock = new RegExp('\\b' + escapeRegex(symbolName) + '\\b');
137128
// Find all export blocks for this package and check if symbol is in any of them
138129
const blockRegex = new RegExp(
139-
'(?:export(?:\\s+type)?)\\s*\\{([^}]*)\\}\\s*from\\s*[\'"]' + escapeRegex(sourcePackage) + '[\'"]',
130+
'(?:export(?:\\s+type)?)\\s*\\{([^}]*)\\}\\s*from\\s*[\'"]' +
131+
escapeRegex(sourcePackage) +
132+
'[\'"]',
140133
'gs',
141134
);
142135
let blockMatch;
@@ -147,14 +140,16 @@ export function insertReExport(
147140
const keyword = kind === 'type' ? 'export type' : 'export';
148141

149142
// For value exports, avoid matching 'export type {' blocks
150-
const keywordPattern = kind === 'value'
151-
? 'export\\s+(?!type\\s)'
152-
: escapeRegex(keyword) + '\\s*';
143+
const keywordPattern = kind === 'value' ? 'export\\s+(?!type\\s)' : escapeRegex(keyword) + '\\s*';
153144

154145
// Try single-line block first: export { Foo, Bar } from 'package';
155146
// (no newlines between { and })
156147
const singleLineRegex = new RegExp(
157-
'(' + keywordPattern + '\\{\\s*)([^}\\n]+)(\\s*\\}\\s*from\\s*[\'"]' + escapeRegex(sourcePackage) + '[\'"];)',
148+
'(' +
149+
keywordPattern +
150+
'\\{\\s*)([^}\\n]+)(\\s*\\}\\s*from\\s*[\'"]' +
151+
escapeRegex(sourcePackage) +
152+
'[\'"];)',
158153
);
159154
const singleLineMatch = singleLineRegex.exec(content);
160155
if (singleLineMatch) {
@@ -169,7 +164,11 @@ export function insertReExport(
169164

170165
// Try multi-line block: export type {\n Foo,\n Bar,\n} from 'package';
171166
const multiLineBlockRegex = new RegExp(
172-
'(' + keywordPattern + '\\{[^}]*)(\\}\\s*from\\s*[\'"]' + escapeRegex(sourcePackage) + '[\'"];)',
167+
'(' +
168+
keywordPattern +
169+
'\\{[^}]*)(\\}\\s*from\\s*[\'"]' +
170+
escapeRegex(sourcePackage) +
171+
'[\'"];)',
173172
's',
174173
);
175174
const multiLineMatch = multiLineBlockRegex.exec(content);
@@ -258,7 +257,13 @@ export function applyFixes(
258257

259258
// Determine type vs value from the definition file (or fall back to usage site)
260259
const definitionContent = definitionFilePath
261-
? (() => { try { return readFileSync(definitionFilePath, 'utf-8'); } catch { return usageSiteContent; } })()
260+
? (() => {
261+
try {
262+
return readFileSync(definitionFilePath, 'utf-8');
263+
} catch {
264+
return usageSiteContent;
265+
}
266+
})()
262267
: usageSiteContent;
263268

264269
const kind = determineExportKind(definitionContent, fe.symbolName);

tools/api-report/src/integration.spec.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { mkdirSync, writeFileSync, readFileSync, rmSync, mkdtempSync } from 'node:fs';
33
import { resolve, join } from 'node:path';
44
import { tmpdir } from 'node:os';
5-
import { analyzePackage, resolvePackageInfo, type PackageInfo } from './main.js';
5+
import { analyzePackage, type PackageInfo } from './main.js';
66
import { applyFixes } from './fixer.js';
77

88
let FIXTURE_ROOT: string;
@@ -49,11 +49,7 @@ function createFixture() {
4949
// Internal package.json (mimics @forgerock/sdk-types)
5050
writeFileSync(
5151
resolve(INTERNAL_DIR, 'package.json'),
52-
JSON.stringify(
53-
{ name: '@forgerock/test-internal', version: '0.0.0', type: 'module' },
54-
null,
55-
2,
56-
),
52+
JSON.stringify({ name: '@forgerock/test-internal', version: '0.0.0', type: 'module' }, null, 2),
5753
);
5854

5955
// Client tsconfig.json — use paths to resolve @forgerock/test-internal
@@ -236,10 +232,7 @@ describe('integration: forgotten export detection and fix', () => {
236232
const { forgottenExports } = analyzePackage(makeInfo());
237233
const typesFilePath = resolve(CLIENT_DIR, 'src/types.ts');
238234
applyFixes(forgottenExports, typesFilePath, FIXTURE_ROOT);
239-
writeFileSync(
240-
resolve(CLIENT_DIR, 'dist/src/types.d.ts'),
241-
readFileSync(typesFilePath, 'utf-8'),
242-
);
235+
writeFileSync(resolve(CLIENT_DIR, 'dist/src/types.d.ts'), readFileSync(typesFilePath, 'utf-8'));
243236

244237
// Snapshot the clean types.ts
245238
const cleanContent = readFileSync(typesFilePath, 'utf-8');
@@ -248,7 +241,7 @@ describe('integration: forgotten export detection and fix', () => {
248241
const recheck = analyzePackage(makeInfo());
249242
expect(recheck.forgottenExports).toHaveLength(0);
250243

251-
const { fixed, skipped } = applyFixes(recheck.forgottenExports, typesFilePath, FIXTURE_ROOT);
244+
const { fixed } = applyFixes(recheck.forgottenExports, typesFilePath, FIXTURE_ROOT);
252245
expect(fixed).toHaveLength(0);
253246

254247
// types.ts should be unchanged

0 commit comments

Comments
 (0)