@regele/devtools
Version:
A collection of developer utilities for code processing and text analysis
87 lines (86 loc) • 2.66 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 inconsistent return types
*/
export declare class InconsistentReturnRule extends Rule {
readonly id = "bugs-inconsistent-return";
readonly name = "Inconsistent Return";
readonly description = "Detects functions with inconsistent return types or missing returns";
readonly category = CategoryType.Bugs;
readonly defaultSeverity = SeverityLevel.Warning;
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[];
/**
* Analyze return statements in a function
*
* @param path - AST path
* @returns Return analysis information
*/
private analyzeReturns;
/**
* Get the type of a return statement
*
* @param node - Return statement node
* @returns Type of the return value
*/
private getReturnType;
/**
* Check if all code paths in a function return a value
*
* @param node - Function node
* @returns True if all code paths return a value
*/
private allPathsReturn;
/**
* Check if a block statement returns on all code paths
*
* @param block - Block statement
* @returns True if all code paths return
*/
private blockReturnsOnAllPaths;
/**
* Generate a suggestion for fixing inconsistent returns
*
* @param _ - Original code (unused)
* @param returnInfo - Return analysis information
* @returns Suggested code
*/
protected generateSuggestion(_: string, returnInfo: {
returnTypes: string[];
}): string;
/**
* Generate a suggestion for fixing missing returns
*
* @param _ - Original code (unused)
* @param returnInfo - Return analysis information
* @returns Suggested code
*/
protected generateMissingReturnSuggestion(_: string, _returnInfo: {
returnTypes: string[];
}): string;
/**
* Get the name of the function
*
* @param path - AST path
* @returns Function name or undefined
*/
protected getFunctionName(path: any): string | undefined;
/**
* Get the name of the class containing a method
*
* @param path - AST path
* @returns Class name or undefined
*/
private getClassName;
}