From 9a1959f77a1762c70d6f62e8111ee9be9fc86469 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 28 Mar 2016 14:25:22 -0700 Subject: [PATCH] build(tslint): re-enable linter and fix violations fixes #7798 Closes #7800 --- .../angular2/src/common/directives/ng_for.ts | 1 + .../src/common/directives/ng_plural.ts | 1 + .../radio_control_value_accessor.ts | 3 ++ .../select_control_value_accessor.ts | 6 +++ modules/angular2/src/compiler/css/lexer.ts | 53 ++++++++++--------- modules/angular2/src/compiler/css/parser.ts | 21 +++++++- .../src/compiler/directive_metadata.ts | 2 +- .../angular2/src/compiler/static_reflector.ts | 3 +- .../angular2/src/compiler/view_compiler.ts | 2 +- .../angular2/src/core/debug/debug_renderer.ts | 26 ++++----- modules/angular2/src/core/render/api.ts | 16 +++--- .../src/core/testability/testability.ts | 1 + modules/angular2/src/i18n/shared.ts | 4 +- modules/angular2/src/router/route_registry.ts | 2 +- modules/angular2/src/router/router.ts | 1 + .../rules/route_paths/regex_route_path.ts | 4 +- npm-shrinkwrap.clean.json | 19 ++----- npm-shrinkwrap.json | 41 ++++---------- package.json | 2 +- tools/public_api_guard/public_api_spec.ts | 14 ++--- tools/tslint/requireReturnTypeRule.ts | 6 +-- 21 files changed, 118 insertions(+), 110 deletions(-) diff --git a/modules/angular2/src/common/directives/ng_for.ts b/modules/angular2/src/common/directives/ng_for.ts index 4fd502fee3..8cff678e70 100644 --- a/modules/angular2/src/common/directives/ng_for.ts +++ b/modules/angular2/src/common/directives/ng_for.ts @@ -69,6 +69,7 @@ import {BaseException} from "../../facade/exceptions"; export class NgFor implements DoCheck { /** @internal */ _ngForOf: any; + /** @internal */ _ngForTrackBy: TrackByFn; private _differ: IterableDiffer; diff --git a/modules/angular2/src/common/directives/ng_plural.ts b/modules/angular2/src/common/directives/ng_plural.ts index 243d0052b7..e5e892c862 100644 --- a/modules/angular2/src/common/directives/ng_plural.ts +++ b/modules/angular2/src/common/directives/ng_plural.ts @@ -74,6 +74,7 @@ export abstract class NgLocalization { abstract getPluralCategory(value: any): s @Directive({selector: '[ngPluralCase]'}) export class NgPluralCase { + /** @internal */ _view: SwitchView; constructor(@Attribute('ngPluralCase') public value: string, template: TemplateRef, viewContainer: ViewContainerRef) { diff --git a/modules/angular2/src/common/forms/directives/radio_control_value_accessor.ts b/modules/angular2/src/common/forms/directives/radio_control_value_accessor.ts index b7ab63d546..ee9475643e 100644 --- a/modules/angular2/src/common/forms/directives/radio_control_value_accessor.ts +++ b/modules/angular2/src/common/forms/directives/radio_control_value_accessor.ts @@ -88,9 +88,12 @@ export class RadioButtonState { }) export class RadioControlValueAccessor implements ControlValueAccessor, OnDestroy, OnInit { + /** @internal */ _state: RadioButtonState; + /** @internal */ _control: NgControl; @Input() name: string; + /** @internal */ _fn: Function; onChange = () => {}; onTouched = () => {}; diff --git a/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts b/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts index d69cf32454..308e021d29 100644 --- a/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts +++ b/modules/angular2/src/common/forms/directives/select_control_value_accessor.ts @@ -44,7 +44,9 @@ function _extractId(valueString: string): string { }) export class SelectControlValueAccessor implements ControlValueAccessor { value: any; + /** @internal */ _optionMap: Map = new Map(); + /** @internal */ _idCounter: number = 0; onChange = (_: any) => {}; @@ -63,8 +65,10 @@ export class SelectControlValueAccessor implements ControlValueAccessor { } registerOnTouched(fn: () => any): void { this.onTouched = fn; } + /** @internal */ _registerOption(): string { return (this._idCounter++).toString(); } + /** @internal */ _getOptionId(value: any): string { for (let id of MapWrapper.keys(this._optionMap)) { if (looseIdentical(this._optionMap.get(id), value)) return id; @@ -72,6 +76,7 @@ export class SelectControlValueAccessor implements ControlValueAccessor { return null; } + /** @internal */ _getOptionValue(valueString: string): any { let value = this._optionMap.get(_extractId(valueString)); return isPresent(value) ? value : valueString; @@ -113,6 +118,7 @@ export class NgSelectOption implements OnDestroy { this._select.writeValue(this._select.value); } + /** @internal */ _setElementValue(value: string): void { this._renderer.setElementProperty(this._element.nativeElement, 'value', value); } diff --git a/modules/angular2/src/compiler/css/lexer.ts b/modules/angular2/src/compiler/css/lexer.ts index f7d8a251a2..1f79ea870e 100644 --- a/modules/angular2/src/compiler/css/lexer.ts +++ b/modules/angular2/src/compiler/css/lexer.ts @@ -94,12 +94,14 @@ export class LexedCssResult { constructor(public error: CssScannerError, public token: CssToken) {} } -export function generateErrorMessage(input, message, errorValue, index, row, column) { +export function generateErrorMessage(input: string, message: string, errorValue: string, + index: number, row: number, column: number): string { return `${message} at column ${row}:${column} in expression [` + findProblemCode(input, errorValue, index, column) + ']'; } -export function findProblemCode(input, errorValue, index, column) { +export function findProblemCode(input: string, errorValue: string, index: number, + column: number): string { var endOfProblemLine = index; var current = charCode(input, index); while (current > 0 && !isNewline(current)) { @@ -163,7 +165,9 @@ export class CssScanner { column: number = -1; line: number = 0; + /** @internal */ _currentMode: CssLexerMode = CssLexerMode.BLOCK; + /** @internal */ _currentError: CssScannerError = null; constructor(public input: string, private _trackComments: boolean = false) { @@ -196,7 +200,7 @@ export class CssScanner { this.peekPeek = this.peekAt(this.index + 1); } - peekAt(index): number { + peekAt(index: number): number { return index >= this.length ? $EOF : StringWrapper.charCodeAt(this.input, index); } @@ -295,6 +299,7 @@ export class CssScanner { return new LexedCssResult(error, token); } + /** @internal */ _scan(): CssToken { var peek = this.peek; var peekPeek = this.peekPeek; @@ -348,7 +353,7 @@ export class CssScanner { return this.error(`Unexpected character [${StringWrapper.fromCharCode(peek)}]`); } - scanComment() { + scanComment(): CssToken { if (this.assertCondition(isCommentStart(this.peek, this.peekPeek), "Expected comment start value")) { return null; @@ -375,7 +380,7 @@ export class CssScanner { return new CssToken(start, startingColumn, startingLine, CssTokenType.Comment, str); } - scanWhitespace() { + scanWhitespace(): CssToken { var start = this.index; var startingColumn = this.column; var startingLine = this.line; @@ -386,7 +391,7 @@ export class CssScanner { return new CssToken(start, startingColumn, startingLine, CssTokenType.Whitespace, str); } - scanString() { + scanString(): CssToken { if (this.assertCondition(isStringStart(this.peek, this.peekPeek), "Unexpected non-string starting value")) { return null; @@ -416,7 +421,7 @@ export class CssScanner { return new CssToken(start, startingColumn, startingLine, CssTokenType.String, str); } - scanNumber() { + scanNumber(): CssToken { var start = this.index; var startingColumn = this.column; if (this.peek == $PLUS || this.peek == $MINUS) { @@ -436,7 +441,7 @@ export class CssScanner { return new CssToken(start, startingColumn, this.line, CssTokenType.Number, strValue); } - scanIdentifier() { + scanIdentifier(): CssToken { if (this.assertCondition(isIdentifierStart(this.peek, this.peekPeek), 'Expected identifier starting value')) { return null; @@ -451,7 +456,7 @@ export class CssScanner { return new CssToken(start, startingColumn, this.line, CssTokenType.Identifier, strValue); } - scanCssValueFunction() { + scanCssValueFunction(): CssToken { var start = this.index; var startingColumn = this.column; while (this.peek != $EOF && this.peek != $RPAREN) { @@ -461,7 +466,7 @@ export class CssScanner { return new CssToken(start, startingColumn, this.line, CssTokenType.Identifier, strValue); } - scanCharacter() { + scanCharacter(): CssToken { var start = this.index; var startingColumn = this.column; if (this.assertCondition(isValidCssCharacter(this.peek, this._currentMode), @@ -475,7 +480,7 @@ export class CssScanner { return new CssToken(start, startingColumn, this.line, CssTokenType.Character, c); } - scanAtExpression() { + scanAtExpression(): CssToken { if (this.assertCondition(this.peek == $AT, 'Expected @ value')) { return null; } @@ -521,7 +526,7 @@ function isAtKeyword(current: CssToken, next: CssToken): boolean { return current.numValue == $AT && next.type == CssTokenType.Identifier; } -function isCharMatch(target: number, previous: number, code: number) { +function isCharMatch(target: number, previous: number, code: number): boolean { return code == target && previous != $BACKSLASH; } @@ -529,11 +534,11 @@ function isDigit(code: number): boolean { return $0 <= code && code <= $9; } -function isCommentStart(code: number, next: number) { +function isCommentStart(code: number, next: number): boolean { return code == $SLASH && next == $STAR; } -function isCommentEnd(code: number, next: number) { +function isCommentEnd(code: number, next: number): boolean { return code == $STAR && next == $SLASH; } @@ -555,12 +560,12 @@ function isIdentifierStart(code: number, next: number): boolean { target == $MINUS || target == $_; } -function isIdentifierPart(target: number) { +function isIdentifierPart(target: number): boolean { return ($a <= target && target <= $z) || ($A <= target && target <= $Z) || target == $BACKSLASH || target == $MINUS || target == $_ || isDigit(target); } -function isValidPseudoSelectorCharacter(code: number) { +function isValidPseudoSelectorCharacter(code: number): boolean { switch (code) { case $LPAREN: case $RPAREN: @@ -570,11 +575,11 @@ function isValidPseudoSelectorCharacter(code: number) { } } -function isValidKeyframeBlockCharacter(code: number) { +function isValidKeyframeBlockCharacter(code: number): boolean { return code == $PERCENT; } -function isValidAttributeSelectorCharacter(code: number) { +function isValidAttributeSelectorCharacter(code: number): boolean { // value^*|$~=something switch (code) { case $$: @@ -589,7 +594,7 @@ function isValidAttributeSelectorCharacter(code: number) { } } -function isValidSelectorCharacter(code: number) { +function isValidSelectorCharacter(code: number): boolean { // selector [ key = value ] // IDENT C IDENT C IDENT C // #id, .class, *+~> @@ -610,7 +615,7 @@ function isValidSelectorCharacter(code: number) { } } -function isValidStyleBlockCharacter(code: number) { +function isValidStyleBlockCharacter(code: number): boolean { // key:value; // key:calc(something ... ) switch (code) { @@ -630,7 +635,7 @@ function isValidStyleBlockCharacter(code: number) { } } -function isValidMediaQueryRuleCharacter(code: number) { +function isValidMediaQueryRuleCharacter(code: number): boolean { // (min-width: 7.5em) and (orientation: landscape) switch (code) { case $LPAREN: @@ -644,7 +649,7 @@ function isValidMediaQueryRuleCharacter(code: number) { } } -function isValidAtRuleCharacter(code: number) { +function isValidAtRuleCharacter(code: number): boolean { // @document url(http://www.w3.org/page?something=on#hash), switch (code) { case $LPAREN: @@ -668,7 +673,7 @@ function isValidAtRuleCharacter(code: number) { } } -function isValidStyleFunctionCharacter(code: number) { +function isValidStyleFunctionCharacter(code: number): boolean { switch (code) { case $PERIOD: case $MINUS: @@ -684,7 +689,7 @@ function isValidStyleFunctionCharacter(code: number) { } } -function isValidBlockCharacter(code: number) { +function isValidBlockCharacter(code: number): boolean { // @something { } // IDENT return code == $AT; diff --git a/modules/angular2/src/compiler/css/parser.ts b/modules/angular2/src/compiler/css/parser.ts index 9bfad5ac85..00267ccca6 100644 --- a/modules/angular2/src/compiler/css/parser.ts +++ b/modules/angular2/src/compiler/css/parser.ts @@ -95,7 +95,7 @@ function getDelimFromCharacter(code: number): number { } } -function characterContainsDelimiter(code: number, delimiters: number) { +function characterContainsDelimiter(code: number, delimiters: number): boolean { return bitWiseAnd([getDelimFromCharacter(code), delimiters]) > 0; } @@ -129,6 +129,7 @@ export class CssParser { this._file = new ParseSourceFile(this._scanner.input, _fileName); } + /** @internal */ _resolveBlockType(token: CssToken): BlockType { switch (token.strValue) { case '@-o-keyframes': @@ -179,6 +180,7 @@ export class CssParser { return new ParsedCssResult(errors, ast); } + /** @internal */ _parseStyleSheet(delimiters): CssStyleSheetAST { var results = []; this._scanner.consumeEmptyStatements(); @@ -189,6 +191,7 @@ export class CssParser { return new CssStyleSheetAST(results); } + /** @internal */ _parseRule(delimiters: number): CssRuleAST { if (this._scanner.peek == $AT) { return this._parseAtRule(delimiters); @@ -196,6 +199,7 @@ export class CssParser { return this._parseSelectorRule(delimiters); } + /** @internal */ _parseAtRule(delimiters: number): CssRuleAST { this._scanner.setMode(CssLexerMode.BLOCK); @@ -259,6 +263,7 @@ export class CssParser { } } + /** @internal */ _parseSelectorRule(delimiters: number): CssSelectorRuleAST { var selectors = this._parseSelectors(delimiters); var block = this._parseStyleBlock(delimiters); @@ -267,6 +272,7 @@ export class CssParser { return new CssSelectorRuleAST(selectors, block); } + /** @internal */ _parseSelectors(delimiters: number): CssSelectorAST[] { delimiters = bitWiseOr([delimiters, LBRACE_DELIM]); @@ -286,6 +292,7 @@ export class CssParser { return selectors; } + /** @internal */ _scan(): CssToken { var output = this._scanner.scan(); var token = output.token; @@ -296,6 +303,7 @@ export class CssParser { return token; } + /** @internal */ _consume(type: CssTokenType, value: string = null): CssToken { var output = this._scanner.consume(type, value); var token = output.token; @@ -306,6 +314,7 @@ export class CssParser { return token; } + /** @internal */ _parseKeyframeBlock(delimiters: number): CssBlockAST { delimiters = bitWiseOr([delimiters, RBRACE_DELIM]); this._scanner.setMode(CssLexerMode.KEYFRAME_BLOCK); @@ -322,6 +331,7 @@ export class CssParser { return new CssBlockAST(definitions); } + /** @internal */ _parseKeyframeDefinition(delimiters: number): CssKeyframeDefinitionAST { var stepTokens = []; delimiters = bitWiseOr([delimiters, LBRACE_DELIM]); @@ -336,11 +346,13 @@ export class CssParser { return new CssKeyframeDefinitionAST(stepTokens, styles); } + /** @internal */ _parseKeyframeLabel(delimiters: number): CssToken { this._scanner.setMode(CssLexerMode.KEYFRAME_BLOCK); return mergeTokens(this._collectUntilDelim(delimiters)); } + /** @internal */ _parseSelector(delimiters: number): CssSelectorAST { delimiters = bitWiseOr([delimiters, COMMA_DELIM, LBRACE_DELIM]); this._scanner.setMode(CssLexerMode.SELECTOR); @@ -435,6 +447,7 @@ export class CssParser { return new CssSelectorAST(selectorCssTokens, isComplex); } + /** @internal */ _parseValue(delimiters: number): CssStyleValueAST { delimiters = bitWiseOr([delimiters, RBRACE_DELIM, SEMICOLON_DELIM, NEWLINE_DELIM]); @@ -489,6 +502,7 @@ export class CssParser { return new CssStyleValueAST(tokens, strValue); } + /** @internal */ _collectUntilDelim(delimiters: number, assertType: CssTokenType = null): CssToken[] { var tokens = []; while (!characterContainsDelimiter(this._scanner.peek, delimiters)) { @@ -498,6 +512,7 @@ export class CssParser { return tokens; } + /** @internal */ _parseBlock(delimiters: number): CssBlockAST { delimiters = bitWiseOr([delimiters, RBRACE_DELIM]); @@ -519,6 +534,7 @@ export class CssParser { return new CssBlockAST(results); } + /** @internal */ _parseStyleBlock(delimiters: number): CssBlockAST { delimiters = bitWiseOr([delimiters, RBRACE_DELIM, LBRACE_DELIM]); @@ -541,6 +557,7 @@ export class CssParser { return new CssBlockAST(definitions); } + /** @internal */ _parseDefinition(delimiters: number): CssDefinitionAST { this._scanner.setMode(CssLexerMode.STYLE_BLOCK); @@ -600,6 +617,7 @@ export class CssParser { return new CssDefinitionAST(prop, value); } + /** @internal */ _assertCondition(status: boolean, errorMessage: string, problemToken: CssToken): boolean { if (!status) { this._error(errorMessage, problemToken); @@ -608,6 +626,7 @@ export class CssParser { return false; } + /** @internal */ _error(message: string, problemToken: CssToken) { var length = problemToken.strValue.length; var error = CssParseError.create(this._file, 0, problemToken.line, problemToken.column, length, diff --git a/modules/angular2/src/compiler/directive_metadata.ts b/modules/angular2/src/compiler/directive_metadata.ts index bf5c08ea27..1ce1af272b 100644 --- a/modules/angular2/src/compiler/directive_metadata.ts +++ b/modules/angular2/src/compiler/directive_metadata.ts @@ -214,7 +214,7 @@ export class CompileFactoryMetadata implements CompileIdentifierMetadata { get identifier(): CompileIdentifierMetadata { return this; } - toJson() { return null; } + toJson(): {[key: string]: any} { return null; } } /** diff --git a/modules/angular2/src/compiler/static_reflector.ts b/modules/angular2/src/compiler/static_reflector.ts index 4a15eeccd4..925466e4ee 100644 --- a/modules/angular2/src/compiler/static_reflector.ts +++ b/modules/angular2/src/compiler/static_reflector.ts @@ -121,7 +121,7 @@ export class StaticReflector { } private conversionMap = new Map any>(); - private initializeConversionMap() { + private initializeConversionMap(): any { let core_metadata = 'angular2/src/core/metadata'; let conversionMap = this.conversionMap; conversionMap.set(this.getStaticType(core_metadata, 'Directive'), @@ -244,6 +244,7 @@ export class StaticReflector { (moduleContext, expression) => new HostListenerMetadata( this.getDecoratorParameter(moduleContext, expression, 0), this.getDecoratorParameter(moduleContext, expression, 1))); + return null; } private convertKnownDecorator(moduleContext: string, expression: {[key: string]: any}): any { diff --git a/modules/angular2/src/compiler/view_compiler.ts b/modules/angular2/src/compiler/view_compiler.ts index d3142d153b..9c7f328931 100644 --- a/modules/angular2/src/compiler/view_compiler.ts +++ b/modules/angular2/src/compiler/view_compiler.ts @@ -200,7 +200,7 @@ class CodeGenViewFactory implements ViewFactory { createElementEventListener(renderer: Expression, appView: Expression, boundElementIndex: number, renderNode: Expression, eventAst: BoundEventAst, - targetStatements: Statement[]) { + targetStatements: Statement[]): Expression { var disposableVar = this._nextDisposableVar(); var eventHandlerExpr = codeGenEventHandler(appView, boundElementIndex, eventAst.fullName); targetStatements.push(new Statement( diff --git a/modules/angular2/src/core/debug/debug_renderer.ts b/modules/angular2/src/core/debug/debug_renderer.ts index 955f610fee..2935581514 100644 --- a/modules/angular2/src/core/debug/debug_renderer.ts +++ b/modules/angular2/src/core/debug/debug_renderer.ts @@ -65,7 +65,7 @@ export class DebugDomRenderer implements Renderer { if (isPresent(debugParent) && debugParent instanceof DebugElement) { nodes.forEach((node) => { debugParent.addChild(getDebugNode(node)); }); } - return this._delegate.projectNodes(parentElement, nodes); + this._delegate.projectNodes(parentElement, nodes); } attachViewAfter(node: any, viewRootNodes: any[]) { @@ -78,7 +78,7 @@ export class DebugDomRenderer implements Renderer { debugParent.insertChildrenAfter(debugNode, debugViewRootNodes); } } - return this._delegate.attachViewAfter(node, viewRootNodes); + this._delegate.attachViewAfter(node, viewRootNodes); } detachView(viewRootNodes: any[]) { @@ -88,15 +88,15 @@ export class DebugDomRenderer implements Renderer { debugNode.parent.removeChild(debugNode); } }); - return this._delegate.detachView(viewRootNodes); + this._delegate.detachView(viewRootNodes); } destroyView(hostElement: any, viewAllNodes: any[]) { viewAllNodes.forEach((node) => { removeDebugNodeFromIndex(getDebugNode(node)); }); - return this._delegate.destroyView(hostElement, viewAllNodes); + this._delegate.destroyView(hostElement, viewAllNodes); } - listen(renderElement: any, name: string, callback: Function) { + listen(renderElement: any, name: string, callback: Function): Function { var debugEl = getDebugNode(renderElement); if (isPresent(debugEl)) { debugEl.listeners.push(new EventListener(name, callback)); @@ -113,7 +113,7 @@ export class DebugDomRenderer implements Renderer { if (isPresent(debugEl) && debugEl instanceof DebugElement) { debugEl.properties.set(propertyName, propertyValue); } - return this._delegate.setElementProperty(renderElement, propertyName, propertyValue); + this._delegate.setElementProperty(renderElement, propertyName, propertyValue); } setElementAttribute(renderElement: any, attributeName: string, attributeValue: string) { @@ -121,7 +121,7 @@ export class DebugDomRenderer implements Renderer { if (isPresent(debugEl) && debugEl instanceof DebugElement) { debugEl.attributes.set(attributeName, attributeValue); } - return this._delegate.setElementAttribute(renderElement, attributeName, attributeValue); + this._delegate.setElementAttribute(renderElement, attributeName, attributeValue); } /** @@ -129,7 +129,7 @@ export class DebugDomRenderer implements Renderer { * such as