From 60ea085d7bbe3695ccc05deeedd13f07585f8537 Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Wed, 14 Sep 2022 12:05:19 +0000 Subject: [PATCH 1/2] fix: repair dead-code script finding comments (#1222, #1273) --- scripts/find-dead-code.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/find-dead-code.ts b/scripts/find-dead-code.ts index 82c02d7990..9c7a8dfb4e 100644 --- a/scripts/find-dead-code.ts +++ b/scripts/find-dead-code.ts @@ -3,8 +3,8 @@ import { ClassDeclaration, Node, Project, ReferenceFindableNode, SyntaxKind, ts /* eslint-disable no-console */ -// RegEx for file exceptions where the '// not-dead-code' exception does not work, e.g. for 'export const' -const fileExceptionsRegex = /\/src\/environments\/|.*.production.ts$|utils\/routing.ts$/; +// RegEx for file exceptions +const fileExceptionsRegex = /\/src\/environments\/|.*\.production\.ts|\/server\.ts$/; const classMethodCheckRegex = /.*(Mapper|Helper|Facade|Service|State)$/; @@ -137,8 +137,22 @@ function checkNode(node: Node) { return; } + if ( + node.getKind() === SyntaxKind.VariableDeclaration && + node.getParent().getParent().getKind() === SyntaxKind.VariableStatement && + node + .getParent() + .getParent() + .getLeadingCommentRanges() + .some(c => c.getText().includes('not-dead-code')) + ) { + if (process.env.DEBUG) console.warn('ignoring (1)', node.getText()); + return; + } + const ignoreComment = node.getPreviousSiblingIfKind(SyntaxKind.SingleLineCommentTrivia); if (ignoreComment?.getText().includes('not-dead-code')) { + if (process.env.DEBUG) console.warn('ignoring (2)', node.getText()); return; } From f92edac06f9b00f6d8c41df155ffce3f3904a8e0 Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Wed, 14 Sep 2022 12:15:36 +0000 Subject: [PATCH 2/2] chore: remove unused dead-code excludes --- .../store/__name@dasherize__-store.module.ts.template | 1 - server.ts | 1 - src/app/core/services/api/api.service.ts | 1 - src/app/core/store/store-devtools.module.production.ts | 1 - src/app/core/utils/routing.ts | 1 - src/app/extensions/compare/store/compare-store.module.ts | 2 -- src/app/extensions/contact-us/store/contact-us-store.module.ts | 1 - .../order-templates/store/order-templates-store.module.ts | 1 - src/app/extensions/punchout/store/punchout-store.module.ts | 1 - src/app/extensions/quoting/store/quoting-store.module.ts | 1 - src/app/extensions/rating/store/product-review-store.module.ts | 1 - src/app/extensions/recently/store/recently-store.module.ts | 2 -- src/app/extensions/sentry/store/sentry-store.module.ts | 1 - src/app/extensions/tacton/store/tacton-store.module.ts | 1 - src/app/extensions/tracking/store/tracking-store.module.ts | 1 - src/app/extensions/wishlists/store/wishlists-store.module.ts | 1 - 16 files changed, 18 deletions(-) diff --git a/schematics/src/extension/files/__name@dasherize__/store/__name@dasherize__-store.module.ts.template b/schematics/src/extension/files/__name@dasherize__/store/__name@dasherize__-store.module.ts.template index c8e113fae0..c46edcb896 100644 --- a/schematics/src/extension/files/__name@dasherize__/store/__name@dasherize__-store.module.ts.template +++ b/schematics/src/extension/files/__name@dasherize__/store/__name@dasherize__-store.module.ts.template @@ -9,7 +9,6 @@ const <%= camelize(name) %>Reducers: ActionReducerMap<<%= classify(name) %>State const <%= camelize(name) %>Effects = []; -// not-dead-code @NgModule({ imports: [EffectsModule.forFeature(<%= camelize(name) %>Effects), StoreModule.forFeature('<%= camelize(name) %>', <%= camelize(name) %>Reducers)], }) diff --git a/server.ts b/server.ts index 984da60688..8ff45ac2cd 100644 --- a/server.ts +++ b/server.ts @@ -59,7 +59,6 @@ global['navigator'] = win.navigator; */ // The Express app is exported so that it can be used by serverless Functions. -// not-dead-code export function app() { const logging = /on|1|true|yes/.test(process.env.LOGGING?.toLowerCase()); diff --git a/src/app/core/services/api/api.service.ts b/src/app/core/services/api/api.service.ts index 16096f18ff..3501500937 100644 --- a/src/app/core/services/api/api.service.ts +++ b/src/app/core/services/api/api.service.ts @@ -295,7 +295,6 @@ export class ApiService { ); } - // not-dead-code b2bUserEndpoint() { const ids$ = combineLatest([ this.store.pipe(select(getLoggedInUser)), diff --git a/src/app/core/store/store-devtools.module.production.ts b/src/app/core/store/store-devtools.module.production.ts index b9a721b9a7..7d3122d4ed 100644 --- a/src/app/core/store/store-devtools.module.production.ts +++ b/src/app/core/store/store-devtools.module.production.ts @@ -1,2 +1 @@ -// not-dead-code export const storeDevtoolsModule: unknown[] = []; diff --git a/src/app/core/utils/routing.ts b/src/app/core/utils/routing.ts index c4dd1cdf69..e82ed0a059 100644 --- a/src/app/core/utils/routing.ts +++ b/src/app/core/utils/routing.ts @@ -27,7 +27,6 @@ export function addGlobalGuard( /** * RegEx that finds reserved characters that should not be contained in non functional parts of routes/URLs (e.g product slugs for SEO) */ - // not-dead-code export const reservedCharactersRegEx = /[ &\(\)=]/g; diff --git a/src/app/extensions/compare/store/compare-store.module.ts b/src/app/extensions/compare/store/compare-store.module.ts index b4065151e1..f9a5e08d0f 100644 --- a/src/app/extensions/compare/store/compare-store.module.ts +++ b/src/app/extensions/compare/store/compare-store.module.ts @@ -17,7 +17,6 @@ const compareReducers: ActionReducerMap = { const compareEffects = [CompareEffects]; -// not-dead-code @Injectable() export class DefaultCompareStoreConfig implements StoreConfig { metaReducers = [dataRetentionMeta(this.dataRetention.compare, this.appBaseHref, 'compare', '_compare')]; @@ -30,7 +29,6 @@ export class DefaultCompareStoreConfig implements StoreConfig { export const COMPARE_STORE_CONFIG = new InjectionToken>('compareStoreConfig'); -// not-dead-code @NgModule({ imports: [ EffectsModule.forFeature(compareEffects), diff --git a/src/app/extensions/contact-us/store/contact-us-store.module.ts b/src/app/extensions/contact-us/store/contact-us-store.module.ts index 583f005301..f9617702fc 100644 --- a/src/app/extensions/contact-us/store/contact-us-store.module.ts +++ b/src/app/extensions/contact-us/store/contact-us-store.module.ts @@ -13,7 +13,6 @@ const contactUsReducers: ActionReducerMap = { const contactUsEffects = [ContactEffects]; -// not-dead-code @NgModule({ imports: [EffectsModule.forFeature(contactUsEffects), StoreModule.forFeature('contactUs', contactUsReducers)], }) diff --git a/src/app/extensions/order-templates/store/order-templates-store.module.ts b/src/app/extensions/order-templates/store/order-templates-store.module.ts index dba8e9ed14..83bec926a7 100644 --- a/src/app/extensions/order-templates/store/order-templates-store.module.ts +++ b/src/app/extensions/order-templates/store/order-templates-store.module.ts @@ -24,7 +24,6 @@ export const ORDER_TEMPLATES_STORE_CONFIG = new InjectionToken { export const PUNCHOUT_STORE_CONFIG = new InjectionToken>('punchoutStoreConfig'); -// not-dead-code @NgModule({ imports: [ EffectsModule.forFeature(punchoutEffects), diff --git a/src/app/extensions/quoting/store/quoting-store.module.ts b/src/app/extensions/quoting/store/quoting-store.module.ts index 570c8f1e09..02cea02535 100644 --- a/src/app/extensions/quoting/store/quoting-store.module.ts +++ b/src/app/extensions/quoting/store/quoting-store.module.ts @@ -20,7 +20,6 @@ export class QuotingStoreConfig implements StoreConfig { export const QUOTING_STORE_CONFIG = new InjectionToken>('quotingStoreConfig'); -// not-dead-code @NgModule({ imports: [ EffectsModule.forFeature(quotingEffects), diff --git a/src/app/extensions/rating/store/product-review-store.module.ts b/src/app/extensions/rating/store/product-review-store.module.ts index 2637cc2eac..f4db825423 100644 --- a/src/app/extensions/rating/store/product-review-store.module.ts +++ b/src/app/extensions/rating/store/product-review-store.module.ts @@ -25,7 +25,6 @@ export const PRODUCT_REVIEW_STORE_CONFIG = new InjectionToken = { const recentlyEffects = [RecentlyEffects]; -// not-dead-code @Injectable() export class DefaultRecentlyStoreConfig implements StoreConfig { metaReducers = [ @@ -32,7 +31,6 @@ export class DefaultRecentlyStoreConfig implements StoreConfig { export const RECENTLY_STORE_CONFIG = new InjectionToken>('recentlyStoreConfig'); -// not-dead-code @NgModule({ imports: [ EffectsModule.forFeature(recentlyEffects), diff --git a/src/app/extensions/sentry/store/sentry-store.module.ts b/src/app/extensions/sentry/store/sentry-store.module.ts index c9fb8232a9..1aa8f42033 100644 --- a/src/app/extensions/sentry/store/sentry-store.module.ts +++ b/src/app/extensions/sentry/store/sentry-store.module.ts @@ -12,7 +12,6 @@ const sentryReducers: ActionReducerMap = { const sentryEffects = [SentryConfigEffects]; -// not-dead-code @NgModule({ imports: [EffectsModule.forFeature(sentryEffects), StoreModule.forFeature('sentry', sentryReducers)], }) diff --git a/src/app/extensions/tacton/store/tacton-store.module.ts b/src/app/extensions/tacton/store/tacton-store.module.ts index d93f1331c6..f4e2d9d42a 100644 --- a/src/app/extensions/tacton/store/tacton-store.module.ts +++ b/src/app/extensions/tacton/store/tacton-store.module.ts @@ -37,7 +37,6 @@ export class DefaultTactonStoreConfig implements StoreConfig { export const TACTON_STORE_CONFIG = new InjectionToken>('tactonStoreConfig'); -// not-dead-code @NgModule({ imports: [ EffectsModule.forFeature(tactonEffects), diff --git a/src/app/extensions/tracking/store/tracking-store.module.ts b/src/app/extensions/tracking/store/tracking-store.module.ts index fa55331fb4..fefa744c0d 100644 --- a/src/app/extensions/tracking/store/tracking-store.module.ts +++ b/src/app/extensions/tracking/store/tracking-store.module.ts @@ -12,7 +12,6 @@ const trackingReducers: ActionReducerMap = { const trackingEffects = [TrackingConfigEffects]; -// not-dead-code @NgModule({ imports: [EffectsModule.forFeature(trackingEffects), StoreModule.forFeature('tracking', trackingReducers)], }) diff --git a/src/app/extensions/wishlists/store/wishlists-store.module.ts b/src/app/extensions/wishlists/store/wishlists-store.module.ts index cf3bf70a5c..e9da9d9072 100644 --- a/src/app/extensions/wishlists/store/wishlists-store.module.ts +++ b/src/app/extensions/wishlists/store/wishlists-store.module.ts @@ -22,7 +22,6 @@ export class WishlistStoreConfig implements StoreConfig { export const WISHLIST_STORE_CONFIG = new InjectionToken>('wishlistStoreConfig'); -// not-dead-code @NgModule({ imports: [ EffectsModule.forFeature(wishlistsEffects),