Skip to content

Commit

Permalink
feat(eslint): improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerhahnekamp committed Oct 19, 2024
1 parent 0afa2d9 commit 6b35249
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ describe('encapsulation and excludeRoot config property', () => {
},
});

assertViolation(
'/project/src/router.ts',
'./shared/dialog',
false,
true,
);
assertViolation('/project/src/router.ts', './shared/dialog', false, true);

assertViolation(
'/project/src/holidays/holidays-component.ts',
Expand Down Expand Up @@ -85,11 +80,18 @@ function assertViolation(
false,
),
`import in ${filename} to ${importCommand} should violate encapsulation: ${hasViolation}`,
).toBe(
hasViolation
? (isImportToBarrelLess
? `'${importCommand}' cannot be imported. It is encapsulated.`
: `'${importCommand}' is a deep import from a barrel module. Use the module's barrel file (index.ts) instead.`)
: '',
);
).toBe(getMessage(hasViolation, isImportToBarrelLess, importCommand));
}

function getMessage(
hasViolation: boolean,
isImportToBarrelLess: boolean,
importCommand: string,
) {
if (!hasViolation) {
return '';
}
return isImportToBarrelLess
? `'${importCommand}' cannot be imported. It is encapsulated.`
: `'${importCommand}' is a deep import from a barrel module. Use the module's barrel file (index.ts) instead.`;
}

0 comments on commit 6b35249

Please sign in to comment.