- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow to ignore some vars #24
Conversation
index.js
Outdated
@@ -11,7 +11,9 @@ function regExpQuote(str) { | |||
return str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); | |||
} | |||
|
|||
function findUnusedVars(strDir) { | |||
function findUnusedVars(strDir, opts) { | |||
opts.ignore = opts.ignore || []; |
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.
Are we sure opts
will always exist? Maybe Object.assign
would be a better choice?
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.
We can't assume that indeed. I don't know for sure how I can use Object.assign
for this, can you help me out with that?
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.
const option = Object.assign({}, opt)
Should do the trick
EDIT:
A better fix would be creating a default option something like this:
const defaultOption = {
ignore: '',
};
And after that you can do:
const option = Object.assign(defaultOption, opt);
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.
Wouldn't that still trigger an error on L41 if opts is not defined?
find-unused-sass-variables/index.js
Line 41 in 36ec29f
.filter((variable) => !opts.ignore.includes(variable)); |
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 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.
Didn't notice the edit you made in the comment. I've now changed this.
tests/_variables.scss
Outdated
@@ -1,4 +1,5 @@ | |||
$white: #fff !default; | |||
$a: 10px; | |||
$b : 20px; | |||
$unused : #000; | |||
$b: 20px; |
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.
The space before :
was intentional before we switched to postcss we were using a regex and this could fail.
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.
Oh, ok. I reverted this change
@Johann-S: if you have any free time in the weekend, could you please have a quick look at this? Basically check what type we are passing. |
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.
Our cli.js
should convert ignore list into an array (that's what we do)
But our index.js
shouldn't allow string on the ignore
key, so there is no need to convert string here and we'll be fine 👍
@Johann-S see if you can sort all of this because I see now why @MartijnCuppens wanted this so much :P https://travis-ci.org/twbs/bootstrap/builds/444348045 |
Added a check to ensure we work on an array |
With this PR it's possible to ignore some variables.
Usage:
fusv folder --ignore '$my-var,$my-second-var'
Closes #18