Comparing version 4.0.1 to 4.0.2
@@ -26,2 +26,3 @@ import * as Lint from 'tslint'; | ||
protected visitNgComponent(metadata: ComponentMetadata): void; | ||
protected visitNgModule(decorator: ts.Decorator): void; | ||
protected visitNgDirective(metadata: DirectiveMetadata): void; | ||
@@ -28,0 +29,0 @@ protected visitNgPipe(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; |
@@ -106,2 +106,5 @@ "use strict"; | ||
} | ||
if (name === 'NgModule') { | ||
this.visitNgModule(decorator); | ||
} | ||
if (!decorator.expression.arguments || | ||
@@ -148,2 +151,3 @@ !decorator.expression.arguments.length || | ||
}; | ||
NgWalker.prototype.visitNgModule = function (decorator) { }; | ||
NgWalker.prototype.visitNgDirective = function (metadata) { }; | ||
@@ -150,0 +154,0 @@ NgWalker.prototype.visitNgPipe = function (controller, decorator) { }; |
@@ -20,10 +20,19 @@ "use strict"; | ||
var recursiveAngularExpressionVisitor_1 = require("./angular/templates/recursiveAngularExpressionVisitor"); | ||
var stickyFlagUsable = (function () { | ||
try { | ||
var reg = new RegExp('\d', 'y'); | ||
return true; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
})(); | ||
var InterpolationOpen = config_1.Config.interpolation[0]; | ||
var InterpolationClose = config_1.Config.interpolation[1]; | ||
var InterpolationNoWhitespaceRe = new RegExp(InterpolationOpen + "\\S(.*?)\\S" + InterpolationClose + "|" + InterpolationOpen + | ||
("\\s(.*?)\\S" + InterpolationClose + "|" + InterpolationOpen + "\\S(.*?)\\s" + InterpolationClose), 'g'); | ||
var InterpolationExtraWhitespaceRe = new RegExp(InterpolationOpen + "\\s\\s(.*?)\\s" + InterpolationClose + "|" + InterpolationOpen + "\\s(.*?)\\s\\s" + InterpolationClose, 'g'); | ||
var SemicolonNoWhitespaceNotInSimpleQuoteRe = new RegExp(/;\S(?![^']*')/); | ||
var SemicolonNoWhitespaceNotInDoubleQuoteRe = new RegExp(/;\S(?![^"]*")/); | ||
var getSemicolonReplacements = function (text, absolutePosition) { | ||
var InterpolationWhitespaceRe = new RegExp(InterpolationOpen + "(\\s*)(.*?)(\\s*)" + InterpolationClose, 'g'); | ||
var SemicolonNoWhitespaceNotInSimpleQuoteRe = stickyFlagUsable ? | ||
new RegExp("(?:[^';]|'[^']*'|;(?=\\s))+;(?=\\S)", 'gy') : /(?:[^';]|'[^']*')+;/g; | ||
var SemicolonNoWhitespaceNotInDoubleQuoteRe = stickyFlagUsable ? | ||
new RegExp("(?:[^\";]|\"[^\"]*\"|;(?=\\s))+;(?=\\S)", 'gy') : /(?:[^";]|"[^"]*")+;/g; | ||
var getSemicolonReplacements = function (absolutePosition) { | ||
return [ | ||
@@ -33,2 +42,31 @@ new Lint.Replacement(absolutePosition, 1, '; ') | ||
}; | ||
var checkSemicolonNoWhitespaceWithSticky = function (reg, context, expr, fixedOffset) { | ||
var error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
var exprMatch; | ||
while (exprMatch = reg.exec(expr)) { | ||
var start = fixedOffset + reg.lastIndex; | ||
var absolutePosition = context.getSourcePosition(start - 1); | ||
context.addFailure(context.createFailure(start, 2, error, getSemicolonReplacements(absolutePosition))); | ||
} | ||
}; | ||
var checkSemicolonNoWhitespaceWithoutSticky = function (reg, context, expr, fixedOffset) { | ||
var error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
var lastIndex = 0; | ||
var exprMatch; | ||
while (exprMatch = reg.exec(expr)) { | ||
if (lastIndex !== exprMatch.index) { | ||
break; | ||
} | ||
var nextIndex = reg.lastIndex; | ||
if (nextIndex < expr.length && /\S/.test(expr[nextIndex])) { | ||
var start = fixedOffset + nextIndex; | ||
var absolutePosition = context.getSourcePosition(start - 1); | ||
context.addFailure(context.createFailure(start, 2, error, getSemicolonReplacements(absolutePosition))); | ||
} | ||
lastIndex = nextIndex; | ||
} | ||
}; | ||
var checkSemicolonNoWhitespace = stickyFlagUsable ? | ||
checkSemicolonNoWhitespaceWithSticky : | ||
checkSemicolonNoWhitespaceWithoutSticky; | ||
var InterpolationWhitespaceVisitor = (function (_super) { | ||
@@ -42,18 +80,22 @@ __extends(InterpolationWhitespaceVisitor, _super); | ||
var error = null; | ||
var expr_1 = text.value.source; | ||
var applyRegex = function (regex, failure) { | ||
var match; | ||
while (match = regex.exec(expr_1)) { | ||
var start = text.sourceSpan.start.offset + match.index; | ||
var absolutePosition = context.getSourcePosition(start); | ||
var length_1 = match[0].length; | ||
context.addFailure(context.createFailure(start, length_1, failure, [ | ||
new Lint.Replacement(absolutePosition, length_1, InterpolationOpen + " " + match[0].replace(InterpolationOpen, '').replace(InterpolationClose, '').trim() + " " + InterpolationClose) | ||
])); | ||
var expr = text.value.source; | ||
var checkWhiteSpace = function (subMatch, location, fixTo, position, absolutePosition, lengthFix) { | ||
var length = subMatch.length; | ||
if (length === 1) { | ||
return; | ||
} | ||
var errorText = length === 0 ? 'Missing' : 'Extra'; | ||
context.addFailure(context.createFailure(position, length + lengthFix, errorText + " whitespace in interpolation " + location + "; expecting " + InterpolationOpen + " expr " + InterpolationClose, [ | ||
new Lint.Replacement(absolutePosition, length + lengthFix, fixTo) | ||
])); | ||
}; | ||
InterpolationNoWhitespaceRe.lastIndex = 0; | ||
applyRegex(InterpolationNoWhitespaceRe, "Missing whitespace in interpolation; expecting " + InterpolationOpen + " expr " + InterpolationClose); | ||
InterpolationExtraWhitespaceRe.lastIndex = 0; | ||
applyRegex(InterpolationExtraWhitespaceRe, "Extra whitespace in interpolation; expecting " + InterpolationOpen + " expr " + InterpolationClose); | ||
InterpolationWhitespaceRe.lastIndex = 0; | ||
var match = void 0; | ||
while (match = InterpolationWhitespaceRe.exec(expr)) { | ||
var start = text.sourceSpan.start.offset + match.index; | ||
var absolutePosition = context.getSourcePosition(start); | ||
checkWhiteSpace(match[1], 'start', InterpolationOpen + " ", start, absolutePosition, InterpolationOpen.length); | ||
var positionFix = InterpolationOpen.length + match[1].length + match[2].length; | ||
checkWhiteSpace(match[3], 'end', " " + InterpolationClose, start + positionFix, absolutePosition + positionFix, InterpolationClose.length); | ||
} | ||
} | ||
@@ -76,20 +118,10 @@ _super.prototype.visitBoundText.call(this, text, context); | ||
var directive = prop.sourceSpan.toString(); | ||
var rawExpression = directive.split('=')[1].trim(); | ||
var expr = rawExpression.substring(1, rawExpression.length - 1).trim(); | ||
var doubleQuote = rawExpression.substring(0, 1).indexOf('\"') === 0; | ||
var error = null; | ||
if (doubleQuote && SemicolonNoWhitespaceNotInSimpleQuoteRe.test(expr)) { | ||
error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
var internalStart = expr.search(SemicolonNoWhitespaceNotInSimpleQuoteRe) + 1; | ||
var start = prop.sourceSpan.start.offset + internalStart + directive.length - directive.split('=')[1].trim().length + 1; | ||
var absolutePosition = context.getSourcePosition(start - 1); | ||
return context.addFailure(context.createFailure(start, 2, error, getSemicolonReplacements(prop, absolutePosition))); | ||
} | ||
else if (!doubleQuote && SemicolonNoWhitespaceNotInDoubleQuoteRe.test(expr)) { | ||
error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
var internalStart = expr.search(SemicolonNoWhitespaceNotInDoubleQuoteRe) + 1; | ||
var start = prop.sourceSpan.start.offset + internalStart + directive.length - directive.split('=')[1].trim().length + 1; | ||
var absolutePosition = context.getSourcePosition(start - 1); | ||
return context.addFailure(context.createFailure(start, 2, error, getSemicolonReplacements(prop, absolutePosition))); | ||
} | ||
var match = /^([^=]+=\s*)([^]*?)\s*$/.exec(directive); | ||
var rawExpression = match[2]; | ||
var positionFix = match[1].length + 1; | ||
var expr = rawExpression.slice(1, -1).trim(); | ||
var doubleQuote = rawExpression[0] === '"'; | ||
var reg = doubleQuote ? SemicolonNoWhitespaceNotInSimpleQuoteRe : SemicolonNoWhitespaceNotInDoubleQuoteRe; | ||
reg.lastIndex = 0; | ||
checkSemicolonNoWhitespace(reg, context, expr, prop.sourceSpan.start.offset + positionFix); | ||
} | ||
@@ -244,2 +276,3 @@ }; | ||
typescriptOnly: true, | ||
hasFix: true | ||
}; | ||
@@ -246,0 +279,0 @@ return Rule; |
@@ -71,2 +71,3 @@ "use strict"; | ||
typescriptOnly: true, | ||
hasFix: true | ||
}; | ||
@@ -73,0 +74,0 @@ return Rule; |
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
import { NgWalker } from './angular/ngWalker'; | ||
import { ComponentMetadata, DirectiveMetadata } from './angular/metadata'; | ||
export declare class Rule extends Lint.Rules.AbstractRule { | ||
@@ -15,2 +16,5 @@ static metadata: Lint.IRuleMetadata; | ||
visitNgInjectable(classDeclaration: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
protected visitNgDirective(metadata: DirectiveMetadata): void; | ||
protected visitNgPipe(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
protected visitNgComponent(metadata: ComponentMetadata): void; | ||
protected visitNgInput(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]): void; | ||
@@ -17,0 +21,0 @@ protected visitNgOutput(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]): void; |
@@ -50,3 +50,16 @@ "use strict"; | ||
this.isInjectable = true; | ||
_super.prototype.visitNgInjectable.call(this, classDeclaration, decorator); | ||
}; | ||
ClassMetadataWalker.prototype.visitNgDirective = function (metadata) { | ||
this.isInjectable = false; | ||
_super.prototype.visitNgDirective.call(this, metadata); | ||
}; | ||
ClassMetadataWalker.prototype.visitNgPipe = function (controller, decorator) { | ||
this.isInjectable = false; | ||
_super.prototype.visitNgPipe.call(this, controller, decorator); | ||
}; | ||
ClassMetadataWalker.prototype.visitNgComponent = function (metadata) { | ||
this.isInjectable = false; | ||
_super.prototype.visitNgComponent.call(this, metadata); | ||
}; | ||
ClassMetadataWalker.prototype.visitNgInput = function (property, input, args) { | ||
@@ -53,0 +66,0 @@ if (this.isInjectable) { |
@@ -27,2 +27,3 @@ export { Rule as AngularWhitespaceRule } from './angularWhitespaceRule'; | ||
export { Rule as TemplatesNoNegatedAsync } from './templatesNoNegatedAsyncRule'; | ||
export { Rule as TrackByFunctionRule } from './trackByFunctionRule'; | ||
export * from './angular/config'; |
@@ -58,2 +58,4 @@ "use strict"; | ||
exports.TemplatesNoNegatedAsync = templatesNoNegatedAsyncRule_1.Rule; | ||
var trackByFunctionRule_1 = require("./trackByFunctionRule"); | ||
exports.TrackByFunctionRule = trackByFunctionRule_1.Rule; | ||
__export(require("./angular/config")); |
@@ -156,2 +156,3 @@ "use strict"; | ||
typescriptOnly: true, | ||
hasFix: true | ||
}; | ||
@@ -158,0 +159,0 @@ return Rule; |
{ | ||
"name": "codelyzer", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Linting for Angular applications, following angular.io/styleguide.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,3 +54,3 @@ [![Build Status](https://travis-ci.org/mgechev/codelyzer.svg?branch=master)](https://travis-ci.org/mgechev/codelyzer) | ||
```shell | ||
npm i codelyzer@~3.1.0 tslint@^5.0.0 typescript@^2.1.4 @angular/core@4.2.1 @angular/compiler@4.2.1 rxjs@5.0.1 zone.js@0.8.4 | ||
npm i codelyzer@~4.0.0 tslint@^5.0.0 typescript@2.4.0 @angular/core@~5.0.1 @angular/compiler@~5.0.1 rxjs@5.5.0 zone.js@~0.8.4 | ||
``` | ||
@@ -78,4 +78,7 @@ | ||
"no-output-rename": true, | ||
"no-output-on-prefix": true, | ||
"no-forward-ref": true, | ||
"use-life-cycle-interface": true, | ||
"contextual-life-cycle": true, | ||
"trackBy-function": true, | ||
"use-pipe-transform-interface": true, | ||
@@ -114,3 +117,3 @@ "pipe-naming": [true, "camelCase", "sg"], | ||
"rules":{ | ||
"angular-whitespace": [true, "check-interpolation", "check-pipe"], | ||
"angular-whitespace": [true, "check-interpolation", "check-semicolon"], | ||
"banana-in-box": true, | ||
@@ -126,5 +129,8 @@ "templates-no-negated-async": true, | ||
"no-output-rename": true, | ||
"no-output-on-prefix": true, | ||
"no-forward-ref": true, | ||
"use-view-encapsulation": true, | ||
"use-life-cycle-interface": true, | ||
"contextual-life-cycle": true, | ||
"trackBy-function": true, | ||
"use-pipe-transform-interface": true, | ||
@@ -297,9 +303,9 @@ "pipe-naming": [true, "camelCase", "sg"], | ||
[<img alt="Gillespie59" src="https://avatars2.githubusercontent.com/u/555768?v=4&s=117" width="117">](https://github.com/Gillespie59) |[<img alt="Manduro" src="https://avatars0.githubusercontent.com/u/2545042?v=4&s=117" width="117">](https://github.com/Manduro) |[<img alt="karol-depka" src="https://avatars1.githubusercontent.com/u/958486?v=4&s=117" width="117">](https://github.com/karol-depka) |[<img alt="leosvelperez" src="https://avatars3.githubusercontent.com/u/12051310?v=4&s=117" width="117">](https://github.com/leosvelperez) |[<img alt="eromano" src="https://avatars1.githubusercontent.com/u/1030050?v=4&s=117" width="117">](https://github.com/eromano) |[<img alt="scttcper" src="https://avatars3.githubusercontent.com/u/1400464?v=4&s=117" width="117">](https://github.com/scttcper) | | ||
[<img alt="Gillespie59" src="https://avatars2.githubusercontent.com/u/555768?v=4&s=117" width="117">](https://github.com/Gillespie59) |[<img alt="Manduro" src="https://avatars0.githubusercontent.com/u/2545042?v=4&s=117" width="117">](https://github.com/Manduro) |[<img alt="karol-depka" src="https://avatars1.githubusercontent.com/u/958486?v=4&s=117" width="117">](https://github.com/karol-depka) |[<img alt="leosvelperez" src="https://avatars3.githubusercontent.com/u/12051310?v=4&s=117" width="117">](https://github.com/leosvelperez) |[<img alt="Martin-Wegner" src="https://avatars1.githubusercontent.com/u/8995517?v=4&s=117" width="117">](https://github.com/Martin-Wegner) |[<img alt="eromano" src="https://avatars1.githubusercontent.com/u/1030050?v=4&s=117" width="117">](https://github.com/eromano) | | ||
:---: |:---: |:---: |:---: |:---: |:---: | | ||
[Gillespie59](https://github.com/Gillespie59) |[Manduro](https://github.com/Manduro) |[karol-depka](https://github.com/karol-depka) |[leosvelperez](https://github.com/leosvelperez) |[eromano](https://github.com/eromano) |[scttcper](https://github.com/scttcper) | | ||
[Gillespie59](https://github.com/Gillespie59) |[Manduro](https://github.com/Manduro) |[karol-depka](https://github.com/karol-depka) |[leosvelperez](https://github.com/leosvelperez) |[Martin-Wegner](https://github.com/Martin-Wegner) |[eromano](https://github.com/eromano) | | ||
[<img alt="lacolaco" src="https://avatars3.githubusercontent.com/u/1529180?v=4&s=117" width="117">](https://github.com/lacolaco) |[<img alt="tmair" src="https://avatars2.githubusercontent.com/u/1596276?v=4&s=117" width="117">](https://github.com/tmair) |[<img alt="cexbrayat" src="https://avatars3.githubusercontent.com/u/411874?v=4&s=117" width="117">](https://github.com/cexbrayat) |[<img alt="reduckted" src="https://avatars0.githubusercontent.com/u/10321525?v=4&s=117" width="117">](https://github.com/reduckted) | | ||
:---: |:---: |:---: |:---: | | ||
[lacolaco](https://github.com/lacolaco) |[tmair](https://github.com/tmair) |[cexbrayat](https://github.com/cexbrayat) |[reduckted](https://github.com/reduckted) | | ||
[<img alt="scttcper" src="https://avatars3.githubusercontent.com/u/1400464?v=4&s=117" width="117">](https://github.com/scttcper) |[<img alt="lacolaco" src="https://avatars3.githubusercontent.com/u/1529180?v=4&s=117" width="117">](https://github.com/lacolaco) |[<img alt="tmair" src="https://avatars2.githubusercontent.com/u/1596276?v=4&s=117" width="117">](https://github.com/tmair) |[<img alt="cexbrayat" src="https://avatars3.githubusercontent.com/u/411874?v=4&s=117" width="117">](https://github.com/cexbrayat) |[<img alt="reduckted" src="https://avatars0.githubusercontent.com/u/10321525?v=4&s=117" width="117">](https://github.com/reduckted) | | ||
:---: |:---: |:---: |:---: |:---: | | ||
[scttcper](https://github.com/scttcper) |[lacolaco](https://github.com/lacolaco) |[tmair](https://github.com/tmair) |[cexbrayat](https://github.com/cexbrayat) |[reduckted](https://github.com/reduckted) | | ||
@@ -306,0 +312,0 @@ ## License |
@@ -73,2 +73,3 @@ "use strict"; | ||
typescriptOnly: true, | ||
hasFix: true | ||
}; | ||
@@ -75,0 +76,0 @@ return Rule; |
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
368765
130
8067
311