refactor: Replace linting configurations

The previous package was outdated, preventing us from updating TS.
This one also lints YAML and JSON,
and applies many more rules to the test files,
explaining all the changes in this PR.
This commit is contained in:
Joachim Van Herwegen
2023-10-27 11:28:57 +02:00
parent 58daeb684f
commit 6248ed0938
327 changed files with 6424 additions and 3375 deletions

View File

@@ -16,7 +16,7 @@ import type { ResourceIdentifier } from './representation/ResourceIdentifier';
const VERSION = 'solid-0.1';
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line ts/naming-convention
const WebSocketListenerEmitter = createGenericEventEmitterClass<GenericEventEmitter<'closed', () => void>>();
/**

View File

@@ -9,6 +9,7 @@ import { guardedStreamFrom, readableToString } from '../../../util/StreamUtil';
import type { SparqlUpdatePatch } from '../../representation/SparqlUpdatePatch';
import type { BodyParserArgs } from './BodyParser';
import { BodyParser } from './BodyParser';
/**
* {@link BodyParser} that supports `application/sparql-update` content.
* Will convert the incoming update string to algebra in a {@link SparqlUpdatePatch}.

View File

@@ -79,4 +79,3 @@ export class LinkRelObject {
}
}
}

View File

@@ -3,9 +3,9 @@ import type { AcceptHeader } from '../../../util/Header';
import {
parseAccept,
parseAcceptCharset,
parseAcceptDateTime,
parseAcceptEncoding,
parseAcceptLanguage,
parseAcceptDateTime,
} from '../../../util/HeaderUtil';
import type { RepresentationPreferences } from '../../representation/RepresentationPreferences';
import { PreferenceParser } from './PreferenceParser';

View File

@@ -5,7 +5,7 @@ import { guardStream } from '../../util/GuardedStream';
import { guardedStreamFrom } from '../../util/StreamUtil';
import type { Representation } from './Representation';
import type { MetadataIdentifier, MetadataRecord } from './RepresentationMetadata';
import { RepresentationMetadata, isRepresentationMetadata } from './RepresentationMetadata';
import { isRepresentationMetadata, RepresentationMetadata } from './RepresentationMetadata';
/**
* Class with various constructors to facilitate creating a representation.
@@ -108,6 +108,8 @@ export class BasicRepresentation implements Representation {
metadataRest = undefined;
}
if (!isRepresentationMetadata(metadata) || typeof metadataRest === 'string') {
// This combination will always match with a valid overload
// eslint-disable-next-line ts/no-unsafe-argument
metadata = new RepresentationMetadata(metadata as any, metadataRest as any);
}
this.metadata = metadata;

View File

@@ -2,8 +2,8 @@ import { DataFactory, Store } from 'n3';
import type { BlankNode, DefaultGraph, Literal, NamedNode, Quad, Term } from 'rdf-js';
import { getLoggerFor } from '../../logging/LogUtil';
import { ContentType, SIMPLE_MEDIA_RANGE } from '../../util/Header';
import { toNamedTerm, toObjectTerm, isTerm, toLiteral } from '../../util/TermUtil';
import { CONTENT_TYPE_TERM, CONTENT_LENGTH_TERM, XSD, SOLID_META, RDFS } from '../../util/Vocabularies';
import { isTerm, toLiteral, toNamedTerm, toObjectTerm } from '../../util/TermUtil';
import { CONTENT_LENGTH_TERM, CONTENT_TYPE_TERM, RDFS, SOLID_META, XSD } from '../../util/Vocabularies';
import type { ResourceIdentifier } from './ResourceIdentifier';
import { isResourceIdentifier } from './ResourceIdentifier';
@@ -16,7 +16,7 @@ export type MetadataGraph = NamedNode | BlankNode | DefaultGraph | string;
* Determines whether the object is a `RepresentationMetadata`.
*/
export function isRepresentationMetadata(object: any): object is RepresentationMetadata {
return typeof object?.setMetadata === 'function';
return typeof (object as RepresentationMetadata)?.setMetadata === 'function';
}
// Caches named node conversions
@@ -283,7 +283,8 @@ export class RepresentationMetadata {
): boolean {
// This works with N3.js but at the time of writing the typings have not been updated yet.
// If you see this line of code check if the typings are already correct and update this if so.
return (this.store.has as any)(this.id, predicate, object, graph);
// eslint-disable-next-line ts/no-unsafe-call
return (this.store.has as any)(this.id, predicate, object, graph) as boolean;
}
/**
@@ -426,8 +427,8 @@ export class RepresentationMetadata {
}
/**
* Shorthand for the CONTENT_LENGTH predicate.
*/
* Shorthand for the CONTENT_LENGTH predicate.
*/
public get contentLength(): number | undefined {
const length = this.get(CONTENT_LENGTH_TERM);
return length?.value ? Number(length.value) : undefined;

View File

@@ -1,16 +1,16 @@
/**
* Represents preferred values along a single content negotiation dimension.
*
* The number represents how preferred this value is from 0 to 1.
* Follows the quality values rule from RFC 7231:
* "The weight is normalized to a real number in the range 0 through 1,
* where 0.001 is the least preferred and 1 is the most preferred; a
* value of 0 means "not acceptable"."
*
* Because of an open issue in Components.js we cannot use `Record<string, number>` right now.
* https://github.com/LinkedSoftwareDependencies/Components-Generator.js/issues/103
*/
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
* Represents preferred values along a single content negotiation dimension.
*
* The number represents how preferred this value is from 0 to 1.
* Follows the quality values rule from RFC 7231:
* "The weight is normalized to a real number in the range 0 through 1,
* where 0.001 is the least preferred and 1 is the most preferred; a
* value of 0 means "not acceptable"."
*
* Because of an open issue in Components.js we cannot use `Record<string, number>` right now.
* https://github.com/LinkedSoftwareDependencies/Components-Generator.js/issues/103
*/
// eslint-disable-next-line ts/consistent-indexed-object-style
export type ValuePreferences = {[key: string ]: number };
/**

View File

@@ -11,6 +11,6 @@ export interface ResourceIdentifier {
/**
* Determines whether the object is a {@link ResourceIdentifier}.
*/
export function isResourceIdentifier(object: any): object is ResourceIdentifier {
return object && (typeof object.path === 'string');
export function isResourceIdentifier(object: unknown): object is ResourceIdentifier {
return Boolean(object) && (typeof (object as ResourceIdentifier).path === 'string');
}