-
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.
feat: error if wildcard import has alias (#574)
Closes partially #543 ### Summary of Changes Show an error if a wildcard import has an alias. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
- Loading branch information
1 parent
bd73bc5
commit 4ba7873
Showing
4 changed files
with
34 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
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,16 @@ | ||
import { ValidationAcceptor } from 'langium'; | ||
import { SdsImportAlias } from '../generated/ast.js'; | ||
import { isWildcardImport } from '../helpers/astShortcuts.js'; | ||
|
||
export const CODE_IMPORT_WILDCARD_IMPORT_WITH_ALIAS = 'import/wildcard-import-with-alias'; | ||
|
||
export const importAliasMustNotBeUsedForWildcardImports = (node: SdsImportAlias, accept: ValidationAcceptor): void => { | ||
const importNode = node.$container; | ||
|
||
if (importNode && isWildcardImport(importNode)) { | ||
accept('error', 'A wildcard import must not have an alias.', { | ||
node, | ||
code: CODE_IMPORT_WILDCARD_IMPORT_WITH_ALIAS, | ||
}); | ||
} | ||
}; |
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
6 changes: 6 additions & 0 deletions
6
tests/resources/validation/other/imports/wildcard import must not have alias/main.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,6 @@ | ||
package tests.validation.other.modules.wildcardImportMustNotHaveAlias | ||
|
||
// $TEST$ error "A wildcard import must not have an alias." | ||
import stuff.* »as S« | ||
// $TEST$ no error "A wildcard import must not have an alias." | ||
import stuff.Stuff »as S« |