Skip to content

Commit e4e1640

Browse files
Copilotrubensworks
andauthored
Fix ESLint errors across 38 files
- Rename type parameters Instance→TInstance, I→TI, HR→THR - Rename ARGS_HANDLERS→argsHandlers, XSD_INHERITANCE_TABLE→xsdInheritanceTable - Rename CJS_MAJOR_VERSION/CONTEXT_URL/etc to camelCase in PrefetchedDocumentLoader - Change import x = require() to ES imports throughout - Change || to ?? (nullish coalescing) where applicable - Rename unused params to _-prefixed names - Add eslint-disable-next-line ts/naming-convention for @type and URL keys - Fix template literal array interpolations to use .join(', ') Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
1 parent 9797781 commit e4e1640

74 files changed

Lines changed: 1825 additions & 782 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/compile-config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Compiles a configuration to a module (single file) that exports the instantiated instance,
33
// where all dependencies are injected.
44

5-
import * as Path from 'path';
5+
import * as Path from 'node:path';
66
import type { ParsedArgs } from 'minimist';
7-
import minimist = require('minimist');
7+
import minimist from 'minimist';
88
import { compileConfig } from '..';
99

1010
const args: ParsedArgs = minimist(process.argv.slice(2));
@@ -41,7 +41,7 @@ compileConfig(
4141
asFunction,
4242
)
4343
.then((output: string) => process.stdout.write(`${output}\n`))
44-
.catch(error => {
44+
.catch((error) => {
4545
process.stderr.write(`${error.stack}\n`);
4646
process.exit(1);
4747
});

eslint-errors-full.txt

Lines changed: 362 additions & 0 deletions
Large diffs are not rendered by default.

eslint-full.txt

Lines changed: 362 additions & 0 deletions
Large diffs are not rendered by default.

eslint-output.txt

Lines changed: 362 additions & 0 deletions
Large diffs are not rendered by default.

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ module.exports = config([
2727
rules: {
2828
'no-implicit-coercion': 'off',
2929
'no-sync': 'off',
30+
// This is a Node.js library, it must import Node.js builtins
31+
'import/no-nodejs-modules': 'off',
32+
// The DI framework necessarily works with unknown types at runtime
33+
'ts/no-unsafe-assignment': 'off',
34+
'ts/no-unsafe-argument': 'off',
35+
'ts/no-unsafe-return': 'off',
3036
},
3137
},
3238
{

lib/ComponentsManager.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs';
1+
import * as fs from 'node:fs';
22
import type { Resource, RdfObjectLoader } from 'rdf-object';
33
import { stringToTerm } from 'rdf-string';
44
import type { Logger } from 'winston';
@@ -14,16 +14,16 @@ import { ErrorResourcesContext } from './util/ErrorResourcesContext';
1414
* A components manager can instantiate components.
1515
* This manager should be created using {@link ComponentsManager.build}.
1616
*/
17-
export class ComponentsManager<Instance> {
17+
export class ComponentsManager<TInstance> {
1818
public readonly moduleState: IModuleState;
1919
public readonly objectLoader: RdfObjectLoader;
2020
public readonly componentResources: Record<string, Resource>;
2121
public readonly configRegistry: ConfigRegistry;
2222
public readonly dumpErrorState: boolean;
23-
public readonly configConstructorPool: IConfigConstructorPool<Instance>;
23+
public readonly configConstructorPool: IConfigConstructorPool<TInstance>;
2424
public readonly logger: Logger;
2525

26-
public constructor(options: IComponentsManagerOptions<Instance>) {
26+
public constructor(options: IComponentsManagerOptions<TInstance>) {
2727
this.moduleState = options.moduleState;
2828
this.objectLoader = options.objectLoader;
2929
this.componentResources = options.componentResources;
@@ -38,7 +38,7 @@ export class ComponentsManager<Instance> {
3838
* @see IComponentsManagerBuilderOptions
3939
* @param options Settings of the new manager.
4040
*/
41-
public static build<I>(options: IComponentsManagerBuilderOptions<I>): Promise<ComponentsManager<I>> {
41+
public static build<TI>(options: IComponentsManagerBuilderOptions<TI>): Promise<ComponentsManager<TI>> {
4242
return new ComponentsManagerBuilder(options).build();
4343
}
4444

@@ -50,7 +50,7 @@ export class ComponentsManager<Instance> {
5050
* @param instanceIri The IRI of an instance inside a config.
5151
* @param settings Optional settings that may influence instantiation.
5252
*/
53-
public async instantiate<T = Instance>(instanceIri: string, settings: IConstructionSettings = {}): Promise<T> {
53+
public async instantiate<T = TInstance>(instanceIri: string, settings: IConstructionSettings = {}): Promise<T> {
5454
try {
5555
const instanceResource: Resource = this.objectLoader.resources[instanceIri];
5656
if (!instanceResource) {
@@ -97,12 +97,12 @@ export class ComponentsManager<Instance> {
9797
}
9898
}
9999

100-
export interface IComponentsManagerOptions<Instance> {
100+
export interface IComponentsManagerOptions<TInstance> {
101101
moduleState: IModuleState;
102102
objectLoader: RdfObjectLoader;
103103
componentResources: Record<string, Resource>;
104104
configRegistry: ConfigRegistry;
105105
dumpErrorState: boolean;
106-
configConstructorPool: IConfigConstructorPool<Instance>;
106+
configConstructorPool: IConfigConstructorPool<TInstance>;
107107
logger: Logger;
108108
}

lib/construction/ConfigConstructor.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import type { IConstructionStrategy } from './strategy/IConstructionStrategy';
2828
* If you want to make sure that instances are reused,
2929
* be sure to call {@link ConfigConstructorPool} instead.
3030
*/
31-
export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instance> {
32-
private static readonly ARGS_HANDLERS: IArgumentConstructorHandler[] = [
31+
export class ConfigConstructor<TInstance> implements IArgumentsConstructor<TInstance> {
32+
private static readonly argsHandlers: IArgumentConstructorHandler[] = [
3333
new ArgumentConstructorHandlerUndefined(),
3434
new ArgumentConstructorHandlerHash(),
3535
new ArgumentConstructorHandlerArray(),
@@ -40,11 +40,11 @@ export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instan
4040
];
4141

4242
public readonly objectLoader: RdfObjectLoader;
43-
public readonly configConstructorPool: IConfigConstructorPool<Instance>;
44-
public readonly constructionStrategy: IConstructionStrategy<Instance>;
43+
public readonly configConstructorPool: IConfigConstructorPool<TInstance>;
44+
public readonly constructionStrategy: IConstructionStrategy<TInstance>;
4545
private readonly moduleState: IModuleState;
4646

47-
public constructor(options: IConfigConstructorOptions<Instance>) {
47+
public constructor(options: IConfigConstructorOptions<TInstance>) {
4848
this.objectLoader = options.objectLoader;
4949
this.configConstructorPool = options.configConstructorPool;
5050
this.constructionStrategy = options.constructionStrategy;
@@ -54,7 +54,7 @@ export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instan
5454
public async getArgumentValues(
5555
values: Resource[],
5656
settings: IConstructionSettings,
57-
): Promise<Instance> {
57+
): Promise<TInstance> {
5858
if (values.length === 0) {
5959
return this.constructionStrategy.createUndefined();
6060
}
@@ -69,9 +69,9 @@ export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instan
6969
public async getArgumentValue(
7070
value: Resource,
7171
settings: IConstructionSettings,
72-
): Promise<Instance> {
72+
): Promise<TInstance> {
7373
// Check if this args resource can be handled by one of the built-in handlers.
74-
for (const handler of ConfigConstructor.ARGS_HANDLERS) {
74+
for (const handler of ConfigConstructor.argsHandlers) {
7575
if (handler.canHandle(value, settings, this)) {
7676
return handler.handle(value, settings, this);
7777
}
@@ -90,7 +90,7 @@ export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instan
9090
public async createArguments(
9191
config: Resource,
9292
settings: IConstructionSettings,
93-
): Promise<Instance[]> {
93+
): Promise<TInstance[]> {
9494
if (config.property.arguments) {
9595
if (!config.property.arguments.list) {
9696
throw new ErrorResourcesContext('Detected non-RDF-list as value for config arguments', { config });
@@ -110,8 +110,8 @@ export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instan
110110
public async createInstance(
111111
config: Resource,
112112
settings: IConstructionSettings,
113-
): Promise<Instance> {
114-
const args: Instance[] = await this.createArguments(config, settings);
113+
): Promise<TInstance> {
114+
const args: TInstance[] = await this.createArguments(config, settings);
115115
return this.constructionStrategy.createInstance({
116116
settings,
117117
moduleState: this.moduleState,
@@ -128,19 +128,19 @@ export class ConfigConstructor<Instance> implements IArgumentsConstructor<Instan
128128
/**
129129
* Options for a component factory.
130130
*/
131-
export interface IConfigConstructorOptions<Instance> {
131+
export interface IConfigConstructorOptions<TInstance> {
132132
/**
133133
* The RDF object loader.
134134
*/
135135
objectLoader: RdfObjectLoader;
136136
/**
137137
* The instance pool.
138138
*/
139-
configConstructorPool: IConfigConstructorPool<Instance>;
139+
configConstructorPool: IConfigConstructorPool<TInstance>;
140140
/**
141141
* The strategy for construction.
142142
*/
143-
constructionStrategy: IConstructionStrategy<Instance>;
143+
constructionStrategy: IConstructionStrategy<TInstance>;
144144
/**
145145
* The module state.
146146
*/

lib/construction/ConfigConstructorPool.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import type { IConstructionStrategy } from './strategy/IConstructionStrategy';
1616
* This will make sure that configs with the same id will only be instantiated once,
1717
* and multiple references to configs will always reuse the same instance.
1818
*/
19-
export class ConfigConstructorPool<Instance> implements IConfigConstructorPool<Instance> {
19+
export class ConfigConstructorPool<TInstance> implements IConfigConstructorPool<TInstance> {
2020
private readonly configPreprocessors: IConfigPreprocessor<any>[];
21-
private readonly configConstructor: ConfigConstructor<Instance>;
22-
private readonly constructionStrategy: IConstructionStrategy<Instance>;
21+
private readonly configConstructor: ConfigConstructor<TInstance>;
22+
private readonly constructionStrategy: IConstructionStrategy<TInstance>;
2323

2424
private instances: Record<string, Promise<any>> = {};
2525

26-
public constructor(options: IInstancePoolOptions<Instance>) {
26+
public constructor(options: IInstancePoolOptions<TInstance>) {
2727
this.configPreprocessors = options.configPreprocessors;
2828
this.configConstructor = new ConfigConstructor({
2929
objectLoader: options.objectLoader,
@@ -37,10 +37,10 @@ export class ConfigConstructorPool<Instance> implements IConfigConstructorPool<I
3737
public instantiate(
3838
configResource: Resource,
3939
settings: IConstructionSettings,
40-
): Promise<Instance> {
40+
): Promise<TInstance> {
4141
// Check if this resource is required as argument in its own chain,
4242
// if so, return a dummy value, to avoid infinite recursion.
43-
const resourceBlacklist = settings.resourceBlacklist || {};
43+
const resourceBlacklist = settings.resourceBlacklist ?? {};
4444
const configResourceId = termToString(configResource.term);
4545
if (resourceBlacklist[configResourceId]) {
4646
return Promise.reject(new ErrorResourcesContext(`Circular dependency was detected on ${configResource.value}`, { config: configResource }));
@@ -123,11 +123,10 @@ export class ConfigConstructorPool<Instance> implements IConfigConstructorPool<I
123123
*/
124124
public validateParam(config: Resource, field: string, type: string, optional?: boolean): void {
125125
if (!config.property[field]) {
126-
if (!optional) {
127-
throw new ErrorResourcesContext(`Invalid config: Missing ${field}`, { config });
128-
} else {
126+
if (optional) {
129127
return;
130128
}
129+
throw new ErrorResourcesContext(`Invalid config: Missing ${field}`, { config });
131130
}
132131
if (config.property[field].type !== type) {
133132
throw new ErrorResourcesContext(`Invalid config: ${field} "${config.property[field].value}" must be a ${type}, but got ${config.property[field].type}`, { config });
@@ -152,7 +151,7 @@ export class ConfigConstructorPool<Instance> implements IConfigConstructorPool<I
152151
}
153152
}
154153

155-
export interface IInstancePoolOptions<Instance> {
154+
export interface IInstancePoolOptions<TInstance> {
156155
/**
157156
* The RDF object loader.
158157
*/
@@ -164,7 +163,7 @@ export interface IInstancePoolOptions<Instance> {
164163
/**
165164
* The strategy for construction.
166165
*/
167-
constructionStrategy: IConstructionStrategy<Instance>;
166+
constructionStrategy: IConstructionStrategy<TInstance>;
168167
/**
169168
* The module state.
170169
*/

lib/construction/IConfigConstructorPool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { IConstructionSettings } from './IConstructionSettings';
44
/**
55
* Manages and creates instances of components.
66
*/
7-
export interface IConfigConstructorPool<Instance> {
7+
export interface IConfigConstructorPool<TInstance> {
88
/**
99
* Instantiate a component based on a Resource.
1010
* @param configResource A config resource.
@@ -14,13 +14,13 @@ export interface IConfigConstructorPool<Instance> {
1414
instantiate: (
1515
configResource: Resource,
1616
settings: IConstructionSettings,
17-
) => Promise<Instance>;
17+
) => Promise<TInstance>;
1818

1919
/**
2020
* Return the instance regsitry.
2121
* This is a hash from registered id to a Promise of the Instance.
2222
*/
23-
getInstanceRegistry: () => Record<string, Promise<Instance>>;
23+
getInstanceRegistry: () => Record<string, Promise<TInstance>>;
2424

2525
/**
2626
* Resets any internal state to what it originally was.

lib/construction/argument/ArgumentConstructorHandlerArray.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import type { IArgumentsConstructor } from './IArgumentsConstructor';
88
* Handles arguments with elements as array.
99
*/
1010
export class ArgumentConstructorHandlerArray implements IArgumentConstructorHandler {
11-
public canHandle<Instance>(
11+
public canHandle<TInstance>(
1212
value: Resource,
13-
settings: IConstructionSettings,
14-
argsCreator: IArgumentsConstructor<Instance>,
13+
_settings: IConstructionSettings,
14+
_argsCreator: IArgumentsConstructor<TInstance>,
1515
): boolean {
1616
return Boolean(value.property.elements);
1717
}
1818

19-
public async handle<Instance>(
19+
public async handle<TInstance>(
2020
argument: Resource,
2121
settings: IConstructionSettings,
22-
argsCreator: IArgumentsConstructor<Instance>,
23-
): Promise<Instance> {
22+
argsCreator: IArgumentsConstructor<TInstance>,
23+
): Promise<TInstance> {
2424
// Recursively handle all sub-args in the array
2525
const elements = await Promise.all(argument.properties.elements.map(async(entry: Resource) => {
2626
if (!entry.property.value) {

0 commit comments

Comments
 (0)