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

Change Knip ignoreExportsUsedInFile to false and fix #6721

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

andrewHEguardian
Copy link
Contributor

What are you doing in this PR?

Changing the Knip config to not ignore unused exports if they're used within the same file. The main motivation for doing this is that there is a Knip issue where combining ignoreExportsUsedInFile: true and export { foo } notation doesn't detect unused exports. This PR fixes the unnecessary export statements and removes the completely unused exports (and subsequent unused code)

Copy link
Contributor

Size Change: -15.6 kB (-0.66%)

Total Size: 2.35 MB

Filename Size Change
./public/compiled-assets/javascripts/paperSubscriptionCheckoutPage.js 163 kB -754 B (-0.46%)
./public/compiled-assets/javascripts/weeklySubscriptionCheckoutPage.js 160 kB -956 B (-0.6%)
./public/compiled-assets/webpack/187.js 20.1 kB -1.62 kB (-7.48%)
./public/compiled-assets/webpack/643.js 0 B -22.4 kB (removed) 🏆
./public/compiled-assets/webpack/719.js 13.5 kB +13.5 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./public/compiled-assets/javascripts/[countryGroupId]/events/router.js 90.3 kB -161 B (-0.18%)
./public/compiled-assets/javascripts/[countryGroupId]/lazyRouter.js 93.2 kB -33 B (-0.04%)
./public/compiled-assets/javascripts/[countryGroupId]/router.js 254 kB -119 B (-0.05%)
./public/compiled-assets/javascripts/ausMomentMap.js 108 kB +1 B (0%)
./public/compiled-assets/javascripts/contributionsRedirectStyles.js 20 B 0 B
./public/compiled-assets/javascripts/digitalSubscriptionLandingPage.js 223 kB -396 B (-0.18%)
./public/compiled-assets/javascripts/downForMaintenancePage.js 67.3 kB -321 B (-0.47%)
./public/compiled-assets/javascripts/error404Page.js 67.3 kB -320 B (-0.47%)
./public/compiled-assets/javascripts/error500Page.js 67.2 kB -320 B (-0.47%)
./public/compiled-assets/javascripts/favicons.js 617 B 0 B
./public/compiled-assets/javascripts/paperSubscriptionLandingPage.js 87.6 kB -329 B (-0.37%)
./public/compiled-assets/javascripts/payPalErrorPage.js 65.9 kB -173 B (-0.26%)
./public/compiled-assets/javascripts/payPalErrorPageStyles.js 20 B 0 B
./public/compiled-assets/javascripts/promotionTerms.js 73.5 kB -318 B (-0.43%)
./public/compiled-assets/javascripts/subscriptionsLandingPage.js 72.9 kB -257 B (-0.35%)
./public/compiled-assets/javascripts/subscriptionsRedemptionPage.js 118 kB -330 B (-0.28%)
./public/compiled-assets/javascripts/supporterPlusLandingPage.js 226 kB -371 B (-0.16%)
./public/compiled-assets/javascripts/unsupportedBrowserStyles.js 20 B 0 B
./public/compiled-assets/javascripts/weeklySubscriptionLandingPage.js 88.2 kB +117 B (+0.13%)
./public/compiled-assets/webpack/136.js 2.17 kB -1 B (-0.05%)
./public/compiled-assets/webpack/186.js 3.35 kB 0 B
./public/compiled-assets/webpack/3.js 19.2 kB 0 B
./public/compiled-assets/webpack/311.js 40.1 kB 0 B
./public/compiled-assets/webpack/344.js 2.01 kB 0 B
./public/compiled-assets/webpack/397.js 10.2 kB 0 B
./public/compiled-assets/webpack/426.js 36.6 kB -3 B (-0.01%)
./public/compiled-assets/webpack/706.js 107 kB 0 B
./public/compiled-assets/webpack/754.js 9.92 kB -3 B (-0.03%)
./public/compiled-assets/webpack/847.js 26 kB 0 B
./public/compiled-assets/webpack/checkout.js 14.3 kB -7 B (-0.05%)
./public/compiled-assets/webpack/GuardianAdLiteLanding.js 9.05 kB 0 B
./public/compiled-assets/webpack/oneTimeCheckout.js 10 kB 0 B
./public/compiled-assets/webpack/ThankYou.js 1.08 kB 0 B

compressed-size-action

return 'per year';
}

function getCustomAmountA11yHint(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if this would be a useful thing to dig into where it was used and potentially add to our checkout again?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah perhaps worth adding a card for (to investigate and fix if needed)?

Copy link
Member

@tjmw tjmw left a comment

Choose a reason for hiding this comment

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

Great work 👏

There's a lot of unused code removed in here! It's kind of hard to be sure reviewing it but if TS is happy then I think we can be confident 👍

@@ -132,5 +132,3 @@ export function PersonalDetails({
</div>
);
}

export default PersonalDetails;
Copy link
Member

Choose a reason for hiding this comment

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

Weird that this was available as both a default and a named export!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah an odd one

@andrewHEguardian andrewHEguardian merged commit d4fdabb into main Jan 23, 2025
19 checks passed
@andrewHEguardian andrewHEguardian deleted the ahe/knip-ignoreExportsUsedInFile branch January 23, 2025 14:00
@prout-bot
Copy link

Seen on PROD (merged by @andrewHEguardian 9 minutes and 39 seconds ago)

Sentry Release: support-client-side, support

}

export { PersonalDetailsGift, PersonalDetailsDigitalGift };
export { PersonalDetailsGift };
Copy link
Contributor

Choose a reason for hiding this comment

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

inline export perhaps here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally yes but there are a lot of those! And I used knip --fix so I didn't go back and fix

@@ -12,8 +12,8 @@ export type { ActiveProductKey };

export const productCatalog = window.guardian.productCatalog;

export type SupporterPlusVariants = 'control' | 'v1' | 'v2';
export type ContributionVariants = 'control' | 'v1' | 'v2Annual' | 'v2Monthly';
type SupporterPlusVariants = 'control' | 'v1' | 'v2';
Copy link
Contributor

Choose a reason for hiding this comment

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

My mistake in yesterday's PR, its working :)

@@ -8,7 +8,7 @@ module.exports = {
// ! signals that this is production code https://knip.dev/features/production-mode
entry: [...flattenedEntryPoints, 'scripts/build-ssr-content.tsx!'],
project: ['**/*.{js,jsx,ts,tsx,scss}!'],
ignoreExportsUsedInFile: true,
ignoreExportsUsedInFile: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah the reason all these exports are removed and this will pick it up going forwards?

Copy link
Contributor

@paul-daniel-dempsey paul-daniel-dempsey left a comment

Choose a reason for hiding this comment

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

A LOT in there. Might be worth splitting the simple export removals first in a standalone PR and then remainder after (or as batches). The Smoke and Cron tests pass, abtests also so would presume its ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants