tslint-microsoft-contrib
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -9,2 +9,4 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var Utils = require('./utils/Utils'); | ||
var SyntaxKind = require('./utils/SyntaxKind'); | ||
var AstUtils = require('./utils/AstUtils'); | ||
var Rule = (function (_super) { | ||
@@ -27,3 +29,3 @@ __extends(Rule, _super); | ||
}; | ||
Rule.FAILURE_STRING = 'The exported module name must match the file name. Found: '; | ||
Rule.FAILURE_STRING = 'The exported module or identifier name must match the file name. Found: '; | ||
return Rule; | ||
@@ -37,4 +39,33 @@ })(Lint.Rules.AbstractRule); | ||
} | ||
ExportNameWalker.prototype.visitExportAssignment = function (node) { | ||
var exportedName = node.expression.getText(); | ||
ExportNameWalker.prototype.visitSourceFile = function (node) { | ||
var _this = this; | ||
var exportedTopLevelElements = []; | ||
node.statements.forEach(function (element) { | ||
if (element.kind === SyntaxKind.current().ExportAssignment) { | ||
var exportAssignment = element; | ||
_this.validateExport(exportAssignment.expression.getText(), exportAssignment.expression); | ||
} | ||
else if (AstUtils.hasModifier(element.modifiers, SyntaxKind.current().ExportKeyword)) { | ||
exportedTopLevelElements.push(element); | ||
} | ||
}); | ||
this.validateExportedElements(exportedTopLevelElements); | ||
}; | ||
ExportNameWalker.prototype.validateExportedElements = function (exportedElements) { | ||
if (exportedElements.length === 1) { | ||
if (exportedElements[0].kind === SyntaxKind.current().ModuleDeclaration || | ||
exportedElements[0].kind === SyntaxKind.current().ClassDeclaration || | ||
exportedElements[0].kind === SyntaxKind.current().FunctionDeclaration) { | ||
this.validateExport(exportedElements[0].name.text, exportedElements[0]); | ||
} | ||
else if (exportedElements[0].kind === SyntaxKind.current().VariableStatement) { | ||
var variableStatement = exportedElements[0]; | ||
if (variableStatement.declarationList.declarations.length === 1) { | ||
var variableDeclaration = variableStatement.declarationList.declarations[0]; | ||
this.validateExport(variableDeclaration.name.text, variableDeclaration); | ||
} | ||
} | ||
} | ||
}; | ||
ExportNameWalker.prototype.validateExport = function (exportedName, node) { | ||
var regex = new RegExp(exportedName + '\..*'); | ||
@@ -44,7 +75,6 @@ if (!regex.test(this.getFilename())) { | ||
var failureString = Rule.FAILURE_STRING + this.getSourceFile().fileName + ' and ' + exportedName; | ||
var failure = this.createFailure(node.expression.getStart(), node.expression.getWidth(), failureString); | ||
var failure = this.createFailure(node.getStart(), node.getWidth(), failureString); | ||
this.addFailure(failure); | ||
} | ||
} | ||
_super.prototype.visitExportAssignment.call(this, node); | ||
}; | ||
@@ -67,2 +97,3 @@ ExportNameWalker.prototype.getFilename = function () { | ||
})(ErrorTolerantWalker); | ||
exports.ExportNameWalker = ExportNameWalker; | ||
//# sourceMappingURL=exportNameRule.js.map |
@@ -26,3 +26,3 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
NoEmptyInterfacesRuleWalker.prototype.visitInterfaceDeclaration = function (node) { | ||
if (node.members == null || node.members.length === 0) { | ||
if (this.isInterfaceEmpty(node) && !this.hasMultipleParents(node)) { | ||
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + '\'' + node.name.getText() + '\'')); | ||
@@ -32,4 +32,13 @@ } | ||
}; | ||
NoEmptyInterfacesRuleWalker.prototype.isInterfaceEmpty = function (node) { | ||
return node.members == null || node.members.length === 0; | ||
}; | ||
NoEmptyInterfacesRuleWalker.prototype.hasMultipleParents = function (node) { | ||
if (node.heritageClauses == null || node.heritageClauses.length === 0) { | ||
return false; | ||
} | ||
return node.heritageClauses[0].types.length >= 2; | ||
}; | ||
return NoEmptyInterfacesRuleWalker; | ||
})(ErrorTolerantWalker); | ||
//# sourceMappingURL=noEmptyInterfacesRule.js.map |
@@ -10,2 +10,3 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker'); | ||
var AstUtils = require('./utils/AstUtils'); | ||
var Rule = (function (_super) { | ||
@@ -66,3 +67,3 @@ __extends(Rule, _super); | ||
NoUnusedImportsWalker.prototype.visitImportEqualsDeclaration = function (node) { | ||
if (!this.hasModifier(node.modifiers, SyntaxKind.current().ExportKeyword)) { | ||
if (!AstUtils.hasModifier(node.modifiers, SyntaxKind.current().ExportKeyword)) { | ||
this.validateReferencesForVariable(node.name.text, node.name.getStart()); | ||
@@ -72,14 +73,2 @@ } | ||
}; | ||
NoUnusedImportsWalker.prototype.hasModifier = function (modifiers, modifierKind) { | ||
if (modifiers == null) { | ||
return false; | ||
} | ||
var result = false; | ||
modifiers.forEach(function (modifier) { | ||
if (modifier.kind === modifierKind) { | ||
result = true; | ||
} | ||
}); | ||
return result; | ||
}; | ||
NoUnusedImportsWalker.prototype.validateReferencesForVariable = function (name, position) { | ||
@@ -86,0 +75,0 @@ var references = this.languageServices.getReferencesAtPosition('file.ts', position); |
{ | ||
"name": "tslint-microsoft-contrib", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "TSLint Rules for Microsoft", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -9,2 +9,3 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker'); | ||
var AstUtils = require('./utils/AstUtils'); | ||
var Rule = (function (_super) { | ||
@@ -18,3 +19,4 @@ __extends(Rule, _super); | ||
}; | ||
Rule.FAILURE_STRING = 'Replace generic-typed Array with array literal: '; | ||
Rule.GENERICS_FAILURE_STRING = 'Replace generic-typed Array with array literal: '; | ||
Rule.CONSTRUCTOR_FAILURE_STRING = 'Replace Array constructor with an array literal: '; | ||
return Rule; | ||
@@ -32,3 +34,3 @@ })(Lint.Rules.AbstractRule); | ||
if (ref.typeName.text === 'Array') { | ||
var failureString = Rule.FAILURE_STRING + node.getText(); | ||
var failureString = Rule.GENERICS_FAILURE_STRING + node.getText(); | ||
var failure = this.createFailure(node.getStart(), node.getWidth(), failureString); | ||
@@ -40,4 +42,12 @@ this.addFailure(failure); | ||
}; | ||
NoGenericArrayWalker.prototype.visitNewExpression = function (node) { | ||
var functionName = AstUtils.getFunctionName(node); | ||
if (functionName === 'Array') { | ||
var failureString = Rule.CONSTRUCTOR_FAILURE_STRING + node.getText(); | ||
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), failureString)); | ||
} | ||
_super.prototype.visitNewExpression.call(this, node); | ||
}; | ||
return NoGenericArrayWalker; | ||
})(ErrorTolerantWalker); | ||
//# sourceMappingURL=preferArrayLiteralRule.js.map |
@@ -11,8 +11,9 @@ [![npm version](https://badge.fury.io/js/tslint-microsoft-contrib.svg)](https://badge.fury.io/js/tslint-microsoft-contrib) | ||
Version 2.0.0 | ||
Version 2.0.1 | ||
------------- | ||
The project has been in use for at least several months on multiple projects. Please report any bugs or false positives you might find! | ||
The project has been in use for at least several months on multiple projects. Please report any bugs or false positives you might find! | ||
**TSLint version 3.x users**: use project tslint-microsoft-contrib version 2.x | ||
**TSLint version 3.2.x users**: use project tslint-microsoft-contrib version 2.x | ||
**TSLint version 3.1.x users**: Unsupported | ||
**TSLint version 3.0.x users**: Unsupported | ||
**TSLint version 2.x users**: use project tslint-microsoft-contrib version 1.x | ||
@@ -25,5 +26,6 @@ | ||
Alternately, you can download the files directly from GitHub: | ||
Alternately, you can download the files directly from GitHub: | ||
* [Latest Development Version](https://github.com/Microsoft/tslint-microsoft-contrib/tree/releases) | ||
* [2.0.0](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-2.0.0) | ||
* [1.0.0](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-1.0.0) | ||
@@ -95,2 +97,3 @@ * [0.0.4](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-0.0.4) | ||
`no-string-based-set-timeout` | Do not use the version of setTimeout that accepts code as a string argument. However, it is acceptable to use the version of setTimeout where a direct reference to a function is provided as the callback argument | 0.0.1 | ||
`no-unexternalized-strings` | Ensures that double quoted strings are passed to a localize call to provide proper strings for different locales. The rule can be configured using an object literal as document in the [feature request](https://github.com/Microsoft/tslint-microsoft-contrib/issues/95#issuecomment-173149989)| 2.0.1 | ||
`no-unnecessary-semicolons` | Remove unnecessary semicolons | 0.0.1 | ||
@@ -100,3 +103,3 @@ `no-unnecessary-bind` | Do not bind 'this' as the context for a function literal or lambda expression. If you bind 'this' as the context to a function literal, then you should just use a lambda without the bind. If you bind 'this' as the context to a lambda, then you can remove the bind call because 'this' is already the context for lambdas. Works for Underscore methods as well. | 1.0 | ||
`no-with-statement` | Do not use with statements. Assign the item to a new variable instead | 0.0.1 | ||
`prefer-array-literal` | Use array literal syntax when declaring array types instead of the Array object with a generic parameter type. For example, prefer the Javascript from of string[] to the TypeScript form Array<string> | 1.0 | ||
`prefer-array-literal` | Use array literal syntax when declaring or instantiating array types. For example, prefer the Javascript from of string[] to the TypeScript form Array<string>. Prefer '[]' to 'new Array()'. Prefer '[4, 5]' to 'new Array(4,5)'. Prefer '[undefined, undefined]' to 'new Array(4)'. | 1.0 | ||
`promise-must-complete` | When a Promise instance is created, then either the reject() or resolve() parameter must be called on it within all code branches in the scope. For more examples see the [feature request](https://github.com/Microsoft/tslint-microsoft-contrib/issues/34). | 1.0 | ||
@@ -103,0 +106,0 @@ `react-no-dangerous-html` | Do not use React's dangerouslySetInnerHTML API. This rule finds usages of the dangerouslySetInnerHTML API (but not any JSX references). For more info see the [react-no-dangerous-html Rule wiki page](https://github.com/Microsoft/tslint-microsoft-contrib/wiki/react-no-dangerous-html-Rule). | 0.0.2 |
@@ -22,2 +22,15 @@ var ts = require('typescript'); | ||
AstUtils.getFunctionTarget = getFunctionTarget; | ||
function hasModifier(modifiers, modifierKind) { | ||
if (modifiers == null) { | ||
return false; | ||
} | ||
var result = false; | ||
modifiers.forEach(function (modifier) { | ||
if (modifier.kind === modifierKind) { | ||
result = true; | ||
} | ||
}); | ||
return result; | ||
} | ||
AstUtils.hasModifier = hasModifier; | ||
function dumpTypeInfo(expression, languageServices, typeChecker) { | ||
@@ -24,0 +37,0 @@ console.log(expression.getFullText()); |
@@ -18,5 +18,5 @@ var Utils; | ||
if (list != null) { | ||
for (var i = 0; i < list.length; i++) { | ||
result = predicate(result, list[i]); | ||
} | ||
list.forEach(function (element) { | ||
result = predicate(result, element); | ||
}); | ||
} | ||
@@ -23,0 +23,0 @@ return result; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181388
55
3868
144