Skip to content

chore: enable unicorn/prefer-export-from and @typescript-eslint/consistent-type-exports #9833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export default tseslint.config(
minimumDescriptionLength: 5,
},
],
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: true },
],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', disallowTypeAnnotations: true },
Expand Down Expand Up @@ -323,6 +327,7 @@ export default tseslint.config(
'unicorn/no-lonely-if': 'error',
'unicorn/no-typeof-undefined': 'error',
'unicorn/no-useless-spread': 'error',
'unicorn/prefer-export-from': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-string-replace-all': 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ enum TypeModifiers {
type TypeModifiersString = keyof typeof TypeModifiers;

export {
IndividualAndMetaSelectorsString,
type IndividualAndMetaSelectorsString,
MetaSelectors,
MetaSelectorsString,
type MetaSelectorsString,
Modifiers,
ModifiersString,
type ModifiersString,
PredefinedFormats,
PredefinedFormatsString,
type PredefinedFormatsString,
Selectors,
SelectorsString,
type SelectorsString,
TypeModifiers,
TypeModifiersString,
type TypeModifiersString,
UnderscoreOptions,
UnderscoreOptionsString,
type UnderscoreOptionsString,
};
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/naming-convention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,4 @@ function requiresQuoting(
return _requiresQuoting(name, target);
}

export { MessageIds, Options };
export type { MessageIds, Options };
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ export {
checkFunctionExpressionReturnType,
checkFunctionReturnType,
doesImmediatelyReturnFunctionExpression,
FunctionExpression,
FunctionNode,
type FunctionExpression,
type FunctionNode,
isTypedFunctionExpression,
isValidFunctionExpressionReturnType,
ancestorHasReturnType,
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export {
isObjectNotArray,
getParserServices,
nullThrows,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
type InferMessageIdsTypeFromRule,
type InferOptionsTypeFromRule,
NullThrowsReasons,
};
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ function isParenlessArrowFunction(
export {
arrayGroupByToMap,
arraysAreEqual,
Equal,
ExcludeKeys,
type Equal,
type ExcludeKeys,
findFirstResult,
formatWordList,
getEnumNames,
Expand All @@ -246,7 +246,7 @@ export {
isRestParameterDeclaration,
isParenlessArrowFunction,
MemberNameType,
RequireKeys,
type RequireKeys,
typeNodeRequiresParentheses,
upperCaseFirst,
findLastIndex,
Expand Down
8 changes: 4 additions & 4 deletions packages/parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { parse, parseForESLint, ParserOptions } from './parser';
export { parse, parseForESLint, type ParserOptions } from './parser';
export {
clearCaches,
createProgram,
ParserServices,
ParserServicesWithoutTypeInformation,
ParserServicesWithTypeInformation,
type ParserServices,
type ParserServicesWithoutTypeInformation,
type ParserServicesWithTypeInformation,
withoutProjectParserOptions,
} from '@typescript-eslint/typescript-estree';

Expand Down
7 changes: 4 additions & 3 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
AnalyzeOptions,
ScopeManager,
} from '@typescript-eslint/scope-manager';
import type { Lib, TSESTree } from '@typescript-eslint/types';
import type { Lib, ParserOptions, TSESTree } from '@typescript-eslint/types';
import type {
AST,
ParserServices,
Expand All @@ -12,7 +12,6 @@ import type { VisitorKeys } from '@typescript-eslint/visitor-keys';
import type * as ts from 'typescript';

import { analyze } from '@typescript-eslint/scope-manager';
import { ParserOptions } from '@typescript-eslint/types';
import { parseAndGenerateServices } from '@typescript-eslint/typescript-estree';
import { visitorKeys } from '@typescript-eslint/visitor-keys';
import debug from 'debug';
Expand Down Expand Up @@ -188,4 +187,6 @@ function parseForESLint(
return { ast, scopeManager, services, visitorKeys };
}

export { parse, parseForESLint, ParserOptions };
export { parse, parseForESLint };

export type { ParserOptions } from '@typescript-eslint/types';
2 changes: 1 addition & 1 deletion packages/scope-manager/src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ function analyze(
return scopeManager;
}

export { analyze, AnalyzeOptions };
export { analyze, type AnalyzeOptions };
2 changes: 1 addition & 1 deletion packages/scope-manager/src/definition/Definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ type Definition =
| TypeDefinition
| VariableDefinition;

export { Definition };
export type { Definition };
6 changes: 3 additions & 3 deletions packages/scope-manager/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { analyze, AnalyzeOptions } from './analyze';
export { analyze, type AnalyzeOptions } from './analyze';
export * from './definition';
export { Reference } from './referencer/Reference';
export { Visitor } from './referencer/Visitor';
export {
PatternVisitor,
PatternVisitorCallback,
PatternVisitorOptions,
type PatternVisitorCallback,
type PatternVisitorOptions,
} from './referencer/PatternVisitor';
export * from './scope';
export { ScopeManager } from './ScopeManager';
Expand Down
6 changes: 5 additions & 1 deletion packages/scope-manager/src/referencer/PatternVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ class PatternVisitor extends VisitorBase {
}
}

export { PatternVisitor, PatternVisitorCallback, PatternVisitorOptions };
export {
PatternVisitor,
type PatternVisitorCallback,
type PatternVisitorOptions,
};
7 changes: 6 additions & 1 deletion packages/scope-manager/src/referencer/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@ class Reference {
}
}

export { Reference, ReferenceFlag, ReferenceTypeFlag, ReferenceImplicitGlobal };
export {
Reference,
ReferenceFlag,
ReferenceTypeFlag,
type ReferenceImplicitGlobal,
};
2 changes: 1 addition & 1 deletion packages/scope-manager/src/referencer/Referencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,4 +807,4 @@ class Referencer extends Visitor {
}
}

export { Referencer, ReferencerOptions };
export { Referencer, type ReferencerOptions };
7 changes: 5 additions & 2 deletions packages/scope-manager/src/referencer/Visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
PatternVisitorOptions,
} from './PatternVisitor';
import { PatternVisitor } from './PatternVisitor';
import { VisitorBase, VisitorOptions } from './VisitorBase';
import type { VisitorOptions } from './VisitorBase';
import { VisitorBase } from './VisitorBase';

interface VisitPatternOptions extends PatternVisitorOptions {
processRightHandNodes?: boolean;
Expand Down Expand Up @@ -42,4 +43,6 @@
}
}

