-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
ordered-list-marker-value: fix to support 0
as start
#219
ordered-list-marker-value: fix to support 0
as start
#219
Conversation
This comment has been minimized.
This comment has been minimized.
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.
I think this would mostly work! I would feel a bit more comfortable that this isn’t a breaking change with something that checks if node.start
is null/undefined, something like this (if allowed by xo/prettier though):
var shouldBe = pref === 'one' ? 1 : node.start == null ? 1 : node.start
@wooorm Not sure that I understand your point =) I just tried to avoid some critical changes, and simply replaced start value. Do you want me to refactor this like you said? |
Yes, that’s what I meant! With your proposal, if |
@wooorm Updated with strict equality instead of var values = [undefined, null, 0, 1, NaN, ''];
var pref = 'one';
function test1(valuesArr) {
return valuesArr.map(el => (pref === 'one' ? 1 : el) || 0)
};
function test2(valuesArr) {
function getStartValue(value) {
if (typeof value !== "undefined" && value !== null) {
return value
} else {
return 0;
}
}
return valuesArr.map(el => pref === 'one' ? 1 : getStartValue(el))
};
console.log(test1(values)); // [1, 1, 1, 1, 1, 1]
console.log(test2(values)); // [1, 1, 1, 1, 1, 1]
var pref = 'ordered';
console.log(test1(values)); // [0, 0, 0, 1, 0, 0]
console.log(test2(values)); // [0, 0, 0, 1, NaN, ""] |
@wooorm Could you take a look? |
@wooorm Friendly ping |
Thanks for the pings and sorry for not getting back to you sooner! |
We don’t have to care about weird values, because Here is a script I wrote to compare the three algorithms. Algorithm A is the one I proposed, B is your earlier proposal, and C your latest proposal var values = [null, undefined, 0, 1] // Values that `node.start` could have
var preferences = ['single', 'ordered', 'one'] // Options for the rule
preferences.forEach(p => {
console.log('\npreference: %s', p)
values.forEach(function(d) {
var a = p === 'one' ? 1 : d == null ? 1 : d
var b = (p === 'one' ? 1 : d) || 0
var c = p === 'one' ? 1 : typeof d !== 'undefined' && d !== null ? d : 0
console.log('%s: %s | %s | %s', String(d).padStart(10), a, b, c)
})
}) This gives the result:
In these results, we can ignore the Your algorithms now all prefer to start with |
@wooorm Thank you for detailed explanation. Updated code with your algorithm |
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.
Sweet, this is great!
One more nit 😬 Could you add a test? Basically these and these lines, above or below those, but (starting) with 0
s? Thanks!
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.
Perfect! 😊
0
as start
@wooorm I can't find this changes on NPM. Does it released? |
Here's small patch that allow to use 0 as start value in ordered list for https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-ordered-list-marker-value rule.
Why is that need? Because lists like that should be valid:
but it's not with current implementation:
Example
I'm working now on remark lint preset for Gatsby docs and faced with this issue here:
That's not a BREAKING CHANGE and tests seems okay