From 8b6f93b0b1649d5a0c4d48cbd29dae2f4121ac99 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Fri, 4 Oct 2024 17:46:58 +0300 Subject: [PATCH] Lint fixes Change-type: patch --- src/AbstractSQLOptimiser.ts | 21 +++------------------ src/AbstractSQLRules2SQL.ts | 10 +++++----- src/AbstractSQLSchemaOptimiser.ts | 4 ++-- src/referenced-fields.ts | 2 +- test/sbvr/reference-type.js | 2 +- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/AbstractSQLOptimiser.ts b/src/AbstractSQLOptimiser.ts index d5fac64..00da4fe 100644 --- a/src/AbstractSQLOptimiser.ts +++ b/src/AbstractSQLOptimiser.ts @@ -323,7 +323,7 @@ const Field: MetaMatchFn = (args) => { }; const AnyNotNullValue = (args: any): boolean => { - return args != null && (args as any) !== 'Null' && args[0] !== 'Null'; + return args != null && args !== 'Null' && args[0] !== 'Null'; }; const FieldOp = @@ -603,15 +603,7 @@ const typeRules = { case 'RightJoin': case 'FullJoin': case 'CrossJoin': - tables.push( - typeRules[type](rest) as - | FromNode - | InnerJoinNode - | LeftJoinNode - | RightJoinNode - | FullJoinNode - | CrossJoinNode, - ); + tables.push(typeRules[type](rest)); break; case 'Where': case 'GroupBy': @@ -1375,14 +1367,7 @@ const typeRules = { switch (valuesType) { case 'SelectQuery': case 'UnionQuery': - values = [ - [ - 'Values', - typeRules[valuesType](valuesRest) as - | SelectQueryNode - | UnionQueryNode, - ], - ]; + values = [['Values', typeRules[valuesType](valuesRest)]]; break; default: values = [['Values', valuesArray.map(Value)] as ValuesNode]; diff --git a/src/AbstractSQLRules2SQL.ts b/src/AbstractSQLRules2SQL.ts index e73e7db..a7f21e5 100644 --- a/src/AbstractSQLRules2SQL.ts +++ b/src/AbstractSQLRules2SQL.ts @@ -38,7 +38,7 @@ type MatchFn = (args: AbstractSqlType[], indent: string) => string; let fieldOrderings: Binding[] = []; let fieldOrderingsLookup: Dictionary = {}; let engine: Engines = Engines.postgres; -let noBinds: boolean = false; +let noBinds = false; export const comparisons = { Equals: ' = ', @@ -669,7 +669,7 @@ const typeRules: Dictionary = { SelectQuery: (args, indent) => { const tables: string[] = []; const joins: string[] = []; - let select: string = ''; + let select = ''; const groups = { Where: '', GroupBy: '', @@ -869,7 +869,7 @@ const typeRules: Dictionary = { checkArgs('Cast', args, 2); const value = AnyValue(getAbstractSqlQuery(args, 0), indent); const typeName = args[1] as keyof typeof sbvrTypes; - if (!sbvrTypes[typeName] || !sbvrTypes[typeName].types[engine]) { + if (!sbvrTypes[typeName]?.types[engine]) { throw new SyntaxError(`Invalid cast type: ${typeName}`); } let type: string; @@ -1451,7 +1451,7 @@ const typeRules: Dictionary = { const tables: string[] = []; let fields: string[] = []; let values: string[] = []; - let where: string = ''; + let where = ''; for (const arg of args) { if (!isAbstractSqlQuery(arg)) { throw new SyntaxError('`UpdateQuery` args must all be arrays'); @@ -1510,7 +1510,7 @@ const typeRules: Dictionary = { }, DeleteQuery: (args, indent) => { const tables: string[] = []; - let where: string = ''; + let where = ''; for (const arg of args) { if (!isAbstractSqlQuery(arg)) { throw new SyntaxError('`DeleteQuery` args must all be arrays'); diff --git a/src/AbstractSQLSchemaOptimiser.ts b/src/AbstractSQLSchemaOptimiser.ts index 9072128..470e308 100644 --- a/src/AbstractSQLSchemaOptimiser.ts +++ b/src/AbstractSQLSchemaOptimiser.ts @@ -44,7 +44,7 @@ export const generateRuleSlug = ( export const optimizeSchema = ( abstractSqlModel: AbstractSqlModel, - createCheckConstraints: boolean = true, + createCheckConstraints = true, ): AbstractSqlModel => { abstractSqlModel.rules = abstractSqlModel.rules .map((rule): AbstractSqlQuery | undefined => { @@ -126,7 +126,7 @@ export const optimizeSchema = ( ); if (table) { table.checks ??= []; - table.checks!.push({ + table.checks.push({ description: ruleSE, name: generateRuleSlug(tableName, ruleBody), abstractSql: whereNode, diff --git a/src/referenced-fields.ts b/src/referenced-fields.ts index 8a2cacb..23e6a01 100644 --- a/src/referenced-fields.ts +++ b/src/referenced-fields.ts @@ -270,7 +270,7 @@ export const getRuleReferencedFields: EngineInstance['getRuleReferencedFields'] _.isEqual(ruleBody[2], ['Number', 0]) && isSelectQueryNode(ruleBody[1]) ) { - const select = ruleBody[1].find(isSelectNode) as SelectNode; + const select = ruleBody[1].find(isSelectNode)!; select[1] = []; $getRuleReferencedFields(referencedFields, ruleBody[1], IsSafe.Delete); } else { diff --git a/test/sbvr/reference-type.js b/test/sbvr/reference-type.js index 73cd4b2..088b029 100644 --- a/test/sbvr/reference-type.js +++ b/test/sbvr/reference-type.js @@ -29,7 +29,7 @@ describe('reference type', function () { test = getTestHelpers(typeVocab); }); - it('informative - no foreignKey for reference field', async () => { + it('informative - no foreignKey for reference field', () => { test( `\