function walk()

in src/rules/npmNamingRule.ts [168:211]


function walk(ctx: Lint.WalkContext<CriticOptions>): void {
    const { sourceFile } = ctx;
    const { text } = sourceFile;
    const lookFor = (search: string, explanation: string) => {
        const idx = text.indexOf(search);
        if (idx !== -1) {
            ctx.addFailureAt(idx, search.length, failure(Rule.metadata.ruleName, explanation));
        }
    };
    if (isMainFile(sourceFile.fileName, /*allowNested*/ false)) {
        try {
            const optionsWithSuggestions = toOptionsWithSuggestions(ctx.options);
            const diagnostics = critic(sourceFile.fileName, /* sourcePath */ undefined, optionsWithSuggestions);
            const errors = filterErrors(diagnostics, ctx);
            for (const error of errors) {
                switch (error.kind) {
                    case ErrorKind.NoMatchingNpmPackage:
                    case ErrorKind.NoMatchingNpmVersion:
                    case ErrorKind.NonNpmHasMatchingPackage:
                        lookFor("// Type definitions for", errorMessage(error, ctx.options));
                        break;
                    case ErrorKind.DtsPropertyNotInJs:
                    case ErrorKind.DtsSignatureNotInJs:
                    case ErrorKind.JsPropertyNotInDts:
                    case ErrorKind.JsSignatureNotInDts:
                    case ErrorKind.NeedsExportEquals:
                    case ErrorKind.NoDefaultExport:
                        if (error.position) {
                            ctx.addFailureAt(
                                error.position.start,
                                error.position.length,
                                failure(Rule.metadata.ruleName, errorMessage(error, ctx.options)));
                        } else {
                            ctx.addFailure(0, 1, failure(Rule.metadata.ruleName, errorMessage(error, ctx.options)));
                        }
                        break;
                }
            }
        } catch (e) {
            // We're ignoring exceptions.
        }
    }
    // Don't recur, we're done.
}