Skip to content

Commit

Permalink
inlineTypeImport to preferInline
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Nov 6, 2022
1 parent 5d26984 commit 5d5a2d8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/rules/no-duplicates.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ import * from './mod.js?minify'

### Inline Type imports

TypeScript 4.5 introduced a new [feature](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#type-on-import-names) that allows mixing of named value and type imports. In order to support fixing to an inline type import when duplicate imports are detected, `inlineTypeImport` can be set to true.
TypeScript 4.5 introduced a new [feature](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#type-on-import-names) that allows mixing of named value and type imports. In order to support fixing to an inline type import when duplicate imports are detected, `preferInline` can be set to true.

Config:

```json
"import/no-duplicates": ["error", {"inlineTypeImport": true}]
"import/no-duplicates": ["error", {"preferInline": true}]
```

```js
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ function getFix(first, rest, sourceCode, context) {
const [specifiersText] = specifiers.reduce(
([result, needsComma], specifier) => {
const isTypeSpecifier = specifier.importNode.importKind === 'type';
const inlineTypeImport = context.options[0] && context.options[0].inlineTypeImport;
const insertText = `${inlineTypeImport && isTypeSpecifier ? 'type ' : ''}${specifier.text}`;
const preferInline = context.options[0] && context.options[0].preferInline;
const insertText = `${preferInline && isTypeSpecifier ? 'type ' : ''}${specifier.text}`;
return [
needsComma && !specifier.isEmpty
? `${result},${insertText}`
Expand Down Expand Up @@ -260,7 +260,7 @@ module.exports = {
considerQueryString: {
type: 'boolean',
},
inlineTypeImport: {
preferInline: {
type: 'boolean',
},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/src/rules/no-duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ context('TypeScript', function () {
test({
code: "import {type x} from './foo'; import type {y} from './foo'",
...parserConfig,
options: [{ 'inlineTypeImport': false }],
options: [{ 'preferInline': false }],
output: `import {type x,y} from './foo'; `,
errors: [
{
Expand All @@ -556,7 +556,7 @@ context('TypeScript', function () {
test({
code: "import {type x} from 'foo'; import type {y} from 'foo'",
...parserConfig,
options: [{ 'inlineTypeImport': true }],
options: [{ 'preferInline': true }],
output: `import {type x,type y} from 'foo'; `,
errors: [
{
Expand Down

0 comments on commit 5d5a2d8

Please sign in to comment.