-
Notifications
You must be signed in to change notification settings - Fork 269
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 the "needed-extra-regex" option #246
Conversation
Neither the failing tests nor the coverage decrease seems related to my changes. 🤷♂ |
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 @leofeyer! I haven't tested but it looks functional.
I'm sorry about Travis not reporting tests, I'll look into that.
However for coverage, it is indeed related to your change: you add more code than you add tests (relatively). It's important to cover all cases (e.g. needed-extra-regex: ^%.*$
, needed-extra-regex: ^%
, needed-extra-regex: ;$
, needed-extra-regex: ' '
, etc.) including corner cases like multi-line regexes on:
self.check('---\n'
'multiline string 1: |\n'
' line 1\n'
' line 2\n'
...
Also, you need to update documentation if you don't want this to be a hidden feature 😉
Since there are multiple types of regex syntaxes, I think it's worth mentionning that this regex format is PCRE, more info on https://docs.python.org/3/library/re.html#regular-expression-syntax.
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 @leofeyer, it looks good! New documentation is short and clear 👍 (I just have a suggestion)
Also in tests, can you make sure quotes are required when the regex matches? For example:
self.check('---\n'
'string1: \'$foo$\'\n' # fails
'string2: \'%foo%\'\n'
'string3: $foo$\n'
'string4: %foo%\n', # fails
conf, problem1=(2, 10), problem2=(5, 10))
(by the way, does the code in yamllint/rules/quoted_strings.py
correctly ensure that?)
No, this cannot be tested, as it throws a syntax error: |
Sure, but you get the idea, right? The goal is to test that the new option does its job, for example using another regex like By the way, if |
I can try.
Maybe |
Interesting! Since Anyway, since |
Isn't |
Also, if |
Actually
I'm not sure whether it's strictly forbidden to have something like |
I have adjusted the tests in eb3c857 to use |
Great, thanks! 👍 What about my comment #246 (review)? |
This would be a new feature that has nothing to do with my PR, because right now You can test this yourself by changing This is a code snippet that would implement the feature: elif tag == DEFAULT_SCALAR_TAG and token.value:
# Quotes are required because the token begins with a special character
# or matches the extra regex
if token.value[0] in START_TOKENS or (extra_regex != ''
and re.search(extra_regex, token.value)):
msg = "string value is not quoted with %s quotes" % (quote_type) But as I said, it has nothing to do with this PR, therefore I suggest to merge the PR as is and to create a new PR to adjust the checks to enforce quotes if a string matches |
Add ability to: - require strings to be quoted if they match a pattern (PCRE regex) - allow quoted strings if they match a pattern, while `require: only-when-needed` is enforced. Co-Authored-By: Leo Feyer (#246)
OK so this feature has 2 parts:
In my opinion part 2 has "something to do with your PR", as users who read Other things I don't agree with:
For these reasons (and to save time) I will implement this in another PR. |
Add ability to: - require strings to be quoted if they match a pattern (PCRE regex) - allow quoted strings if they match a pattern, while `require: only-when-needed` is enforced. Co-Authored-By: Leo Feyer (#246)
My hunch goes with adding any possible indicator character to the list of |
I know that development is already ongoing, so I'm sorry to be late for the party. Although, after reading the two threads and noticed that what motivated this PR and #246 was actually the fact that
I wanted to give my two cents. If we came to agree that the |
@ruipinge thanks for your feedback. I'm still OK to add But
By the way this is already a problem for users: an issue was open at #242. Let's continue this topic there, but we may have to drop
Good point. You're probably right today, but since the feature is already developed and the use case may arrive in the future (some users may want some types of strings to be quoted, for visual comfort?), I'd be for adding it. What do you think? |
Add ability to: - require strings to be quoted if they match a pattern (PCRE regex) - allow quoted strings if they match a pattern, while `require: only-when-needed` is enforced. Co-Authored-By: Leo Feyer (#246)
Add ability to: - require strings to be quoted if they match a pattern (PCRE regex) - allow quoted strings if they match a pattern, while `require: only-when-needed` is enforced. Co-Authored-By: Leo Feyer (#246)
Change implementation of `required: only-when-needed`, because maintaining a list of `START_TOKENS` and just looking at the first character of string values has proven to be partially broken. Cf. discussion at #246 (comment). Fixes #242.
Change implementation of `required: only-when-needed`, because maintaining a list of `START_TOKENS` and just looking at the first character of string values has proven to be partially broken. Cf. discussion at #246 (comment). Fixes #242 and #244.
Change implementation of `required: only-when-needed`, because maintaining a list of `START_TOKENS` and just looking at the first character of string values has proven to be partially broken. Cf. discussion at #246 (comment). Fixes #242 and #244.
Change implementation of `required: only-when-needed`, because maintaining a list of `START_TOKENS` and just looking at the first character of string values has proven to be partially broken. Cf. discussion at #246 (comment). Fixes #242 and #244.
Add ability to: - require strings to be quoted if they match a pattern (PCRE regex) - allow quoted strings if they match a pattern, while `require: only-when-needed` is enforced. Co-Authored-By: Leo Feyer (#246)
Add ability to: - require strings to be quoted if they match a pattern (PCRE regex) - allow quoted strings if they match a pattern, while `require: only-when-needed` is enforced. Co-Authored-By: Leo Feyer (#246)
This is the follow-up PR to #244, which adds the
needed-extra-regex
option to thequoted-strings
rule.This will suppress the "string value is redundantly quoted" warning for strings starting with a
%
character.