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

style(linting): enable ' --noUnusedLocals' option #2104

Closed
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"copy_src_cjs": "mkdirp ./dist/cjs/src && shx cp -r ./src/* ./dist/cjs/src",
"copy_src_es6": "mkdirp ./dist/es6/src && shx cp -r ./src/* ./dist/es6/src",
"commit": "git-cz",
"compile_dist_cjs": "tsc ./dist/cjs/src/Rx.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_module_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom ",
"compile_dist_es6_for_docs": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts ./dist/es6/src/MiscJSDoc.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_dist_cjs": "tsc ./dist/cjs/src/Rx.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --noUnusedLocals --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_module_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --noUnusedLocals --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom ",
"compile_dist_es6_for_docs": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts ./dist/es6/src/MiscJSDoc.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --noUnusedLocals --suppressImplicitAnyIndexErrors --moduleResolution node",
"cover": "shx rm -rf dist/cjs && tsc src/Rx.ts src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --outDir dist/cjs --sourceMap --target ES5 -d && nyc --reporter=lcov --reporter=html --exclude=spec/support/**/* --exclude=spec-js/**/* --exclude=node_modules mocha --opts spec/support/default.opts spec-js",
"decision_tree_widget": "cd doc/decision-tree-widget && npm run build && cd ../..",
"doctoc": "doctoc CONTRIBUTING.md",
Expand Down
3 changes: 2 additions & 1 deletion src/Operator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Observable } from './Observable';
import { Subscriber } from './Subscriber';
import { TeardownLogic } from './Subscription';

export interface Operator<T, R> {
call(subscriber: Subscriber<R>, source: any): TeardownLogic;
call(subscriber: Subscriber<R>, source: Observable<T>): TeardownLogic;
}
7 changes: 6 additions & 1 deletion src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ import { $$observable as observable } from './symbol/observable';
* @property {Scheduler} animationFrame Schedules work with `requestAnimationFrame`.
* Use this for synchronizing with the platform's painting
*/
let Scheduler = {
let Scheduler: {
asap: AsapScheduler;
queue: QueueScheduler;
animationFrame: AnimationFrameScheduler;
async: AsyncScheduler;
} = {
Copy link
Member

Choose a reason for hiding this comment

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

Are these annotations necessary? I figured TS could easily infer the types from the assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't make it, TypeScript compiler make it error (This might be a compiler's issue?). But there is no problem. We can avoid such error with just writing expliciltly code.

asap,
queue,
animationFrame,
Expand Down
3 changes: 2 additions & 1 deletion src/observable/ArrayLikeObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class ArrayLikeObservable<T> extends Observable<T> {

protected _subscribe(subscriber: Subscriber<T>): TeardownLogic {
let index = 0;
const { arrayLike, scheduler } = this;
const arrayLike = this.arrayLike;
const scheduler = this.scheduler;
Copy link
Member

Choose a reason for hiding this comment

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

Any reason? I think we want to keep our existing, destructure style. Is there a subtle difference I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for to avoid a TypeScript compiler's bug (It will be fixed in TS2.1).

const length = arrayLike.length;

if (scheduler) {
Expand Down
5 changes: 3 additions & 2 deletions src/observable/BoundCallbackObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ export class BoundCallbackObservable<T> extends Observable<T> {
if (!subject) {
subject = this.subject = new AsyncSubject<T>();
const handler = function handlerFn(...innerArgs: any[]) {
const source = (<any>handlerFn).source;
const { selector, subject } = source;
const source: BoundCallbackObservable<T> = (<any>handlerFn).source;
const { subject } = source;
const selector = source.selector;
if (selector) {
const result = tryCatch(selector).apply(this, innerArgs);
if (result === errorObject) {
Expand Down
5 changes: 3 additions & 2 deletions src/observable/BoundNodeCallbackObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export class BoundNodeCallbackObservable<T> extends Observable<T> {
if (!subject) {
subject = this.subject = new AsyncSubject<T>();
const handler = function handlerFn(...innerArgs: any[]) {
const source = (<any>handlerFn).source;
const { selector, subject } = source;
const source: BoundNodeCallbackObservable<T> = (<any>handlerFn).source;
const { subject } = source;
const selector = source.selector;
const err = innerArgs.shift();

if (err) {
Expand Down
3 changes: 1 addition & 2 deletions src/observable/ConnectableObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class RefCountOperator<T> implements Operator<T, T> {
constructor(private connectable: ConnectableObservable<T>) {
}
call(subscriber: Subscriber<T>, source: any): TeardownLogic {

const { connectable } = this;
const connectable = this.connectable;
(<any> connectable)._refCount++;

const refCounter = new RefCountSubscriber(subscriber, connectable);
Expand Down
6 changes: 3 additions & 3 deletions src/observable/ErrorObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface DispatchArg {
* @extends {Ignored}
* @hide true
*/
export class ErrorObservable extends Observable<any> {
export class ErrorObservable<E> extends Observable<any> {

/**
* Creates an Observable that emits no items to the Observer and immediately
Expand Down Expand Up @@ -54,7 +54,7 @@ export class ErrorObservable extends Observable<any> {
* @name throw
* @owner Observable
*/
static create<T>(error: any, scheduler?: Scheduler) {
static create<E>(error: E, scheduler?: Scheduler): ErrorObservable<E> {
return new ErrorObservable(error, scheduler);
}

Expand All @@ -63,7 +63,7 @@ export class ErrorObservable extends Observable<any> {
subscriber.error(error);
}

constructor(public error: any, private scheduler?: Scheduler) {
constructor(public error: E, private scheduler?: Scheduler) {
super();
}

Expand Down
5 changes: 3 additions & 2 deletions src/observable/ForkJoinObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ForkJoinSubscriber<T> extends OuterSubscriber<T, T> {
private haveValues = 0;

constructor(destination: Subscriber<T>,
private sources: Array<SubscribableOrPromise<any>>,
sources: Array<SubscribableOrPromise<any>>,
private resultSelector?: (...values: Array<any>) => T) {
super(destination);

Expand Down Expand Up @@ -117,7 +117,8 @@ class ForkJoinSubscriber<T> extends OuterSubscriber<T, T> {

notifyComplete(innerSub: InnerSubscriber<T, T>): void {
const destination = this.destination;
const { haveValues, resultSelector, values } = this;
const { haveValues, values } = this;
const resultSelector = this.resultSelector;
const len = values.length;

if (!(<any>innerSub)._hasValue) {
Expand Down
8 changes: 6 additions & 2 deletions src/observable/IfObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class IfObservable<T, R> extends Observable<T> {
}

protected _subscribe(subscriber: Subscriber<T|R>): TeardownLogic {
const { condition, thenSource, elseSource } = this;
const condition = this.condition;
const thenSource = this.thenSource;
const elseSource = this.elseSource;

return new IfSubscriber(subscriber, condition, thenSource, elseSource);
}
Expand All @@ -40,7 +42,9 @@ class IfSubscriber<T, R> extends OuterSubscriber<T, T> {
}

private tryIf(): void {
const { condition, thenSource, elseSource } = this;
const condition = this.condition;
const thenSource = this.thenSource;
const elseSource = this.elseSource;

let result: boolean;
try {
Expand Down
3 changes: 2 additions & 1 deletion src/observable/IteratorObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class IteratorObservable<T> extends Observable<T> {
protected _subscribe(subscriber: Subscriber<T>): TeardownLogic {

let index = 0;
const { iterator, scheduler } = this;
const iterator = this.iterator;
const scheduler = this.scheduler;

if (scheduler) {
return scheduler.schedule(IteratorObservable.dispatch, 0, {
Expand Down
3 changes: 2 additions & 1 deletion src/observable/PairsObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export class PairsObservable<T> extends Observable<Array<string | T>> {
}

protected _subscribe(subscriber: Subscriber<Array<string | T>>): TeardownLogic {
const {keys, scheduler} = this;
const keys = this.keys;
const scheduler = this.scheduler;
const length = keys.length;

if (scheduler) {
Expand Down
3 changes: 2 additions & 1 deletion src/observable/UsingObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class UsingObservable<T> extends Observable<T> {
}

protected _subscribe(subscriber: Subscriber<T>): TeardownLogic {
const { resourceFactory, observableFactory } = this;
const resourceFactory = this.resourceFactory;
const observableFactory = this.observableFactory;

let resource: AnonymousSubscription;

Expand Down
4 changes: 3 additions & 1 deletion src/operator/bufferCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class BufferCountSubscriber<T> extends Subscriber<T> {

protected _next(value: T) {
const count = this.count++;
const { destination, bufferSize, startBufferEvery, buffers } = this;
const { destination, buffers } = this;
const bufferSize = this.bufferSize;
const startBufferEvery = this.startBufferEvery;
const startOn = (startBufferEvery == null) ? bufferSize : startBufferEvery;

if (count % startOn === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/operator/bufferTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class BufferTimeSubscriber<T> extends Subscriber<T> {

constructor(destination: Subscriber<T[]>,
private bufferTimeSpan: number,
private bufferCreationInterval: number,
bufferCreationInterval: number,
private maxBufferSize: number,
private scheduler: Scheduler) {
super(destination);
Expand Down
2 changes: 1 addition & 1 deletion src/operator/bufferToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BufferToggleSubscriber<T, O> extends OuterSubscriber<T, O> {
private contexts: Array<BufferContext<T>> = [];

constructor(destination: Subscriber<T[]>,
private openings: SubscribableOrPromise<O>,
openings: SubscribableOrPromise<O>,
private closingSelector: (value: O) => SubscribableOrPromise<any> | void) {
super(destination);
this.add(subscribeToResult(this, openings));
Expand Down
2 changes: 1 addition & 1 deletion src/operator/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function concatStatic<T, R>(...observables: (ObservableInput<any> | Sched
* @name concat
* @owner Observable
*/
export function concatStatic<T, R>(...observables: Array<ObservableInput<any> | Scheduler>): Observable<R> {
export function concatStatic<R>(...observables: Array<ObservableInput<any> | Scheduler>): Observable<R> {
let scheduler: Scheduler = null;
let args = <any[]>observables;
if (isScheduler(args[observables.length - 1])) {
Expand Down
6 changes: 3 additions & 3 deletions src/operator/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DelaySubscriber<T> extends Subscriber<T> {
}));
}

private scheduleNotification(notification: Notification<any>): void {
private scheduleNotification(notification: Notification<T>): void {
if (this.errored === true) {
return;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ class DelaySubscriber<T> extends Subscriber<T> {
}

class DelayMessage<T> {
constructor(private time: number,
private notification: any) {
constructor(public time: number,
public notification: Notification<T>) {
Copy link
Member

Choose a reason for hiding this comment

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

Did these need to change from private to public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old code was wrong. These members should be public to be used in DelaySubscriber

}
}
3 changes: 2 additions & 1 deletion src/operator/exhaustMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class SwitchFirstMapSubscriber<T, I, R> extends OuterSubscriber<T, I> {
notifyNext(outerValue: T, innerValue: I,
outerIndex: number, innerIndex: number,
innerSub: InnerSubscriber<T, I>): void {
const { resultSelector, destination } = this;
const destination = this.destination;
const resultSelector = this.resultSelector;
if (resultSelector) {
this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/operator/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export class FindValueSubscriber<T> extends Subscriber<T> {
}

protected _next(value: T): void {
const { predicate, thisArg } = this;
const predicate = this.predicate;
const thisArg = this.thisArg;
const index = this.index++;
try {
const result = predicate.call(thisArg || this, value, index, this.source);
Expand Down
3 changes: 2 additions & 1 deletion src/operator/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export class GroupedObservable<K, T> extends Observable<T> {

protected _subscribe(subscriber: Subscriber<T>) {
const subscription = new Subscription();
const {refCountSubscription, groupSubject} = this;
const groupSubject = this.groupSubject;
const refCountSubscription = this.refCountSubscription;
if (refCountSubscription && !refCountSubscription.closed) {
subscription.add(new InnerRefCountSubscription(refCountSubscription));
}
Expand Down
2 changes: 1 addition & 1 deletion src/operator/last.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LastSubscriber<T, R> extends Subscriber<T> {
constructor(destination: Subscriber<R>,
private predicate?: (value: T, index: number, source: Observable<T>) => boolean,
private resultSelector?: ((value: T, index: number) => R) | void,
private defaultValue?: any,
defaultValue?: any,
Copy link
Member

Choose a reason for hiding this comment

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

Why did this need to be changed to not be a private property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaultValue is not used in LastSubscriber

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this option make it the error.

private source?: Observable<T>) {
super(destination);
if (typeof defaultValue !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion src/operator/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function mergeStatic<T, R>(...observables: (ObservableInput<any> | Schedu
* @name merge
* @owner Observable
*/
export function mergeStatic<T, R>(...observables: Array<ObservableInput<any> | Scheduler | number>): Observable<R> {
export function mergeStatic<R>(...observables: Array<ObservableInput<any> | Scheduler | number>): Observable<R> {
let concurrent = Number.POSITIVE_INFINITY;
let scheduler: Scheduler = null;
let last: any = observables[observables.length - 1];
Expand Down
2 changes: 1 addition & 1 deletion src/operator/multicast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class MulticastOperator<T> implements Operator<T, T> {
private selector: (source: Observable<T>) => Observable<T>) {
}
call(subscriber: Subscriber<T>, source: any): any {
const { selector } = this;
const selector = this.selector;
const subject = this.subjectFactory();
const subscription = selector(subject).subscribe(subscriber);
subscription.add(source._subscribe(subject));
Expand Down
3 changes: 2 additions & 1 deletion src/operator/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class RepeatSubscriber<T> extends Subscriber<T> {
}
complete() {
if (!this.isStopped) {
const { source, count } = this;
const count = this.count;
const source = this.source;
if (count === 0) {
return super.complete();
} else if (count > -1) {
Expand Down
3 changes: 2 additions & 1 deletion src/operator/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class RetrySubscriber<T> extends Subscriber<T> {
}
error(err: any) {
if (!this.isStopped) {
const { source, count } = this;
const count = this.count;
const source = this.source;
if (count === 0) {
return super.error(err);
} else if (count > -1) {
Expand Down
6 changes: 3 additions & 3 deletions src/operator/sampleTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class SampleTimeSubscriber<T> extends Subscriber<T> {
hasValue: boolean = false;

constructor(destination: Subscriber<T>,
private period: number,
private scheduler: Scheduler) {
period: number,
scheduler: Scheduler) {
super(destination);
this.add(scheduler.schedule(dispatchNotification, period, { subscriber: this, period }));
}
Expand All @@ -84,7 +84,7 @@ class SampleTimeSubscriber<T> extends Subscriber<T> {
}
}

function dispatchNotification<T>(state: any) {
function dispatchNotification(state: any) {
let { subscriber, period } = state;
subscriber.notifyNext();
(<any>this).schedule(state, period);
Expand Down
5 changes: 3 additions & 2 deletions src/operator/sequenceEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SequenceEqualSubscriber<T, R> extends Subscriber<T> {
private _oneComplete = false;

constructor(destination: Observer<R>,
private compareTo: Observable<T>,
compareTo: Observable<T>,
private comparor: (a: T, b: T) => boolean) {
super(destination);
this.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, this)));
Expand All @@ -107,7 +107,8 @@ export class SequenceEqualSubscriber<T, R> extends Subscriber<T> {
}

checkValues() {
const { _a, _b, comparor } = this;
const { _a, _b, } = this;
const comparor = this.comparor;
while (_a.length > 0 && _b.length > 0) {
let a = _a.shift();
let b = _b.shift();
Expand Down
3 changes: 2 additions & 1 deletion src/operator/switchMapTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class SwitchMapToSubscriber<T, I, R> extends OuterSubscriber<T, I> {
notifyNext(outerValue: T, innerValue: I,
outerIndex: number, innerIndex: number,
innerSub: InnerSubscriber<T, I>): void {
const { resultSelector, destination } = this;
const resultSelector = this.resultSelector;
const destination = this.destination;
if (resultSelector) {
this.tryResultSelector(outerValue, innerValue, outerIndex, innerIndex);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/operator/takeUntil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TakeUntilOperator<T> implements Operator<T, T> {
class TakeUntilSubscriber<T, R> extends OuterSubscriber<T, R> {

constructor(destination: Subscriber<any>,
private notifier: Observable<any>) {
notifier: Observable<any>) {
super(destination);
this.add(subscribeToResult(this, notifier));
}
Expand Down
6 changes: 3 additions & 3 deletions src/operator/windowTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class WindowTimeSubscriber<T> extends Subscriber<T> {
private windows: Subject<T>[] = [];

constructor(protected destination: Subscriber<Observable<T>>,
private windowTimeSpan: number,
private windowCreationInterval: number,
private scheduler: Scheduler) {
windowTimeSpan: number,
windowCreationInterval: number,
scheduler: Scheduler) {
super(destination);
if (windowCreationInterval !== null && windowCreationInterval >= 0) {
let window = this.openWindow();
Expand Down
2 changes: 1 addition & 1 deletion src/operator/windowToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class WindowToggleSubscriber<T, O> extends OuterSubscriber<T, any> {

if (outerValue === this.openings) {

const { closingSelector } = this;
const closingSelector = this.closingSelector;
const closingNotifier = tryCatch(closingSelector)(innerValue);

if (closingNotifier === errorObject) {
Expand Down
Loading