-
Notifications
You must be signed in to change notification settings - Fork 49
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
Fix/linting in ci #534
Fix/linting in ci #534
Conversation
WalkthroughThe changes in this pull request involve modifications to several files, primarily focusing on enhancing error handling and logging practices, refining test coverage for specific functions, and simplifying code structures. Notable adjustments include updates to ESLint configuration to ignore certain files, the addition of unit tests for the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (4)
.github/workflows/test.yaml
is excluded by!**/*.yaml
packages/test/package.json
is excluded by!**/*.json
packages/util/package.json
is excluded by!**/*.json
packages/vendure-scripts/package.json
is excluded by!**/*.json
📒 Files selected for processing (5)
eslint-base.config.js
(1 hunks)packages/vendure-plugin-campaign-tracker/src/services/campaign-util.spec.ts
(0 hunks)packages/vendure-plugin-invoices/src/services/invoice.service.ts
(1 hunks)packages/vendure-plugin-primary-collection/src/util/export-primary-collections.ts
(1 hunks)packages/vendure-plugin-shipping-extensions/src/config/distance-based-shipping-calculator.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- packages/vendure-plugin-campaign-tracker/src/services/campaign-util.spec.ts
🔇 Additional comments (1)
eslint-base.config.js (1)
18-18
: Verify if excluding all UI code from linting is intentional
Adding **/src/ui/**
excludes all UI-related code from linting, which seems to conflict with the PR objective of implementing linting for all packages. Consider:
- Using a more specific pattern if only certain UI files need exclusion
- Adding a comment explaining why UI code is excluded
Let's check what UI files would be excluded:
const allProducts = await productRepo | ||
.createQueryBuilder('product') | ||
.innerJoin( | ||
Collection, | ||
'primaryCollection', | ||
'primaryCollection.id = product.customFieldsPrimarycollectionId' | ||
) | ||
.select(['product.id', 'primaryCollection.id']) | ||
.getRawMany()) as ProductPrimaryCollectionPartial[]; | ||
.getRawMany(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type safety to raw query results
The raw query results lack type information, which necessitates unsafe type assertions later in the code.
Consider adding a type for the raw query result:
type RawProductCollection = {
product_id: string;
primaryCollection_id: string;
}
And then use it in the query:
.getRawMany() as RawProductCollection[];
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
productId: product.product_id, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
primaryCollectionId: product.primaryCollection_id, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation for raw query results
The code assumes the raw query always returns valid data, which could lead to runtime errors.
Add property checks before assignment:
data.push({
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
- productId: product.product_id,
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
- primaryCollectionId: product.primaryCollection_id,
+ productId: product.product_id ?? null,
+ primaryCollectionId: product.primaryCollection_id ?? null,
});
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | |
productId: product.product_id, | |
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | |
primaryCollectionId: product.primaryCollection_id, | |
}); | |
data.push({ | |
productId: product.product_id ?? null, | |
primaryCollectionId: product.primaryCollection_id ?? null, | |
}); |
} catch (e) { | ||
//eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any | ||
Logger.error( | ||
//eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
`Failed to calculate shipping for ${method.name}: ${e.message}`, | ||
`Failed to calculate shipping for ${method.name}: ${ | ||
(e as Error)?.message | ||
}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Simplify error handling and remove eslint bypasses
The error handling can be simplified while maintaining type safety.
- } catch (e) {
- //eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
- Logger.error(
- //eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- `Failed to calculate shipping for ${method.name}: ${
- (e as Error)?.message
- }`,
- loggerCtx
- );
+ } catch (error: unknown) {
+ Logger.error(
+ `Failed to calculate shipping for ${method.name}: ${error instanceof Error ? error.message : 'Unknown error'}`,
+ loggerCtx
+ );
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
} catch (e) { | |
//eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any | |
Logger.error( | |
//eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | |
`Failed to calculate shipping for ${method.name}: ${e.message}`, | |
`Failed to calculate shipping for ${method.name}: ${ | |
(e as Error)?.message | |
}`, | |
} catch (error: unknown) { | |
Logger.error( | |
`Failed to calculate shipping for ${method.name}: ${error instanceof Error ? error.message : 'Unknown error'}`, | |
loggerCtx | |
); |
browser.close().catch((e: Error) => { | ||
Logger.error( | ||
`Failed to close puppeteer browser: ${e?.message}`, | ||
loggerCtx | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Prevent potential memory leak in browser cleanup.
The browser cleanup could fail silently and leak memory if an error occurs during closure. Consider using finally
block for cleanup.
-browser.close().catch((e: Error) => {
- Logger.error(
- `Failed to close puppeteer browser: ${e?.message}`,
- loggerCtx
- );
-});
+try {
+ await browser.close();
+} catch (e) {
+ Logger.error(
+ `Failed to close puppeteer browser: ${e?.message}`,
+ loggerCtx
+ );
+}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
browser.close().catch((e: Error) => { | |
Logger.error( | |
`Failed to close puppeteer browser: ${e?.message}`, | |
loggerCtx | |
); | |
}); | |
try { | |
await browser.close(); | |
} catch (e) { | |
Logger.error( | |
`Failed to close puppeteer browser: ${e?.message}`, | |
loggerCtx | |
); | |
} |
path: tmpFilePath, | ||
format: 'A4', | ||
margin: { bottom: 100, top: 100, left: 50, right: 50 }, | ||
}); | ||
} catch (e) { | ||
// Warning, because this will be retried, or is returned to the user | ||
Logger.warn( | ||
`Failed to generate invoice: ${JSON.stringify((e as any)?.message)}`, | ||
`Failed to generate invoice: ${JSON.stringify((e as Error)?.message)}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix error serialization to handle circular references.
The JSON.stringify
on the error object could fail if the error contains circular references. Use util.inspect
instead for safer error serialization.
-`Failed to generate invoice: ${JSON.stringify((e as Error)?.message)}`,
+`Failed to generate invoice: ${util.inspect((e as Error)?.message, false, 2)}`,
Committable suggestion skipped: line range outside the PR's diff.
Description
Checklist
📌 Always:
👍 Most of the time:
📦 For publishable packages:
package.json
CHANGELOG.md
See this example