Skip to content

Enable import autofix? #31

@MichaelMitchell-at

Description

@MichaelMitchell-at

I noticed that the import autofix is disabled here

ts-fix/src/index.ts

Lines 260 to 262 in 2898fac

function isNotAppliedFix(fixAndDiagnostic: FixAndDiagnostic): boolean {
return !fixAndDiagnostic.fix.changes.length
|| fixAndDiagnostic.fix.fixName === 'import'

I can maybe see why it's disabled by default, but it would be nice to at least be able to use it if -f import is explicitly provided on the CLI. One use case is that the autofixer for isolatedDeclarations sometimes adds type annotations using inline imports, e.g.

const foo: import('some/module').Foo = ...;

which is not our, and probably not many others', preferred style.

So what I'll do is use a regular expression to just remove all the import('...'). parts, but then now I need to add top-level imports for a bunch of types. This is where the import autofix comes in clutch. I commented out that line above in ts-fix and ran the autofixer and it pretty much worked flawlessly.

Just wanted to provide a data point, but feel free to close if not likely to be implemented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions