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
Add ignoreFunctions: [] to length-zero-no-unit #5082
Add ignoreFunctions: [] to length-zero-no-unit #5082
Conversation
Added conditions and tests
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.
Thanks for your PR, some comments:
New tesst and changed map for some
@JuanFML I have reworked things a little bit, take a look |
@vankop Yeah they work perfectly your changes, thanks a lot! I don't have to commit again do I? With your commit is all done? |
yes, all is fine |
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.
Thank you for working on this!
Could you add test cases, please?
/* it should report only first 0px */
a { margin: 0px var(--prop, 0px) }
/* it should report only second 0px */
a { margin: calc(5px + var(--prop, 0px)) 0px }
Revisiting after the refactoring in #5256. I think a simple conditional just after line 52 should work now: if (isFunction(valueNode) && optionsMatches(secondary, 'ignoreFunctions', value)) return false; With the following tests: testRule({
ruleName,
config: [true, { ignoreFunctions: ['var', /^--/] }],
accept: [
{
code: 'a { top: var(--foo, 0px); }',
},
{
code: 'a { top: --bar(0px); }',
},
],
reject: [
{
code: 'a { margin: var(--foo, 0px) 0px --bar(0px); }',
fixed: 'a { margin: var(--foo, 0px) 0 --bar(0px); }',
message: messages.rejected,
line: 1,
column: 30,
},
],
}); We'll need to require const _ = require('lodash'); And update the options validator on line 41: ignoreFunctions: [_.isString, _.isRegExp], And add a function isFunction({ type }) {
return type === 'function';
} The docs can look like this, e.g. Given:
The following patterns are not considered violations: a { top: var(--foo, 0px); } a { top: --bar(0px); } @JuanFML Would you like to update the pull request? |
Added condition to ignore when function is detected and a test to check it with.
Fixes issue #4945
I left some comments in the code as it is another type of solution, this is my first PR, so please let me know if the solution wasn't what you were looking for, in order to fix it. There would be still left to add to the README.md file the new option added, although I wanted to get it checked first before adding it.