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

eslint sort-import vs dprint sort imports #595

Closed
mohamedmansour opened this issue Jan 2, 2024 · 3 comments
Closed

eslint sort-import vs dprint sort imports #595

mohamedmansour opened this issue Jan 2, 2024 · 3 comments
Labels

Comments

@mohamedmansour
Copy link

mohamedmansour commented Jan 2, 2024

I am using version 0.44.0 and eslint sort-import config:

    "sort-imports": [
      "error",
      {
        "ignoreDeclarationSort": true,
        "allowSeparatedGroups": true
      }
    ],

Does this sort:

import { StubResizeObserver, fetchHTML, stubResizeObserver } from '../../test_utils/test-helper.js';

Meanwhile dprint does:

import { fetchHTML, StubResizeObserver, stubResizeObserver } from '../../test_utils/test-helper.js';

I tried using dprint config like:

  "typescript": {
    "lineWidth": 120,
    "quoteStyle": "preferSingle",
    "binaryExpression.operatorPosition": "sameLine",
    "typeLiteral.separatorKind": "comma",
    "module.sortImportDeclarations": "caseSensitive",
    "module.sortExportDeclarations": "caseSensitive"
  },
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.88.7.wasm"
  ]

But it always does a case insensitive sort. I am trying to match eslint and dprint together to make the DX nicer, any recommendations?

@dsherret
Copy link
Member

dsherret commented Jan 2, 2024

Use:

{
  "exportDeclaration.sortNamedExports": "caseSensitive",
  "importDeclaration.sortNamedImports": "caseSensitive"
}

Then you can remove the eslint rule as it's no longer necessary because the formatter handles it for you now.

Side note: module.sortImportDeclarations is for sorting individual import declarations in a module rather than the named imports within an import declaration.

https://dprint.dev/playground/#code/JYWwDg9gTgLgBAbzgZRgVwEYCUCmBnYALxwHkM8coA3SgGjgDMcYBjACwAkAVAWQBl6edNnxFS5SjShwAvoygQQcAOQA6VQHp1GmPhgB9NDGAAbPDr0BaNjhNhKqgFZ5lAbiA/config/N4WAUABBBECmAeAHA9gJwC4BFYGMA2AhqgegJbIB2AdAM5roByBAtrACYCiS9N0AXDBwEasAMqwKNUmQBusaABpwUaKWYoM2fERLlqdDE1ZsAkup79BwsRKmz54AL7ggA/plugin/typescript

@mohamedmansour
Copy link
Author

That worked, thank you! I didn't see this Config page at first! Thank you https://dprint.dev/plugins/typescript/config/

@adrian-gierakowski
Copy link

For what it’s worth, when I first discovered dprint, I struggled to find individual plugin config docs as well. So maybe something could be improved about the website

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants