Skip to content

Commit

Permalink
[refactor] Some StrictTyped linter errors: Index to Record, || to ??,…
Browse files Browse the repository at this point in the history
… for-of, typed self, client errors in tests
  • Loading branch information
amivanoff committed Sep 21, 2024
1 parent 16d6043 commit b36cea0
Show file tree
Hide file tree
Showing 23 changed files with 445 additions and 393 deletions.
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"files.eol": "\n",
"editor.tabSize": 2,
//"files.autoSave": "afterDelay",
"eslint.debug": true,
"eslint.useESLintClass": true,
"eslint.useFlatConfig": true,
"eslint.validate": ["javascript", "typescript"],
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
Expand Down Expand Up @@ -76,6 +79,7 @@
"strstarts",
"Subcat",
"timeseries",
"treenode",
"triplestore",
"typeahead",
"undelegate",
Expand All @@ -88,8 +92,7 @@
"jest.jestCommandLine": "node_modules/.bin/jest --detectOpenHandles",
"jest.runMode": "on-demand",
"jest.shell": "/bin/zsh",
"eslint.useFlatConfig": true,
"stylelint.packageManager": "pnpm",
"js/ts.implicitProjectConfig.module": "ES2022",
"js/ts.implicitProjectConfig.target": "ESNext",
"js/ts.implicitProjectConfig.target": "ESNext"
}
58 changes: 37 additions & 21 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import jsEsLint from "@eslint/js";
import tsEsLint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";
import jest from "eslint-plugin-jest";


