cognitive-complexity-ts
Version:
This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf). It produces a JSON summary and a GUI for exploring the complexity of your codebase.
44 lines (43 loc) • 2.98 kB
TypeScript
import * as ts from "typescript";
import { ColumnAndLine } from "../../shared/types";
export type ForLikeStatement = ts.ForStatement | ts.ForInOrOfStatement;
export type FunctionNode = ts.AccessorDeclaration | ts.ArrowFunction | ts.FunctionDeclaration | ts.FunctionExpression | ts.MethodDeclaration;
export declare function getColumnAndLine(node: ts.Node): ColumnAndLine;
export declare function getIdentifier(node: ts.Node): string | undefined;
export declare function getFirstNonParenthesizedAncestor(node: ts.Node): ts.Node;
export declare function getNodeKind(node: ts.Node): "class" | "function" | "module" | "type" | undefined;
export declare function getTextWithoutBrackets(node: ts.Node): string;
export declare function isBreakOrContinueToLabel(node: ts.Node): boolean;
export declare function isContainer(node: ts.Node): boolean;
export declare function isForLikeStatement(node: ts.Node): node is ForLikeStatement;
export declare function isFunctionNode(node: ts.Node): node is FunctionNode;
export declare function isSyntaxList(node: ts.Node): node is ts.SyntaxList;
export declare function isNewSequenceOfBinaryOperators(node: ts.Node, precedingOperator: ChainableBinaryOperator["kind"] | undefined): boolean;
export declare function isNewSequenceOfBinaryTypeOperators(node: ts.Node, precedingTypeOperator: ChainableBinaryTypeOperator["kind"] | undefined): boolean;
export type ChainableBinaryOperator = ts.Node & {
kind: ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.QuestionQuestionToken;
};
export declare function isChainableBinaryOperator(node: ts.Node): node is ChainableBinaryOperator;
export type ChainableBinaryTypeOperator = ts.Node & {
kind: ts.SyntaxKind.AmpersandToken | ts.SyntaxKind.BarToken;
};
export declare function isChainableBinaryTypeOperator(node: ts.Node): node is ChainableBinaryTypeOperator;
/**
* A node that causes an end to a sequence of binary operators
* (i.e. A && B { C && D }, the curly braces end the prior sequence;
* C will not be interpreted as part of the last sequence.
*/
export declare function breaksASequenceOfBinaryOperators(node: ts.Node): boolean;
/**
* A node that doesn't cause an end to a sequence of binary operators
* (i.e. A && Node && B, the 2 && are in the same sequence)
* but the node's children don't form part of that sequence
* (i.e. A && Node(B && C) && D, this is two sequences, one inside Node(), the other outside)
*/
export declare function pausesASequenceOfBinaryOperators(node: ts.Node): node is ts.ElementAccessExpression | ts.CallLikeExpression | ts.PrefixUnaryExpression;
/**
* @see {pausesASequenceOfBinaryOperators} but for type operators
*/
export declare function pausesASequenceOfBinaryTypeOperators(node: ts.Node): node is ts.ParenthesizedExpression | ts.TypeReferenceNode | ts.AsExpression;
export declare function passThroughNameBeingAssigned(node: ts.Node): boolean;
export declare function report(node: ts.Node, depth?: number): void;