Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

FileHeader Rule throwing exception #1694

Closed
nickzelei opened this issue Nov 7, 2016 · 2 comments
Closed

FileHeader Rule throwing exception #1694

nickzelei opened this issue Nov 7, 2016 · 2 comments

Comments

@nickzelei
Copy link

nickzelei commented Nov 7, 2016

Bug Report

  • TSLint version: 3.15.*
  • TypeScript version: 1.8.10
  • Running TSLint via: CLI

Stack Trace

TypeError: Cannot read property 'search' of undefined
    at FileHeaderWalker.visitSourceFile (\node_modules\tslint\lib\rules\fileHeaderRule.js:61:28)
    at FileHeaderWalker.SyntaxWalker.visitNode (\node_modules\tslint\lib\language\walker\syntaxWalker.js:414:22)
    at FileHeaderWalker.SyntaxWalker.walk (\node_modules\tslint\lib\language\walker\syntaxWalker.js:7:14)
    at Rule.AbstractRule.applyWithWalker (\node_modules\tslint\lib\language\rule\abstractRule.js:19:16)
    at Rule.apply (\node_modules\tslint\lib\rules\fileHeaderRule.js:17:21)
    at Linter.lint (\node_modules\tslint\lib\tslint.js:68:37)
    at processFile (\node_modules\tslint\lib\tslint-cli.js:138:29)
    at \node_modules\tslint\lib\tslint-cli.js:177:74
    at Array.forEach (native)
    at Object.<anonymous> (\node_modules\tslint\lib\tslint-cli.js:177:41)
    FileHeaderWalker.prototype.visitSourceFile = function (node) {
        if (this.headerRegexp) {
            var text = node.getFullText();
            var offset = 0;
            if (text.indexOf("#!") === 0) {
                offset = text.indexOf("\n") + 1;
                text = text.substring(offset);
            }
            var match = text.match(this.commentRegexp);
            if (!match) {
                this.addFailure(this.createFailure(offset, 0, Rule.FAILURE_STRING));
            }
            else {
                var comment = match[2] ? match[2] : match[3];
                if (comment.search(this.headerRegexp) < 0) { // FAILING LINE
                    this.addFailure(this.createFailure(offset, 0, Rule.FAILURE_STRING));
                }
            }
        }
    };

Actual behavior

This is being executed on a file that does not currently contain a file header. The file has code in it, but the entirety of the file is commented out.

@adidahiya
Copy link
Contributor

looks like a logic bug. accepting bugfix PRs!

@andy-hanson
Copy link
Contributor

Looks like this was fixed in #1913.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants