Skip to content

Commit

Permalink
class-declaration-abstractness-changed with adding rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamatha1718 committed Dec 22, 2024
1 parent eb1fde0 commit b358dd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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
16 changes: 12 additions & 4 deletions packages/concerto-analysis/src/comparers/class-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ const classDeclarationTypeChanged: ComparerFactory = (context) => ({
if (aType === bType) {
return;
}

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 changeSeverity = isAbstract(a) ? 'minor' : 'major';
const changeKey =isAbstract(a) ? `class-declaration-abstract-to-concrete` : `class-declaration-concrete-to-abstract`;
context.report({
key: 'class-declaration-abstractness-changed',
message: `The class "${a.getName()}" changed from ${changeType} (${changeSeverity} change).`,
key: changeKey,
message: `The class "${a.getName()}" changed from ${changeType}.`,
element: a
});
}
Expand Down

0 comments on commit b358dd9

Please sign in to comment.