Skip to content

Commit

Permalink
Fix SonarCloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Jul 11, 2024
1 parent 34c5f77 commit 4a01c17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
14 changes: 5 additions & 9 deletions eslint-plugin/lib/rules/no-import-all-from-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@ module.exports = {
ImportDeclaration(node) {
const currentLibrary = node.source.value;

if (notAllowedLibraries.includes(currentLibrary)) {
context.report({
node,
messageId: "ShouldNotImportAllFromLibrary",
data: { library: currentLibrary },
});
} else if (
const forbiddenByName = notAllowedLibraries.includes(currentLibrary);
const forbiddenByNamespace =
importByNamespaceNotAllowedLibraries.includes(currentLibrary) &&
node.specifiers.some(
(specifier) => specifier.type === "ImportNamespaceSpecifier",
)
) {
);

if (forbiddenByName || forbiddenByNamespace) {
context.report({
node,
messageId: "ShouldNotImportAllFromLibrary",
Expand Down
37 changes: 15 additions & 22 deletions eslint-plugin/lib/rules/prefer-collections-with-pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const isPaginated = (objectType) => {
}
} else if (objectType.type === "TSTypeLiteral") {
if (
objectType.members != null &&
objectType.members.some(
objectType.members?.some(
(member) => member.key != null && isPaginationName(member.key.name),
)
) {
Expand All @@ -47,6 +46,18 @@ const isPaginated = (objectType) => {
return false;
};

const isNestGetDecorator = (decorator) =>
decorator.expression.callee.name.toLowerCase() === "get" &&
(decorator.expression.arguments.length === 0 ||
!decorator.expression.arguments[0].value.includes(":"));

const isInNestControllerClass = (decorator) =>
decorator.parent.parent.parent.type === "ClassDeclaration" &&
decorator.parent.parent.parent.decorators.find(
(decorator) =>
decorator.expression.callee.name.toLowerCase() === "controller",
);

const report = (context, node) =>
context.report({ node, messageId: "PreferReturnCollectionsWithPagination" });

Expand All @@ -68,29 +79,11 @@ module.exports = {
},
defaultOptions: [],
create(context) {
const isValidDecorator = (decorator) => {
return (
decorator.expression.callee.name.toLowerCase() === "get" &&
(decorator.expression.arguments.length === 0 ||
!decorator.expression.arguments[0].value.includes(":"))
);
};

return {
Decorator(node) {
if (
isValidDecorator(node) &&
node.parent.parent.parent.type === "ClassDeclaration" &&
node.parent.parent.parent.decorators.find(
(decorator) =>
decorator.expression.callee.name.toLowerCase() === "controller",
)
) {
if (isNestGetDecorator(node) && isInNestControllerClass(node)) {
const getMethod = node.parent;
const returnType =
getMethod.value.returnType != null
? getMethod.value.returnType.typeAnnotation
: null;
const returnType = getMethod.value.returnType?.typeAnnotation;

if (returnType != null) {
if (
Expand Down
12 changes: 3 additions & 9 deletions eslint-plugin/lib/rules/provide-print-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ module.exports = {
} else if (child.expression != null) {
if (child.expression.value != null) {
element = child.expression.value;
} else if (
child.expression.quasis != null &&
child.expression.quasis.length > 0
) {
} else if (child.expression.quasis?.length > 0) {
element = child.expression.quasis[0].value.cooked;
}
}
return element != null && element.includes("@media print");
return element?.includes("@media print");
})
);
};
Expand All @@ -71,10 +68,7 @@ module.exports = {
);

if (!hasValidElement) {
context.report({
node: node,
messageId: "noPrintCSSProvided",
});
context.report({ node, messageId: "noPrintCSSProvided" });
}
}
},
Expand Down

0 comments on commit 4a01c17

Please sign in to comment.