Skip to content

Commit 6f12316

Browse files
bradzacherljharb
authored andcommitted
[Fix] consistent-type-specifier-style: fix accidental removal of comma in certain cases
1 parent 5680a1f commit 6f12316

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
99
### Fixed
1010
- [`no-duplicates`]: remove duplicate identifiers in duplicate imports ([#2577], thanks [@joe-matsec])
1111
- TypeScript config: fix resolver extension settings (thanks [@gajus])
12+
- [`consistent-type-specifier-style`]: fix accidental removal of comma in certain cases ([#2754], thanks [@bradzacher])
1213

1314
### Changed
1415
- [Docs] [`no-duplicates`]: fix example schema ([#2684], thanks [@simmo])
@@ -1065,6 +1066,7 @@ for info on changes for earlier releases.
10651066

10661067
[`memo-parser`]: ./memo-parser/README.md
10671068

1069+
[#2754]: https://github.com/import-js/eslint-plugin-import/pull/2754
10681070
[#2699]: https://github.com/import-js/eslint-plugin-import/pull/2699
10691071
[#2664]: https://github.com/import-js/eslint-plugin-import/pull/2664
10701072
[#2613]: https://github.com/import-js/eslint-plugin-import/pull/2613

src/rules/consistent-type-specifier-style.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ function isComma(token) {
77
function removeSpecifiers(fixes, fixer, sourceCode, specifiers) {
88
for (const specifier of specifiers) {
99
// remove the trailing comma
10-
const comma = sourceCode.getTokenAfter(specifier, isComma);
11-
if (comma) {
12-
fixes.push(fixer.remove(comma));
10+
const token = sourceCode.getTokenAfter(specifier);
11+
if (token && isComma(token)) {
12+
fixes.push(fixer.remove(token));
1313
}
1414
fixes.push(fixer.remove(specifier));
1515
}

tests/src/rules/consistent-type-specifier-style.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,33 @@ const COMMON_TESTS = {
168168
type: 'ImportSpecifier',
169169
}],
170170
},
171+
// https://github.com/import-js/eslint-plugin-import/issues/2753
172+
{
173+
code: `\
174+
import { Component, type ComponentProps } from "package-1";
175+
import {
176+
Component1,
177+
Component2,
178+
Component3,
179+
Component4,
180+
Component5,
181+
} from "package-2";`,
182+
output: `\
183+
import { Component } from "package-1";
184+
import type {ComponentProps} from "package-1";
185+
import {
186+
Component1,
187+
Component2,
188+
Component3,
189+
Component4,
190+
Component5,
191+
} from "package-2";`,
192+
options: ['prefer-top-level'],
193+
errors: [{
194+
message: 'Prefer using a top-level type-only import instead of inline type specifiers.',
195+
type: 'ImportSpecifier',
196+
}],
197+
},
171198

172199
//
173200
// prefer-inline

0 commit comments

Comments
 (0)