Skip to content

Commit

Permalink
chore(lint): require semicolons
Browse files Browse the repository at this point in the history
Relying on ASI (automatic semicolon insertion)
is allowed in TypeScript because JavaScript allows
it. However, when we run clang-format it doesn’t
understand that these statements are terminated
with a newline and changes the indentation, in bad
cases even breaking the code.

Fixes #817
  • Loading branch information
alexeagle committed Jul 15, 2015
1 parent 33500e9 commit 93055f7
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions gulpfile.js
Expand Up @@ -278,6 +278,7 @@ gulp.task('lint', ['build.tools'], function() {
// https://github.com/palantir/tslint#supported-rules
var tslintConfig = {
"rules": {
"semicolon": true,
"requireReturnType": true
}
};
Expand Down
Expand Up @@ -182,7 +182,7 @@ export class ChangeDetectorJITGenerator {
var lines = ListWrapper.createFixedSize(directiveFieldNames.length);
for (var i = 0, iLen = directiveFieldNames.length; i < iLen; ++i) {
lines[i] =
`${directiveFieldNames[i]} = directives.getDirectiveFor(${DIRECTIVES_ACCESSOR}[${i}].directiveIndex);`
`${directiveFieldNames[i]} = directives.getDirectiveFor(${DIRECTIVES_ACCESSOR}[${i}].directiveIndex);`;
}
return lines.join('\n');
}
Expand All @@ -192,7 +192,7 @@ export class ChangeDetectorJITGenerator {
var lines = ListWrapper.createFixedSize(detectorFieldNames.length);
for (var i = 0, iLen = detectorFieldNames.length; i < iLen; ++i) {
lines[i] = `${detectorFieldNames[i]} =
directives.getDetectorFor(${DIRECTIVES_ACCESSOR}[${i}].directiveIndex);`
directives.getDetectorFor(${DIRECTIVES_ACCESSOR}[${i}].directiveIndex);`;
}
return lines.join('\n');
}
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/change_detection/parser/parser.ts
Expand Up @@ -167,7 +167,7 @@ class _ParseAST {
expectIdentifierOrKeyword(): string {
var n = this.next;
if (!n.isIdentifier() && !n.isKeyword()) {
this.error(`Unexpected token ${n}, expected identifier or keyword`)
this.error(`Unexpected token ${n}, expected identifier or keyword`);
}
this.advance();
return n.toString();
Expand All @@ -176,7 +176,7 @@ class _ParseAST {
expectIdentifierOrKeywordOrString(): string {
var n = this.next;
if (!n.isIdentifier() && !n.isKeyword() && !n.isString()) {
this.error(`Unexpected token ${n}, expected identifier, keyword, or string`)
this.error(`Unexpected token ${n}, expected identifier, keyword, or string`);
}
this.advance();
return n.toString();
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/change_detection/pipes/date_pipe.ts
Expand Up @@ -96,5 +96,5 @@ export class DatePipe extends BasePipe implements PipeFactory {

supports(obj): boolean { return isDate(obj) || isNumber(obj); }

create(cdRef: ChangeDetectorRef): Pipe { return this }
create(cdRef: ChangeDetectorRef): Pipe { return this; }
}
Expand Up @@ -130,7 +130,7 @@ export class IterableChanges extends BasePipe {
record = this._verifyReinsertion(record, item, index);
}
record = record._next;
index++
index++;
});
this._length = index;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/change_detection/pipes/json_pipe.ts
Expand Up @@ -29,5 +29,5 @@ import {ChangeDetectorRef} from '../change_detector_ref';
export class JsonPipe extends BasePipe implements PipeFactory {
transform(value, args: List<any> = null): string { return Json.stringify(value); }

create(cdRef: ChangeDetectorRef): Pipe { return this }
create(cdRef: ChangeDetectorRef): Pipe { return this; }
}
2 changes: 1 addition & 1 deletion modules/angular2/src/change_detection/pipes/number_pipe.ts
Expand Up @@ -48,7 +48,7 @@ export class NumberPipe extends BasePipe implements PipeFactory {

supports(obj): boolean { return isNumber(obj); }

create(cdRef: ChangeDetectorRef): Pipe { return this }
create(cdRef: ChangeDetectorRef): Pipe { return this; }
}

/**
Expand Down
Expand Up @@ -65,7 +65,7 @@ export class ObservablePipe implements Pipe {

_subscribe(obs: Observable): void {
this._observable = obs;
this._subscription = ObservableWrapper.subscribe(obs, value => {this._updateLatestValue(value)},
this._subscription = ObservableWrapper.subscribe(obs, value => this._updateLatestValue(value),
e => { throw e; });
}

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/change_detection/pipes/pipes.ts
Expand Up @@ -95,7 +95,7 @@ export class Pipes {
},
// Dependency technically isn't optional, but we can provide a better error message this way.
deps: [[Pipes, new UnboundedMetadata(), new OptionalMetadata()]]
})
});
}

private _getListOfFactories(type: string, obj: any): PipeFactory[] {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/annotations/decorators.ts
Expand Up @@ -52,7 +52,7 @@ export interface ViewDecorator extends TypeDecorator {
renderer?: string,
styles?: List<string>,
styleUrls?: List<string>,
}): ViewDecorator
}): ViewDecorator;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/application.ts
Expand Up @@ -300,7 +300,7 @@ export function bootstrap(appComponentType: Type,
bootstrapProcess.resolve(new ApplicationRef(componentRef, appComponentType, appInjector));
};
PromiseWrapper.then(compRefToken, tick,
(err, stackTrace) => {bootstrapProcess.reject(err, stackTrace)});
(err, stackTrace) => bootstrapProcess.reject(err, stackTrace));
});

return bootstrapProcess.promise;
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/compiler/view_manager_utils.ts
Expand Up @@ -100,7 +100,7 @@ export class AppViewManagerUtils {
if (atIndex == 0) {
sibling = null;
} else {
sibling = ListWrapper.last(viewContainer.views[atIndex - 1].rootElementInjectors)
sibling = ListWrapper.last(viewContainer.views[atIndex - 1].rootElementInjectors);
}
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) {
Expand Down
10 changes: 5 additions & 5 deletions modules/angular2/src/core/zone/ng_zone.ts
Expand Up @@ -62,7 +62,7 @@ export class NgZone {
if (global.zone) {
this._disabled = false;
this._mountZone = global.zone;
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace)
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace);
} else {
this._disabled = true;
this._mountZone = null;
Expand Down Expand Up @@ -159,9 +159,9 @@ export class NgZone {

if (enableLongStackTrace) {
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone,
{onError: function(e) { ngZone._onError(this, e) }});
{onError: function(e) { ngZone._onError(this, e); }});
} else {
errorHandling = {onError: function(e) { ngZone._onError(this, e) }};
errorHandling = {onError: function(e) { ngZone._onError(this, e); }};
}

return zone.fork(errorHandling)
Expand Down Expand Up @@ -200,7 +200,7 @@ export class NgZone {
}
}
}
}
};
},
'$scheduleMicrotask': function(parentScheduleMicrotask) {
return function(fn) {
Expand All @@ -213,7 +213,7 @@ export class NgZone {
}
};
parentScheduleMicrotask.call(this, microtask);
}
};
},
_innerZone: true
});
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/directives/ng_switch.ts
Expand Up @@ -164,7 +164,7 @@ export class NgSwitchWhen {
this._view = new SwitchView(viewContainer, protoViewRef);
}

onDestroy() { this._switch }
onDestroy() { this._switch; }

set ngSwitchWhen(value) {
this._switch._onWhenValueChanged(this._value, value, this._view);
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/facade/collection.ts
Expand Up @@ -22,7 +22,7 @@ var createMapFromPairs: {(pairs: List<any>): Map<any, any>} = (function() {
map.set(pair[0], pair[1]);
}
return map;
}
};
})();
var createMapFromMap: {(m: Map<any, any>): Map<any, any>} = (function() {
try {
Expand All @@ -35,7 +35,7 @@ var createMapFromMap: {(m: Map<any, any>): Map<any, any>} = (function() {
var map = new Map();
m.forEach((v, k) => { map.set(k, v); });
return map;
}
};
})();
var _clearValues: {(m: Map<any, any>)} = (function() {
if ((<any>(new Map()).keys()).next) {
Expand All @@ -49,7 +49,7 @@ var _clearValues: {(m: Map<any, any>)} = (function() {
} else {
return function _clearValuesWithForeEach(m: Map<any, any>) {
m.forEach((v, k) => { m.set(k, null); });
}
};
}
})();

Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/facade/intl.ts
Expand Up @@ -14,7 +14,7 @@ declare module Intl {
format(value: number): string;
}

var NumberFormat: { new (locale?: string, options?: NumberFormatOptions): NumberFormat; }
var NumberFormat: {new (locale?: string, options?: NumberFormatOptions): NumberFormat};

interface DateTimeFormatOptions {
localeMatcher?: string;
Expand All @@ -35,7 +35,7 @@ declare module Intl {
format(date?: Date | number): string;
}

var DateTimeFormat: { new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; }
var DateTimeFormat: {new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat};
}

export enum NumberFormatStyle {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/forms/validators.ts
Expand Up @@ -26,7 +26,7 @@ export class Validators {
return isPresent(errors) ? StringMapWrapper.merge(res, errors) : res;
}, {});
return StringMapWrapper.isEmpty(res) ? null : res;
}
};
}

static group(c: modelModule.ControlGroup): StringMap<string, boolean> {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/http/backends/xhr_backend.ts
Expand Up @@ -42,7 +42,7 @@ export class XHRConnection implements Connection {
responseOptions = baseResponseOptions.merge(responseOptions);
}

ObservableWrapper.callNext(this.response, new Response(responseOptions))
ObservableWrapper.callNext(this.response, new Response(responseOptions));
});
// TODO(jeffbcross): make this more dynamic based on body type

Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/render/dom/compiler/style_inliner.ts
Expand Up @@ -80,8 +80,7 @@ export class StyleInliner {
if (isPromise(inlinedCss)) {
// wait until nested @import are inlined
return (<Promise<string>>inlinedCss)
.then((css) => {return prefix + this._transformImportedCss(css, mediaQuery, url) +
'\n'});
.then((css) => prefix + this._transformImportedCss(css, mediaQuery, url) + '\n');
} else {
// there are no nested @import, return the css
return prefix + this._transformImportedCss(<string>inlinedCss, mediaQuery, url) + '\n';
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/util/decorators.ts
Expand Up @@ -70,7 +70,7 @@ export interface ParameterDecorator {
/**
* Invoke as ES7 decorator.
*/
(cls: Type, unusedKey: any, index: number): void
(cls: Type, unusedKey: any, index: number): void;
}

function extractAnnotation(annotation: any): any {
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/web-workers/shared/serializer.ts
Expand Up @@ -102,7 +102,7 @@ export class Serializer {

class ASTWithSourceSerializer {
static serialize(tree: ASTWithSource): Object {
return { 'input': tree.source, 'location': tree.location }
return { 'input': tree.source, 'location': tree.location };
}

static deserialize(obj: any, data: string): AST {
Expand Down Expand Up @@ -186,7 +186,7 @@ class ElementBinderSerializer {
'eventBindings': Serializer.serialize(binder.eventBindings, EventBinding),
'textBindings': Serializer.serialize(binder.textBindings, ASTWithSource),
'readAttributes': Serializer.mapToObject(binder.readAttributes)
}
};
}

static deserialize(obj): ElementBinder {
Expand All @@ -211,7 +211,7 @@ class ProtoViewDtoSerializer {
return {
'render': null, 'elementBinders': Serializer.serialize(view.elementBinders, ElementBinder),
'variableBindings': Serializer.mapToObject(view.variableBindings), 'type': view.type
}
};
}

static deserialize(obj): ProtoViewDto {
Expand Down

1 comment on commit 93055f7

@jeffbcross
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to fail on enforce-format. Locally, I'm getting this after rebase, for a file I haven't touched:

WARNING: Files are not properly formatted. Please run
./node_modules/clang-format/index.js -i -style="file" angular/modules/angular2/src/web-workers/shared/serializer.ts

Please sign in to comment.