format-imports-vscode
format-imports-vscode copied to clipboard
"formatExports": true doesn't sort exports!!
Describe the bug
When I run the extension in any file of my project, the extension does not sort the export
statements! I have enabled the "configuration.formatExports": true
, but still nothing changes.
However, it sorts the import
statements very well!
To Reproduce
- Go to
settings.json
- Add the following line:
"tsImportSorter.configuration.formatExports": true
- Go to an
index.ts
file of yours that exports lots of components or variables, and through theCommand Palette
runSort Imports/Exports
- See that the
export
statements remain in the same order, and don't change alphabetically
Expected behavior
I would expect that the export
statements are sorted too, by their paths
names.
Screenshots
Actual behavior
Expected behavior
OS (please complete the following information):
- OS: Windows 11
- Version: 22H2
VS Code (please complete the following information):
- Version: 1.70.2
package.json
{
"name": "next-commerce",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"analyze": "BUNDLE_ANALYZE=both next build",
"lint": "next lint",
"prettier-fix": "prettier --write .",
"find:unused": "npx next-unused"
},
"sideEffects": false,
"dependencies": {
"@chakra-ui/react": "1.8.8",
"@emotion/react": "11",
"@emotion/styled": "11",
"@radix-ui/react-dropdown-menu": "^0.1.6",
"@react-spring/web": "^9.4.1",
"@vercel/commerce": "^0.0.1",
"@vercel/commerce-bigcommerce": "^0.0.1",
"@vercel/commerce-local": "^0.0.1",
"autoprefixer": "^10.4.2",
"body-scroll-lock": "^4.0.0-beta.0",
"clsx": "^1.1.1",
"email-validator": "^2.0.4",
"framer-motion": "6",
"js-cookie": "^3.0.1",
"keen-slider": "^6.6.3",
"lodash.random": "^3.2.0",
"lodash.throttle": "^4.1.1",
"next": "^12.0.8",
"next-themes": "^0.0.15",
"postcss": "^8.3.5",
"postcss-nesting": "^8.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-fast-marquee": "^1.3.1",
"react-merge-refs": "^1.1.0",
"react-use-measure": "^2.1.1",
"sass": "^1.54.5",
"tabbable": "^5.2.1",
"tailwindcss": "^3.0.13"
},
"devDependencies": {
"@next/bundle-analyzer": "^12.0.8",
"@types/body-scroll-lock": "^3.1.0",
"@types/js-cookie": "^3.0.1",
"@types/lodash.random": "^3.2.6",
"@types/lodash.throttle": "^4.1.6",
"@types/node": "^18.7.13",
"@types/react": "^18.0.17",
"eslint": "^8.6.0",
"eslint-config-next": "^12.0.8",
"eslint-config-prettier": "^8.3.0",
"lint-staged": "^12.1.7",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-preset-env": "^7.2.3",
"prettier": "^2.7.1",
"typescript": "4.8.2"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": [
"eslint",
"prettier --write",
"git add"
],
"**/*.{md,mdx,json}": [
"prettier --write",
"git add"
]
},
"next-unused": {
"alias": {
"@lib/*": [
"lib/*"
],
"@styles/*": [
"styles/*"
],
"@modules/*": [
"modules/*"
],
"@config/*": [
"config/*"
],
"@components/*": [
"components/*"
],
"@utils/*": [
"utils/*"
]
},
"debug": true,
"include": [
"components",
"lib",
"pages"
],
"exclude": [],
"entrypoints": [
"pages"
]
}
}
tsconfig.json (if any)
{
"compilerOptions": {
"baseUrl": ".",
"target": "esnext",
"module": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"paths": {
"@lib/*": ["lib/*"],
"@utils/*": ["utils/*"],
"@config/*": ["config/*"],
"@styles/*": ["styles/*"],
"@modules/*": ["modules/*"],
"@components/*": ["components/*"],
"@commerce": ["../packages/commerce/src"],
"@commerce/*": ["../packages/commerce/src/*"],
"@framework": ["..\\packages\\local\\src"],
"@framework/*": ["..\\packages\\local\\src/*"]
}
},
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
"exclude": ["node_modules"]
}
.prettierrc/.prettierrc.js/prettier.config.js/.prettierrc.toml (if any) filename: .prettierrc
{
"semi": true,
"trailingComma": "es5",
"singleQuote": false,
"printWidth": 100,
"tabWidth": 2,
"arrowParens": "avoid",
"bracketSpacing": true
}
@georgekrax Thanks for your feedback!
There was a similar issue before (https://github.com/daidodo/format-imports-vscode/issues/43):
Details about how exports are formatted can be found https://github.com/daidodo/format-imports-vscode/issues/6#issuecomment-619386911. And sorting exports by paths is not supported yet because the requirement isn't clear.
But still, I'm open to suggestions and ideas.
@daidodo Oh okay, thanks for the update!
Do you plan to support a "sorting exports" feature?
Depends on how clear the requirements are.
Exports can be at the front, middle or end of the file. There is no standard about how they should be organised, AFAIK.
Well, that is a reasonable question from your side.
I would use this feature (sorting exports) only on index.ts
files, where I export only a chunk of various components/variables/types. Only in that case I would find it useful, as in the pictures above that I have attached. Otherwise, I believe it wouldn't matter to sort them.
settings.json
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
If I enable the default/automatic sorting imports functionality of VS Code, then it also sorts the exports!