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

Skip to content
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
17 changes: 9 additions & 8 deletions packages/eslint-plugin/src/rules/no-confusing-void-expression.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import type {
NodeWithParent,
TSESLint,
TSESTree,
} from '@typescript-eslint/utils';

import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'ts-api-utils';
Expand Down Expand Up @@ -300,8 +304,8 @@ export default createRule<Options, MessageId>({
* @param node The void expression node to check.
* @returns Invalid ancestor node if it was found. `null` otherwise.
*/
function findInvalidAncestor(node: TSESTree.Node): InvalidAncestor | null {
const parent = nullThrows(node.parent, NullThrowsReasons.MissingParent);
function findInvalidAncestor(node: NodeWithParent): InvalidAncestor | null {
const parent = node.parent;
if (
parent.type === AST_NODE_TYPES.SequenceExpression &&
node !== parent.expressions[parent.expressions.length - 1]
Expand Down Expand Up @@ -365,17 +369,14 @@ export default createRule<Options, MessageId>({
/** Checks whether the return statement is the last statement in a function body. */
function isFinalReturn(node: TSESTree.ReturnStatement): boolean {
// the parent must be a block
const block = nullThrows(node.parent, NullThrowsReasons.MissingParent);
const block = node.parent;
if (block.type !== AST_NODE_TYPES.BlockStatement) {
// e.g. `if (cond) return;` (not in a block)
return false;
}

// the block's parent must be a function
const blockParent = nullThrows(
block.parent,
NullThrowsReasons.MissingParent,
);
const blockParent = block.parent;
if (
![
AST_NODE_TYPES.ArrowFunctionExpression,
Expand Down
10 changes: 4 additions & 6 deletions packages/eslint-plugin/src/util/collectUnusedVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ function isMergableExported(variable: ScopeVariable): boolean {

if (
(MERGABLE_TYPES.has(def.node.type) &&
def.node.parent?.type === AST_NODE_TYPES.ExportNamedDeclaration) ||
def.node.parent?.type === AST_NODE_TYPES.ExportDefaultDeclaration
def.node.parent.type === AST_NODE_TYPES.ExportNamedDeclaration) ||
def.node.parent.type === AST_NODE_TYPES.ExportDefaultDeclaration
) {
return true;
}
Expand All @@ -458,14 +458,12 @@ function isExported(variable: ScopeVariable): boolean {
let node = definition.node;

if (node.type === AST_NODE_TYPES.VariableDeclarator) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
node = node.parent!;
node = node.parent;
} else if (definition.type === TSESLint.Scope.DefinitionType.Parameter) {
return false;
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return node.parent!.type.startsWith('Export');
return node.parent.type.startsWith('Export');
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/scope-manager/src/definition/DefinitionBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TSESTree } from '@typescript-eslint/types';
import type { NodeWithParent, TSESTree } from '@typescript-eslint/types';

import type { DefinitionType } from './DefinitionType';

Expand All @@ -8,7 +8,7 @@ const generator = createIdGenerator();

export abstract class DefinitionBase<
Type extends DefinitionType,
Node extends TSESTree.Node,
Node extends NodeWithParent,
Parent extends TSESTree.Node | null,
Name extends TSESTree.Node,
> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { TSESTree } from '@typescript-eslint/types';
import type { NodeWithParent, TSESTree } from '@typescript-eslint/types';

import { DefinitionBase } from './DefinitionBase';
import { DefinitionType } from './DefinitionType';

export class ImplicitGlobalVariableDefinition extends DefinitionBase<
DefinitionType.ImplicitGlobalVariable,
TSESTree.Node,
NodeWithParent,
null,
TSESTree.BindingName
> {
Expand Down
4 changes: 2 additions & 2 deletions packages/scope-manager/src/referencer/Reference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TSESTree } from '@typescript-eslint/types';
import type { NodeWithParent, TSESTree } from '@typescript-eslint/types';

import type { Scope } from '../scope';
import type { Variable } from '../variable';
Expand All @@ -12,7 +12,7 @@ export enum ReferenceFlag {
}

export interface ReferenceImplicitGlobal {
node: TSESTree.Node;
node: NodeWithParent;
pattern: TSESTree.BindingName;
ref?: Reference;
}
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/ts-estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,4 @@ declare module './generated/ast-spec' {
}

export * as TSESTree from './generated/ast-spec';
export type NodeWithParent = Exclude<TSESTree.Node, TSESTree.Program>;
2 changes: 1 addition & 1 deletion packages/utils/src/ts-estree.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// for convenience's sake - export the types directly from here so consumers
// don't need to reference/install both packages in their code

export {
AST_NODE_TYPES,
AST_TOKEN_TYPES,
TSESTree,
} from '@typescript-eslint/types';
export type { NodeWithParent } from '@typescript-eslint/types';

export type {
ParserServices,
Expand Down
Loading