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

Fail on declaration files which have no declare keyword #196

Open
1 task
zanminkian opened this issue Dec 6, 2024 · 5 comments
Open
1 task

Fail on declaration files which have no declare keyword #196

zanminkian opened this issue Dec 6, 2024 · 5 comments
Assignees

Comments

@zanminkian
Copy link

Your Environment

  • Prettier version: 3.4.2
  • node version: 22.11.0
  • package manager: pnpm@9
  • IDE: VScode

Describe the bug

This plugin will throw errors when the source code base contains a file below.

// foo1.d.ts
module "foo1" {
  const name: string;
  export default name;
}

To Reproduce

  1. git clone [email protected]:zanminkian/bug-report.git and then checkout to branch prettier-plugin-sort-imports-bug
  2. Read the README.md
  3. pnpm i
  4. ./node_modules/.bin/prettier ./src/foo1.d.ts -w: Failed!

Expected behavior

No errors

Screenshots, code sample, etc

See the repo.

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

See the repo.

Error log

See the repo.

Contribute to @ianvs/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇
@zanminkian
Copy link
Author

@fbartho
Copy link
Collaborator

fbartho commented Dec 6, 2024

I'm unfamiliar with a prettier.config that looks like this!

https://github.com/zanminkian/bug-report/blob/prettier-plugin-sort-imports-bug/prettier.config.js

What's going on here? At the minimum, I believe you want to specify our typescript version flag?

@fbartho
Copy link
Collaborator

fbartho commented Dec 6, 2024

(I'm mostly surprised by createRequire, I haven't used or tested that!)

@zanminkian
Copy link
Author

I copied the config from my private project. I have updated the prettier.config.js:

export default {
  plugins: ["@ianvs/prettier-plugin-sort-imports"],
  // importOrderParserPlugins: ["typescript", "jsx", "decorators-legacy"],
};

It still fail. If I remove the plugins, all the things work well without errors. So I believe this is a bug belong to @ianvs/prettier-plugin-sort-imports.

@zanminkian
Copy link
Author

BTW: running npx tsc in the reproduced repo works well. So a declaration file (*.d.ts) without declare keyword in it is valid for typescript.

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

No branches or pull requests

3 participants