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

fix: repair dead-code script exclude comments search #1273

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
})
Expand Down
18 changes: 16 additions & 2 deletions scripts/find-dead-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)$/;

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
1 change: 0 additions & 1 deletion src/app/core/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ export class ApiService {
);
}

// not-dead-code
b2bUserEndpoint() {
const ids$ = combineLatest([
this.store.pipe(select(getLoggedInUser)),
Expand Down
1 change: 0 additions & 1 deletion src/app/core/store/store-devtools.module.production.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// not-dead-code
export const storeDevtoolsModule: unknown[] = [];
1 change: 0 additions & 1 deletion src/app/core/utils/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/app/extensions/compare/store/compare-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const compareReducers: ActionReducerMap<CompareState> = {

const compareEffects = [CompareEffects];

// not-dead-code
@Injectable()
export class DefaultCompareStoreConfig implements StoreConfig<CompareState> {
metaReducers = [dataRetentionMeta<CompareState>(this.dataRetention.compare, this.appBaseHref, 'compare', '_compare')];
Expand All @@ -30,7 +29,6 @@ export class DefaultCompareStoreConfig implements StoreConfig<CompareState> {

export const COMPARE_STORE_CONFIG = new InjectionToken<StoreConfig<CompareState>>('compareStoreConfig');

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(compareEffects),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const contactUsReducers: ActionReducerMap<ContactUsState> = {

const contactUsEffects = [ContactEffects];

// not-dead-code
@NgModule({
imports: [EffectsModule.forFeature(contactUsEffects), StoreModule.forFeature('contactUs', contactUsReducers)],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const ORDER_TEMPLATES_STORE_CONFIG = new InjectionToken<StoreConfig<Order
'orderTemplatesStoreConfig'
);

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(orderTemplatesEffects),
Expand Down
1 change: 0 additions & 1 deletion src/app/extensions/punchout/store/punchout-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class PunchoutStoreConfig implements StoreConfig<PunchoutState> {

export const PUNCHOUT_STORE_CONFIG = new InjectionToken<StoreConfig<PunchoutState>>('punchoutStoreConfig');

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(punchoutEffects),
Expand Down
1 change: 0 additions & 1 deletion src/app/extensions/quoting/store/quoting-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class QuotingStoreConfig implements StoreConfig<QuotingState> {

export const QUOTING_STORE_CONFIG = new InjectionToken<StoreConfig<QuotingState>>('quotingStoreConfig');

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(quotingEffects),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const PRODUCT_REVIEW_STORE_CONFIG = new InjectionToken<StoreConfig<Produc
'productReviewStoreConfig'
);

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(productReviewsEffects),
Expand Down
2 changes: 0 additions & 2 deletions src/app/extensions/recently/store/recently-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const recentlyReducers: ActionReducerMap<RecentlyState> = {

const recentlyEffects = [RecentlyEffects];

// not-dead-code
@Injectable()
export class DefaultRecentlyStoreConfig implements StoreConfig<RecentlyState> {
metaReducers = [
Expand All @@ -32,7 +31,6 @@ export class DefaultRecentlyStoreConfig implements StoreConfig<RecentlyState> {

export const RECENTLY_STORE_CONFIG = new InjectionToken<StoreConfig<RecentlyState>>('recentlyStoreConfig');

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(recentlyEffects),
Expand Down
1 change: 0 additions & 1 deletion src/app/extensions/sentry/store/sentry-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const sentryReducers: ActionReducerMap<SentryState> = {

const sentryEffects = [SentryConfigEffects];

// not-dead-code
@NgModule({
imports: [EffectsModule.forFeature(sentryEffects), StoreModule.forFeature('sentry', sentryReducers)],
})
Expand Down
1 change: 0 additions & 1 deletion src/app/extensions/tacton/store/tacton-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class DefaultTactonStoreConfig implements StoreConfig<TactonState> {

export const TACTON_STORE_CONFIG = new InjectionToken<StoreConfig<TactonState>>('tactonStoreConfig');

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(tactonEffects),
Expand Down
1 change: 0 additions & 1 deletion src/app/extensions/tracking/store/tracking-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const trackingReducers: ActionReducerMap<TrackingState> = {

const trackingEffects = [TrackingConfigEffects];

// not-dead-code
@NgModule({
imports: [EffectsModule.forFeature(trackingEffects), StoreModule.forFeature('tracking', trackingReducers)],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class WishlistStoreConfig implements StoreConfig<WishlistsState> {

export const WISHLIST_STORE_CONFIG = new InjectionToken<StoreConfig<WishlistsState>>('wishlistStoreConfig');

// not-dead-code
@NgModule({
imports: [
EffectsModule.forFeature(wishlistsEffects),
Expand Down