Skip to content

Commit

Permalink
Merge pull request #242 from balena-io-modules/renovate/major-@balena…
Browse files Browse the repository at this point in the history
…lint

Update dependency @balena/lint to v8
  • Loading branch information
thgreasi authored Mar 26, 2024
2 parents 7ce4140 + 8353653 commit 79cfa07
Show file tree
Hide file tree
Showing 40 changed files with 243 additions and 183 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: ['./node_modules/@balena/lint/config/.eslintrc.js'],
parserOptions: {
project: 'tsconfig.js.json',
sourceType: 'module',
},
env: {
// TODO: Drop this once we convert all .js tests to .ts
mocha: true,
},
root: true,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@balena/lf-to-abstract-sql": "^5.0.0",
"@balena/lint": "^6.2.2",
"@balena/lint": "^8.0.0",
"@balena/odata-parser": "^3.0.0",
"@balena/odata-to-abstract-sql": "^6.0.1",
"@balena/sbvr-parser": "^1.4.3",
Expand Down
21 changes: 11 additions & 10 deletions src/AbstractSQLCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
export const enum Engines {
/* eslint-disable @typescript-eslint/no-shadow -- this is fine since we only assign plain string values to the enum items */
postgres = 'postgres',
mysql = 'mysql',
websql = 'websql',
/* eslint-enable @typescript-eslint/no-shadow */
}

import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
import {
AbstractSQLRules2SQL,
Binding,
SqlResult,
} from './AbstractSQLRules2SQL';
import type { Binding, SqlResult } from './AbstractSQLRules2SQL';
import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL';
export { Binding, SqlResult } from './AbstractSQLRules2SQL';
import type { SbvrType } from '@balena/sbvr-types';
import sbvrTypes from '@balena/sbvr-types';
import * as _ from 'lodash';
import { optimizeSchema, generateRuleSlug } from './AbstractSQLSchemaOptimiser';
import type {
ReferencedFields,
RuleReferencedFields,
ModifiedFields,
} from './referenced-fields';
import {
getReferencedFields,
getRuleReferencedFields,
getModifiedFields,
ReferencedFields,
RuleReferencedFields,
ModifiedFields,
insertAffectedIdsBinds,
} from './referenced-fields';

Expand Down Expand Up @@ -328,7 +329,7 @@ export type SelectQueryStatementNode =
export type SelectQueryNode = ['SelectQuery', ...SelectQueryStatementNode[]];
export type UnionQueryNode = [
'UnionQuery',
// tslint:disable-next-line:array-type typescript fails on a circular reference when `Array<T>` form
// eslint-disable-next-line @typescript-eslint/array-type -- Typescript fails on a circular reference when prettier changes this to an `Array<T>` form
...(UnionQueryNode | SelectQueryNode)[],
];
export type InsertQueryNode = [
Expand Down Expand Up @@ -987,7 +988,7 @@ CREATE TABLE ${ifNotExistsStr}"${table.name}" (
// Self-dependencies are ok.
if (
dependency !== resourceName &&
schemaDependencyMap.hasOwnProperty(dependency)
Object.prototype.hasOwnProperty.call(schemaDependencyMap, dependency)
) {
unsolvedDependency = true;
break;
Expand Down
22 changes: 15 additions & 7 deletions src/AbstractSQLOptimiser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'lodash';

import { Dictionary } from 'lodash';
import {
import type { Dictionary } from 'lodash';
import type {
AbstractSqlQuery,
AbstractSqlType,
AddDateDurationNode,
Expand Down Expand Up @@ -424,7 +424,7 @@ const Value = (arg: string | AbstractSqlQuery): ValuesNodeTypes => {
switch (arg) {
case 'Default':
return arg;
default:
default: {
const [type, ...rest] = arg;
switch (type) {
case 'Null':
Expand All @@ -445,6 +445,7 @@ const Value = (arg: string | AbstractSqlQuery): ValuesNodeTypes => {
default:
throw new SyntaxError(`Invalid type for Value ${type}`);
}
}
}
};

Expand Down Expand Up @@ -501,6 +502,7 @@ const JoinMatch =
const ruleBody = BooleanValue(getAbstractSqlQuery(rest, 0));
return [joinType, from, ['On', ruleBody]] as unknown as T;
}
// eslint-disable-next-line no-fallthrough
default:
throw new SyntaxError(
`'${joinType}' clause does not support '${type}' clause`,
Expand Down Expand Up @@ -706,9 +708,11 @@ const typeRules = {
_.identity,
),
Cast: matchArgs<CastNode>('Cast', AnyValue, _.identity),
// eslint-disable-next-line id-denylist
Number: NumberMatch('Number'),
Real: NumberMatch('Real'),
Integer: NumberMatch('Integer'),
// eslint-disable-next-line id-denylist
Boolean: matchArgs<BooleanNode>('Boolean', _.identity),
EmbeddedText: matchArgs('EmbeddedText', _.identity),
Null: matchArgs<NullNode>('Null'),
Expand Down Expand Up @@ -916,11 +920,12 @@ const typeRules = {
}
const [type, ...rest] = arg;
switch (type) {
case 'When':
case 'When': {
checkArgs('When', rest, 2);
const matches = BooleanValue(getAbstractSqlQuery(rest, 0));
const resultValue = AnyValue(getAbstractSqlQuery(rest, 1));
return ['When', matches, resultValue];
}
case 'Else':
if (index !== args.length - 1) {
throw new SyntaxError('Else must be the last element of a Case');
Expand Down Expand Up @@ -1346,7 +1351,7 @@ const typeRules = {
checkMinArgs('Update fields', rest, 1);
fields = [arg as FieldsNode];
break;
case 'Values':
case 'Values': {
if (values.length !== 0) {
throw new SyntaxError(
`'InsertQuery' can only accept one '${type}'`,
Expand All @@ -1372,6 +1377,7 @@ const typeRules = {
}
}
break;
}
case 'From':
tables.push(typeRules[type](rest));
break;
Expand Down Expand Up @@ -1425,7 +1431,7 @@ const typeRules = {
checkMinArgs('Update fields', rest, 1);
fields = [arg as FieldsNode];
break;
case 'Values':
case 'Values': {
if (values.length !== 0) {
throw new SyntaxError(
`'UpdateQuery' can only accept one '${type}'`,
Expand All @@ -1436,6 +1442,7 @@ const typeRules = {
checkMinArgs('Update values array', valuesArray, 1);
values = [['Values', valuesArray.map(Value)]];
break;
}
case 'From':
tables.push(typeRules[type](rest));
break;
Expand Down Expand Up @@ -1596,7 +1603,7 @@ export const AbstractSQLOptimiser = (
case 'DeleteQuery':
abstractSQL = typeRules[type](rest);
break;
case 'UpsertQuery':
case 'UpsertQuery': {
checkArgs('UpsertQuery', rest, 2);
const insertQuery = getAbstractSqlQuery(rest, 0);
const updateQuery = getAbstractSqlQuery(rest, 1);
Expand All @@ -1614,6 +1621,7 @@ export const AbstractSQLOptimiser = (
typeRules.UpdateQuery(updateQuery.slice(1)),
];
break;
}
default:
abstractSQL = AnyValue(abstractSQL) as AbstractSqlQuery;
}
Expand Down
Loading

0 comments on commit 79cfa07

Please sign in to comment.