提交 6a07f2d9 编写于 作者: J Joao Moreno

add tslint duplicateImportsRule

上级 89f24181
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var path_1 = require('path');
var Lint = require('tslint/lib/lint');
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new ImportPatterns(sourceFile, this.getOptions()));
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var ImportPatterns = (function (_super) {
__extends(ImportPatterns, _super);
function ImportPatterns(file, opts) {
_super.call(this, file, opts);
this.imports = Object.create(null);
}
ImportPatterns.prototype.visitImportDeclaration = function (node) {
var path = node.moduleSpecifier.getText();
// remove quotes
path = path.slice(1, -1);
if (path[0] === '.') {
path = path_1.join(path_1.dirname(node.getSourceFile().fileName), path);
}
if (this.imports[path]) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Duplicate imports for '" + path + "'."));
}
this.imports[path] = true;
};
return ImportPatterns;
}(Lint.RuleWalker));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as ts from 'typescript';
import { join, dirname } from 'path';
import * as Lint from 'tslint/lib/lint';
export class Rule extends Lint.Rules.AbstractRule {
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new ImportPatterns(sourceFile, this.getOptions()));
}
}
class ImportPatterns extends Lint.RuleWalker {
private imports: { [path: string]: boolean; } = Object.create(null);
constructor(file: ts.SourceFile, opts: Lint.IOptions) {
super(file, opts);
}
protected visitImportDeclaration(node: ts.ImportDeclaration): void {
let path = node.moduleSpecifier.getText();
// remove quotes
path = path.slice(1, -1);
if (path[0] === '.') {
path = join(dirname(node.getSourceFile().fileName), path);
}
if (this.imports[path]) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), `Duplicate imports for '${path}'.`));
}
this.imports[path] = true;
}
}
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
"use strict"; "use strict";
var __extends = (this && this.__extends) || function (d, b) { var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}; };
var Lint = require('tslint/lib/lint'); var Lint = require('tslint/lib/lint');
var minimatch = require('minimatch'); var minimatch = require('minimatch');
var Rule = (function (_super) { var Rule = (function (_super) {
__extends(Rule, _super); __extends(Rule, _super);
function Rule() { function Rule() {
_super.apply(this, arguments); _super.apply(this, arguments);
} }
Rule.prototype.apply = function (sourceFile) { Rule.prototype.apply = function (sourceFile) {
var configs = this.getOptions().ruleArguments; var configs = this.getOptions().ruleArguments;
for (var _i = 0, configs_1 = configs; _i < configs_1.length; _i++) { for (var _i = 0, configs_1 = configs; _i < configs_1.length; _i++) {
var config = configs_1[_i]; var config = configs_1[_i];
if (minimatch(sourceFile.fileName, config.target)) { if (minimatch(sourceFile.fileName, config.target)) {
return this.applyWithWalker(new ImportPatterns(sourceFile, this.getOptions(), config)); return this.applyWithWalker(new ImportPatterns(sourceFile, this.getOptions(), config));
} }
} }
return []; return [];
}; };
return Rule; return Rule;
}(Lint.Rules.AbstractRule)); }(Lint.Rules.AbstractRule));
exports.Rule = Rule; exports.Rule = Rule;
var ImportPatterns = (function (_super) { var ImportPatterns = (function (_super) {
__extends(ImportPatterns, _super); __extends(ImportPatterns, _super);
function ImportPatterns(file, opts, _config) { function ImportPatterns(file, opts, _config) {
_super.call(this, file, opts); _super.call(this, file, opts);
this._config = _config; this._config = _config;
} }
ImportPatterns.prototype.visitImportDeclaration = function (node) { ImportPatterns.prototype.visitImportDeclaration = function (node) {
var path = node.moduleSpecifier.getText(); var path = node.moduleSpecifier.getText();
// remove quotes // remove quotes
path = path.slice(1, -1); path = path.slice(1, -1);
// ignore relative paths // ignore relative paths
if (path[0] === '.') { if (path[0] === '.') {
return; return;
} }
if (!minimatch(path, this._config.restrictions)) { if (!minimatch(path, this._config.restrictions)) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Imports violates '" + this._config.restrictions + "'-restriction.")); this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Imports violates '" + this._config.restrictions + "'-restriction."));
} }
}; };
return ImportPatterns; return ImportPatterns;
}(Lint.RuleWalker)); }(Lint.RuleWalker));
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
"use strict"; "use strict";
var __extends = (this && this.__extends) || function (d, b) { var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}; };
var Lint = require('tslint/lib/lint'); var Lint = require('tslint/lib/lint');
var path_1 = require('path'); var path_1 = require('path');
var Rule = (function (_super) { var Rule = (function (_super) {
__extends(Rule, _super); __extends(Rule, _super);
function Rule() { function Rule() {
_super.apply(this, arguments); _super.apply(this, arguments);
} }
Rule.prototype.apply = function (sourceFile) { Rule.prototype.apply = function (sourceFile) {
var parts = path_1.dirname(sourceFile.fileName).split(/\\|\//); var parts = path_1.dirname(sourceFile.fileName).split(/\\|\//);
var ruleArgs = this.getOptions().ruleArguments[0]; var ruleArgs = this.getOptions().ruleArguments[0];
var config; var config;
for (var i = parts.length - 1; i >= 0; i--) { for (var i = parts.length - 1; i >= 0; i--) {
if (ruleArgs[parts[i]]) { if (ruleArgs[parts[i]]) {
config = { config = {
allowed: new Set(ruleArgs[parts[i]]).add(parts[i]), allowed: new Set(ruleArgs[parts[i]]).add(parts[i]),
disallowed: new Set() disallowed: new Set()
}; };
Object.keys(ruleArgs).forEach(function (key) { Object.keys(ruleArgs).forEach(function (key) {
if (!config.allowed.has(key)) { if (!config.allowed.has(key)) {
config.disallowed.add(key); config.disallowed.add(key);
} }
}); });
break; break;
} }
} }
if (!config) { if (!config) {
return []; return [];
} }
return this.applyWithWalker(new LayeringRule(sourceFile, config, this.getOptions())); return this.applyWithWalker(new LayeringRule(sourceFile, config, this.getOptions()));
}; };
return Rule; return Rule;
}(Lint.Rules.AbstractRule)); }(Lint.Rules.AbstractRule));
exports.Rule = Rule; exports.Rule = Rule;
var LayeringRule = (function (_super) { var LayeringRule = (function (_super) {
__extends(LayeringRule, _super); __extends(LayeringRule, _super);
function LayeringRule(file, config, opts) { function LayeringRule(file, config, opts) {
_super.call(this, file, opts); _super.call(this, file, opts);
this._config = config; this._config = config;
} }
LayeringRule.prototype.visitImportDeclaration = function (node) { LayeringRule.prototype.visitImportDeclaration = function (node) {
var path = node.moduleSpecifier.getText(); var path = node.moduleSpecifier.getText();
if (path[0] === '.') { // remove quotes
path = path_1.join(path_1.dirname(node.getSourceFile().fileName), path); path = path.slice(1, -1);
} if (path[0] === '.') {
var parts = path_1.dirname(path).split(/\\|\//); path = path_1.join(path_1.dirname(node.getSourceFile().fileName), path);
for (var i = parts.length - 1; i >= 0; i--) { }
var part = parts[i]; var parts = path_1.dirname(path).split(/\\|\//);
if (this._config.allowed.has(part)) { for (var i = parts.length - 1; i >= 0; i--) {
// GOOD - same layer var part = parts[i];
return; if (this._config.allowed.has(part)) {
} // GOOD - same layer
if (this._config.disallowed.has(part)) { return;
// BAD - wrong layer }
var message = "Bad layering. You are not allowed to access '" + part + "' from here, allowed layers are: [" + LayeringRule._print(this._config.allowed) + "]"; if (this._config.disallowed.has(part)) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), message)); // BAD - wrong layer
return; var message = "Bad layering. You are not allowed to access '" + part + "' from here, allowed layers are: [" + LayeringRule._print(this._config.allowed) + "]";
} this.addFailure(this.createFailure(node.getStart(), node.getWidth(), message));
} return;
}; }
LayeringRule._print = function (set) { }
var r = []; };
set.forEach(function (e) { return r.push(e); }); LayeringRule._print = function (set) {
return r.join(', '); var r = [];
}; set.forEach(function (e) { return r.push(e); });
return LayeringRule; return r.join(', ');
}(Lint.RuleWalker)); };
return LayeringRule;
}(Lint.RuleWalker));
...@@ -52,8 +52,11 @@ class LayeringRule extends Lint.RuleWalker { ...@@ -52,8 +52,11 @@ class LayeringRule extends Lint.RuleWalker {
} }
protected visitImportDeclaration(node: ts.ImportDeclaration): void { protected visitImportDeclaration(node: ts.ImportDeclaration): void {
let path = node.moduleSpecifier.getText(); let path = node.moduleSpecifier.getText();
// remove quotes
path = path.slice(1, -1);
if (path[0] === '.') { if (path[0] === '.') {
path = join(dirname(node.getSourceFile().fileName), path); path = join(dirname(node.getSourceFile().fileName), path);
} }
......
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
"use strict"; "use strict";
var __extends = (this && this.__extends) || function (d, b) { var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}; };
var ts = require('typescript'); var ts = require('typescript');
var Lint = require('tslint/lib/lint'); var Lint = require('tslint/lib/lint');
/** /**
* Implementation of the no-unexternalized-strings rule. * Implementation of the no-unexternalized-strings rule.
*/ */
var Rule = (function (_super) { var Rule = (function (_super) {
__extends(Rule, _super); __extends(Rule, _super);
function Rule() { function Rule() {
_super.apply(this, arguments); _super.apply(this, arguments);
} }
Rule.prototype.apply = function (sourceFile) { Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions())); return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions()));
}; };
return Rule; return Rule;
}(Lint.Rules.AbstractRule)); }(Lint.Rules.AbstractRule));
exports.Rule = Rule; exports.Rule = Rule;
function isStringLiteral(node) { function isStringLiteral(node) {
return node && node.kind === ts.SyntaxKind.StringLiteral; return node && node.kind === ts.SyntaxKind.StringLiteral;
} }
function isObjectLiteral(node) { function isObjectLiteral(node) {
return node && node.kind === ts.SyntaxKind.ObjectLiteralExpression; return node && node.kind === ts.SyntaxKind.ObjectLiteralExpression;
} }
function isPropertyAssignment(node) { function isPropertyAssignment(node) {
return node && node.kind === ts.SyntaxKind.PropertyAssignment; return node && node.kind === ts.SyntaxKind.PropertyAssignment;
} }
var NoUnexternalizedStringsRuleWalker = (function (_super) { var NoUnexternalizedStringsRuleWalker = (function (_super) {
__extends(NoUnexternalizedStringsRuleWalker, _super); __extends(NoUnexternalizedStringsRuleWalker, _super);
function NoUnexternalizedStringsRuleWalker(file, opts) { function NoUnexternalizedStringsRuleWalker(file, opts) {
var _this = this; var _this = this;
_super.call(this, file, opts); _super.call(this, file, opts);
this.signatures = Object.create(null); this.signatures = Object.create(null);
this.ignores = Object.create(null); this.ignores = Object.create(null);
this.messageIndex = undefined; this.messageIndex = undefined;
this.keyIndex = undefined; this.keyIndex = undefined;
this.usedKeys = Object.create(null); this.usedKeys = Object.create(null);
var options = this.getOptions(); var options = this.getOptions();
var first = options && options.length > 0 ? options[0] : null; var first = options && options.length > 0 ? options[0] : null;
if (first) { if (first) {
if (Array.isArray(first.signatures)) { if (Array.isArray(first.signatures)) {
first.signatures.forEach(function (signature) { return _this.signatures[signature] = true; }); first.signatures.forEach(function (signature) { return _this.signatures[signature] = true; });
} }
if (Array.isArray(first.ignores)) { if (Array.isArray(first.ignores)) {
first.ignores.forEach(function (ignore) { return _this.ignores[ignore] = true; }); first.ignores.forEach(function (ignore) { return _this.ignores[ignore] = true; });
} }
if (typeof first.messageIndex !== 'undefined') { if (typeof first.messageIndex !== 'undefined') {
this.messageIndex = first.messageIndex; this.messageIndex = first.messageIndex;
} }
if (typeof first.keyIndex !== 'undefined') { if (typeof first.keyIndex !== 'undefined') {
this.keyIndex = first.keyIndex; this.keyIndex = first.keyIndex;
} }
} }
} }
NoUnexternalizedStringsRuleWalker.prototype.visitSourceFile = function (node) { NoUnexternalizedStringsRuleWalker.prototype.visitSourceFile = function (node) {
var _this = this; var _this = this;
_super.prototype.visitSourceFile.call(this, node); _super.prototype.visitSourceFile.call(this, node);
Object.keys(this.usedKeys).forEach(function (key) { Object.keys(this.usedKeys).forEach(function (key) {
var occurences = _this.usedKeys[key]; var occurences = _this.usedKeys[key];
if (occurences.length > 1) { if (occurences.length > 1) {
occurences.forEach(function (occurence) { occurences.forEach(function (occurence) {
_this.addFailure((_this.createFailure(occurence.key.getStart(), occurence.key.getWidth(), "Duplicate key " + occurence.key.getText() + " with different message value."))); _this.addFailure((_this.createFailure(occurence.key.getStart(), occurence.key.getWidth(), "Duplicate key " + occurence.key.getText() + " with different message value.")));
}); });
} }
}); });
}; };
NoUnexternalizedStringsRuleWalker.prototype.visitStringLiteral = function (node) { NoUnexternalizedStringsRuleWalker.prototype.visitStringLiteral = function (node) {
this.checkStringLiteral(node); this.checkStringLiteral(node);
_super.prototype.visitStringLiteral.call(this, node); _super.prototype.visitStringLiteral.call(this, node);
}; };
NoUnexternalizedStringsRuleWalker.prototype.checkStringLiteral = function (node) { NoUnexternalizedStringsRuleWalker.prototype.checkStringLiteral = function (node) {
var text = node.getText(); var text = node.getText();
var doubleQuoted = text.length >= 2 && text[0] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE && text[text.length - 1] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE; var doubleQuoted = text.length >= 2 && text[0] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE && text[text.length - 1] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE;
var info = this.findDescribingParent(node); var info = this.findDescribingParent(node);
// Ignore strings in import and export nodes. // Ignore strings in import and export nodes.
if (info && info.ignoreUsage) { if (info && info.ignoreUsage) {
return; return;
} }
var callInfo = info ? info.callInfo : null; var callInfo = info ? info.callInfo : null;
var functionName = callInfo ? callInfo.callExpression.expression.getText() : null; var functionName = callInfo ? callInfo.callExpression.expression.getText() : null;
if (functionName && this.ignores[functionName]) { if (functionName && this.ignores[functionName]) {
return; return;
} }
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) { if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText())); this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText()));
return; return;
} }
// We have a single quoted string outside a localize function name. // We have a single quoted string outside a localize function name.
if (!doubleQuoted && !this.signatures[functionName]) { if (!doubleQuoted && !this.signatures[functionName]) {
return; return;
} }
// We have a string that is a direct argument into the localize call. // We have a string that is a direct argument into the localize call.
var keyArg = callInfo.argIndex === this.keyIndex var keyArg = callInfo.argIndex === this.keyIndex
? callInfo.callExpression.arguments[this.keyIndex] ? callInfo.callExpression.arguments[this.keyIndex]
: null; : null;
if (keyArg) { if (keyArg) {
if (isStringLiteral(keyArg)) { if (isStringLiteral(keyArg)) {
this.recordKey(keyArg, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined); this.recordKey(keyArg, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);
} }
else if (isObjectLiteral(keyArg)) { else if (isObjectLiteral(keyArg)) {
for (var i = 0; i < keyArg.properties.length; i++) { for (var i = 0; i < keyArg.properties.length; i++) {
var property = keyArg.properties[i]; var property = keyArg.properties[i];
if (isPropertyAssignment(property)) { if (isPropertyAssignment(property)) {
var name = property.name.getText(); var name_1 = property.name.getText();
if (name === 'key') { if (name_1 === 'key') {
var initializer = property.initializer; var initializer = property.initializer;
if (isStringLiteral(initializer)) { if (isStringLiteral(initializer)) {
this.recordKey(initializer, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined); this.recordKey(initializer, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);
} }
break; break;
} }
} }
} }
} }
} }
var messageArg = callInfo.argIndex === this.messageIndex var messageArg = callInfo.argIndex === this.messageIndex
? callInfo.callExpression.arguments[this.messageIndex] ? callInfo.callExpression.arguments[this.messageIndex]
: null; : null;
if (messageArg && messageArg !== node) { if (messageArg && messageArg !== node) {
this.addFailure(this.createFailure(messageArg.getStart(), messageArg.getWidth(), "Message argument to '" + callInfo.callExpression.expression.getText() + "' must be a string literal.")); this.addFailure(this.createFailure(messageArg.getStart(), messageArg.getWidth(), "Message argument to '" + callInfo.callExpression.expression.getText() + "' must be a string literal."));
return; return;
} }
}; };
NoUnexternalizedStringsRuleWalker.prototype.recordKey = function (keyNode, messageNode) { NoUnexternalizedStringsRuleWalker.prototype.recordKey = function (keyNode, messageNode) {
var text = keyNode.getText(); var text = keyNode.getText();
var occurences = this.usedKeys[text]; var occurences = this.usedKeys[text];
if (!occurences) { if (!occurences) {
occurences = []; occurences = [];
this.usedKeys[text] = occurences; this.usedKeys[text] = occurences;
} }
if (messageNode) { if (messageNode) {
if (occurences.some(function (pair) { return pair.message ? pair.message.getText() === messageNode.getText() : false; })) { if (occurences.some(function (pair) { return pair.message ? pair.message.getText() === messageNode.getText() : false; })) {
return; return;
} }
} }
occurences.push({ key: keyNode, message: messageNode }); occurences.push({ key: keyNode, message: messageNode });
}; };
NoUnexternalizedStringsRuleWalker.prototype.findDescribingParent = function (node) { NoUnexternalizedStringsRuleWalker.prototype.findDescribingParent = function (node) {
var parent; var parent;
while ((parent = node.parent)) { while ((parent = node.parent)) {
var kind = parent.kind; var kind = parent.kind;
if (kind === ts.SyntaxKind.CallExpression) { if (kind === ts.SyntaxKind.CallExpression) {
var callExpression = parent; var callExpression = parent;
return { callInfo: { callExpression: callExpression, argIndex: callExpression.arguments.indexOf(node) } }; return { callInfo: { callExpression: callExpression, argIndex: callExpression.arguments.indexOf(node) } };
} }
else if (kind === ts.SyntaxKind.ImportEqualsDeclaration || kind === ts.SyntaxKind.ImportDeclaration || kind === ts.SyntaxKind.ExportDeclaration) { else if (kind === ts.SyntaxKind.ImportEqualsDeclaration || kind === ts.SyntaxKind.ImportDeclaration || kind === ts.SyntaxKind.ExportDeclaration) {
return { ignoreUsage: true }; return { ignoreUsage: true };
} }
else if (kind === ts.SyntaxKind.VariableDeclaration || kind === ts.SyntaxKind.FunctionDeclaration || kind === ts.SyntaxKind.PropertyDeclaration else if (kind === ts.SyntaxKind.VariableDeclaration || kind === ts.SyntaxKind.FunctionDeclaration || kind === ts.SyntaxKind.PropertyDeclaration
|| kind === ts.SyntaxKind.MethodDeclaration || kind === ts.SyntaxKind.VariableDeclarationList || kind === ts.SyntaxKind.InterfaceDeclaration || kind === ts.SyntaxKind.MethodDeclaration || kind === ts.SyntaxKind.VariableDeclarationList || kind === ts.SyntaxKind.InterfaceDeclaration
|| kind === ts.SyntaxKind.ClassDeclaration || kind === ts.SyntaxKind.EnumDeclaration || kind === ts.SyntaxKind.ModuleDeclaration || kind === ts.SyntaxKind.ClassDeclaration || kind === ts.SyntaxKind.EnumDeclaration || kind === ts.SyntaxKind.ModuleDeclaration
|| kind === ts.SyntaxKind.TypeAliasDeclaration || kind === ts.SyntaxKind.SourceFile) { || kind === ts.SyntaxKind.TypeAliasDeclaration || kind === ts.SyntaxKind.SourceFile) {
return null; return null;
} }
node = parent; node = parent;
} }
}; };
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"'; NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
return NoUnexternalizedStringsRuleWalker; return NoUnexternalizedStringsRuleWalker;
}(Lint.RuleWalker)); }(Lint.RuleWalker));
...@@ -98,15 +98,15 @@ function skipDirectories() { ...@@ -98,15 +98,15 @@ function skipDirectories() {
} }
exports.skipDirectories = skipDirectories; exports.skipDirectories = skipDirectories;
function cleanNodeModule(name, excludes, includes) { function cleanNodeModule(name, excludes, includes) {
var glob = function (path) { return '**/node_modules/' + name + (path ? '/' + path : ''); }; var toGlob = function (path) { return '**/node_modules/' + name + (path ? '/' + path : ''); };
var negate = function (str) { return '!' + str; }; var negate = function (str) { return '!' + str; };
var allFilter = _filter(glob('**'), { restore: true }); var allFilter = _filter(toGlob('**'), { restore: true });
var globs = [glob('**')].concat(excludes.map(_.compose(negate, glob))); var globs = [toGlob('**')].concat(excludes.map(_.compose(negate, toGlob)));
var input = es.through(); var input = es.through();
var nodeModuleInput = input.pipe(allFilter); var nodeModuleInput = input.pipe(allFilter);
var output = nodeModuleInput.pipe(_filter(globs)); var output = nodeModuleInput.pipe(_filter(globs));
if (includes) { if (includes) {
var includeGlobs = includes.map(glob); var includeGlobs = includes.map(toGlob);
output = es.merge(output, nodeModuleInput.pipe(_filter(includeGlobs))); output = es.merge(output, nodeModuleInput.pipe(_filter(includeGlobs)));
} }
output = output.pipe(allFilter.restore); output = output.pipe(allFilter.restore);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册