parent
830aecd1a7
commit
e9332c66d2
12
gulpfile.js
12
gulpfile.js
|
@ -329,17 +329,7 @@ gulp.task('lint', ['build.tools'], function() {
|
||||||
var tslint = require('gulp-tslint');
|
var tslint = require('gulp-tslint');
|
||||||
// Built-in rules are at
|
// Built-in rules are at
|
||||||
// https://github.com/palantir/tslint#supported-rules
|
// https://github.com/palantir/tslint#supported-rules
|
||||||
var tslintConfig = {
|
var tslintConfig = require('./tslint.json');
|
||||||
"rules": {
|
|
||||||
"requireInternalWithUnderscore": true,
|
|
||||||
"requireParameterType": true,
|
|
||||||
"requireReturnType": true,
|
|
||||||
"semicolon": true,
|
|
||||||
|
|
||||||
// TODO: find a way to just screen for reserved names
|
|
||||||
"variable-name": false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/testing/**'])
|
return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/testing/**'])
|
||||||
.pipe(tslint({
|
.pipe(tslint({
|
||||||
tslint: require('tslint').default,
|
tslint: require('tslint').default,
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
import {RuleFailure} from 'tslint/lib/lint';
|
||||||
|
import {AbstractRule} from 'tslint/lib/rules';
|
||||||
|
import {RuleWalker} from 'tslint/lib/language/walker';
|
||||||
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
|
export class Rule extends AbstractRule {
|
||||||
|
public static FAILURE_STRING = "duplicate module import";
|
||||||
|
|
||||||
|
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
|
||||||
|
const typedefWalker = new ModuleImportWalker(sourceFile, this.getOptions());
|
||||||
|
return this.applyWithWalker(typedefWalker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModuleImportWalker extends RuleWalker {
|
||||||
|
importModulesSeen: string[] = [];
|
||||||
|
|
||||||
|
protected visitImportDeclaration(node: ts.ImportDeclaration): void {
|
||||||
|
this.visitModuleSpecifier(node.moduleSpecifier);
|
||||||
|
super.visitImportDeclaration(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration): void {
|
||||||
|
this.visitModuleSpecifier(node.moduleReference);
|
||||||
|
super.visitImportEqualsDeclaration(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private checkTypeAnnotation(location: number, typeAnnotation: ts.TypeNode, name?: ts.Node) {
|
||||||
|
if (typeAnnotation == null) {
|
||||||
|
let ns = "<name missing>";
|
||||||
|
if (name != null && name.kind === ts.SyntaxKind.Identifier) {
|
||||||
|
ns = (<ts.Identifier>name).text;
|
||||||
|
}
|
||||||
|
if (ns.charAt(0) === '_') return;
|
||||||
|
let failure = this.createFailure(location, 1, "expected parameter " + ns + " to have a type");
|
||||||
|
this.addFailure(failure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private visitModuleSpecifier(moduleSpecifier: ts.Node) {
|
||||||
|
var text = moduleSpecifier.getText();
|
||||||
|
if (this.importModulesSeen.indexOf(text) >= 0) {
|
||||||
|
let failure =
|
||||||
|
this.createFailure(moduleSpecifier.getEnd(), 1, "Duplicate imports from module " + text);
|
||||||
|
this.addFailure(failure);
|
||||||
|
}
|
||||||
|
this.importModulesSeen.push(text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"requireInternalWithUnderscore": true,
|
||||||
|
"requireParameterType": true,
|
||||||
|
"requireReturnType": true,
|
||||||
|
"duplicateModuleImport": false,
|
||||||
|
"semicolon": true,
|
||||||
|
"variable-name": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue