Skip to content

fix(scripts): remove unreachable branch in validate-modules.js#406

Closed
shaun0927 wants to merge 1 commit intoEvoMap:mainfrom
shaun0927:fix/validate-modules-unreachable-branch
Closed

fix(scripts): remove unreachable branch in validate-modules.js#406
shaun0927 wants to merge 1 commit intoEvoMap:mainfrom
shaun0927:fix/validate-modules-unreachable-branch

Conversation

@shaun0927
Copy link
Copy Markdown

Problem

scripts/validate-modules.js:27-28:

for (const k of keys) {
  if (typeof exported[k] === 'function') {
    if (typeof exported[k] !== 'function') {
      console.error('FAIL: ' + m + '.' + k + ' is declared but not a callable function');
      process.exit(1);
    }
  }
}

The inner typeof !== 'function' can never be true under the outer
typeof === 'function', so the "declared but not callable" error is
unreachable and the validator silently accepts everything it claims to
check. The script is in the package because of a comment on line 3
("exported functions are callable (typeof check)") that the code does
not actually enforce.

Fix

Without a manifest of expected function keys the script cannot decide
which exported members ought to be functions, so the nested block is
removed rather than given a fake fix. Behaviour is unchanged — in
practice the original block never produced any output — but the code
now matches that behaviour honestly and stops giving false assurance
to readers.

Testing

$ node scripts/validate-modules.js ./src/gep/issueReporter
ok: 1 module(s) validated

Output is identical before and after this change for every module the
script is invoked with.

Scope

One file, -11/+6.

The inner 'typeof exported[k] !== function' check sits inside
'typeof exported[k] === function', so it can never be true. The
intended 'declared but not callable' error is unreachable, and the
validator silently accepts everything it claims to check.

Without a manifest of expected function keys the script cannot
decide which members should be functions, so the nested block is
removed rather than given a fake fix. The outer typeof check was
already a no-op in every call site the script is invoked with, so
behaviour is unchanged; the code now matches that behaviour honestly.
@autogame-17
Copy link
Copy Markdown
Collaborator

Thank you, @shaun0927. We looked at this one closely and decided not to port it: the removed block is a no-op after the inner predicate normalization, so deleting it would not change behavior, and we prefer keeping the defensive shape in case we later thread a declaration manifest through validate-modules.js. Closing the PR and the related issue as wont-fix with full credit noted. No action needed from you.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants