Skip to content

Commit

Permalink
Fixes for linting rules
Browse files Browse the repository at this point in the history
Extraacts utils namespaces to separate modules.
Adds missing typings where possible.
Removes this to self aliasing.
  • Loading branch information
stuarthendren committed Feb 17, 2024
1 parent 22f5de2 commit 3d32bfd
Show file tree
Hide file tree
Showing 62 changed files with 1,556 additions and 1,393 deletions.
28 changes: 19 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
}
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_",
},
],
},
}
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ export { default as Dataset } from './rdf/dataset.js'
export { default as Graph } from './rdf/graph.js'
export { default as HashMapDataset } from './rdf/hashmap-dataset.js'
// RDF terms Utilities
export { rdf } from './utils.js'
export { rdf } from './utils/index.js'
export { stages }
2 changes: 1 addition & 1 deletion src/engine/cache/bgp-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { BinarySearchTree } from 'binary-search-tree'
import { differenceWith, findIndex, maxBy } from 'lodash'
import * as SPARQL from 'sparqljs'
import { Bindings } from '../../rdf/bindings.js'
import { rdf, sparql } from '../../utils.js'
import { rdf, sparql } from '../../utils/index.js'
import { PipelineStage } from '../pipeline/pipeline-engine.js'
import { Pipeline } from '../pipeline/pipeline.js'
import { AsyncCacheEntry, AsyncLRUCache } from './cache-base.js'
Expand Down
10 changes: 5 additions & 5 deletions src/engine/context/execution-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ SOFTWARE.

'use strict'

import { rdf } from '../../utils.js'
import { rdf } from '../../utils/index.js'
import { BGPCache } from '../cache/bgp-cache.js'
import { QueryHints } from './query-hints.js'

/**
* An execution context conatains control information for query execution.
*/
export default class ExecutionContext {
protected _properties: Map<symbol, any>
protected _properties: Map<symbol, unknown>
protected _hints: QueryHints
protected _defaultGraphs: Array<rdf.NamedNode | rdf.Variable>
protected _namedGraphs: rdf.NamedNode[]
Expand Down Expand Up @@ -125,8 +125,8 @@ export default class ExecutionContext {
* @param key - Key associated with the property
* @return The value associated with the key
*/
getProperty(key: symbol): any | null {
return this._properties.get(key)
getProperty<T>(key: symbol): T {
return this._properties.get(key) as T
}

/**
Expand All @@ -143,7 +143,7 @@ export default class ExecutionContext {
* @param key - Key of the property
* @param value - Value of the property
*/
setProperty(key: symbol, value: any): void {
setProperty(key: symbol, value: unknown): void {
this._properties.set(key, value)
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/pipeline/pipeline-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface StreamPipelineInput<T> {
* Report an error that occurs during execution
* @param err - The error to report
*/
error(err: any): void
error(err: unknown): void
}

/**
Expand All @@ -78,7 +78,7 @@ export interface PipelineStage<T> {
*/
subscribe(
onData: (value: T) => void,
onError: (err: any) => void,
onError: (err: unknown) => void,
onEnd: () => void,
): void

Expand Down
24 changes: 16 additions & 8 deletions src/engine/pipeline/rxjs-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ SOFTWARE.

'use strict'

import { concat, EMPTY, from, Observable, of, Subscriber } from 'rxjs'
import {
concat,
EMPTY,
from,
Observable,
ObservableInput,
of,
Subscriber,
} from 'rxjs'
import {
bufferCount,
catchError,
Expand All @@ -46,18 +54,16 @@ import {
} from 'rxjs/operators'
import { PipelineEngine, StreamPipelineInput } from './pipeline-engine.js'

// Declare a module with the same name as the imported module
declare module 'rxjs' {
// Inside, declare an interface with the same name as the class you're extending
// Make sure to include the generic parameter
interface Observable<T> {
toArray(): Promise<T[]>
}
}

// Now TypeScript knows about the new method, and you can add it to the prototype
Observable.prototype.toArray = function () {
return new Promise((resolve, reject) => {
// Can't avoid any here because we don't have access to the T type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const results: any[] = []
this.subscribe(
(b) => {
Expand Down Expand Up @@ -90,7 +96,7 @@ export class RxjsStreamInput<T> implements StreamPipelineInput<T> {
this._subscriber.complete()
}

error(err: any): void {
error(err: unknown): void {
this._subscriber.error(err)
}
}
Expand All @@ -108,8 +114,10 @@ export default class RxjsPipeline extends PipelineEngine {
return of(...values)
}

from(x: any): Observable<any> {
return from(x)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
from(x: unknown): Observable<any> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return from(x as ObservableInput<any>)
}

fromAsync<T>(cb: (input: StreamPipelineInput<T>) => void): Observable<T> {
Expand Down
8 changes: 4 additions & 4 deletions src/engine/pipeline/vector-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class VectorStage<T> implements PipelineStage<T> {

subscribe(
onData: (value: T) => void,
onError: (err: any) => void,
onError: (err: unknown) => void,
onEnd: () => void,
): void {
try {
Expand Down Expand Up @@ -95,10 +95,10 @@ export class VectorStage<T> implements PipelineStage<T> {

export class VectorStreamInput<T> implements StreamPipelineInput<T> {
private readonly _resolve: (value: T[]) => void
private readonly _reject: (err: any) => void
private readonly _reject: (err: unknown) => void
private _content: Array<T>

constructor(resolve: any, reject: any) {
constructor(resolve: (value: T[]) => void, reject: (err: unknown) => void) {
this._resolve = resolve
this._reject = reject
this._content = []
Expand All @@ -108,7 +108,7 @@ export class VectorStreamInput<T> implements StreamPipelineInput<T> {
this._content.push(value)
}

error(err: any): void {
error(err: unknown): void {
this._reject(err)
}

Expand Down
Loading

0 comments on commit 3d32bfd

Please sign in to comment.