Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: error if pipeline file is in a safeds.xy package #673

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions src/language/validation/other/modules.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { ValidationAcceptor } from 'langium';
import { isSdsDeclaration, isSdsPipeline, isSdsSegment, SdsDeclaration, SdsModule } from '../../generated/ast.js';
import { isInPipelineFile, isInStubFile } from '../../helpers/fileExtensions.js';
import { getModuleMembers } from '../../helpers/nodeProperties.js';

export const CODE_MODULE_MISSING_PACKAGE = 'module/missing-package';
export const CODE_MODULE_FORBIDDEN_IN_PIPELINE_FILE = 'module/forbidden-in-pipeline-file';
export const CODE_MODULE_FORBIDDEN_IN_STUB_FILE = 'module/forbidden-in-stub-file';

export const moduleWithDeclarationsMustStatePackage = (node: SdsModule, accept: ValidationAcceptor): void => {
if (!node.name) {
const declarations = node.members.filter(isSdsDeclaration);
if (declarations.length > 0) {
accept('error', 'A module with declarations must state its package.', {
node: declarations[0],
property: 'name',
code: CODE_MODULE_MISSING_PACKAGE,
});
}
}
};
export const CODE_MODULE_MISSING_PACKAGE = 'module/missing-package';
export const CODE_MODULE_PIPELINE_FILE_IN_SAFEDS_PACKAGE = 'module/pipeline-file-in-safeds-package';

export const moduleDeclarationsMustMatchFileKind = (node: SdsModule, accept: ValidationAcceptor): void => {
const declarations = node.members.filter(isSdsDeclaration);
Expand Down Expand Up @@ -52,3 +41,26 @@ export const declarationIsAllowedInPipelineFile = (declaration: SdsDeclaration):
export const declarationIsAllowedInStubFile = (declaration: SdsDeclaration): boolean => {
return !isSdsPipeline(declaration) && !isSdsSegment(declaration);
};

export const moduleWithDeclarationsMustStatePackage = (node: SdsModule, accept: ValidationAcceptor): void => {
if (!node.name) {
const members = getModuleMembers(node);
if (members.length > 0) {
accept('error', 'A module with declarations must state its package.', {
node: members[0],
property: 'name',
code: CODE_MODULE_MISSING_PACKAGE,
});
}
}
};

export const pipelineFileMustNotBeInSafedsPackage = (node: SdsModule, accept: ValidationAcceptor): void => {
if (isInPipelineFile(node) && node.name?.startsWith('safeds')) {
accept('error', "A pipeline file must not be in a 'safeds' package.", {
node,
property: 'name',
code: CODE_MODULE_PIPELINE_FILE_IN_SAFEDS_PACKAGE,
});
}
};
7 changes: 6 additions & 1 deletion src/language/validation/safe-ds-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ import {
parameterMustHaveTypeHint,
resultMustHaveTypeHint,
} from './types.js';
import { moduleDeclarationsMustMatchFileKind, moduleWithDeclarationsMustStatePackage } from './other/modules.js';
import {
moduleDeclarationsMustMatchFileKind,
moduleWithDeclarationsMustStatePackage,
pipelineFileMustNotBeInSafedsPackage,
} from './other/modules.js';
import { typeParameterConstraintLeftOperandMustBeOwnTypeParameter } from './other/declarations/typeParameterConstraints.js';
import { parameterListMustNotHaveRequiredParametersAfterOptionalParameters } from './other/declarations/parameterLists.js';
import { unionTypeMustHaveTypes, unionTypeShouldNotHaveDuplicateTypes } from './other/types/unionTypes.js';
Expand Down Expand Up @@ -228,6 +232,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
moduleMemberMustHaveNameThatIsUniqueInPackage(services),
moduleMustContainUniqueNames,
moduleWithDeclarationsMustStatePackage,
pipelineFileMustNotBeInSafedsPackage,
pythonModuleShouldDifferFromSafeDsPackage(services),
],
SdsNamedType: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »tests.validation.other.modules.pipelineFilesMustNotBeInSafedsPackage«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ error "A pipeline file must not be in a 'safeds' package."

package »safeds«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ error "A pipeline file must not be in a 'safeds' package."

package »safeds.validation.other.modules.pipelineFilesMustNotBeInSafedsPackage«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »tests.validation.other.modules.pipelineFilesMustNotBeInSafedsPackage«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »safeds«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »safeds.validation.other.modules.pipelineFilesMustNotBeInSafedsPackage«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »tests.validation.other.modules.pipelineFilesMustNotBeInSafedsPackage«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »safeds«
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no error "A pipeline file must not be in a 'safeds' package."

package »safeds.validation.other.modules.pipelineFilesMustNotBeInSafedsPackage«