Skip to content

chore: enable sort-type-constituents internally #7028

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
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ module.exports = {
allowRegExp: true,
},
],
'@typescript-eslint/sort-type-constituents': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-spec/tests/util/parsers/parser-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export interface ParserResponseError {
readonly type: ParserResponseType.Error;
readonly error: unknown;
}
export type ParserResponse = ParserResponseSuccess | ParserResponseError;
export type ParserResponse = ParserResponseError | ParserResponseSuccess;
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function doIndent(line: string, indent: number): string {
return line;
}

function getQuote(code: string): "'" | '"' | null {
function getQuote(code: string): '"' | "'" | null {
const hasSingleQuote = code.includes("'");
const hasDoubleQuote = code.includes('"');
if (hasSingleQuote && hasDoubleQuote) {
Expand Down Expand Up @@ -95,12 +95,12 @@ type Options = [
type MessageIds =
| 'invalidFormatting'
| 'invalidFormattingErrorTest'
| 'prettierException'
| 'singleLineQuotes'
| 'templateLiteralEmptyEnds'
| 'templateLiteralLastLineIndent'
| 'templateStringRequiresIndent'
| 'templateStringMinimumIndent'
| 'prettierException';
| 'templateStringRequiresIndent';

export default createRule<Options, MessageIds>({
name: 'plugin-test-formatting',
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin-tslint/src/rules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const createRule = ESLintUtils.RuleCreator(
);
export type RawRulesConfig = Record<
string,
| null
| undefined
| boolean
| unknown[]
| boolean
| {
severity?: RuleSeverity | 'warn' | 'none' | 'default';
severity?: RuleSeverity | 'default' | 'none' | 'warn';
options?: unknown;
}
| null
| undefined
>;

export type MessageIds = 'failure';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as util from '../util';

type RuleNode =
| TSESTree.BlockStatement
| TSESTree.ClassBody
| TSESTree.Program
| TSESTree.TSModuleBlock
| TSESTree.TSTypeLiteral
| TSESTree.TSInterfaceBody
| TSESTree.BlockStatement;
| TSESTree.TSModuleBlock
| TSESTree.TSTypeLiteral;
type Member =
| TSESTree.ClassElement
| TSESTree.ProgramStatement
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/array-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ function typeNeedsParentheses(node: TSESTree.Node): boolean {
}
}

export type OptionString = 'array' | 'generic' | 'array-simple';
export type OptionString = 'array-simple' | 'array' | 'generic';
type Options = [
{
default: OptionString;
readonly?: OptionString;
},
];
type MessageIds =
| 'errorStringGeneric'
| 'errorStringArray'
| 'errorStringArraySimple'
| 'errorStringGeneric'
| 'errorStringGenericSimple';

export default util.createRule<Options, MessageIds>({
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/ban-ts-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const defaultMinimumDescriptionLength = 3;

type MessageIds =
| 'tsDirectiveComment'
| 'tsDirectiveCommentRequiresDescription'
| 'tsDirectiveCommentDescriptionNotMatchPattern';
| 'tsDirectiveCommentDescriptionNotMatchPattern'
| 'tsDirectiveCommentRequiresDescription';

export default util.createRule<[Options], MessageIds>({
name: 'ban-ts-comment',
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/ban-tslint-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ENABLE_DISABLE_REGEX =

const toText = (
text: string,
type: AST_TOKEN_TYPES.Line | AST_TOKEN_TYPES.Block,
type: AST_TOKEN_TYPES.Block | AST_TOKEN_TYPES.Line,
): string =>
type === AST_TOKEN_TYPES.Line
? ['//', text.trim()].join(' ')
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/ban-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import * as util from '../util';

type Types = Record<
string,
| null
| boolean
| string
| {
message: string;
fixWith?: string;
suggest?: readonly string[];
}
| null
>;

export type Options = [
Expand All @@ -35,7 +35,7 @@ function stringifyNode(
}

function getCustomMessage(
bannedType: null | true | string | { message?: string; fixWith?: string },
bannedType: string | true | { message?: string; fixWith?: string } | null,
): string {
if (bannedType == null || bannedType === true) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/brace-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default createRule<Options, MessageIds>({
return {
...rules,
'TSInterfaceBody, TSModuleBlock'(
node: TSESTree.TSModuleBlock | TSESTree.TSInterfaceBody,
node: TSESTree.TSInterfaceBody | TSESTree.TSModuleBlock,
): void {
const openingCurly = sourceCode.getFirstToken(node)!;
const closingCurly = sourceCode.getLastToken(node)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface NodeWithModifiers {

const printNodeModifiers = (
node: NodeWithModifiers,
final: 'readonly' | 'get',
final: 'get' | 'readonly',
): string =>
`${node.accessibility ?? ''}${
node.static ? ' static' : ''
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/comma-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Options = [
after: boolean;
},
];
type MessageIds = 'unexpected' | 'missing';
type MessageIds = 'missing' | 'unexpected';

export default createRule<Options, MessageIds>({
name: 'comma-spacing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import { createRule } from '../util';

type MessageIds = 'preferTypeAnnotation' | 'preferConstructor';
type Options = ['type-annotation' | 'constructor'];
type MessageIds = 'preferConstructor' | 'preferTypeAnnotation';
type Options = ['constructor' | 'type-annotation'];

export default createRule<Options, MessageIds>({
name: 'consistent-generic-constructors',
Expand Down Expand Up @@ -35,9 +35,9 @@ export default createRule<Options, MessageIds>({
return {
'VariableDeclarator,PropertyDefinition,:matches(FunctionDeclaration,FunctionExpression) > AssignmentPattern'(
node:
| TSESTree.VariableDeclarator
| TSESTree.AssignmentPattern
| TSESTree.PropertyDefinition
| TSESTree.AssignmentPattern,
| TSESTree.VariableDeclarator,
): void {
function getLHSRHS(): [
TSESTree.BindingName | TSESTree.PropertyDefinition,
Expand Down Expand Up @@ -84,8 +84,8 @@ export default createRule<Options, MessageIds>({
messageId: 'preferTypeAnnotation',
fix(fixer) {
function getIDToAttachAnnotation():
| TSESTree.Token
| TSESTree.Node {
| TSESTree.Node
| TSESTree.Token {
if (node.type !== AST_NODE_TYPES.PropertyDefinition) {
return lhsName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';

import { createRule } from '../util';

type MessageIds = 'preferRecord' | 'preferIndexSignature';
type Options = ['record' | 'index-signature'];
type MessageIds = 'preferIndexSignature' | 'preferRecord';
type Options = ['index-signature' | 'record'];

export default createRule<Options, MessageIds>({
name: 'consistent-indexed-object-style',
Expand Down Expand Up @@ -32,7 +32,7 @@ export default createRule<Options, MessageIds>({

function checkMembers(
members: TSESTree.TypeElement[],
node: TSESTree.TSTypeLiteral | TSESTree.TSInterfaceDeclaration,
node: TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeLiteral,
parentId: TSESTree.Identifier | undefined,
prefix: string,
postfix: string,
Expand Down
14 changes: 7 additions & 7 deletions packages/eslint-plugin/src/rules/consistent-type-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import * as util from '../util';

// intentionally mirroring the options
export type MessageIds =
| 'as'
| 'angle-bracket'
| 'as'
| 'never'
| 'unexpectedObjectTypeAssertion'
| 'replaceObjectTypeAssertionWithAnnotation'
| 'replaceObjectTypeAssertionWithSatisfies';
| 'replaceObjectTypeAssertionWithSatisfies'
| 'unexpectedObjectTypeAssertion';
type OptUnion =
| {
assertionStyle: 'as' | 'angle-bracket';
objectLiteralTypeAssertions?: 'allow' | 'allow-as-parameter' | 'never';
assertionStyle: 'angle-bracket' | 'as';
objectLiteralTypeAssertions?: 'allow-as-parameter' | 'allow' | 'never';
}
| {
assertionStyle: 'never';
Expand Down Expand Up @@ -117,7 +117,7 @@ export default util.createRule<Options, MessageIds>({
}

function reportIncorrectAssertionType(
node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression,
node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion,
): void {
const messageId = options.assertionStyle;

Expand Down Expand Up @@ -168,7 +168,7 @@ export default util.createRule<Options, MessageIds>({
}

function checkExpression(
node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression,
node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion,
): void {
if (
options.assertionStyle === 'never' ||
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/consistent-type-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ interface ReportValueExport {
}

type MessageIds =
| 'typeOverValue'
| 'multipleExportsAreTypes'
| 'singleExportIsType'
| 'multipleExportsAreTypes';
| 'typeOverValue';

export default util.createRule<Options, MessageIds>({
name: 'consistent-type-exports',
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-plugin/src/rules/consistent-type-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import * as util from '../util';

type Prefer = 'type-imports' | 'no-type-imports';
type FixStyle = 'separate-type-imports' | 'inline-type-imports';
type Prefer = 'no-type-imports' | 'type-imports';
type FixStyle = 'inline-type-imports' | 'separate-type-imports';

type Options = [
{
Expand Down Expand Up @@ -33,13 +33,13 @@ interface ReportValueImport {
}

type MessageIds =
| 'typeOverValue'
| 'someImportsAreOnlyTypes'
| 'aImportInDecoMeta'
| 'aImportIsOnlyTypes'
| 'valueOverType'
| 'noImportTypeAnnotations'
| 'someImportsAreOnlyTypes'
| 'someImportsInDecoMeta'
| 'aImportInDecoMeta';
| 'typeOverValue'
| 'valueOverType';
export default util.createRule<Options, MessageIds>({
name: 'consistent-type-imports',
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export default util.createRule<Options, MessageIds>({
function isAllowedFunction(
node:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionExpression
| TSESTree.FunctionDeclaration,
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression,
): boolean {
if (options.allowFunctionsWithoutTypeParameters && !node.typeParameters) {
return true;
Expand Down Expand Up @@ -164,8 +164,8 @@ export default util.createRule<Options, MessageIds>({
function isIIFE(
node:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionExpression
| TSESTree.FunctionDeclaration,
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression,
): boolean {
return node.parent.type === AST_NODE_TYPES.CallExpression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ interface Config {
type Options = [Config];

type MessageIds =
| 'unwantedPublicAccessibility'
| 'addExplicitAccessibility'
| 'missingAccessibility'
| 'addExplicitAccessibility';
| 'unwantedPublicAccessibility';

export default util.createRule<Options, MessageIds>({
name: 'explicit-member-accessibility',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type Options = [
},
];
type MessageIds =
| 'missingReturnType'
| 'anyTypedArg'
| 'anyTypedArgUnnamed'
| 'missingArgType'
| 'missingArgTypeUnnamed'
| 'anyTypedArg'
| 'anyTypedArgUnnamed';
| 'missingReturnType';

export default util.createRule<Options, MessageIds>({
name: 'explicit-module-boundary-types',
Expand Down Expand Up @@ -154,7 +154,7 @@ export default util.createRule<Options, MessageIds>({
};

function checkParameters(
node: TSESTree.TSEmptyBodyFunctionExpression | FunctionNode,
node: FunctionNode | TSESTree.TSEmptyBodyFunctionExpression,
): void {
function checkParameter(param: TSESTree.Parameter): void {
function report(
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/func-call-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import type { TSESTree } from '@typescript-eslint/utils';
import * as util from '../util';

export type Options = [
'never' | 'always',
'always' | 'never',
{
allowNewlines?: boolean;
}?,
];
export type MessageIds =
| 'unexpectedWhitespace'
| 'missing'
| 'unexpectedNewline'
| 'missing';
| 'unexpectedWhitespace';

export default util.createRule<Options, MessageIds>({
name: 'func-call-spacing',
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ export default util.createRule<Options, MessageIds>({
*/
function TSPropertySignatureToProperty(
node:
| TSESTree.TSPropertySignature
| TSESTree.TSEnumMember
| TSESTree.TSPropertySignature
| TSESTree.TypeElement,
type:
| AST_NODE_TYPES.PropertyDefinition
| AST_NODE_TYPES.Property = AST_NODE_TYPES.Property,
| AST_NODE_TYPES.Property
| AST_NODE_TYPES.PropertyDefinition = AST_NODE_TYPES.Property,
): TSESTree.Node | null {
const base = {
// indent doesn't actually use these
Expand Down
Loading