<commit_before>import * as ts from 'typescript';
import * as Lint from 'tslint/lib/lint';

/**
 * A base walker class that gracefully handles unexpected errors.
 * Errors are often thrown when the TypeChecker is invoked.
 */
class ErrorTolerantWalker extends Lint.RuleWalker {
    protected visitNode(node: ts.Node): void {
        try {
            super.visitNode(node);
        } catch (e) {
            var msg: string = 'An error occurred visiting a node.'
                + '\nWalker: ' + this.getClassName()
                + '\nNode: ' + (node.getFullText ? node.getFullText() : '<unknown>')
                + '\n' + e;

            this.addFailure(this.createFailure(
                node.getStart ? node.getStart() : 0,
                node.getWidth ? node.getWidth() : 0,
                msg));
        }
    }

    private getClassName(): string {
        // Some versions of IE have the word "function" in the constructor name and
        // have the function body there as well. This rips out and returns the function name.
        var result: string = this.constructor.toString().match(/function\s+([\w\$]+)\s*\(/)[1] || '';
        if (result == null || result.length === 0) {
            throw new Error('Could not determine class name from input: ' + this.constructor.toString());
        }
        return result;
    }

}

export = ErrorTolerantWalker;<commit_msg>[Issue #71, #94] relaxed ErrorTolerantWalker to not create tslint failures when the compiler fails<commit_after>import * as ts from 'typescript';
import * as Lint from 'tslint/lib/lint';

/**
 * A base walker class that gracefully handles unexpected errors.
 * Errors are often thrown when the TypeChecker is invoked.
 */
class ErrorTolerantWalker extends Lint.RuleWalker {

    private static DEBUG: boolean = false;

    protected visitNode(node: ts.Node): void {
        try {
            super.visitNode(node);
        } catch (e) {
            // turn this on when trying out new rules on foreign codebases
            if (ErrorTolerantWalker.DEBUG) {
                var msg: string = 'An error occurred visiting a node.'
                    + '\nWalker: ' + this.getClassName()
                    + '\nNode: ' + (node.getFullText ? node.getFullText() : '<unknown>')
                    + '\n' + e;

                this.addFailure(this.createFailure(
                    node.getStart ? node.getStart() : 0,
                    node.getWidth ? node.getWidth() : 0,
                    msg));
            }
        }
    }

    private getClassName(): string {
        // Some versions of IE have the word "function" in the constructor name and
        // have the function body there as well. This rips out and returns the function name.
        var result: string = this.constructor.toString().match(/function\s+([\w\$]+)\s*\(/)[1] || '';
        if (result == null || result.length === 0) {
            throw new Error('Could not determine class name from input: ' + this.constructor.toString());
        }
        return result;
    }

}

export = ErrorTolerantWalker;
{'fraction_non_alphanumeric': 0.11724363161332463, 'fraction_numerical': 0.003919007184846506, 'mean_word_length': 2.066066066066066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4801981', 'n_tokens_mistral': 852, 'n_tokens_neox': 810, 'n_words': 268}