Skip to content

Commit

Permalink
fix: repair dead-code script finding comments (#1222, #1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored and shauke committed Sep 21, 2022
1 parent e0cbc91 commit 0a550ea
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit 0a550ea

Please sign in to comment.