This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
Restricted Linter options type #1168
Merged
jkillian
merged 9 commits into
palantir:master
from
JoshuaKGoldberg:linter-options-type
Apr 28, 2016
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
54359f9
Merge remote-tracking branch 'refs/remotes/palantir/master'
d6857cf
Merge remote-tracking branch 'refs/remotes/palantir/master'
8d79b52
Added check for non-object linter options
2f4909d
Changed linter options to allow odd inputs
54fe0fb
Merge remote-tracking branch 'refs/remotes/palantir/master'
87ca51f
Merge branch 'master' of https://github.com/JoshuaKGoldberg/tslint in…
9130842
Removed unnecessary npm-debug.log
d13594f
Slight linting rule fixups
9f69969
Slightly changed default linter settings
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ import { | |
} from "./configuration"; | ||
import {EnableDisableRulesWalker} from "./enableDisableRules"; | ||
import {findFormatter} from "./formatterLoader"; | ||
import {ILinterOptions, LintResult} from "./lint"; | ||
import {ILinterOptionsRaw, ILinterOptions, LintResult} from "./lint"; | ||
import {loadRules} from "./ruleLoader"; | ||
import {arrayify} from "./utils"; | ||
|
||
|
@@ -44,11 +44,10 @@ class Linter { | |
private source: string; | ||
private options: ILinterOptions; | ||
|
||
constructor(fileName: string, source: string, options: ILinterOptions) { | ||
constructor(fileName: string, source: string, options: ILinterOptionsRaw) { | ||
this.fileName = fileName; | ||
this.source = source; | ||
this.options = options; | ||
this.computeFullOptions(); | ||
this.options = this.computeFullOptions(options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this! Better to return a new object than mutate |
||
} | ||
|
||
public lint(): LintResult { | ||
|
@@ -99,13 +98,19 @@ class Linter { | |
return rules.some((r) => r.equals(rule)); | ||
} | ||
|
||
private computeFullOptions() { | ||
let {configuration, rulesDirectory} = this.options; | ||
if (configuration == null) { | ||
configuration = DEFAULT_CONFIG; | ||
private computeFullOptions(options: ILinterOptionsRaw = {}): ILinterOptions { | ||
if (typeof options !== "object") { | ||
throw new Error("Unknown Linter options type: " + typeof options); | ||
} | ||
this.options.rulesDirectory = arrayify(rulesDirectory).concat(arrayify(configuration.rulesDirectory)); | ||
this.options.configuration = configuration; | ||
|
||
let { configuration, formatter, formattersDirectory, rulesDirectory } = options; | ||
|
||
return { | ||
configuration: configuration || DEFAULT_CONFIG, | ||
formatter: formatter || "prose", | ||
formattersDirectory: formattersDirectory, | ||
rulesDirectory: arrayify(rulesDirectory).concat(arrayify(configuration.rulesDirectory)), | ||
}; | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed feelings about if we really need a new interface here - I'm sort of inclined to just making the properties of
ILinterOptions
optional. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a TypeScript issue filed somewhere for letting us do something like
ILinterOptions?
, where every field inILinterOptions
would be marked optional (so exactly this).My problem with re-using one interface for this is that after this initial parsing, the fields aren't all optional. The semantic intent changes from input option settings to stored options data, so IMO the type should as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, let's keep this then. It shouldn't cause any backwards compat issues for library users as fulfilling the previous
ILinterOptions
interface will still fulfill theILinterOptionsRaw
interface. Maybe we should make theformattersDirectory
field optional on both though, since it really is optional