export { Visitor, VisitorBase, VisitorOptions };
export { Visitor };

export { VisitorBase, type VisitorOptions } from './VisitorBase';

Check warning on line 48 in packages/scope-manager/src/referencer/Visitor.ts

View check run for this annotation

Codecov / codecov/patch

packages/scope-manager/src/referencer/Visitor.ts#L48

Added line #L48 was not covered by tests
7 changes: 5 additions & 2 deletions packages/scope-manager/src/referencer/VisitorBase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/types';
import { VisitorKeys, visitorKeys } from '@typescript-eslint/visitor-keys';
import type { VisitorKeys } from '@typescript-eslint/visitor-keys';
import { visitorKeys } from '@typescript-eslint/visitor-keys';

interface VisitorOptions {
childVisitorKeys?: VisitorKeys | null;
Expand Down Expand Up @@ -83,4 +84,6 @@ abstract class VisitorBase {
}
}

export { VisitorBase, VisitorOptions, VisitorKeys };
export { VisitorBase, type VisitorOptions };

export type { VisitorKeys } from '@typescript-eslint/visitor-keys';
2 changes: 1 addition & 1 deletion packages/scope-manager/src/referencer/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Referencer, ReferencerOptions } from './Referencer';
export { Referencer, type ReferencerOptions } from './Referencer';
2 changes: 1 addition & 1 deletion packages/scope-manager/src/scope/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ type Scope =
| TypeScope
| WithScope;

export { Scope };
export type { Scope };
2 changes: 1 addition & 1 deletion packages/scope-manager/src/variable/ImplicitLibVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ class ImplicitLibVariable extends ESLintScopeVariable implements Variable {
}
}

export { ImplicitLibVariable, ImplicitLibVariableOptions };
export { ImplicitLibVariable, type ImplicitLibVariableOptions };
2 changes: 1 addition & 1 deletion packages/scope-manager/src/variable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Variable } from './Variable';
export { ESLintScopeVariable } from './ESLintScopeVariable';
export {
ImplicitLibVariable,
ImplicitLibVariableOptions,
type ImplicitLibVariableOptions,
} from './ImplicitLibVariable';
export { Variable } from './Variable';

Expand Down
7 changes: 5 additions & 2 deletions packages/scope-manager/tests/test-utils/parse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as tseslint from '@typescript-eslint/typescript-estree';

import { analyze, AnalyzeOptions } from '../../src/analyze';
import type { AnalyzeOptions } from '../../src/analyze';
import { analyze } from '../../src/analyze';

type SourceType = AnalyzeOptions['sourceType'];

Expand Down Expand Up @@ -59,4 +60,6 @@ function parseAndAnalyze(
return { ast, scopeManager };
}

export { parse, parseAndAnalyze, AnalyzeOptions };
export { parse, parseAndAnalyze };

export type { AnalyzeOptions } from '../../src/analyze';
2 changes: 1 addition & 1 deletion packages/types/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ type Lib =
| 'webworker.importscripts'
| 'webworker.iterable';

export { Lib };
export type { Lib };
2 changes: 1 addition & 1 deletion packages/types/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface ParserOptions {
warnOnUnsupportedTypeScriptVersion?: boolean;
}

export {
export type {
CacheDurationSeconds,
DebugLevel,
EcmaVersion,
Expand Down
8 changes: 4 additions & 4 deletions packages/typescript-eslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import type { TSESLint } from '@typescript-eslint/utils';
import pluginBase from '@typescript-eslint/eslint-plugin';
import * as parserBase from '@typescript-eslint/parser';

import type { ConfigWithExtends } from './config-helper';

import { config } from './config-helper';
import allConfig from './configs/all';
import baseConfig from './configs/base';
Expand Down Expand Up @@ -138,7 +136,7 @@ const configs = {
};

export type Config = TSESLint.FlatConfig.ConfigFile;
export type { ConfigWithExtends };

/*
we do both a default and named exports to allow people to use this package from
both CJS and ESM in very natural ways.
Expand Down Expand Up @@ -186,4 +184,6 @@ export default {
parser,
plugin,
};
export { config, configs, parser, plugin };
export { configs, parser, plugin };

export { config, type ConfigWithExtends } from './config-helper';
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ interface WatchCompilerHostOfConfigFile<T extends ts.BuilderProgram>
extraFileExtensions?: readonly ts.FileExtensionInfo[];
}

export { WatchCompilerHostOfConfigFile };
export type { WatchCompilerHostOfConfigFile };
8 changes: 4 additions & 4 deletions packages/typescript-estree/src/create-program/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ function createHash(content: string): string {
}

export {
ASTAndDefiniteProgram,
ASTAndNoProgram,
ASTAndProgram,
type ASTAndDefiniteProgram,
type ASTAndNoProgram,
type ASTAndProgram,
CORE_COMPILER_OPTIONS,
canonicalDirname,
CanonicalPath,
type CanonicalPath,
createDefaultCompilerOptionsFromExtra,
createHash,
ensureAbsolutePath,
Expand Down
6 changes: 3 additions & 3 deletions packages/typescript-estree/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export {
AST,
type AST,
parse,
parseAndGenerateServices,
ParseAndGenerateServicesResult,
type ParseAndGenerateServicesResult,
} from './parser';
export {
export type {
ParserServices,
ParserServicesWithTypeInformation,
ParserServicesWithoutTypeInformation,
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type * as ts from 'typescript';

import type { TSESTree, TSESTreeToTSNode, TSNode, TSToken } from './ts-estree';

export { ProjectServiceOptions } from '@typescript-eslint/types';
export type { ProjectServiceOptions } from '@typescript-eslint/types';

//////////////////////////////////////////////////////////
// MAKE SURE THIS IS KEPT IN SYNC WITH THE WEBSITE DOCS //
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ function parseAndGenerateServices<T extends TSESTreeOptions = TSESTreeOptions>(
}

export {
AST,
type AST,
parse,
parseAndGenerateServices,
ParseAndGenerateServicesResult,
type ParseAndGenerateServicesResult,
clearDefaultProjectMatchedFiles,
clearProgramCache,
clearParseAndGenerateServicesCalls,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/eslint-utils/InferTypesFromRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ type InferMessageIdsTypeFromRule<T> =
? MessageIds
: unknown;

export { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule };
export type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule };
4 changes: 2 additions & 2 deletions packages/utils/src/eslint-utils/RuleCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import type {

import { applyDefault } from './applyDefault';

export type { RuleListener, RuleModule };

// we automatically add the url
export type NamedCreateRuleMetaDocs = Omit<RuleMetaDataDocs, 'url'>;

Expand Down Expand Up @@ -119,3 +117,5 @@ RuleCreator.withoutDocs = function withoutDocs<
): RuleModule<MessageIds, Options> {
return createRule(args);
};

export { type RuleListener, type RuleModule } from '../ts-eslint/Rule';
11 changes: 5 additions & 6 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as ASTUtils from './ast-utils';
import * as ESLintUtils from './eslint-utils';
import * as JSONSchema from './json-schema';
import * as TSESLint from './ts-eslint';
import * as TSUtils from './ts-utils';
export * as ASTUtils from './ast-utils';

export { ASTUtils, ESLintUtils, JSONSchema, TSESLint, TSUtils };
export * as ESLintUtils from './eslint-utils';
export * as JSONSchema from './json-schema';
export * as TSESLint from './ts-eslint';
export * from './ts-estree';
export * as TSUtils from './ts-utils';
Loading
Loading