-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
plain-scalar: always
rule misses optional quotes
#124
Comments
I think the following check needs to take into account the position of the character in the string and/or whether it's followed by whitespace or not (in the case of eslint-plugin-yml/src/rules/plain-scalar.ts Lines 110 to 112 in 576f58f
|
Thank you for this issue. e.g. - ["e,e": "f,f"]
- [e,e: f,f] Also, removing quotes from them can be difficult for humans to read, so I think it may need to be an option. |
That makes sense. For me, the most important factor is consistency. I want the plugin to force a decision. Even if the quotes are not needed from the spec in this case, I would be fine, if they were added consistently. So as long as changing the setting to Implementation wise this could take a real "dumb" approach: Could we do the following? When a quoted value is found:
This would avoid the need to try to replicate the spec. WDYT? |
The suggestion I made above, does not take this into account. I see that point, but I fear the "readability" part might be subjective and a lot harder to implement. One general approach to this would be to say: Whenever a scalar can not be represented as a plain scalar in any one context, add quotes to this scalar in all contexts. Although I don't really know where we would end up with that. How many different contexts would we need to take into consideration? Would we add "too many" quotes because of that? |
That idea sounds good to me. I don't want to re-parse the entire document as much as possible, but it can be difficult for me.
I was thinking of using pattern to exclude it from the check. But I forgot that the option already existed 😅. |
I noticed a case where
plain-scalar: always
would not report an error, even though the quotes in use were optional.Then I ran
eslint --fix
withplain-scalar: never
temporarily on my whole code-base, which added quotes everywhere. After runningeslint --fix
withplain-scalar: always
again, I still had a diff remaining. However, I would expect this action to be 100% reversible. The remaining diff means that there are some optional quotes, that are not caught byplain-scalar: always
.The following diff to the unit tests, highlights those cases:
Adding those test-cases to the valid fixtures makes the tests still pass. However, in each of those cases the same input is given once with quotes and once without. The
plain-scalar
rule should throw errors in all of the quoted examples here, because those quotes are optional.The text was updated successfully, but these errors were encountered: