Skip to content

Commit

Permalink
style: apply automated linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
megalinter-bot committed Oct 12, 2023
1 parent 86c8ec6 commit eb45e34
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/language/helpers/safe-ds-node-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
isSdsAssignment,
isSdsBlock,
isSdsCall,
isSdsCallable, isSdsClass, isSdsEnumVariant,
isSdsCallable,
isSdsClass,
isSdsEnumVariant,
isSdsNamedType,
isSdsReference,
isSdsSegment,
Expand Down
24 changes: 13 additions & 11 deletions src/language/validation/other/statements/assignments.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {isSdsCall, isSdsPipeline, SdsAssignment, SdsYield} from '../../../generated/ast.js';
import { isSdsCall, isSdsPipeline, SdsAssignment, SdsYield } from '../../../generated/ast.js';
import { getContainerOfType, ValidationAcceptor } from 'langium';
import { SafeDsServices } from '../../../safe-ds-module.js';
import {abstractResultsOrEmpty, assigneesOrEmpty} from '../../../helpers/nodeProperties.js';
import {pluralize} from "../../../helpers/stringUtils.js";
import { abstractResultsOrEmpty, assigneesOrEmpty } from '../../../helpers/nodeProperties.js';
import { pluralize } from '../../../helpers/stringUtils.js';

export const CODE_ASSIGNMENT_IMPLICITLY_IGNORED_RESULT = 'assignment/implicitly-ignored-result';
export const CODE_ASSIGMENT_NOTHING_ASSIGNED = 'assignment/nothing-assigned';
Expand All @@ -25,25 +25,27 @@ export const assignmentShouldNotImplicitlyIgnoreResult = (services: SafeDsServic
const nodeMapper = services.helpers.NodeMapper;

return (node: SdsAssignment, accept: ValidationAcceptor): void => {
const expression = node.expression
const expression = node.expression;
if (!isSdsCall(expression)) {
return
return;
}

const assignees = assigneesOrEmpty(node)
const callable = nodeMapper.callToCallableOrUndefined(expression)
const results = abstractResultsOrEmpty(callable)
const assignees = assigneesOrEmpty(node);
const callable = nodeMapper.callToCallableOrUndefined(expression);
const results = abstractResultsOrEmpty(callable);

if (results.length > assignees.length) {
const kind = pluralize(results.length - assignees.length, 'result')
const names = results.slice(assignees.length).map(result => `'${result.name}'`).join(', ')
const kind = pluralize(results.length - assignees.length, 'result');
const names = results
.slice(assignees.length)
.map((result) => `'${result.name}'`)
.join(', ');

accept('warning', `The assignment implicitly ignores the ${kind} ${names}.`, {
node,
code: CODE_ASSIGNMENT_IMPLICITLY_IGNORED_RESULT,
});
}

};
};

Expand Down
8 changes: 3 additions & 5 deletions src/language/validation/safe-ds-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
yieldMustNotBeUsedInPipeline,
} from './other/statements/assignments.js';
import {
attributeMustHaveTypeHint, callReceiverMustBeCallable,
attributeMustHaveTypeHint,
callReceiverMustBeCallable,
namedTypeMustSetAllTypeParameters,
parameterMustHaveTypeHint,
resultMustHaveTypeHint,
Expand Down Expand Up @@ -126,10 +127,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
SdsArgumentList: [argumentListMustNotHavePositionalArgumentsAfterNamedArguments],
SdsAttribute: [attributeMustHaveTypeHint],
SdsBlockLambda: [blockLambdaMustContainUniqueNames],
SdsCall: [
callArgumentListShouldBeNeeded(services),
callReceiverMustBeCallable(services),
],
SdsCall: [callArgumentListShouldBeNeeded(services), callReceiverMustBeCallable(services)],
SdsCallableType: [
callableTypeMustContainUniqueNames,
callableTypeMustNotHaveOptionalParameters,
Expand Down
19 changes: 12 additions & 7 deletions src/language/validation/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { getContainerOfType, ValidationAcceptor } from 'langium';
import {
isSdsAnnotation,
isSdsCallable, isSdsClass,
isSdsLambda, isSdsMemberAccess, isSdsPipeline, isSdsReference, isSdsSchema,
isSdsCallable,
isSdsClass,
isSdsLambda,
isSdsMemberAccess,
isSdsPipeline,
isSdsReference,
isSdsSchema,
SdsAttribute,
SdsCall,
SdsNamedType,
Expand All @@ -26,17 +31,17 @@ export const callReceiverMustBeCallable = (services: SafeDsServices) => {
const nodeMapper = services.helpers.NodeMapper;

return (node: SdsCall, accept: ValidationAcceptor): void => {
let receiver = node.receiver
let receiver = node.receiver;
if (isSdsMemberAccess(receiver)) {
receiver = receiver.member
receiver = receiver.member;
}

if (isSdsReference(receiver)) {
const target = receiver.target.ref
const target = receiver.target.ref;

// We already report other errors at this position in those cases
if (!target || isSdsAnnotation(target) || isSdsPipeline(target) || isSdsSchema(target)) {
return
return;
}
}

Expand All @@ -47,7 +52,7 @@ export const callReceiverMustBeCallable = (services: SafeDsServices) => {
code: CODE_TYPE_CALLABLE_RECEIVER,
});
} else if (isSdsClass(callable) && !callable.parameterList) {
accept('error', "Cannot instantiate a class that has no constructor.", {
accept('error', 'Cannot instantiate a class that has no constructor.', {
node: node.receiver,
code: CODE_TYPE_CALLABLE_RECEIVER,
});
Expand Down

0 comments on commit eb45e34

Please sign in to comment.