Skip to content

Commit

Permalink
Add mixed mode for consistent-type-imports rule
Browse files Browse the repository at this point in the history
This ads a new mode called "" for consistent-type-imports rule which will only trigger, if all imports of an import declaration are type only imports.

References typescript-eslint#2769
  • Loading branch information
olee committed Dec 5, 2020
1 parent ccb6b94 commit a491fd7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/consistent-type-imports.ts
Expand Up @@ -6,7 +6,7 @@ import {
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type Prefer = 'type-imports' | 'no-type-imports';
type Prefer = 'type-imports' | 'no-type-imports' | 'type-imports-mixed';

type Options = [
{
Expand Down Expand Up @@ -94,7 +94,7 @@ export default util.createRule<Options, MessageIds>({
const sourceImportsMap: { [key: string]: SourceImports } = {};

return {
...(prefer === 'type-imports'
...(prefer !== 'no-type-imports'
? {
// prefer type imports
ImportDeclaration(node: TSESTree.ImportDeclaration): void {
Expand Down Expand Up @@ -157,7 +157,7 @@ export default util.createRule<Options, MessageIds>({
}
}

if (typeSpecifiers.length) {
if (typeSpecifiers.length && (prefer === 'type-imports' || valueSpecifiers.length === 0)) {
sourceImports.reportValueImports.push({
node,
typeSpecifiers,
Expand Down

0 comments on commit a491fd7

Please sign in to comment.