-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
077daff
commit e9f23a0
Showing
7 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ValidationAcceptor } from 'langium'; | ||
import { isSdsDeclaration, SdsImport } from '../../generated/ast.js'; | ||
import { SafeDsServices } from '../../safe-ds-module.js'; | ||
import {isEmpty} from "radash"; | ||
|
||
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 = | ||
(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.`, { | ||
node, | ||
property: 'package', | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package tests.other.imports.empty |
15 changes: 15 additions & 0 deletions
15
tests/resources/validation/other/imports/main with issues.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tests.other.imports | ||
|
||
// $TEST$ error "The package 'tests.other.imports.missing' does not exist." | ||
from »tests.other.imports.missing« import * | ||
// $TEST$ error ""The package 'tests.other.imports.missing' does not exist." | ||
from »tests.other.imports.missing« import C | ||
// $TEST$ error ""The package 'tests.other.imports.missing' does not exist." | ||
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 |
8 changes: 8 additions & 0 deletions
8
tests/resources/validation/other/imports/main without issues.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package tests.other.imports | ||
|
||
// $TEST$ no error r"The package '\.*' does not exist\." | ||
// $TEST$ no warning r"The package '\.*' is empty\." | ||
|
||
from tests.other.imports.nonEmpty import * | ||
from tests.other.imports.nonEmpty import C | ||
from tests.other.imports.nonEmpty import C as D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package tests.other.imports.nonEmpty | ||
|
||
class C |