Skip to content

Remove uses of null in services #8823

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

Merged
1 commit merged into from
May 25, 2016
Merged
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
14 changes: 2 additions & 12 deletions src/services/formatting/ruleOperation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
///<reference path='references.ts' />
/* tslint:disable:no-null-keyword */

/* @internal */
namespace ts.formatting {
export class RuleOperation {
public Context: RuleOperationContext;
public Action: RuleAction;

constructor() {
this.Context = null;
this.Action = null;
}
constructor(public Context: RuleOperationContext, public Action: RuleAction) {}

public toString(): string {
return "[context=" + this.Context + "," +
Expand All @@ -22,10 +15,7 @@ namespace ts.formatting {
}

static create2(context: RuleOperationContext, action: RuleAction) {
const result = new RuleOperation();
result.Context = context;
result.Action = action;
return result;
return new RuleOperation(context, action);
}
}
}
5 changes: 2 additions & 3 deletions src/services/formatting/rulesMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
///<reference path='references.ts' />
/* tslint:disable:no-null-keyword */

/* @internal */
namespace ts.formatting {
Expand Down Expand Up @@ -62,14 +61,14 @@ namespace ts.formatting {
public GetRule(context: FormattingContext): Rule {
const bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind);
const bucket = this.map[bucketIndex];
if (bucket != null) {
if (bucket) {
for (const rule of bucket.Rules()) {
if (rule.Operation.Context.InContext(context)) {
return rule;
}
}
}
return null;
return undefined;
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/services/formatting/rulesProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference path="references.ts"/>
/* tslint:disable:no-null-keyword */

/* @internal */
namespace ts.formatting {
Expand All @@ -26,8 +25,7 @@ namespace ts.formatting {
}

public ensureUpToDate(options: ts.FormatCodeOptions) {
// TODO: Should this be '==='?
if (this.options == null || !ts.compareDataObjects(this.options, options)) {
if (!this.options || !ts.compareDataObjects(this.options, options)) {
const activeRules = this.createActiveRules(options);
const rulesMap = RulesMap.create(activeRules);

Expand Down