-
Notifications
You must be signed in to change notification settings - Fork 280
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
hyphen: Add min-spaces-after and check-scalars options #606
base: master
Are you sure you want to change the base?
Conversation
1a8230a
to
6e0e8d1
Compare
This permits checking style when people want sequences to have a fixed number of spaces greater than 1 for example. We may also use these options to identify typos where we expect everything starting with an hyphen to be a sequence.
6e0e8d1
to
15dbaed
Compare
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.
Hello and thanks for contributing!
The min-spaces-after
change is legitimate, and could be merged soon. Please see my proposals in the comments below.
About the check-scalars
option, I'm not sure I'm favorable to it. And checking every scalar for a starting -
in a YAML file is probably very bad for performance. But maybe I don't understand its use and usefulness for yamllint. Can you please propose it in a different pull request or issue, with example use-cases?
(For info, the examples you give:
object: [elem1, ...]
-bar:
would not be valid YAML anyway if the scalar -bar:
was turned into a list item - bar:
.)
if conf['max-spaces-after'] == 0: | ||
return '"max-spaces-after" cannot be set to 0' |
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 prefer removing this, because otherwise it would make sense to perform the same check for min-spaces-after
too (which isn't allowed to be zero), and probably in many other rules too.
@@ -28,6 +41,8 @@ | |||
rules: | |||
hyphens: | |||
max-spaces-after: 1 | |||
min-spaces-after: -1 # Disabled |
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.
# Disabled
isn't noted for other rules with -1
as default value (braces, brackets...) For consistency, I propose not to add here neither.
Or even better: let's set min-spaces-after: 1
as the default (instead of -1
), and as the disabled value, since having less than one space results in a syntax error anyway. It should add some clarity for users. What do you think?
Also can you place min-spaces-after
option before max-spaces-after
?
-foo: # starter of a new sequence named "-foo"; | ||
# without the colon, a syntax error will be raised. |
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.
This is a bit irrelevant to the example, and only adds confusion in my opinion. Let's remove it?
:: | ||
|
||
sequence: | ||
-key # Mind the spaces before the hyphen to enforce | ||
# the sequence and avoid a syntax error |
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.
Same here: this seems irrelevant and adds confusion: let's remove it.
* ``max-spaces-after`` defines the maximal number of spaces allowed after | ||
hyphens. | ||
hyphens. Set to a negative integer if you want to allow any number of | ||
spaces. |
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.
-
Suggested change
* ``max-spaces-after`` defines the maximal number of spaces allowed after hyphens. hyphens. Set to a negative integer if you want to allow any number of spaces. * ``max-spaces-after`` defines the maximal number of spaces allowed after hyphens. Set to ``-1`` if you want to allow any number of spaces. -2
in the future) - Can you place
max-spaces-after
aftermin-spaces-after
?
* ``min-spaces-after`` defines the minimal number of spaces expected after | ||
hyphens. Set to a negative integer if you want to allow any number of | ||
spaces. When set to a positive value, cannot be greater than | ||
``max-spaces-after``. |
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 propose to be a bit simpler:
* ``min-spaces-after`` defines the minimal number of spaces expected after | |
hyphens. Set to a negative integer if you want to allow any number of | |
spaces. When set to a positive value, cannot be greater than | |
``max-spaces-after``. | |
* ``min-spaces-after`` defines the minimal number of spaces expected after | |
hyphens. The default and minimum value is ``1``. |
(the rest is obvious and will throw a configuration error if needed)
if problem is not None: | ||
yield problem | ||
|
||
if conf['min-spaces-after'] > 0: |
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.
Doing the check if conf['min-spaces-after'] == 1
is useless (it cannot be lower than 1) and will degrade performance.
I propose:
if conf['min-spaces-after'] > 0: | |
if conf['min-spaces-after'] > 1: |
I'm going to push additional commits. For a cleaner history, will you do the rebase or should I do it on my side? About the rational behind
From a YAML point of view this is a valid scalar syntax but as we see that the scalar starts with an hyphen we may think this syntax is a typo. On the first sight we may think that From my point of view, |
OK! The best would be to rebase and squash into one commit with a nice title, ready to be merged.
Thanks for the explanation. |
This permits checking style when people want sequences to have a fixed number of spaces greater than 1 for example.
We may also use these options to identify typos where we expect everything starting with an hyphen to be a sequence.