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

fix: simplify validate-addons logic & npm-exists #67

Merged
merged 2 commits into from
Feb 25, 2017
Merged

Conversation

evenstensberg
Copy link
Member

Simplifies the usage of validate-addons and replaces the manual mock of
nom-exists with the actual.

@evenstensberg
Copy link
Member Author

Want to remove the mock implementation from so much here, but the entire parser is circular, we should try to use ´jest.mockfn` instead for some of this, so we can remove some manual mocks.

@evenstensberg evenstensberg changed the title hotfix: simplify validate-addons logic & npm-exists fix: simplify validate-addons logic & npm-exists Feb 22, 2017
@@ -1,30 +1,28 @@
const exists = require('./npm-exists');
const resolvePackages = require('./resolve-packages');

module.exports = (addons) => addons.map( pkg => checkExistence(pkg));
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Let's always use function declarations when defining functions
  2. Let's name this function validateAddons
  3. There is no need to create the closure in map / create a separate function
  4. Please add JSDoc to the exported function since this is the API
module.exports = function validateAddons(addons) {
  return addons.map(checkExistence);
}

@evenstensberg
Copy link
Member Author

@okonet Changed. I like abstracting each check to an "pure" function in a sense that it looks less verbose. About the inline arrow functions, I agree, but I assumed the checkExistence function spoke for itself.

Copy link
Contributor

@okonet okonet left a comment

Choose a reason for hiding this comment

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

I think validateAddons can be dropped here since it's just a map?

* @returns { <Function|Error> } resolvePackages - Returns an process to install the pkg
*/

module.exports = function validateAddons(addons) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to export this function? It seems that it could be easily done in the code where you have to check.

Also, why not addons.map(checkExistence)?


module.exports = function validateAddons(addons) {
return addons.map( pkg => checkExistence(pkg));
};

/*
* @function checkExistence
Copy link
Contributor

Choose a reason for hiding this comment

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

I would export this function and do the map elsewhere. Should we rename it to npmPackageExist?

* on npm and throws an error if it is not from @checkExistence
*
* @param { Array } pkg - Array of packages to check existence of
* @returns { <Function|Error> } resolvePackages - Returns an process to install the pkg
Copy link
Contributor

Choose a reason for hiding this comment

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

It will return an Array, actually.

* Loops through an array and checks if a package is registered
* on npm and throws an error if it is not from @checkExistence
*
* @param { Array } pkg - Array of packages to check existence of
Copy link
Contributor

Choose a reason for hiding this comment

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

It takes an Array<String>

Simplifies the usage of validate-addons and replaces the manual mock of
nom-exists with the actual.

fix: refactor function convention and add jsdcos

fix: rename validateAddons to npmPackagesExists

Renames the validateAddons packages to npmPackagesExists. Synced with
master to get latest changes from origin. Also added lint ignore to
coverage folder.

fix: remove coverage folder from commit

fix: rename test header
@okonet
Copy link
Contributor

okonet commented Feb 25, 2017

I wouldn't commit coverage to the repo. The that it should work is to generate it during the check. Let's revert the .gitignore and merge. We need to work on the CI setup a bit more I think.

@evenstensberg
Copy link
Member Author

evenstensberg commented Feb 25, 2017

@okonet Done. I'm leaving the merging to you :) Dunno why the coverage is included in the PR, but I removed it in gitignore and eslintignore.

@okonet
Copy link
Contributor

okonet commented Feb 25, 2017

I still can see the coverage file in the changes tab :/

@evenstensberg
Copy link
Member Author

yeah, me2 :( Let me try deleting the folder.

fix: remove coverage folder
@evenstensberg
Copy link
Member Author

there we go 👍

@okonet
Copy link
Contributor

okonet commented Feb 25, 2017

LGTM please squash and merge!

@evenstensberg evenstensberg merged commit 68a2dfd into master Feb 25, 2017
@evenstensberg evenstensberg deleted the fix/tests branch February 25, 2017 19:04
evenstensberg added a commit that referenced this pull request Mar 4, 2017
* hotfix: simplify validate-addons logic & npm-exists

Simplifies the usage of validate-addons and replaces the manual mock of
nom-exists with the actual.

fix: refactor function convention and add jsdcos

fix: rename validateAddons to npmPackagesExists

Renames the validateAddons packages to npmPackagesExists. Synced with
master to get latest changes from origin. Also added lint ignore to
coverage folder.

fix: remove coverage folder from commit

fix: rename test header

* fix: remove coverage from build

fix: remove coverage folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants