Skip to content

Commit

Permalink
make MegaLinter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
robmeth committed Aug 20, 2024
1 parent ed1b7b8 commit 0cc4d6f
Show file tree
Hide file tree
Showing 21 changed files with 20 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,13 @@ import {
isTslConstant,
TslConstant,
TslTimespan,
isTslData,
TslData,
isTslBlock,
TslTimeunit,
isTslExpression,
isTslString,
isTslParenthesizedExpression,
isTslResult,
isTslReturnStatement,
isTslLiteral,
isTslInt,
isTslDate,
isTslNull,
isTslBoolean,
isTslFloat,
Expand All @@ -94,7 +89,6 @@ import { TTSLNodeMapper } from '../helpers/ttsl-node-mapper.js';
import { TTSLPartialEvaluator } from '../partialEvaluation/ttsl-partial-evaluator.js';
import { TTSLServices } from '../ttsl-module.js';
import { TTSLFunction } from '../builtins/ttsl-ds-functions.js';
import { Console } from 'console';

export const CODEGEN_PREFIX = '__gen_';

Expand Down Expand Up @@ -155,18 +149,6 @@ const UTILITY_NULL_SAFE_INDEXED_ACCESS: UtilityFunction = {
typeVariables: [`${CODEGEN_PREFIX}T`],
};

const UTILITY_NULL_SAFE_MEMBER_ACCESS: UtilityFunction = {
name: `${CODEGEN_PREFIX}null_safe_member_access`,
code: expandToNode`def ${CODEGEN_PREFIX}null_safe_member_access(receiver: Any, member_name: str) -> ${CODEGEN_PREFIX}T | None:`
.appendNewLine()
.indent({
indentedChildren: ['return getattr(receiver, member_name) if receiver is not None else None'],
indentation: PYTHON_INDENT,
}),
imports: [{ importPath: 'typing', declarationName: 'Any' }],
typeVariables: [`${CODEGEN_PREFIX}T`],
};

const UTILITY_AGGREGATION: UtilityFunction = {
name: `${CODEGEN_PREFIX}aggregation`,
code: expandToNode`def ${CODEGEN_PREFIX}aggregation(dataFrame: pd, data, id, function: str) -> pd | None:`
Expand Down Expand Up @@ -1101,9 +1083,8 @@ export class TTSLPythonGenerator {

private generateFunctionParameter(
funct: TslFunction,
frame: GenerationInfoFrame,
): CompositeGeneratorNode | undefined {
if(funct.timeunit != undefined|| funct.groupedBy != undefined){
if(funct.timeunit !== undefined|| funct.groupedBy !== undefined){
return expandToNode`timeunit = None, groupedBy = None, date = None`
}
return undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class TTSLNodeMapper {
// link the arguments of the call properly, even if the user forgot to make the call null-safe. In this
// case, an error is being shown anyway.
const receiverType = this.typeComputer().computeType(node.receiver);
const nonNullableReceiverType = this.typeComputer().computeNonNullableType(receiverType);

if(isTslReference(node.receiver)){
if(isTslCallable(node.receiver.target.ref)){
Expand Down
11 changes: 0 additions & 11 deletions packages/ttsl-lang/src/language/lsp/ttsl-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ import newLines = Formatting.newLines;
import noSpace = Formatting.noSpace;
import oneSpace = Formatting.oneSpace;

const newLinesWithIndent = function (count: number, options?: FormattingActionOptions): FormattingAction {
return {
options: options ?? {},
moves: [
{
tabs: 1,
lines: count,
},
],
};
};

export class TTSLFormatter extends AbstractFormatter {
protected override format(node: AstNode): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractSemanticTokenProvider, SemanticTokenAcceptor } from 'langium/lsp';
import { AstNode, AstUtils } from 'langium';
import { AstNode } from 'langium';
import { SemanticTokenModifiers, SemanticTokenTypes } from 'vscode-languageserver';
import {
isTslArgument,
Expand All @@ -16,10 +16,6 @@ import {
import { TTSLServices } from '../ttsl-module.js';

export class TTSLSemanticTokenProvider extends AbstractSemanticTokenProvider {
constructor(services: TTSLServices) {
super(services);
}

protected highlightElement(node: AstNode, acceptor: SemanticTokenAcceptor): void {
if (isTslArgument(node)) {
if (node.parameter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CstUtils,
type DocumentationProvider,
GrammarUtils,
isNamed,
type LangiumDocument,
type MaybePromise,
} from 'langium';
Expand Down
2 changes: 0 additions & 2 deletions packages/ttsl-lang/src/language/partialEvaluation/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
TslResult,
type TslCallable,
type TslDeclaration,
type TslExpression,
type TslParameter,
} from '../generated/ast.js';
import { getParameters } from '../helpers/nodeProperties.js';
import { escapeString } from '../grammar/ttsl-value-converter.js';

export type ParameterSubstitutions = Map<TslParameter, EvaluatedNode>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ import {
type TslPrefixOperation,
type TslTemplateString,
isTslAggregation,
TslAggregation,
TslModifier,
isTslGroupedBy,
isTslVisibility,
isTslTimeunit,
isTslString,
isTslParenthesizedExpression,
} from '../generated/ast.js';
Expand Down Expand Up @@ -130,7 +125,7 @@ export class TTSLPartialEvaluator {
if (isTslAssignee(node)) {
return this.evaluateAssignee(node, substitutions, visited);
} else if (isTslDeclaration(node)) {
return this.evaluateDeclaration(node, substitutions, visited);
return this.evaluateDeclaration(node, substitutions);
} else if (isTslExpression(node)) {
return this.evaluateExpression(node, substitutions, visited);
} /* c8 ignore start */ else {
Expand Down Expand Up @@ -167,7 +162,6 @@ export class TTSLPartialEvaluator {
private evaluateDeclaration(
node: TslDeclaration,
substitutions: ParameterSubstitutions,
visited: VisitedState[],
): EvaluatedNode {
if (isTslFunction(node)) {
return new NamedCallable(node);
Expand Down Expand Up @@ -223,7 +217,7 @@ export class TTSLPartialEvaluator {
} else if (isTslTypeCast(node)) {
return this.evaluateWithRecursionCheck(node.expression, substitutions, visited);
} else if (isTslAggregation(node)) {
return this.evaluateAggregation(node, substitutions, visited);
return this.evaluateAggregation();
} else if (isTslParenthesizedExpression(node)) {
return this.evaluateWithRecursionCheck(node, substitutions, visited);
} /* c8 ignore start */ else {
Expand Down Expand Up @@ -490,26 +484,10 @@ export class TTSLPartialEvaluator {
return UnknownEvaluatedNode;
}

private evaluateAggregation(node: TslAggregation, substitutions: ParameterSubstitutions, visited: VisitedState[]): EvaluatedNode {
const data = this.evaluateExpression(node.data, substitutions, visited).unwrap();
const funct = this.evaluateExpression(node.function, substitutions, visited).unwrap();
const groupedBy = this.evaluateModifier(node.groupedBy, substitutions, visited).unwrap();

private evaluateAggregation(): EvaluatedNode {
return UnknownEvaluatedNode;
}

private evaluateModifier(node: TslModifier, substitutions: ParameterSubstitutions, visited: VisitedState[]): EvaluatedNode {
if (isTslGroupedBy(node)) {
return this.evaluateExpression(node.id, substitutions, visited);
} else if (isTslVisibility(node)) {
throw new Error(`noch nicht evaluierbar`);
} else if (isTslTimeunit(node)) {
throw new Error(`noch nicht evaluierbar`);
}/* c8 ignore start */ else {
throw new Error(`Unexpected Modifier type: ${node.$type}`);
} /* c8 ignore stop */
}

private evaluateCallableCall(
callable: TslCallable | TslParameter,
args: TslArgument[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
} from '../helpers/nodeProperties.js';
import { TTSLNodeMapper } from '../helpers/ttsl-node-mapper.js';
import { TTSLServices } from '../ttsl-module.js';
import { TTSLTypeComputer } from '../typing/ttsl-type-computer.js';
import { TTSLPackageManager } from '../workspace/ttsl-package-manager.js';

export class TTSLScopeProvider extends DefaultScopeProvider {
Expand Down
2 changes: 0 additions & 2 deletions packages/ttsl-lang/src/language/typing/ttsl-type-checker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TTSLServices } from '../ttsl-module.js';
import {
AnyType,
DictionaryType,
Expand All @@ -8,7 +7,6 @@ import {

export class TTSLTypeChecker {

constructor(services: TTSLServices) {}

// -----------------------------------------------------------------------------------------------------------------
// General cases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class TTSLTypeComputer {
/**
* Computes the lowest common supertype for the given types. The result is simplified as much as possible.
*/
private lowestCommonSupertype(types: Type[], options: LowestCommonSupertypeOptions = {}): Type {
private lowestCommonSupertype(types: Type[]): Type {
// A single type is its own lowest common supertype
if (types.length === 1) {
return types[0]!;
Expand Down
12 changes: 6 additions & 6 deletions packages/ttsl-lang/src/language/validation/aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export const groupedFunctionHasValidID = () => {
export const groupedFunctionHasAggregation = () => {
return (node: TslFunction, accept: ValidationAcceptor) => {
let id = node.groupedBy?.id.target.ref?.name
if (id != undefined){
if (id !== undefined){
let parameters = getParameters(node)
let isGrouped = false
parameters.forEach(elm => {
if (elm.groupedBy?.id.target.ref?.name == id){
if (elm.groupedBy?.id.target.ref?.name === id){
isGrouped = true
}
});
Expand All @@ -82,11 +82,11 @@ export const groupedFunctionHasAggregation = () => {

function hasAggregation(statements: TslStatement[]| undefined, id: string): boolean{
let result = false
if(statements == undefined){
if(statements === undefined){
return result
}
statements.forEach(elm => {
if(isTslExpressionStatement(elm) && isTslAggregation(elm.expression) && elm.expression.groupedBy.id.target.ref?.name == id){
if(isTslExpressionStatement(elm) && isTslAggregation(elm.expression) && elm.expression.groupedBy.id.target.ref?.name === id){
result = true
} else if(isTslConditionalStatement(elm)){
result = (hasAggregation(elm.ifBlock.statements, id) && hasAggregation(elm.elseBlock?.statements, id))
Expand All @@ -96,8 +96,8 @@ function hasAggregation(statements: TslStatement[]| undefined, id: string): bool
if(isTslAggregation(elm.expression)){
result = true
}else if(elm.assigneeList?.assignees.filter(isTslPlaceholder)){
elm.assigneeList.assignees.filter(isTslPlaceholder).forEach(elm => {
if(elm.groupedBy?.id.target.ref?.name == id){
elm.assigneeList.assignees.filter(isTslPlaceholder).forEach(placeholder => {
if(placeholder.groupedBy?.id.target.ref?.name === id){
result = true
}
})
Expand Down
2 changes: 0 additions & 2 deletions packages/ttsl-lang/src/language/validation/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
getImports,
getModuleMembers,
getPackageName,
getParameters,
getResults,
} from '../helpers/nodeProperties.js';
import { TTSLServices } from '../ttsl-module.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const argumentListMustNotSetParameterMultipleTimes = (services: TTSLServi
return (node: TslArgumentList, accept: ValidationAcceptor): void => {
// We already report other errors in this case
const containingCall = AstUtils.getContainerOfType(node, isTslCall);
const callable = nodeMapper.callToCallable(containingCall);

const args = getArguments(node);
const duplicates = duplicatesBy(args, argumentToParameterOrUndefined);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AstUtils, ValidationAcceptor } from 'langium';
import { isTslCallable, TslParameter } from '../../../generated/ast.js';
import { ValidationAcceptor } from 'langium';
import { TslParameter } from '../../../generated/ast.js';
import { Parameter } from '../../../helpers/nodeProperties.js';
import { TTSLServices } from '../../../ttsl-module.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
isTslAssignment,
isTslBlock,
isTslParameter,
isTslPlaceholder,
isTslReference,
isTslStatement,
TslPlaceholder,
Expand All @@ -15,7 +13,7 @@ import { last } from '../../../../helpers/collections.js';

export const CODE_PLACEHOLDER_UNUSED = 'placeholder/unused';

export const placeholdersMustNotBeAnAlias = (node: TslPlaceholder, accept: ValidationAcceptor): void => {
export const placeholdersMustNotBeAnAlias = (node: TslPlaceholder): void => {
if (node.$containerIndex ?? 0 > 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isTslCall, isTslFunction, TslAssignment} from '../../../generated/ast.js';
import { isTslFunction, TslAssignment} from '../../../generated/ast.js';
import { ValidationAcceptor } from 'langium';
import { TTSLServices } from '../../../ttsl-module.js';
import { getResults, getAssignees } from '../../../helpers/nodeProperties.js';
Expand All @@ -21,8 +21,6 @@ export const assignmentAssigneeMustGetValue =
};

export const assignmentShouldNotImplicitlyIgnoreResult = (services: TTSLServices) => {
const nodeMapper = services.helpers.NodeMapper;

return (node: TslAssignment, accept: ValidationAcceptor): void => {
const expression = node.expression;
if (!isTslFunction(expression)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ttsl-lang/src/language/validation/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const functionResultListShouldNotBeEmpty = (services: TTSLServices) => {
return;
}

if (node.result && node.body.statements.filter(isTslReturnStatement).at(0) == undefined) {
if (node.result && node.body.statements.filter(isTslReturnStatement).at(0) === undefined) {
accept('info', 'This result list can be removed.', {
node,
property: 'result',
Expand Down
8 changes: 2 additions & 6 deletions packages/ttsl-lang/src/language/validation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const callArgumentTypesMustMatchParameterTypes = (services: TTSLServices)
const argumentType = typeComputer.computeType(argument);
const parameterType = typeComputer.computeType(parameter);

if (!(argumentType.toString == parameterType.toString || parameterType instanceof AnyType)) {
if (!(argumentType.toString === parameterType.toString || parameterType instanceof AnyType)) {
accept('error', `Expected type '${parameterType}' but got '${argumentType}'.`, {
node: argument,
property: 'value',
Expand Down Expand Up @@ -97,7 +97,6 @@ export const indexedAccessReceiverMustBeListOrMap = (services: TTSLServices) =>
};

export const indexedAccessIndexMustHaveCorrectType = (services: TTSLServices) => {
const typeChecker = services.types.TypeChecker;
const typeComputer = services.types.TypeComputer;

return (node: TslIndexedAccess, accept: ValidationAcceptor): void => {
Expand All @@ -116,7 +115,6 @@ export const indexedAccessIndexMustHaveCorrectType = (services: TTSLServices) =>
};

export const infixOperationOperandsMustHaveCorrectType = (services: TTSLServices) => {
const typeChecker = services.types.TypeChecker;
const typeComputer = services.types.TypeComputer;

return (node: TslInfixOperation, accept: ValidationAcceptor): void => {
Expand Down Expand Up @@ -218,7 +216,6 @@ export const mapMustNotContainNamedTuples = (services: TTSLServices) => {
};

export const parameterDefaultValueTypeMustMatchParameterType = (services: TTSLServices) => {
const typeChecker = services.types.TypeChecker;
const typeComputer = services.types.TypeComputer;

return (node: TslParameter, accept: ValidationAcceptor) => {
Expand All @@ -230,7 +227,7 @@ export const parameterDefaultValueTypeMustMatchParameterType = (services: TTSLSe
const defaultValueType = typeComputer.computeType(defaultValue);
const parameterType = typeComputer.computeType(node);

if (!(defaultValueType.toString == parameterType.toString)) {
if (!(defaultValueType.toString === parameterType.toString)) {
accept('error', `Expected type '${parameterType}' but got '${defaultValueType}'.`, {
node,
property: 'defaultValue',
Expand All @@ -241,7 +238,6 @@ export const parameterDefaultValueTypeMustMatchParameterType = (services: TTSLSe
};

export const prefixOperationOperandMustHaveCorrectType = (services: TTSLServices) => {
const typeChecker = services.types.TypeChecker;
const typeComputer = services.types.TypeComputer;

return (node: TslPrefixOperation, accept: ValidationAcceptor): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
LangiumDocuments,
} from 'langium';
import { getPackageName, isPackagePrivate, isPrivate } from '../helpers/nodeProperties.js';
import { isTslDeclaration, isTslFunction } from '../generated/ast.js';
import { isTslDeclaration } from '../generated/ast.js';

export class TTSLPackageManager {
private readonly astNodeLocator: AstNodeLocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ describe('TTSLCommentProvider', () => {
throw new AssertionError({ message: 'Node not found.' });
}

console.log(node.$type + ': ' + commentProvider.getComment(node) + '\n');
expect(commentProvider.getComment(node)).toStrictEqual(expectedComment);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AstNode, EmptyFileSystem } from 'langium';
import { describe, expect, it } from 'vitest';
import { normalizeLineBreaks } from '../../../src/helpers/strings.js';
import {
isTslConstant,
isTslFunction,
isTslParameter,
isTslResult,
Expand Down

0 comments on commit 0cc4d6f

Please sign in to comment.