Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a760946

Browse files
chore(eslint-plugin): remove useless union types (typescript-eslint#3421)
1 parent 99aab06 commit a760946

File tree

7 files changed

+29
-36
lines changed

7 files changed

+29
-36
lines changed

packages/eslint-plugin/src/rules/comma-spacing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ export default createRule<Options, MessageIds>({
108108
*/
109109
function validateCommaSpacing(
110110
commaToken: TSESTree.PunctuatorToken,
111-
prevToken: TSESTree.Token | TSESTree.Comment | null,
112-
nextToken: TSESTree.Token | TSESTree.Comment | null,
111+
prevToken: TSESTree.Token | null,
112+
nextToken: TSESTree.Token | null,
113113
): void {
114114
if (
115115
prevToken &&

packages/eslint-plugin/src/rules/consistent-type-imports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ interface ReportValueImport {
3131
}
3232

3333
function isImportToken(
34-
token: TSESTree.Token | TSESTree.Comment,
34+
token: TSESTree.Token,
3535
): token is TSESTree.KeywordToken & { value: 'import' } {
3636
return token.type === AST_TOKEN_TYPES.Keyword && token.value === 'import';
3737
}
3838

3939
function isTypeToken(
40-
token: TSESTree.Token | TSESTree.Comment,
40+
token: TSESTree.Token,
4141
): token is TSESTree.IdentifierToken & { value: 'type' } {
4242
return token.type === AST_TOKEN_TYPES.Identifier && token.value === 'type';
4343
}

packages/eslint-plugin/src/rules/indent-new-do-not-use/BinarySearchTree.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import { TSESTree } from '@typescript-eslint/experimental-utils';
55
import createTree from 'functional-red-black-tree';
66

7-
export type TokenOrComment = TSESTree.Token | TSESTree.Comment;
87
export interface TreeValue {
98
offset: number;
10-
from: TokenOrComment | null;
9+
from: TSESTree.Token | null;
1110
force: boolean;
1211
}
1312

packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE
33

44
import { TSESTree } from '@typescript-eslint/experimental-utils';
5-
import {
6-
BinarySearchTree,
7-
TokenOrComment,
8-
TreeValue,
9-
} from './BinarySearchTree';
5+
import { BinarySearchTree, TreeValue } from './BinarySearchTree';
106
import { TokenInfo } from './TokenInfo';
117

128
/**
@@ -17,9 +13,9 @@ export class OffsetStorage {
1713
private readonly indentSize: number;
1814
private readonly indentType: string;
1915
private readonly tree: BinarySearchTree;
20-
private readonly lockedFirstTokens: WeakMap<TokenOrComment, TokenOrComment>;
21-
private readonly desiredIndentCache: WeakMap<TokenOrComment, string>;
22-
private readonly ignoredTokens: WeakSet<TokenOrComment>;
16+
private readonly lockedFirstTokens: WeakMap<TSESTree.Token, TSESTree.Token>;
17+
private readonly desiredIndentCache: WeakMap<TSESTree.Token, string>;
18+
private readonly ignoredTokens: WeakSet<TSESTree.Token>;
2319
/**
2420
* @param tokenInfo a TokenInfo instance
2521
* @param indentSize The desired size of each indentation level
@@ -38,7 +34,7 @@ export class OffsetStorage {
3834
this.ignoredTokens = new WeakSet();
3935
}
4036

41-
private getOffsetDescriptor(token: TokenOrComment): TreeValue {
37+
private getOffsetDescriptor(token: TSESTree.Token): TreeValue {
4238
return this.tree.findLe(token.range[0]).value;
4339
}
4440

@@ -50,8 +46,8 @@ export class OffsetStorage {
5046
* @param offsetToken The second token, whose offset should be matched to the first token
5147
*/
5248
public matchOffsetOf(
53-
baseToken: TokenOrComment,
54-
offsetToken: TokenOrComment,
49+
baseToken: TSESTree.Token,
50+
offsetToken: TSESTree.Token,
5551
): void {
5652
/*
5753
* lockedFirstTokens is a map from a token whose indentation is controlled by the "first" option to
@@ -120,8 +116,8 @@ export class OffsetStorage {
120116
* @param offset The desired indent level
121117
*/
122118
public setDesiredOffset(
123-
token: TokenOrComment,
124-
fromToken: TokenOrComment | null,
119+
token: TSESTree.Token,
120+
fromToken: TSESTree.Token | null,
125121
offset: number,
126122
): void {
127123
this.setDesiredOffsets(token.range, fromToken, offset);
@@ -154,7 +150,7 @@ export class OffsetStorage {
154150
*/
155151
public setDesiredOffsets(
156152
range: [number, number],
157-
fromToken: TokenOrComment | null,
153+
fromToken: TSESTree.Token | null,
158154
offset = 0,
159155
force = false,
160156
): void {
@@ -212,7 +208,7 @@ export class OffsetStorage {
212208
* Gets the desired indent of a token
213209
* @returns The desired indent of the token
214210
*/
215-
public getDesiredIndent(token: TokenOrComment): string {
211+
public getDesiredIndent(token: TSESTree.Token): string {
216212
if (!this.desiredIndentCache.has(token)) {
217213
if (this.ignoredTokens.has(token)) {
218214
/*
@@ -263,7 +259,7 @@ export class OffsetStorage {
263259
/**
264260
* Ignores a token, preventing it from being reported.
265261
*/
266-
ignoreToken(token: TokenOrComment): void {
262+
ignoreToken(token: TSESTree.Token): void {
267263
if (this.tokenInfo.isFirstTokenOfLine(token)) {
268264
this.ignoredTokens.add(token);
269265
}

packages/eslint-plugin/src/rules/indent-new-do-not-use/TokenInfo.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE
33

44
import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';
5-
import { TokenOrComment } from './BinarySearchTree';
65

76
/**
87
* A helper class to get token-based info related to indentation
@@ -37,16 +36,16 @@ export class TokenInfo {
3736
* @returns The first token on the given line
3837
*/
3938
public getFirstTokenOfLine(
40-
token: TokenOrComment | TSESTree.Node,
41-
): TokenOrComment {
39+
token: TSESTree.Token | TSESTree.Node,
40+
): TSESTree.Token {
4241
return this.firstTokensByLineNumber.get(token.loc.start.line)!;
4342
}
4443

4544
/**
4645
* Determines whether a token is the first token in its line
4746
* @returns `true` if the token is the first on its line
4847
*/
49-
public isFirstTokenOfLine(token: TokenOrComment): boolean {
48+
public isFirstTokenOfLine(token: TSESTree.Token): boolean {
5049
return this.getFirstTokenOfLine(token) === token;
5150
}
5251

@@ -55,7 +54,7 @@ export class TokenInfo {
5554
* @param token Token to examine. This should be the first token on its line.
5655
* @returns The indentation characters that precede the token
5756
*/
58-
public getTokenIndent(token: TokenOrComment): string {
57+
public getTokenIndent(token: TSESTree.Token): string {
5958
return this.sourceCode.text.slice(
6059
token.range[0] - token.loc.start.column,
6160
token.range[0],

packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
TSESTree,
1010
} from '@typescript-eslint/experimental-utils';
1111

12-
import { TokenOrComment } from './BinarySearchTree';
1312
import { OffsetStorage } from './OffsetStorage';
1413
import { TokenInfo } from './TokenInfo';
1514
import {
@@ -474,7 +473,7 @@ export default createRule<Options, MessageIds>({
474473
* @param token Token violating the indent rule
475474
* @param neededIndent Expected indentation string
476475
*/
477-
function report(token: TokenOrComment, neededIndent: string): void {
476+
function report(token: TSESTree.Token, neededIndent: string): void {
478477
const actualIndent = Array.from(tokenInfo.getTokenIndent(token));
479478
const numSpaces = actualIndent.filter(char => char === ' ').length;
480479
const numTabs = actualIndent.filter(char => char === '\t').length;
@@ -503,7 +502,7 @@ export default createRule<Options, MessageIds>({
503502
* @returns `true` if the token's indentation is correct
504503
*/
505504
function validateTokenIndent(
506-
token: TokenOrComment,
505+
token: TSESTree.Token,
507506
desiredIndent: string,
508507
): boolean {
509508
const indentation = tokenInfo.getTokenIndent(token);
@@ -1653,21 +1652,21 @@ export default createRule<Options, MessageIds>({
16531652
addParensIndent(sourceCode.ast.tokens);
16541653

16551654
/*
1656-
* Create a Map from (tokenOrComment) => (precedingToken).
1655+
* Create a Map from (token) => (precedingToken).
16571656
* This is necessary because sourceCode.getTokenBefore does not handle a comment as an argument correctly.
16581657
*/
16591658
const precedingTokens = sourceCode.ast.comments.reduce(
16601659
(commentMap, comment) => {
1661-
const tokenOrCommentBefore = sourceCode.getTokenBefore(comment, {
1660+
const tokenBefore = sourceCode.getTokenBefore(comment, {
16621661
includeComments: true,
16631662
})!;
16641663

16651664
return commentMap.set(
16661665
comment,
1667-
commentMap.get(tokenOrCommentBefore) ?? tokenOrCommentBefore,
1666+
commentMap.get(tokenBefore) ?? tokenBefore,
16681667
);
16691668
},
1670-
new WeakMap<TokenOrComment, TSESTree.Token>(),
1669+
new WeakMap<TSESTree.Token, TSESTree.Token>(),
16711670
);
16721671

16731672
sourceCode.lines.forEach((_, lineIndex) => {

packages/eslint-plugin/src/rules/object-curly-spacing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ export default createRule<Options, MessageIds>({
164164
function validateBraceSpacing(
165165
node: TSESTree.TSMappedType | TSESTree.TSTypeLiteral,
166166
first: TSESTree.Token,
167-
second: TSESTree.Token | TSESTree.Comment,
168-
penultimate: TSESTree.Token | TSESTree.Comment,
167+
second: TSESTree.Token,
168+
penultimate: TSESTree.Token,
169169
last: TSESTree.Token,
170170
): void {
171171
if (isTokenOnSameLine(first, second)) {

0 commit comments

Comments
 (0)