Skip to content
This repository was archived by the owner on May 11, 2018. It is now read-only.

Extract option normalization into independant file #125

Merged
merged 1 commit into from
Jan 18, 2017

Conversation

baer
Copy link
Contributor

@baer baer commented Jan 9, 2017

This PR moves all preset option validation logic into a separate file. 95% of this PR is simply moving code from the index.js => normalize-options.js with the exception of the following:

  • Error messages were edited for clarity and consistency. They are now of the format Invalid Option: <problem> or Deprecation Warning: <problem>
  • The invariant library was pulled in to help make the code a bit more readable.
  • With the exception of setting default values, normalizeOptions does not mutate or change the input object. Part of what set me down the path of this refactor was unexpectedly finding that validateIncludeOption and validateExcludeOption not only altered the input but changed the shape.
  • lodash/intersection was pulled into the plugin bundle for clarity.

Thanks for all the great work on this repo! If you find this change too invasive, I'm happy to try to scale back in places. The impetus for all of this was finding that validation was actually mutating which could be fixed in other ways. Thanks for doing all ya'll do here!

@baer baer force-pushed the feature/extract-option-validation branch from d41370c to 0c9d4f0 Compare January 9, 2017 08:16
@@ -51,7 +34,7 @@ export const isPluginRequired = (supportedEnvironments, plugin) => {
const lowestTargetedVersion = supportedEnvironments[environment];

if (typeof lowestTargetedVersion === "string") {
throw new Error(`Target version must be a number,
throw new Error(`Target version must be a number,
'${lowestTargetedVersion}' was given for '${environment}'`);
Copy link
Member

Choose a reason for hiding this comment

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

invariant(
    typeof lowestTargetedVersion === "number",
    `Target version must be a number, '${lowestTargetedVersion}' was given for '${environment}'`
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I tried not to touch index.js anywhere that wasn't related to extracting option parsing but if this PR goes through I'd love to follow up with one to improve all logging and error messages like this.

Copy link
Member

@yavorsky yavorsky left a comment

Choose a reason for hiding this comment

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

☑️

@baer baer force-pushed the feature/extract-option-validation branch from 0c9d4f0 to 1dc7238 Compare January 17, 2017 03:29
@baer
Copy link
Contributor Author

baer commented Jan 17, 2017

Thanks for the review @yavorsky! I saw this PR had a few merge conflicts which are now fixed. Now that it's approved and will merge cleanly, what is the merge process? Should I just press the button or should I wait for you / @hzoo or somebody to do it.

🍻 cheers!

@baer
Copy link
Contributor Author

baer commented Jan 17, 2017

NOTE: I now see that #124 added a yarnfile - this PR does not update the yarnfile.lock. I am working to get yarn running properly on this machine - do not merge on my behalf until I make that fix.

@baer baer mentioned this pull request Jan 17, 2017
@baer baer force-pushed the feature/extract-option-validation branch from 1dc7238 to 4cd5c28 Compare January 17, 2017 17:33
@baer
Copy link
Contributor Author

baer commented Jan 17, 2017

Now that #145 is in, this should be okay to merge.

@hzoo
Copy link
Member

hzoo commented Jan 17, 2017

sure 👍

if (opts.whitelist && !hasBeenWarned) {
console.warn(
`Deprecation Warning: The "whitelist" option has been deprecated in favor of "include" to
matchthe newly added "exclude" option (instead of "blacklist").`
Copy link
Member

Choose a reason for hiding this comment

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

Nit: matchthe -> match the


invariant(
unknownOpts.length === 0,
`Invalid Option: The ${type} of '${unknownOpts}' is not a valid plugins/built-in. Please check
Copy link
Member

@existentialism existentialism Jan 17, 2017

Choose a reason for hiding this comment

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

Reads sort of strange:

The exclude of ${unknownOpts} is not a valid plugin/built-ins

Thoughts on just tweaking the original?

Invalid Option: The plugins/built-ins '${unknownOpts}' passed to the '${type}' option are not valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dig it.

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

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

👍, just two nits

Verified

This commit was signed with the committer’s verified signature.
danepowell Dane Powell
@baer baer force-pushed the feature/extract-option-validation branch from 4cd5c28 to b8c768f Compare January 18, 2017 17:01
@baer baer merged commit 7acd181 into master Jan 18, 2017
@baer baer deleted the feature/extract-option-validation branch January 18, 2017 17:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants