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

No unused variables #449

Merged
merged 3 commits into from
Apr 7, 2017
Merged

No unused variables #449

merged 3 commits into from
Apr 7, 2017

Conversation

matteofigus
Copy link
Member

@matteofigus matteofigus commented Apr 7, 2017

Removed some 💩 by setting no unused var setting in jshint and then correcting all the stuff.

@matteofigus matteofigus changed the title No unused variables [wip] No unused variables Apr 7, 2017
@matteofigus matteofigus changed the title [wip] No unused variables No unused variables Apr 7, 2017
Copy link
Member

@mattiaerre mattiaerre left a comment

Choose a reason for hiding this comment

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

over to you @matteofigus in general this LGTM

@@ -22,7 +22,7 @@ module.exports = function(dependencies, components){
delete require.cache[pathToModule];
}

var required = require(pathToModule);
require(pathToModule);
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand what this piece of code does 😊

Copy link
Member Author

@matteofigus matteofigus Apr 7, 2017

Choose a reason for hiding this comment

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

The easiest way to know if you can require something is to wrap a require into a try/catch. Given the only value of this is to ensure this doesn't throw (this module gets a list of required dependencies for a module that are not installed), no need to assign the value to a "required" variable (which, in fact, the linter finds as unused).

The reason for the previous lines is that require has an internal cache and if you required something before and then installed it on the flight (by programmatically using npm as we do as result of this module's execution) it remembers the dep doesn't exist, so here comes the need of invalidating this cache to be sure a lookup for that dep is performed again.

Consider that another way to achieve this is to verify the existence of __dirname/node_modules/dependency but this is crazy complicated because of how different versions of npm and yarn save deps in node_modules folder. Also require has a lot of logic to try to guess where your dependency is and it's just convenient to rely on it for that.

@@ -1,7 +1,7 @@
'use strict';

var async = require('async');
var colors = require('colors');
var colors = require('colors/safe');
Copy link
Member

Choose a reason for hiding this comment

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

new version of colors?

Copy link
Member Author

Choose a reason for hiding this comment

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

colors exposes the classic mode, which just overrides global strings by allowing to do "string".red or the "safe" mode colors.red("string"). We use the safe mode almost everywhere but we missed this before..

@@ -17,7 +17,7 @@
"plusplus" : false, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : false, // true: Require all defined variables be used
"unused" : true, // true: Require all defined variables be used
Copy link
Member

Choose a reason for hiding this comment

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

me ❤️ it

@mattiaerre
Copy link
Member

@matteofigus thanks, shall I merge this?

@mattiaerre mattiaerre merged commit 8dbb347 into master Apr 7, 2017
@mattiaerre mattiaerre deleted the housekeeping-3 branch April 7, 2017 18:24
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