Skip to content

js: a file skipped for a parse error makes everything it imports or re-exports look unused #219

Open

Description

@DaisukeYoda

Bug

When the parser rejects a file, the file is dropped from the run and the summary says so. Its import and export ... from statements are dropped with it, so the import graph in unused_code.go no longer knows that the file used anything. Every export the skipped file imported or re-exported is then reported as unused_export / unused_exported_function, and files it alone imported become orphan_file.

A barrel is the worst case. got's source/index.ts re-exports most of the public API with export *, and line 27 is export type * from './as-promise/types.js', which the parser rejects (#97). The whole barrel is skipped, and applyUrlOverride in source/core/options.ts is reported as an unused exported function although index.ts re-exports it. The other value exports of options.ts escape only because another file imports them by name.

Repro

source/index.ts          export * from './core/options.js';
                         export type * from './types.js';
source/types.ts          export type Foo = string;
source/core/options.ts   export function applyUrlOverride(url: string) { ... }
                         export class Options { url(u) { return applyUrlOverride(u); } }
polyscan analyze --select deadcode --format json .

Actual

⚠️  1 of 3 files skipped (parse errors)
    [source/index.ts] parse_error: syntax error at line 2
source/core/options.ts:1  unused_exported_function  applyUrlOverride
source/core/options.ts:4  unused_exported_function  Options

Expected

No unused-export findings on options.ts. Either the import graph still collects the import and re-export statements of a file whose body fails to parse, or the run suppresses unused_export, unused_exported_function and orphan_file findings while any file is skipped, and says so in the summary.

Impact

The findings carry warning severity and lower the dead code score, and nothing in the finding links it to the skipped file. #97 widens the parser; this is about degrading gracefully whenever a file is skipped, for whatever reason. Observed on got at 6b5aafc with polyscan 0.6.1 (1 of 97 files skipped).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions