<commit_before>﻿/**
 * Code Verification - Ensure Public API Has Tests
 * -----------------------------------------------
 * This code verification checks that all methods and properties
 * in the public api appear in the tests.
 * -----------------------------------------------
 */
import { TypeGuards, Node, ReferenceFindableNode, Scope } from "ts-simple-ast";
import { TsSimpleAstInspector } from "../inspectors";
import { hasInternalDocTag } from "../common";
import { Problem } from "./Problem";

export function ensurePublicApiHasTests(inspector: TsSimpleAstInspector, addProblem: (problem: Problem) => void) {
    const nodes: (Node & ReferenceFindableNode)[] = [];

    for (const dec of [...inspector.getPublicClasses(), ...inspector.getPublicInterfaces()]) {
        const filePath = dec.getSourceFile().getFilePath();
        // ignore paths that don't need testing
        if (filePath.endsWith("src/typescript/typescript.ts")
            || filePath.endsWith("src/utils/TypeGuards.ts")
            || filePath.endsWith("src/compiler/kindToNodeMappings.ts")
            || filePath.endsWith("src/codeBlockWriter/code-block-writer.ts"))
            continue;

        for (const node of [...dec.getMethods(), ...dec.getProperties()]) {
            if (TypeGuards.isScopedNode(node) && node.getScope() !== Scope.Public)
                continue;
            if (hasInternalDocTag(node))
                continue;
            nodes.push(node);
        }
    }

    for (const node of nodes) {
        const referencingNodes = node.findReferencesAsNodes();
        const testsReference = referencingNodes.some(n => n.getSourceFile().getFilePath().includes("/src/tests"));

        if (!testsReference)
            addProblem({
                filePath: node.getSourceFile().getFilePath(),<commit_msg>chore: #422 - Update to work with method overloads.<commit_after>﻿/**
 * Code Verification - Ensure Public API Has Tests
 * -----------------------------------------------
 * This code verification checks that all methods and properties
 * in the public api appear in the tests.
 * -----------------------------------------------
 */
import { TypeGuards, Node, ReferenceFindableNode, Scope } from "ts-simple-ast";
import { TsSimpleAstInspector } from "../inspectors";
import { hasInternalDocTag } from "../common";
import { Problem } from "./Problem";

export function ensurePublicApiHasTests(inspector: TsSimpleAstInspector, addProblem: (problem: Problem) => void) {
    const nodes: (Node & ReferenceFindableNode)[] = [];

    function tryAddNode(node: Node & ReferenceFindableNode) {
        if (TypeGuards.isScopedNode(node) && node.getScope() !== Scope.Public)
            return;
        if (hasInternalDocTag(node))
            return;
        nodes.push(node);
    }

    for (const dec of [...inspector.getPublicClasses(), ...inspector.getPublicInterfaces()]) {
        const filePath = dec.getSourceFile().getFilePath();
        // ignore paths that don't need testing
        if (filePath.endsWith("src/typescript/typescript.ts")
            || filePath.endsWith("src/utils/TypeGuards.ts")
            || filePath.endsWith("src/compiler/kindToNodeMappings.ts")
            || filePath.endsWith("src/codeBlockWriter/code-block-writer.ts"))
            continue;

        for (const node of dec.getProperties())
            tryAddNode(node);
        for (const node of dec.getMethods()) {
            if (TypeGuards.isMethodDeclaration(node)) {
                const overloads = node.getOverloads();
                if (overloads.length > 0) {
                    for (const overload of overloads)
                        tryAddNode(overload);
                    continue;
                }
            }
            tryAddNode(node);
        }
    }

    for (const node of nodes) {
        const referencingNodes = node.findReferencesAsNodes();
        const testsReference = referencingNodes.some(n => n.getSourceFile().getFilePath().includes("/src/tests"));

        if (!testsReference)
            addProblem({
                filePath: node.getSourceFile().getFilePath(),
{'fraction_non_alphanumeric': 0.1647546985599219, 'fraction_numerical': 0.000976324139614352, 'mean_word_length': 2.2090837901331244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4884536', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1037, 'n_words': 249}