@regele/devtools
Version:
A collection of developer utilities for code processing and text analysis
53 lines (52 loc) • 1.67 kB
TypeScript
import * as parser from '@babel/parser';
import * as t from '@babel/types';
import { Rule } from '../rule';
import { CategoryType, CodeFinding, SeverityLevel } from '../../types';
/**
* Rule to detect unhandled promises
*/
export declare class UnhandledPromiseRule extends Rule {
readonly id = "bugs-unhandled-promise";
readonly name = "Unhandled Promise";
readonly description = "Detects promises without proper error handling";
readonly category = CategoryType.Bugs;
readonly defaultSeverity = SeverityLevel.Error;
readonly requiresAST = true;
/**
* Apply the rule to the given code
*
* @param code - Source code
* @param ast - Parsed AST
* @param filePath - Path to the file
* @returns Array of findings
*/
apply(code: string, ast: parser.ParseResult<t.File>, filePath: string): CodeFinding[];
/**
* Check if a call expression returns a promise
*
* @param node - Call expression node
* @returns True if the call likely returns a promise
*/
private isPromiseReturningCall;
/**
* Check if a promise is properly handled
*
* @param path - AST path
* @returns True if the promise is handled
*/
private isPromiseHandled;
/**
* Generate a suggestion for handling promises
*
* @param code - Original code
* @returns Suggested code
*/
protected generateSuggestion(code: string): string;
/**
* Get the name of the function containing this code
*
* @param path - AST path
* @returns Function name or undefined
*/
protected getFunctionName(path: any): string | undefined;
}