export default [
{
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
ignores: [
'/.git/*',
'/.github/*',
'/.husky/*',
'/.vscode/*',
'/dist/*',
'/es/*',
'/lib/*',
'/example/*'
],
},
{
languageOptions: {
globals: {
Expand All @@ -27,11 +14,23 @@ export default [
},
},
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
jsEsLint.configs.recommended,
//https://typescript-eslint.io/getting-started/typed-linting/
...tsEsLint.configs.recommended/*TypeChecked*/,
...tsEsLint.configs.strict/*TypeChecked*/,
...tsEsLint.configs.stylistic/*TypeChecked*/,
eslintConfigPrettier,
/*{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},*/
{
rules: {
'@typescript-eslint/no-dynamic-delete': 'off', // TODO: Consider Map instead of JS object for this
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'off',
Expand All @@ -49,14 +48,31 @@ export default [
},
},
{
files: ["tests/**"],
files: ["**/*.{js,mjs,cjs,ts}"],
ignores: [
'/.git/*',
'/.github/*',
'/.husky/*',
'/.vscode/*',
'/dist/*',
'/es/*',
'/lib/*',
'eslint.config.*',
'/eslint.config.*',
'**/eslint.config.js',
],
},
{
files: ["test/**"],
...jest.configs['flat/recommended'],
rules: {
...jest.configs['flat/recommended'].rules,
'@typescript-eslint/no-unused-vars': 'off',
'jest/valid-expect': 0,
'jest/valid-expect-in-promise': 0,
'jest/no-jasmine-globals': 'off',
//'@typescript-eslint/no-unsafe-call': 'off',
//'@typescript-eslint/no-explicit-any': 'off',
//'jest/valid-expect': 0,
//'jest/valid-expect-in-promise': 0,
//'jest/no-jasmine-globals': 'off',
},
},
];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"build-tsc": "pnpm tsc --project ./tsconfig-build.json",
"test": "cross-env NODE_ENV=--experimental-vm-modules jest --runInBand",
"test:ci": "cross-env NODE_ENV=--experimental-vm-modules jest --ci --coverage --maxWorkers=2",
"lint": "eslint \"{src,stories,test}**/*.{js,jsx,ts,tsx}\"",
"lint": "eslint \"{src,test}/**/*.{js,ts}\"",
"prepare": "husky && pnpm build",
"format": "./node_modules/.bin/prettier --write \"{src,stories,test}/**/*.{js,jsx,ts,tsx,json,md}\"",
"format": "./node_modules/.bin/prettier --write \"{src,test}/**/*.{js,ts,json,md}\"",
"lint-staged": "lint-staged"
},
"peerDependencies": {
Expand Down
18 changes: 4 additions & 14 deletions src/ObjectProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ export function json2str(data: any): string {
return data;
}

export interface JsObject {
[key: string]: any;
}
export type JsObject = Record<string, any>;

export interface JsStrObj {
[key: string]: string;
}
export type JsStrObj = Record<string, string>;

export interface JsStrObjObj {
[key: string]: string | JsStrObjObj;
Expand Down Expand Up @@ -49,11 +45,7 @@ export interface JSONSchema7LDProperty extends JSONSchema7 {
valueModifiability?: string | undefined; // user or non -- system
shapeModifiability?: string | undefined; // user or non -- system

properties?:
| {
[key: string]: JSONSchema7LDPropertyDefinition;
}
| undefined;
properties?: Record<string, JSONSchema7LDPropertyDefinition> | undefined;
}

export type JSONSchema7LDDefinition = JSONSchema7LD;
Expand Down Expand Up @@ -81,9 +73,7 @@ export interface JSONSchema7LD extends Omit<JSONSchema7, 'allOf'>, JsObject {
//defaultFormat?: string;
//iconReference?: string;

properties: {
[key: string]: JSONSchema7LDPropertyDefinition;
};
properties: Record<string, JSONSchema7LDPropertyDefinition>;
}

export function copyObjectProps(objTo: JsObject, objFrom: JsObject): void {
Expand Down
6 changes: 3 additions & 3 deletions src/ObjectProviderImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function propertyNameShapeToSchema(shapePropsUri: string): string {
function propertyShapeToJsonSchemaProperty(
shapeProp: JsObject,
shapePropUri: string,
schemaProps: { [key: string]: JSONSchema7LDPropertyDefinition },
schemaProps: Record<string, JSONSchema7LDPropertyDefinition>,
schemaContexts: JsObject,
schemaReqs: string[],
): string | undefined {
Expand Down Expand Up @@ -168,8 +168,8 @@ function propertyShapeToJsonSchemaProperty(

export function propertyShapesToSchemaProperties(
shapeProps: any[] | undefined,
): [{ [key: string]: JSONSchema7LDPropertyDefinition }, JsObject, string[]] {
const schemaProps: { [key: string]: JSONSchema7LDPropertyDefinition } = {};
): [Record<string, JSONSchema7LDPropertyDefinition>, JsObject, string[]] {
const schemaProps: Record<string, JSONSchema7LDPropertyDefinition> = {};
const schemaContexts: JsObject = {};
const schemaReqs: string[] = [];
if (shapeProps) {
Expand Down
10 changes: 3 additions & 7 deletions src/SparqlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export interface ServerResponse {
};
results: Results;
}
export interface Bindings {
[key: string]: Term;
}
export type Bindings = Record<string, Term>;
export interface Results {
bindings: Bindings[];
}
Expand Down Expand Up @@ -241,10 +239,8 @@ export interface SparqlClient {

clearGraph(graph?: string): Promise<any>;

createRepositoryAndSetCurrent(repParam: JsObject): Promise<void>;
createRepositoryAndSetCurrent(repParam: JsObject, repType: string): Promise<void>;
createRepositoryAndSetCurrent(repParam: JsObject, repType?: string): Promise<void>;

createRepository(repParam: JsObject): Promise<void>;
createRepository(repParam: JsObject, repType: string): Promise<void>;
createRepository(repParam: JsObject, repType?: string): Promise<void>;
deleteRepository(repId: string): Promise<void>;
}
20 changes: 10 additions & 10 deletions src/SparqlClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function createRepositoryConfig(repParam: JsObject = {}, repType = 'nativ
sail:iterationCacheSyncThreshold "${repParam['Query Iteration Cache size'] || 10000}";
ns:tripleIndexes "${repParam['Triple indexes'] || 'spoc,posc'}";
sb:evaluationStrategyFactory "${
repParam['EvaluationStrategyFactory'] ||
repParam.EvaluationStrategyFactory ||
'org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategyFactory'
}"
]
Expand Down Expand Up @@ -71,7 +71,7 @@ export function createRepositoryConfig(repParam: JsObject = {}, repType = 'nativ
sail:iterationCacheSyncThreshold "${repParam['Query Iteration Cache size'] || 10000}";
ns:tripleIndexes "${repParam['Triple indexes'] || 'spoc,posc'}";
sb:evaluationStrategyFactory "${
repParam['EvaluationStrategyFactory'] ||
repParam.EvaluationStrategyFactory ||
'org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategyFactory'
}"
]
Expand Down Expand Up @@ -110,7 +110,7 @@ export function createRepositoryConfig(repParam: JsObject = {}, repType = 'nativ
sail:iterationCacheSyncThreshold "${repParam['Query Iteration Cache size'] || 10000}";
ns:tripleIndexes "${repParam['Triple indexes'] || 'spoc,posc'}";
sb:evaluationStrategyFactory "${
repParam['EvaluationStrategyFactory'] ||
repParam.EvaluationStrategyFactory ||
'org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategyFactory'
}"
]
Expand All @@ -134,8 +134,8 @@ export function createRepositoryConfig(repParam: JsObject = {}, repType = 'nativ
rep:repositoryImpl [
rep:repositoryType "openrdf:VirtuosoRepository" ;
vr:hostList "${repParam['Host list'] || 'localhost:1111'}" ;
vr:username "${repParam['Username'] || 'dba'}" ;
vr:password "${repParam['Password'] || 'dba'}" ;
vr:username "${repParam.Username || 'dba'}" ;
vr:password "${repParam.Password || 'dba'}" ;
vr:defGraph "${repParam['Default graph name'] || 'sesame:nil'}" ;
vr:roundRobin ${repParam['Use RoundRobin for connection'] || false} ;
vr:useLazyAdd ${repParam['Enable using batch optimization'] || false} ;
Expand All @@ -144,7 +144,7 @@ export function createRepositoryConfig(repParam: JsObject = {}, repType = 'nativ
vr:fetchSize ${repParam['Buffer fetch size'] || 100} ;
vr:ruleSet "${repParam['Inference RuleSet name'] || null}";
vr:macroLib "${repParam['Inference MacroLib name'] || null}";
vr:concurrency ${repParam['ConcurrencyMode'] || 0} ;
vr:concurrency ${repParam.ConcurrencyMode || 0} ;
vr:useDefGraphForQueries ${
repParam["Use defGraph with SPARQL queries, if query default graph wasn't set"] || true
}
Expand All @@ -168,7 +168,7 @@ export class SparqlClientImpl implements SparqlClient {
}

setServerUrl(url: string, nsUrl?: string): void {
this.nsUrl = nsUrl || '';
this.nsUrl = nsUrl ?? '';
this.serverUrl = url;
this.regenerateUrls();
}
Expand Down Expand Up @@ -210,7 +210,7 @@ export class SparqlClientImpl implements SparqlClient {
});
}
}
ns['sesame'] = 'http://www.openrdf.org/schema/sesame#';
ns.sesame = 'http://www.openrdf.org/schema/sesame#';
return ns;
}

Expand All @@ -219,7 +219,7 @@ export class SparqlClientImpl implements SparqlClient {
statements = statements.replace(/^#.*$/gm, '');
//console.debug(() => `uploadStatements statements=${statements}`);
const params: JsObject = { baseURI };
if (graph) params['context'] = graph;
if (graph) params.context = graph;
const response = await sendPostStatements(this.statementsUrl, statements, params);
if (response.status < 200 && response.status > 204) return Promise.reject('Cannot upload statements');
}
Expand Down Expand Up @@ -299,7 +299,7 @@ export class SparqlClientImpl implements SparqlClient {
}
}

async sparqlUpdate(query: string, queryParams: JsObject = {}): Promise<AxiosResponse<any>> {
async sparqlUpdate(query: string, queryParams: JsObject = {}): Promise<AxiosResponse> {
//console.debug(() => `sparqlUpdate url=${this.repositoryUrl} queryParams=${json2str(queryParams)}`);
return executeUpdate(this.statementsUrl, query, queryParams);
}
Expand Down
10 changes: 5 additions & 5 deletions src/SparqlGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function getSchemaPropUri(schema: JSONSchema7LD, propertyKey: string): st
}

export function getSchemaPropType(
properties: { [key: string]: JSONSchema7LDProperty },
properties: Record<string, JSONSchema7LDProperty>,
context: JsObject,
propertyKey: string,
): string | undefined {
Expand Down Expand Up @@ -253,7 +253,7 @@ export interface EntConstrInternal extends EntConstrData {
qTypeFilters: any[];
// partial query (variables and conditions)
query: {
variables: { [s: string]: any };
variables: Record<string, any>;
bgps: any[];
filters: any[];
binds: any[];
Expand All @@ -270,12 +270,12 @@ export interface EntConstrInternal extends EntConstrData {
* Outgoing References dictionary
* ConditionProp: EntConstrNumberInArray
*/
relatedTo: { [s: string]: number };
relatedTo: Record<string, number>;
/**
* Incoming References dictionary
* ConditionProp: EntConstrNumberInArray
*/
relatedFrom: { [s: string]: number };
relatedFrom: Record<string, number>;
bindsVars: JsObject;
subEntConstr?: EntConstrInternal;
}
Expand Down Expand Up @@ -819,7 +819,7 @@ export function getDataTriples(entConstr: EntConstrInternal): any[] {
} else if (property.type === 'array') {
const prop = {
...property,
...(<any>property.items),
...(property.items as any),
};
if (Array.isArray(value)) {
value.forEach((v) => {
Expand Down
3 changes: 1 addition & 2 deletions src/SparqlGenSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export async function selectObjectsArrayProperties(
client: SparqlClient,
) {
//console.debug('selectObjectsArrayProperties');
for (let index = 0; index < entConstrs.length; index++) {
const entConstr = entConstrs[index];
for (const entConstr of entConstrs) {
const schema = entConstr.schema;
const anyContext = schema['@context'];
const context = anyContext !== undefined && typeof anyContext !== 'string' ? anyContext : {};
Expand Down
4 changes: 1 addition & 3 deletions src/models/MstColl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export function getMstLiteralPropValue(mstModel: any, name: string) {
return undefined;
}

export interface MstModels {
[key: string]: IAnyComplexType;
}
export type MstModels = Record<string, IAnyComplexType>;

const mstCollSchemas: MstModels = {};

Expand Down
Loading

0 comments on commit b36cea0

Please sign in to comment.