Skip to content

Commit

Permalink
feat: remove warning that package is empty (#1159)
Browse files Browse the repository at this point in the history
Closes #1153

### Summary of Changes

Remove the warning that an imported package is empty. It was always
shown together with an error that a package did not exist. Now, only the
error is shown.
  • Loading branch information
lars-reimann authored May 5, 2024
1 parent 07623fc commit b13c5df
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
17 changes: 3 additions & 14 deletions packages/safe-ds-lang/src/language/validation/other/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,17 @@ import { SdsImport } from '../../generated/ast.js';
import { SafeDsServices } from '../../safe-ds-module.js';
import { isEmpty } from '../../../helpers/collections.js';

export const CODE_IMPORT_MISSING_PACKAGE = 'import/missing-package';
export const CODE_IMPORT_EMPTY_PACKAGE = 'import/empty-package';

export const importPackageMustExist =
(services: SafeDsServices) =>
(node: SdsImport, accept: ValidationAcceptor): void => {
if (!services.workspace.PackageManager.hasPackage(node.package)) {
accept('error', `The package '${node.package}' does not exist.`, {
node,
property: 'package',
});
}
};

export const importPackageShouldNotBeEmpty =
export const importPackageMustNotBeEmpty =
(services: SafeDsServices) =>
(node: SdsImport, accept: ValidationAcceptor): void => {
const declarationsInPackage = services.workspace.PackageManager.getDeclarationsInPackage(node.package);
if (isEmpty(declarationsInPackage)) {
accept('warning', `The package '${node.package}' is empty.`, {
accept('error', `The package '${node.package}' is empty.`, {
node,
property: 'package',
code: CODE_IMPORT_EMPTY_PACKAGE,
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import {
referenceTargetMustNotBeAnnotationPipelineOrSchema,
} from './other/expressions/references.js';
import { templateStringMustHaveExpressionBetweenTwoStringParts } from './other/expressions/templateStrings.js';
import { importPackageMustExist, importPackageShouldNotBeEmpty } from './other/imports.js';
import { importPackageMustNotBeEmpty } from './other/imports.js';
import {
moduleDeclarationsMustMatchFileKind,
moduleWithDeclarationsMustStatePackage,
Expand Down Expand Up @@ -289,7 +289,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
pythonNameMustNotBeSetIfPythonMacroIsSet(services),
overridingAndOverriddenMethodsMustNotHavePythonMacro(services),
],
SdsImport: [importPackageMustExist(services), importPackageShouldNotBeEmpty(services)],
SdsImport: [importPackageMustNotBeEmpty(services)],
SdsImportedDeclaration: [importedDeclarationAliasShouldDifferFromDeclarationName(services)],
SdsIndexedAccess: [
indexedAccessIndexMustBeValid(services),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package tests.other.imports

// $TEST$ error "The package 'tests.other.imports.missing' does not exist."
// $TEST$ error "The package 'tests.other.imports.missing' is empty."
from »tests.other.imports.missing« import *
// $TEST$ error "The package 'tests.other.imports.missing' does not exist."
// $TEST$ error "The package 'tests.other.imports.missing' is empty."
from »tests.other.imports.missing« import C
// $TEST$ error "The package 'tests.other.imports.missing' does not exist."
// $TEST$ error "The package 'tests.other.imports.missing' is empty."
from »tests.other.imports.missing« import C as D

// $TEST$ warning "The package 'tests.other.imports.empty' is empty."
from »tests.other.imports.empty« import *
// $TEST$ warning "The package 'tests.other.imports.empty' is empty."
from »tests.other.imports.empty« import C
// $TEST$ warning "The package 'tests.other.imports.empty' is empty."
from »tests.other.imports.empty« import C as D
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tests.other.imports

// $TEST$ no error r"The package '\.*' does not exist\."
// $TEST$ no warning r"The package '\.*' is empty\."
// $TEST$ no error r"The package '\.*' is empty\."

from tests.other.imports.nonEmpty import *
from tests.other.imports.nonEmpty import C
Expand Down

0 comments on commit b13c5df

Please sign in to comment.