chore(lint): replace enforce-copyright-header rule with the native equivalent

This commit is contained in:
Joao Dias 2016-10-29 12:40:15 +02:00 committed by vsavkin
parent 938ed1c76d
commit a0aecac0e5
2 changed files with 1 additions and 33 deletions

View File

@ -1,32 +0,0 @@
import {RuleWalker} from 'tslint/lib/language/walker';
import {RuleFailure} from 'tslint/lib/lint';
import {AbstractRule} from 'tslint/lib/rules';
import * as ts from 'typescript';
export class Rule extends AbstractRule {
public static FAILURE_STRING = 'missing copyright header';
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
const walker = new EnforceCopyrightHeaderWalker(sourceFile, this.getOptions());
return this.applyWithWalker(walker);
}
}
class EnforceCopyrightHeaderWalker extends RuleWalker {
private regex: RegExp = /\/\*[\s\S]*?Copyright Google Inc\.[\s\S]*?\*\//;
public visitSourceFile(node: ts.SourceFile) {
// check for a shebang
let text = node.getFullText();
let offset = 0;
if (text.indexOf('#!') === 0) {
offset = text.indexOf('\n') + 1;
text = text.substring(offset);
}
// look for the copyright header
let match = text.match(this.regex);
if (!match || match.index !== 0) {
this.addFailure(this.createFailure(offset, offset + 1, Rule.FAILURE_STRING));
}
}
}

View File

@ -4,7 +4,7 @@
"node_modules/vrsource-tslint-rules/rules" "node_modules/vrsource-tslint-rules/rules"
], ],
"rules": { "rules": {
"enforce-copyright-header": true, "file-header": [true, "Copyright Google Inc\\."],
"no-duplicate-imports": true, "no-duplicate-imports": true,
"no-duplicate-variable": true, "no-duplicate-variable": true,
"no-jasmine-focus": true, "no-jasmine-focus": true,