Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require return types on public methods #2746

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion gulpfile.js
Expand Up @@ -37,6 +37,7 @@ var replace = require('gulp-replace');
var insert = require('gulp-insert');
var uglify = require('gulp-uglify');
var shouldLog = require('./tools/build/logging');
var tslint = require('gulp-tslint');

require('./tools/check-environment')({
requiredNpmVersion: '>=2.9.0',
Expand Down Expand Up @@ -245,6 +246,19 @@ gulp.task('enforce-format', function() {
});
});

gulp.task('lint', ['build.tools'], function() {
// https://github.com/palantir/tslint#supported-rules
var tslintConfig = {
"rules": {
"requireReturnType": true
}
};

return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/test_lib/**'])
.pipe(tslint({configuration: tslintConfig, rulesDirectory: 'dist/tools/tslint'}))
.pipe(tslint.report('prose'));
});

// ------------
// check circular dependencies in Node.js context
gulp.task('build/checkCircularDependencies', function (done) {
Expand Down Expand Up @@ -591,7 +605,7 @@ gulp.task('pre-test-checks', function(done) {
});

gulp.task('post-test-checks', function(done) {
runSequence('enforce-format', sequenceComplete(done));
runSequence('lint', 'enforce-format', sequenceComplete(done));
});


Expand Down
Expand Up @@ -138,9 +138,9 @@ export class ChangeDetectorJITGenerator {
.map((d) => this._genGetDetector(d.directiveIndex));
}

_genGetDirective(d: DirectiveIndex) { return `this.directive_${d.name}`; }
_genGetDirective(d: DirectiveIndex): string { return `this.directive_${d.name}`; }

_genGetDetector(d: DirectiveIndex) { return `this.detector_${d.name}`; }
_genGetDetector(d: DirectiveIndex): string { return `this.detector_${d.name}`; }

_getNonNullPipeNames(): List<string> {
var pipes = [];
Expand All @@ -152,7 +152,7 @@ export class ChangeDetectorJITGenerator {
return pipes;
}

_genFieldDefinitions() {
_genFieldDefinitions(): string {
var fields = [];
fields = fields.concat(this._fieldNames);
fields = fields.concat(this._getNonNullPipeNames());
Expand Down Expand Up @@ -226,7 +226,7 @@ export class ChangeDetectorJITGenerator {
return `${rec}${this._maybeGenLastInDirective(r)}`;
}

_genDirectiveLifecycle(r: ProtoRecord) {
_genDirectiveLifecycle(r: ProtoRecord): string {
if (r.name === "onCheck") {
return this._genOnCheck(r);
} else if (r.name === "onInit") {
Expand Down
74 changes: 38 additions & 36 deletions modules/angular2/src/change_detection/change_detection_util.ts
Expand Up @@ -35,7 +35,7 @@ var _simpleChanges = [
new SimpleChange(null, null)
];

function _simpleChange(previousValue, currentValue) {
function _simpleChange(previousValue, currentValue): SimpleChange {
var index = _simpleChangesIndex++ % 20;
var s = _simpleChanges[index];
s.previousValue = previousValue;
Expand All @@ -44,41 +44,43 @@ function _simpleChange(previousValue, currentValue) {
}

export class ChangeDetectionUtil {
static uninitialized() { return uninitialized; }

static arrayFn0() { return []; }
static arrayFn1(a1) { return [a1]; }
static arrayFn2(a1, a2) { return [a1, a2]; }
static arrayFn3(a1, a2, a3) { return [a1, a2, a3]; }
static arrayFn4(a1, a2, a3, a4) { return [a1, a2, a3, a4]; }
static arrayFn5(a1, a2, a3, a4, a5) { return [a1, a2, a3, a4, a5]; }
static arrayFn6(a1, a2, a3, a4, a5, a6) { return [a1, a2, a3, a4, a5, a6]; }
static arrayFn7(a1, a2, a3, a4, a5, a6, a7) { return [a1, a2, a3, a4, a5, a6, a7]; }
static arrayFn8(a1, a2, a3, a4, a5, a6, a7, a8) { return [a1, a2, a3, a4, a5, a6, a7, a8]; }
static arrayFn9(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
static uninitialized(): Object { return uninitialized; }

static arrayFn0(): any[] { return []; }
static arrayFn1(a1): any[] { return [a1]; }
static arrayFn2(a1, a2): any[] { return [a1, a2]; }
static arrayFn3(a1, a2, a3): any[] { return [a1, a2, a3]; }
static arrayFn4(a1, a2, a3, a4): any[] { return [a1, a2, a3, a4]; }
static arrayFn5(a1, a2, a3, a4, a5): any[] { return [a1, a2, a3, a4, a5]; }
static arrayFn6(a1, a2, a3, a4, a5, a6): any[] { return [a1, a2, a3, a4, a5, a6]; }
static arrayFn7(a1, a2, a3, a4, a5, a6, a7): any[] { return [a1, a2, a3, a4, a5, a6, a7]; }
static arrayFn8(a1, a2, a3, a4, a5, a6, a7, a8): any[] {
return [a1, a2, a3, a4, a5, a6, a7, a8];
}
static arrayFn9(a1, a2, a3, a4, a5, a6, a7, a8, a9): any[] {
return [a1, a2, a3, a4, a5, a6, a7, a8, a9];
}

static operation_negate(value) { return !value; }
static operation_add(left, right) { return left + right; }
static operation_subtract(left, right) { return left - right; }
static operation_multiply(left, right) { return left * right; }
static operation_divide(left, right) { return left / right; }
static operation_remainder(left, right) { return left % right; }
static operation_equals(left, right) { return left == right; }
static operation_not_equals(left, right) { return left != right; }
static operation_identical(left, right) { return left === right; }
static operation_not_identical(left, right) { return left !== right; }
static operation_less_then(left, right) { return left < right; }
static operation_greater_then(left, right) { return left > right; }
static operation_less_or_equals_then(left, right) { return left <= right; }
static operation_greater_or_equals_then(left, right) { return left >= right; }
static operation_logical_and(left, right) { return left && right; }
static operation_logical_or(left, right) { return left || right; }
static cond(cond, trueVal, falseVal) { return cond ? trueVal : falseVal; }

static mapFn(keys: List<any>) {
function buildMap(values) {
static operation_negate(value): any { return !value; }
static operation_add(left, right): any { return left + right; }
static operation_subtract(left, right): any { return left - right; }
static operation_multiply(left, right): any { return left * right; }
static operation_divide(left, right): any { return left / right; }
static operation_remainder(left, right): any { return left % right; }
static operation_equals(left, right): any { return left == right; }
static operation_not_equals(left, right): any { return left != right; }
static operation_identical(left, right): any { return left === right; }
static operation_not_identical(left, right): any { return left !== right; }
static operation_less_then(left, right): any { return left < right; }
static operation_greater_then(left, right): any { return left > right; }
static operation_less_or_equals_then(left, right): any { return left <= right; }
static operation_greater_or_equals_then(left, right): any { return left >= right; }
static operation_logical_and(left, right): any { return left && right; }
static operation_logical_or(left, right): any { return left || right; }
static cond(cond, trueVal, falseVal): any { return cond ? trueVal : falseVal; }

static mapFn(keys: List<any>): any {
function buildMap(values): StringMap<any, any> {
var res = StringMapWrapper.create();
for (var i = 0; i < keys.length; ++i) {
StringMapWrapper.set(res, keys[i], values[i]);
Expand Down Expand Up @@ -113,7 +115,7 @@ export class ChangeDetectionUtil {
}
}

static keyedAccess(obj, args) { return obj[args[0]]; }
static keyedAccess(obj, args): any { return obj[args[0]]; }

static unwrapValue(value: any): any {
if (value instanceof WrappedValue) {
Expand All @@ -129,15 +131,15 @@ export class ChangeDetectionUtil {

static throwDehydrated() { throw new DehydratedException(); }

static changeDetectionMode(strategy: string) {
static changeDetectionMode(strategy: string): string {
return strategy == ON_PUSH ? CHECK_ONCE : CHECK_ALWAYS;
}

static simpleChange(previousValue: any, currentValue: any): SimpleChange {
return _simpleChange(previousValue, currentValue);
}

static addChange(changes, propertyName: string, change) {
static addChange(changes, propertyName: string, change): Map<any, any> {
if (isBlank(changes)) {
changes = {};
}
Expand Down
Expand Up @@ -318,7 +318,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
}
}

function isSame(a, b) {
function isSame(a, b): boolean {
if (a === b) return true;
if (a instanceof String && b instanceof String && a == b) return true;
if ((a !== a) && (b !== b)) return true;
Expand Down