Skip to content

Commit b805083

Browse files
authored
Change rules to prefer top-level type markers (#9)
To be able to leverage `verbatimModuleSyntax` without errors or workarounds, we need to switch to top-level `type` markers instead of inline markers. See examples [here](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/consistent-type-specifier-style.md#examples). This will ensure that TypeScript does not try to load modules from which only types are imported, which will make it faster during build-time. It's also a prerequisite to running TypeScript with Node directly, which we may or may not do but would like the option to try. Notes: - It sounds like we should eventually remove the `@typescript-eslint/consistent-type-imports` rule entirely based on [this recommendation](https://typescript-eslint.io/rules/consistent-type-imports/#comparison-with-importsnotusedasvalues--verbatimmodulesyntax). But I thought it best to leave it there until we complete the transition in the `platform` repo, or until we notice it causing conflicts. - My preferred rule would be "top-level if only type imports, otherwise inline" but I did not find any such rule. If others care deeply about this, we could attempt to create it. This would be released as a major/breaking change.
1 parent 97dcf61 commit b805083

File tree

3 files changed

+69
-37
lines changed

3 files changed

+69
-37
lines changed

package-lock.json

Lines changed: 63 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@typescript-eslint/utils": "^8.29.1",
88
"eslint-plugin-eslint-comments": "^3.2.0",
99
"eslint-plugin-github": "^5.1.8",
10-
"eslint-plugin-import": "^2.31.0",
10+
"eslint-plugin-import": "github:qawolf/eslint-plugin-import#prefer-top-level-if-only-type-imports",
1111
"eslint-plugin-jest": "^28.11.0",
1212
"eslint-plugin-n": "^17.18.0",
1313
"eslint-plugin-perfectionist": "^4.11.0",

src/config/formatting.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ export const formattingRules = {
99
// Also see import/consistent-type-specifier-style: they do similar, but slightly different things
1010
"@typescript-eslint/consistent-type-imports": [
1111
"error",
12-
{ fixStyle: "inline-type-imports" },
12+
{ fixStyle: "separate-type-imports" },
1313
],
1414

1515
curly: ["error", "multi-or-nest"],
1616

1717
// Also see @typescript-eslint/consistent-type-imports: they do similar, but slightly different things
18-
"import/consistent-type-specifier-style": ["error", "prefer-inline"],
18+
"import/consistent-type-specifier-style": [
19+
"error",
20+
"prefer-top-level-if-only-type-imports",
21+
],
1922

2023
"object-shorthand": ["error", "always", { avoidExplicitReturnArrows: true }],
2124

0 commit comments

Comments
 (0)