Skip to content

Commit

Permalink
refactor: move const modifier info into style category (#621)
Browse files Browse the repository at this point in the history
### Summary of Changes

Move the info that the `const` modifier on annotation parameters can be
removed to the style checker.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot authored Oct 9, 2023
1 parent ed7953a commit a51a644
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 58 deletions.
17 changes: 0 additions & 17 deletions src/language/validation/other/declarations/annotations.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/language/validation/other/expressions/lambdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const lambdaParameterMustNotHaveConstModifier = (node: SdsLambda, accept:
if (parameter.isConstant) {
accept('error', 'The const modifier is not applicable to parameters of lambdas.', {
node: parameter,
property: 'name',
property: 'isConstant',
code: CODE_LAMBDA_CONST_MODIFIER,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/language/validation/other/types/callableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const callableTypeParameterMustNotHaveConstModifier = (
if (parameter.isConstant) {
accept('error', 'The const modifier is not applicable to parameters of callable types.', {
node: parameter,
property: 'name',
property: 'isConstant',
code: CODE_CALLABLE_TYPE_CONST_MODIFIER,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/language/validation/safe-ds-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
annotationCallArgumentListShouldBeNeeded,
annotationParameterListShouldNotBeEmpty,
annotationParameterShouldNotHaveConstModifier,
assignmentShouldHaveMoreThanWildcardsAsAssignees,
callArgumentListShouldBeNeeded,
classBodyShouldNotBeEmpty,
Expand Down Expand Up @@ -61,7 +62,6 @@ import {
} from './builtins/experimental.js';
import { placeholderShouldBeUsed } from './other/declarations/placeholders.js';
import { segmentParameterShouldBeUsed, segmentResultMustBeAssignedExactlyOnce } from './other/declarations/segments.js';
import { annotationParameterShouldNotHaveConstModifier } from './other/declarations/annotations.js';
import { lambdaParameterMustNotHaveConstModifier } from './other/expressions/lambdas.js';

/**
Expand Down
19 changes: 18 additions & 1 deletion src/language/validation/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { UnknownType } from '../typing/model.js';
export const CODE_STYLE_UNNECESSARY_ASSIGNMENT = 'style/unnecessary-assignment';
export const CODE_STYLE_UNNECESSARY_ARGUMENT_LIST = 'style/unnecessary-argument-list';
export const CODE_STYLE_UNNECESSARY_BODY = 'style/unnecessary-body';
export const CODE_STYLE_UNNECESSARY_CONST_MODIFIER = 'style/unnecessary-const-modifier';
export const CODE_STYLE_UNNECESSARY_CONSTRAINT_LIST = 'style/unnecessary-constraint-list';
export const CODE_STYLE_UNNECESSARY_ELVIS_OPERATOR = 'style/unnecessary-elvis-operator';
export const CODE_STYLE_UNNECESSARY_PARAMETER_LIST = 'style/unnecessary-parameter-list';
Expand Down Expand Up @@ -120,6 +121,22 @@ export const enumBodyShouldNotBeEmpty = (node: SdsEnumBody, accept: ValidationAc
}
};

// -----------------------------------------------------------------------------
// Unnecessary const modifier
// -----------------------------------------------------------------------------

export const annotationParameterShouldNotHaveConstModifier = (node: SdsAnnotation, accept: ValidationAcceptor) => {
for (const parameter of parametersOrEmpty(node)) {
if (parameter.isConstant) {
accept('info', 'Annotation parameters are always const, so this modifier can be removed.', {
node: parameter,
property: 'isConstant',
code: CODE_STYLE_UNNECESSARY_CONST_MODIFIER,
});
}
}
};

// -----------------------------------------------------------------------------
// Unnecessary constraint lists
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -224,7 +241,7 @@ export const namedTypeTypeArgumentListShouldBeNeeded = (node: SdsNamedType, acce
if (isEmpty(typeParametersOrEmpty(namedTypeDeclaration))) {
accept('info', 'This type argument list can be removed.', {
node: typeArgumentList,
code: CODE_STYLE_UNNECESSARY_ARGUMENT_LIST,
code: CODE_STYLE_UNNECESSARY_TYPE_ARGUMENT_LIST,
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tests.validation.other.declarations.parameters.illegalConstModifier

fun f(
g: (
// $TEST$ error "The const modifier is not applicable to parameters of callable types."
»const« p1: Int
) -> ()
)

pipeline myPipeline {
(
// $TEST$ error "The const modifier is not applicable to parameters of lambdas."
»const« p1: Int
) {};

(
// $TEST$ error "The const modifier is not applicable to parameters of lambdas."
»const« p1: Int
) -> 1;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tests.validation.other.declarations.parameters.illegalConstModifier

// $TEST$ no error "The const modifier is not applicable to parameters of callable types."

fun f(
g: (p2: Int) -> ()
)

pipeline myPipeline {
(p2: Int) {};

(p2: Int) -> 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tests.validation.style.unnecessaryConstModifierOnAnnotationParameters

annotation MyAnnotation(
// $TEST$ info "Annotation parameters are always const, so this modifier can be removed."
»const« p1: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tests.validation.style.unnecessaryConstModifierOnAnnotationParameters

annotation MyAnnotation(
// $TEST$ no info "Annotation parameters are always const, so this modifier can be removed."
p2: Int,
)

0 comments on commit a51a644

Please sign in to comment.