tslint-microsoft-contrib
Advanced tools
Comparing version 0.0.1 to 0.0.3
@@ -24,9 +24,16 @@ var AstUtils; | ||
} | ||
return false; | ||
} | ||
if (expression.kind === 158) { | ||
if (expression.expression.name && expression.expression.name.text === 'bind') { | ||
if (isExpressionEvaluatingToFunction(expression.expression.expression, languageServices, typeChecker)) { | ||
return true; | ||
} | ||
return true; | ||
} | ||
try { | ||
var signature = typeChecker.getResolvedSignature(expression); | ||
var expressionType = typeChecker.getReturnTypeOfSignature(signature); | ||
return isTypeFunction(expressionType, typeChecker); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
@@ -41,3 +48,11 @@ if (expression.kind === 156) { | ||
} | ||
var expressionType = typeChecker.getTypeAtLocation(expression); | ||
if (isTypeFunction(typeChecker.getTypeAtLocation(expression), typeChecker)) { | ||
return true; | ||
} | ||
if (expression.getFullText() === 'functionArg') { | ||
} | ||
return false; | ||
} | ||
AstUtils.isExpressionEvaluatingToFunction = isExpressionEvaluatingToFunction; | ||
function isTypeFunction(expressionType, typeChecker) { | ||
var signatures = typeChecker.getSignaturesOfType(expressionType, 0); | ||
@@ -50,7 +65,4 @@ if (signatures != null && signatures.length > 0) { | ||
} | ||
if (expression.getFullText() === 'functionArg') { | ||
} | ||
return false; | ||
} | ||
AstUtils.isExpressionEvaluatingToFunction = isExpressionEvaluatingToFunction; | ||
function dumpTypeInfo(expression, languageServices, typeChecker) { | ||
@@ -57,0 +69,0 @@ console.log(expression.getFullText()); |
@@ -52,6 +52,6 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
node.parameters.forEach(function (parameter) { | ||
if (parameter.questionToken != null) { | ||
if (parameter.questionToken != null || parameter.initializer != null) { | ||
optionalParameterFound = true; | ||
} | ||
else if (optionalParameterFound) { | ||
else if (optionalParameterFound && parameter.initializer == null) { | ||
var msg = Rule.FAILURE_STRING + parameter.getFullText(); | ||
@@ -58,0 +58,0 @@ _this.addFailure(_this.createFailure(parameter.name.getStart(), parameter.name.getWidth(), msg)); |
@@ -17,4 +17,10 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var languageService = ts.createLanguageService(languageServiceHost, documentRegistry); | ||
return this.applyWithWalker(new NoUnusedImportsWalker(sourceFile, this.getOptions(), languageService)); | ||
var referencedDotImports = this.getReferencedDotImports(sourceFile, this.getOptions()); | ||
return this.applyWithWalker(new NoUnusedImportsWalker(sourceFile, this.getOptions(), languageService, referencedDotImports)); | ||
}; | ||
Rule.prototype.getReferencedDotImports = function (sourceFile, options) { | ||
var gatherImportHandler = new GatherNoRequireImportsWalker(sourceFile, options); | ||
this.applyWithWalker(gatherImportHandler); | ||
return gatherImportHandler.noRequireReferences; | ||
}; | ||
Rule.FAILURE_STRING = 'unused import: '; | ||
@@ -24,10 +30,37 @@ return Rule; | ||
exports.Rule = Rule; | ||
var GatherNoRequireImportsWalker = (function (_super) { | ||
__extends(GatherNoRequireImportsWalker, _super); | ||
function GatherNoRequireImportsWalker() { | ||
_super.apply(this, arguments); | ||
this.noRequireReferences = {}; | ||
} | ||
GatherNoRequireImportsWalker.prototype.visitImportEqualsDeclaration = function (node) { | ||
var moduleReference = node.moduleReference; | ||
if (moduleReference.kind === 127) { | ||
if (moduleReference.left != null) { | ||
this.gatherReferenceFromImport(moduleReference.left.text); | ||
} | ||
} | ||
_super.prototype.visitImportEqualsDeclaration.call(this, node); | ||
}; | ||
GatherNoRequireImportsWalker.prototype.gatherReferenceFromImport = function (qualifiedName) { | ||
var _this = this; | ||
if (qualifiedName) { | ||
qualifiedName.split('.').forEach(function (name) { | ||
_this.noRequireReferences[name] = true; | ||
}); | ||
} | ||
}; | ||
return GatherNoRequireImportsWalker; | ||
})(Lint.RuleWalker); | ||
var NoUnusedImportsWalker = (function (_super) { | ||
__extends(NoUnusedImportsWalker, _super); | ||
function NoUnusedImportsWalker(sourceFile, options, languageServices) { | ||
function NoUnusedImportsWalker(sourceFile, options, languageServices, noRequireReferences) { | ||
_super.call(this, sourceFile, options); | ||
this.noRequireReferences = {}; | ||
this.languageServices = languageServices; | ||
this.noRequireReferences = noRequireReferences; | ||
} | ||
NoUnusedImportsWalker.prototype.visitImportEqualsDeclaration = function (node) { | ||
if (!Lint.hasModifier(node.modifiers, 78)) { | ||
if (!this.hasModifier(node.modifiers, 78)) { | ||
this.validateReferencesForVariable(node.name.text, node.name.getStart()); | ||
@@ -37,6 +70,20 @@ } | ||
}; | ||
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) { | ||
var highlights = this.languageServices.getDocumentHighlights('file.ts', position, ['file.ts']); | ||
if (highlights[0].highlightSpans.length <= 1) { | ||
this.addFailure(this.createFailure(position, name.length, Rule.FAILURE_STRING + '\'' + name + '\'')); | ||
var references = this.languageServices.getReferencesAtPosition('file.ts', position); | ||
if (references.length <= 1 && !this.noRequireReferences[name]) { | ||
var failureString = Rule.FAILURE_STRING + '\'' + name + '\''; | ||
var failure = this.createFailure(position, name.length, failureString); | ||
this.addFailure(failure); | ||
} | ||
@@ -43,0 +90,0 @@ }; |
{ | ||
"name": "tslint-microsoft-contrib", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"description": "TSLint Rules for Microsoft", | ||
@@ -34,2 +34,2 @@ "repository": { | ||
"analyze": true | ||
} | ||
} |
@@ -7,3 +7,3 @@ | ||
Version 0.0.1 | ||
Version 0.0.4 | ||
------------- | ||
@@ -63,2 +63,3 @@ This software is not yet released with a 1.0 version. | ||
* `no-with-statement` Do not use with statements. Assign the item to a new variable instead | ||
* `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). | ||
@@ -77,9 +78,26 @@ | ||
grunt all | ||
Debug code | ||
----------- | ||
If command fails because of file access permissions, prefix it with sudo. | ||
npm install -g node-inspector | ||
node-inspector | ||
In another terminal window run: | ||
# on *nix machines: | ||
node --debug-brk /usr/local/bin/grunt mochaTest | ||
# on Windows machines: | ||
node --debug-brk /c/Users/[your alias]/AppData/Roaming/npm/node_modules/grunt-cli/bin/grunt | ||
Open in browser: | ||
http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 | ||
Set a breakpoint somewhere in your code and resume execution. Your breakpoint should be hit. | ||
Creating a new Release | ||
---------------------- | ||
1. Bump up the version number in package.json | ||
2. Run `grunt all` to build the latest sources | ||
3. Commit | ||
4. Create a git tag for the new release and push it | ||
Refer to the [Releases Wiki Page](https://github.com/Microsoft/tslint-microsoft-contrib/wiki/Releases) |
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
56804
27
1108
101