Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class-declaration-abstractness-changed #974

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/concerto-analysis/src/compare-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const defaultCompareConfig: CompareConfig = {
'optional-property-added': CompareResult.PATCH,
'required-property-removed': CompareResult.MAJOR,
'optional-property-removed': CompareResult.MAJOR,
'class-declaration-abstract-to-concrete': CompareResult.MINOR,
'class-declaration-concrete-to-abstract': CompareResult.MAJOR,
'namespace-changed': CompareResult.ERROR,
'enum-value-added': CompareResult.PATCH,
'enum-value-removed': CompareResult.MAJOR,
Expand Down
24 changes: 19 additions & 5 deletions packages/concerto-analysis/src/comparers/class-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,25 @@ const classDeclarationTypeChanged: ComparerFactory = (context) => ({
if (aType === bType) {
return;
}
context.report({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing type-change report shouldn't be removed. Instead, the if statement above should be inverted (aType !== bType or whatever) and the report should be put in there.

key: 'class-declaration-type-changed',
message: `The ${aType} "${a.getName()}" changed type from ${aType} to ${bType}`,
element: a
});
if(aType !== bType){
context.report({
key: `class-declaration-type-changed`,
message: `The ${aType} "${a.getName()}" changed from ${aType} to ${bType}`,
element: a
});
}

//add Logic for abstractness changes
const isAbstract = (declaration) => declaration.isAbstract();
if (isAbstract(a) !== isAbstract(b)) {
const changeType = isAbstract(a) ? 'abstract to concrete' : 'concrete to abstract';
const changeKey =isAbstract(a) ? `class-declaration-abstract-to-concrete` : `class-declaration-concrete-to-abstract`;
context.report({
key: changeKey,
message: `The class "${a.getName()}" changed from ${changeType}.`,
element: a
});
}
}
});

Expand Down