-
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.
Closes partially #543 ### Summary of Changes Port additional checks from old Xtext version: * Template string without expression between string parts * Yield in pipeline * Missing type hints * Missing package in module with declarations * Declarations in module that are not allowed by the file type --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
c26d33a
commit 2803305
Showing
36 changed files
with
386 additions
and
17 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
21 changes: 21 additions & 0 deletions
21
src/language/validation/other/expressions/templateStrings.ts
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,21 @@ | ||
import { isSdsTemplateStringPart, SdsTemplateString } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
|
||
export const CODE_TEMPLATE_STRING_MISSING_TEMPLATE_EXPRESSION = 'template-string/missing-template-expression'; | ||
|
||
export const templateStringMustHaveExpressionBetweenTwoStringParts = ( | ||
node: SdsTemplateString, | ||
accept: ValidationAcceptor, | ||
): void => { | ||
for (let i = 0; i < node.expressions.length - 1; i++) { | ||
const first = node.expressions[i]; | ||
const second = node.expressions[i + 1]; | ||
|
||
if (isSdsTemplateStringPart(first) && isSdsTemplateStringPart(second)) { | ||
accept('error', 'There must be an expression between two string parts.', { | ||
node: second, | ||
code: CODE_TEMPLATE_STRING_MISSING_TEMPLATE_EXPRESSION, | ||
}); | ||
} | ||
} | ||
}; |
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,48 @@ | ||
import { ValidationAcceptor } from 'langium'; | ||
import { isSdsDeclaration, isSdsPipeline, isSdsSegment, SdsModule } from '../../generated/ast.js'; | ||
import { isInPipelineFile, isInStubFile } from '../../constants/fileExtensions.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 moduleDeclarationsMustMatchFileKind = (node: SdsModule, accept: ValidationAcceptor): void => { | ||
const declarations = node.members.filter(isSdsDeclaration); | ||
|
||
if (isInPipelineFile(node)) { | ||
for (const declaration of declarations) { | ||
if (!isSdsPipeline(declaration) && !isSdsSegment(declaration)) { | ||
accept('error', 'A pipeline file must only declare pipelines and segments.', { | ||
node: declaration, | ||
property: 'name', | ||
code: CODE_MODULE_FORBIDDEN_IN_PIPELINE_FILE, | ||
}); | ||
} | ||
} | ||
} else if (isInStubFile(node)) { | ||
for (const declaration of declarations) { | ||
if (isSdsPipeline(declaration) || isSdsSegment(declaration)) { | ||
accept('error', 'A stub file must not declare pipelines or segments.', { | ||
node: declaration, | ||
property: 'name', | ||
code: CODE_MODULE_FORBIDDEN_IN_STUB_FILE, | ||
}); | ||
} | ||
} | ||
} | ||
}; |
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 @@ | ||
import { isSdsPipeline, SdsYield } from '../../../generated/ast.js'; | ||
import { getContainerOfType, ValidationAcceptor } from 'langium'; | ||
|
||
export const CODE_ASSIGMENT_YIELD_FORBIDDEN_IN_PIPELINE = 'assignment/yield-forbidden-in-pipeline'; | ||
|
||
export const yieldMustNotBeUsedInPipeline = (node: SdsYield, accept: ValidationAcceptor): void => { | ||
const containingPipeline = getContainerOfType(node, isSdsPipeline); | ||
|
||
if (containingPipeline) { | ||
accept('error', 'Yield must not be used in a pipeline.', { | ||
node, | ||
code: CODE_ASSIGMENT_YIELD_FORBIDDEN_IN_PIPELINE, | ||
}); | ||
} | ||
}; |
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
File renamed without changes.
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,42 @@ | ||
import { getContainerOfType, ValidationAcceptor } from 'langium'; | ||
import { isSdsCallable, isSdsLambda, SdsAttribute, SdsParameter, SdsResult } from '../generated/ast.js'; | ||
|
||
export const CODE_TYPE_MISSING_TYPE_HINT = 'type/missing-type-hint'; | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Missing type hints | ||
// ----------------------------------------------------------------------------- | ||
|
||
export const attributeMustHaveTypeHint = (node: SdsAttribute, accept: ValidationAcceptor): void => { | ||
if (!node.type) { | ||
accept('error', 'An attribute must have a type hint.', { | ||
node, | ||
property: 'name', | ||
code: CODE_TYPE_MISSING_TYPE_HINT, | ||
}); | ||
} | ||
}; | ||
|
||
export const parameterMustHaveTypeHint = (node: SdsParameter, accept: ValidationAcceptor): void => { | ||
if (!node.type) { | ||
const containingCallable = getContainerOfType(node, isSdsCallable); | ||
|
||
if (!isSdsLambda(containingCallable)) { | ||
accept('error', 'A parameter must have a type hint.', { | ||
node, | ||
property: 'name', | ||
code: CODE_TYPE_MISSING_TYPE_HINT, | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
export const resultMustHaveTypeHint = (node: SdsResult, accept: ValidationAcceptor): void => { | ||
if (!node.type) { | ||
accept('error', 'A result must have a type hint.', { | ||
node, | ||
property: 'name', | ||
code: CODE_TYPE_MISSING_TYPE_HINT, | ||
}); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
...es/validation/other/expressions/template strings/missing template expression/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,11 @@ | ||
package tests.validation.other.expressions.templateStrings.missingTemplateExpression | ||
|
||
pipeline test { | ||
// $TEST$ error "There must be an expression between two string parts." | ||
// $TEST$ error "There must be an expression between two string parts." | ||
"start {{ »}} inner {{« »}} end"«; | ||
|
||
// $TEST$ no error "There must be an expression between two string parts." | ||
// $TEST$ no error "There must be an expression between two string parts." | ||
"start {{ 1 »}} inner {{« 1 »}} end"«; | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/resources/validation/other/modules/declarations in pipeline files/main.sdspipe
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,33 @@ | ||
package tests.validation.other.modules.declarationsInPipelineFiles | ||
|
||
// $TEST$ error "A pipeline file must only declare pipelines and segments." | ||
annotation »MyAnnotation« | ||
// $TEST$ error "A pipeline file must only declare pipelines and segments." | ||
class »MyClass« { | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
attr »a«: Int | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
class »MyNestedClass« | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
enum »MyEnum« | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
fun »myFunction«() | ||
} | ||
// $TEST$ error "A pipeline file must only declare pipelines and segments." | ||
enum »MyEnum« { | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
»MyEnumInstance« | ||
} | ||
// $TEST$ error "A pipeline file must only declare pipelines and segments." | ||
fun »myFunction«() | ||
// $TEST$ error "A pipeline file must only declare pipelines and segments." | ||
schema »MySchema« {} | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
pipeline »myPipeline« {} | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
segment »mySegment«() {} |
33 changes: 33 additions & 0 deletions
33
tests/resources/validation/other/modules/declarations in stub files/main.sdsstub
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,33 @@ | ||
package tests.validation.other.modules.declarationsInStubFiles | ||
|
||
// $TEST$ error "A stub file must not declare pipelines or segments." | ||
pipeline »myPipeline« {} | ||
// $TEST$ error "A stub file must not declare pipelines or segments." | ||
segment »mySegment«() {} | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
annotation »MyAnnotation« | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
class »MyClass« { | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
attr »a«: Int | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
class »MyNestedClass« | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
enum »MyEnum« | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
fun »myFunction«() | ||
} | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
enum »MyEnum« { | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
»MyEnumInstance« | ||
} | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
fun »myFunction«() | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
schema »MySchema« {} |
33 changes: 33 additions & 0 deletions
33
tests/resources/validation/other/modules/declarations in test files/main.sdsstub
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,33 @@ | ||
package tests.validation.other.modules.declarationsInTestFiles | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
annotation »MyAnnotation« | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
class »MyClass« { | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
attr »a«: Int | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
class »MyNestedClass« | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
enum »MyEnum« | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
fun »myFunction«() | ||
} | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
enum »MyEnum« { | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
»MyEnumInstance« | ||
} | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
fun »myFunction«() | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
schema »MySchema« {} | ||
|
||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
pipeline »myPipeline« {} | ||
// $TEST$ no error "A pipeline file must only declare pipelines and segments." | ||
segment »mySegment«() {} |
1 change: 1 addition & 0 deletions
1
tests/resources/validation/other/modules/must state package/pipeline file (empty).sdspipe
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 @@ | ||
// $TEST$ no error "A module with declarations must state its package." |
3 changes: 3 additions & 0 deletions
3
...rces/validation/other/modules/must state package/pipeline file (only annotations).sdspipe
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 @@ | ||
// $TEST$ no error "A module with declarations must state its package." | ||
|
||
@AnnotationCall |
3 changes: 3 additions & 0 deletions
3
...esources/validation/other/modules/must state package/pipeline file (only imports).sdspipe
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 @@ | ||
// $TEST$ no error "A module with declarations must state its package." | ||
|
||
import myPackage |
7 changes: 7 additions & 0 deletions
7
...on/other/modules/must state package/pipeline file (with declarations and package).sdspipe
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,7 @@ | ||
package tests.validation.other.modules.mustStatePackage | ||
|
||
// $TEST$ no error "A module with declarations must state its package." | ||
segment »s«() {} | ||
|
||
// $TEST$ no error "A module with declarations must state its package." | ||
segment »t«() {} |
5 changes: 5 additions & 0 deletions
5
...other/modules/must state package/pipeline file (with declarations but no package).sdspipe
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,5 @@ | ||
// $TEST$ error "A module with declarations must state its package." | ||
segment »s«() {} | ||
|
||
// $TEST$ no error "A module with declarations must state its package." | ||
segment »t«() {} |
1 change: 1 addition & 0 deletions
1
tests/resources/validation/other/modules/must state package/stub file (empty).sdsstub
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 @@ | ||
// $TEST$ no error "A module with declarations must state its package." |
3 changes: 3 additions & 0 deletions
3
...esources/validation/other/modules/must state package/stub file (only annotations).sdsstub
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 @@ | ||
// $TEST$ no error "A module with declarations must state its package." | ||
|
||
@AnnotationCall |
3 changes: 3 additions & 0 deletions
3
tests/resources/validation/other/modules/must state package/stub file (only imports).sdsstub
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 @@ | ||
// $TEST$ no error "A module with declarations must state its package." | ||
|
||
import myPackage |
7 changes: 7 additions & 0 deletions
7
...dation/other/modules/must state package/stub file (with declarations and package).sdsstub
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,7 @@ | ||
package tests.validation.other.modules.mustStatePackage | ||
|
||
// $TEST$ no error "A module with declarations must state its package." | ||
class »C« | ||
|
||
// $TEST$ no error "A module with declarations must state its package." | ||
class »D« |
5 changes: 5 additions & 0 deletions
5
...ion/other/modules/must state package/stub file (with declarations but no package).sdsstub
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,5 @@ | ||
// $TEST$ error "A module with declarations must state its package." | ||
class »C« | ||
|
||
// $TEST$ no error "A module with declarations must state its package." | ||
class »D« |
16 changes: 16 additions & 0 deletions
16
...esources/validation/other/statements/assignments/yield forbidden in pipeline/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,16 @@ | ||
package tests.validation.other.statements.assignments.yieldForbiddenInPipeline | ||
|
||
segment s() { | ||
// $TEST$ no error "Yield must not be used in a pipeline." | ||
»yield a« = 1; | ||
} | ||
|
||
pipeline p { | ||
// $TEST$ error "Yield must not be used in a pipeline." | ||
»yield a« = 1; | ||
|
||
() { | ||
// $TEST$ no error "Yield must not be used in a pipeline." | ||
»yield a« = 1; | ||
}; | ||
} |
2 changes: 1 addition & 1 deletion
2
...yntax/unnecessary assignment/main.sdstest → ...style/unnecessary assignment/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
2 changes: 1 addition & 1 deletion
2
...ax/unnecessary body in class/main.sdstest → ...le/unnecessary body in class/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
2 changes: 1 addition & 1 deletion
2
...tax/unnecessary body in enum/main.sdstest → ...yle/unnecessary body in enum/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
Oops, something went wrong.