Skip to content

Commit

Permalink
check ts version if prefer inline set
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Dec 8, 2022
1 parent 4e79fc7 commit 0576641
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/rules/no-duplicates.js
@@ -1,5 +1,7 @@
import resolve from 'eslint-module-utils/resolve';
import docsUrl from '../docsUrl';
import semver from 'semver';
import typescriptPkg from 'typescript/package.json';

function checkImports(imported, context) {
for (const [module, nodes] of imported.entries()) {
Expand Down Expand Up @@ -109,7 +111,12 @@ function getFix(first, rest, sourceCode, context) {
const [specifiersText] = specifiers.reduce(
([result, needsComma], specifier) => {
const isTypeSpecifier = specifier.importNode.importKind === 'type';

const preferInline = context.options[0] && context.options[0]['prefer-inline'];
if (preferInline && !semver.satisfies(typescriptPkg.version, '>= 4.5')) {
throw new Error('Your version of TypeScript does not support inline type imports.');
}

const insertText = `${preferInline && isTypeSpecifier ? 'type ' : ''}${specifier.text}`;
return [
needsComma && !specifier.isEmpty
Expand Down

0 comments on commit 0576641

Please sign in to comment.