Hello community,

here is the log from the commit of package python-yamllint for openSUSE:Factory 
checked in at 2020-07-08 19:12:41
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-yamllint (Old)
 and      /work/SRC/openSUSE:Factory/.python-yamllint.new.3060 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-yamllint"

Wed Jul  8 19:12:41 2020 rev:10 rq:819117 version:1.23.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-yamllint/python-yamllint.changes  
2020-04-16 23:03:26.431684763 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-yamllint.new.3060/python-yamllint.changes    
    2020-07-08 19:12:57.415101363 +0200
@@ -1,0 +2,7 @@
+Tue Jul  7 06:14:04 UTC 2020 - Steve Kowalik <[email protected]>
+
+-  Update to 1.23.0:
+  * Allow rules to validate their configuration
+  * Add options extra-required and extra-allowed to quoted-strings
+
+-------------------------------------------------------------------

Old:
----
  yamllint-1.22.1.tar.gz

New:
----
  yamllint-1.23.0.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-yamllint.spec ++++++
--- /var/tmp/diff_new_pack.0NLIKS/_old  2020-07-08 19:13:01.339114902 +0200
+++ /var/tmp/diff_new_pack.0NLIKS/_new  2020-07-08 19:13:01.343114916 +0200
@@ -18,7 +18,7 @@
 
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 Name:           python-yamllint
-Version:        1.22.1
+Version:        1.23.0
 Release:        0
 Summary:        A linter for YAML files
 License:        GPL-3.0-only

++++++ yamllint-1.22.1.tar.gz -> yamllint-1.23.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yamllint-1.22.1/PKG-INFO new/yamllint-1.23.0/PKG-INFO
--- old/yamllint-1.22.1/PKG-INFO        2020-04-15 07:57:48.000000000 +0200
+++ new/yamllint-1.23.0/PKG-INFO        2020-04-17 10:34:16.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.2
 Name: yamllint
-Version: 1.22.1
+Version: 1.23.0
 Summary: A linter for YAML files.
 Home-page: https://github.com/adrienverge/yamllint
 Author: Adrien Vergé
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yamllint-1.22.1/tests/rules/test_quoted_strings.py 
new/yamllint-1.23.0/tests/rules/test_quoted_strings.py
--- old/yamllint-1.22.1/tests/rules/test_quoted_strings.py      2020-04-15 
07:54:25.000000000 +0200
+++ new/yamllint-1.23.0/tests/rules/test_quoted_strings.py      2020-04-17 
10:30:12.000000000 +0200
@@ -16,6 +16,8 @@
 
 from tests.common import RuleTestCase
 
+from yamllint import config
+
 
 class QuotedTestCase(RuleTestCase):
     rule_id = 'quoted-strings'
@@ -357,3 +359,79 @@
                    'k5: :wq\n'
                    'k6: ":wq"\n',                  # fails
                    conf, problem1=(3, 5), problem2=(5, 5), problem3=(7, 5))
+
+    def test_only_when_needed_extras(self):
+        conf = ('quoted-strings:\n'
+                '  required: true\n'
+                '  extra-allowed: [^http://]\n')
+        self.assertRaises(config.YamlLintConfigError, self.check, '', conf)
+
+        conf = ('quoted-strings:\n'
+                '  required: true\n'
+                '  extra-required: [^http://]\n')
+        self.assertRaises(config.YamlLintConfigError, self.check, '', conf)
+
+        conf = ('quoted-strings:\n'
+                '  required: false\n'
+                '  extra-allowed: [^http://]\n')
+        self.assertRaises(config.YamlLintConfigError, self.check, '', conf)
+
+        conf = ('quoted-strings:\n'
+                '  required: true\n')
+        self.check('---\n'
+                   '- 123\n'
+                   '- "123"\n'
+                   '- localhost\n'                  # fails
+                   '- "localhost"\n'
+                   '- http://localhost\n'           # fails
+                   '- "http://localhost"\n'
+                   '- ftp://localhost\n'            # fails
+                   '- "ftp://localhost"\n',
+                   conf, problem1=(4, 3), problem2=(6, 3), problem3=(8, 3))
+
+        conf = ('quoted-strings:\n'
+                '  required: only-when-needed\n'
+                '  extra-allowed: [^ftp://]\n'
+                '  extra-required: [^http://]\n')
+        self.check('---\n'
+                   '- 123\n'
+                   '- "123"\n'
+                   '- localhost\n'
+                   '- "localhost"\n'                # fails
+                   '- http://localhost\n'           # fails
+                   '- "http://localhost"\n'
+                   '- ftp://localhost\n'
+                   '- "ftp://localhost"\n',
+                   conf, problem1=(5, 3), problem2=(6, 3))
+
+        conf = ('quoted-strings:\n'
+                '  required: false\n'
+                '  extra-required: [^http://, ^ftp://]\n')
+        self.check('---\n'
+                   '- 123\n'
+                   '- "123"\n'
+                   '- localhost\n'
+                   '- "localhost"\n'
+                   '- http://localhost\n'           # fails
+                   '- "http://localhost"\n'
+                   '- ftp://localhost\n'            # fails
+                   '- "ftp://localhost"\n',
+                   conf, problem1=(6, 3), problem2=(8, 3))
+
+        conf = ('quoted-strings:\n'
+                '  required: only-when-needed\n'
+                '  extra-allowed: [^ftp://, ";$", " "]\n')
+        self.check('---\n'
+                   '- localhost\n'
+                   '- "localhost"\n'                # fails
+                   '- ftp://localhost\n'
+                   '- "ftp://localhost"\n'
+                   '- i=i+1\n'
+                   '- "i=i+1"\n'                # fails
+                   '- i=i+2;\n'
+                   '- "i=i+2;"\n'
+                   '- foo\n'
+                   '- "foo"\n'                      # fails
+                   '- foo bar\n'
+                   '- "foo bar"\n',
+                   conf, problem1=(3, 3), problem2=(7, 3), problem3=(11, 3))
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yamllint-1.22.1/yamllint/__init__.py 
new/yamllint-1.23.0/yamllint/__init__.py
--- old/yamllint-1.22.1/yamllint/__init__.py    2020-04-15 07:55:42.000000000 
+0200
+++ new/yamllint-1.23.0/yamllint/__init__.py    2020-04-17 10:30:32.000000000 
+0200
@@ -22,7 +22,7 @@
 
 
 APP_NAME = 'yamllint'
-APP_VERSION = '1.22.1'
+APP_VERSION = '1.23.0'
 APP_DESCRIPTION = __doc__
 
 __author__ = u'Adrien Vergé'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yamllint-1.22.1/yamllint/config.py 
new/yamllint-1.23.0/yamllint/config.py
--- old/yamllint-1.22.1/yamllint/config.py      2020-04-15 07:54:25.000000000 
+0200
+++ new/yamllint-1.23.0/yamllint/config.py      2020-04-17 10:30:12.000000000 
+0200
@@ -157,11 +157,12 @@
                     raise YamlLintConfigError(
                         'invalid config: option "%s" of "%s" should be in %s'
                         % (optkey, rule.ID, options[optkey]))
-            # Example: CONF = {option: ['flag1', 'flag2']}
-            #          → {option: [flag1]}      → {option: [flag1, flag2]}
+            # Example: CONF = {option: ['flag1', 'flag2', int]}
+            #          → {option: [flag1]}      → {option: [42, flag1, flag2]}
             elif isinstance(options[optkey], list):
                 if (type(conf[optkey]) is not list or
-                        any(flag not in options[optkey]
+                        any(flag not in options[optkey] and
+                            type(flag) not in options[optkey]
                             for flag in conf[optkey])):
                     raise YamlLintConfigError(
                         ('invalid config: option "%s" of "%s" should only '
@@ -177,6 +178,12 @@
         for optkey in options:
             if optkey not in conf:
                 conf[optkey] = options_default[optkey]
+
+        if hasattr(rule, 'VALIDATE'):
+            res = rule.VALIDATE(conf)
+            if res:
+                raise YamlLintConfigError('invalid config: %s: %s' %
+                                          (rule.ID, res))
     else:
         raise YamlLintConfigError(('invalid config: rule "%s": should be '
                                    'either "enable", "disable" or a dict')
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yamllint-1.22.1/yamllint/rules/quoted_strings.py 
new/yamllint-1.23.0/yamllint/rules/quoted_strings.py
--- old/yamllint-1.22.1/yamllint/rules/quoted_strings.py        2020-04-15 
07:54:25.000000000 +0200
+++ new/yamllint-1.23.0/yamllint/rules/quoted_strings.py        2020-04-17 
10:30:12.000000000 +0200
@@ -26,6 +26,11 @@
 * ``required`` defines whether using quotes in string values is required
   (``true``, default) or not (``false``), or only allowed when really needed
   (``only-when-needed``).
+* ``extra-required`` is a list of PCRE regexes to force string values to be
+  quoted, if they match any regex. This option can only be used with
+  ``required: false`` and  ``required: only-when-needed``.
+* ``extra-allowed`` is a list of PCRE regexes to allow quoted string values,
+  even if ``required: only-when-needed`` is set.
 
 **Note**: Multi-line strings (with ``|`` or ``>``) will not be checked.
 
@@ -63,8 +68,44 @@
    ::
 
     foo: 'bar'
+
+#. With ``quoted-strings: {required: false, extra-required: [^http://,
+   ^ftp://]}``
+
+   the following code snippet would **PASS**:
+   ::
+
+    - localhost
+    - "localhost"
+    - "http://localhost";
+    - "ftp://localhost";
+
+   the following code snippet would **FAIL**:
+   ::
+
+    - http://localhost
+    - ftp://localhost
+
+#. With ``quoted-strings: {required: only-when-needed, extra-allowed:
+   [^http://, ^ftp://], extra-required: [QUOTED]}``
+
+   the following code snippet would **PASS**:
+   ::
+
+    - localhost
+    - "http://localhost";
+    - "ftp://localhost";
+    - "this is a string that needs to be QUOTED"
+
+   the following code snippet would **FAIL**:
+   ::
+
+    - "localhost"
+    - this is a string that needs to be QUOTED
 """
 
+import re
+
 import yaml
 
 from yamllint.linter import LintProblem
@@ -72,9 +113,23 @@
 ID = 'quoted-strings'
 TYPE = 'token'
 CONF = {'quote-type': ('any', 'single', 'double'),
-        'required': (True, False, 'only-when-needed')}
+        'required': (True, False, 'only-when-needed'),
+        'extra-required': [str],
+        'extra-allowed': [str]}
 DEFAULT = {'quote-type': 'any',
-           'required': True}
+           'required': True,
+           'extra-required': [],
+           'extra-allowed': []}
+
+
+def VALIDATE(conf):
+    if conf['required'] is True and len(conf['extra-allowed']) > 0:
+        return 'cannot use both "required: true" and "extra-allowed"'
+    if conf['required'] is True and len(conf['extra-required']) > 0:
+        return 'cannot use both "required: true" and "extra-required"'
+    if conf['required'] is False and len(conf['extra-allowed']) > 0:
+        return 'cannot use both "required: false" and "extra-allowed"'
+
 
 DEFAULT_SCALAR_TAG = u'tag:yaml.org,2002:str'
 
@@ -125,36 +180,48 @@
         return
 
     quote_type = conf['quote-type']
-    required = conf['required']
-
-    # Completely relaxed about quotes (same as the rule being disabled)
-    if required is False and quote_type == 'any':
-        return
 
     msg = None
-    if required is True:
+    if conf['required'] is True:
 
         # Quotes are mandatory and need to match config
         if token.style is None or not _quote_match(quote_type, token.style):
-            msg = "string value is not quoted with %s quotes" % (quote_type)
+            msg = "string value is not quoted with %s quotes" % quote_type
 
-    elif required is False:
+    elif conf['required'] is False:
 
         # Quotes are not mandatory but when used need to match config
         if token.style and not _quote_match(quote_type, token.style):
-            msg = "string value is not quoted with %s quotes" % (quote_type)
+            msg = "string value is not quoted with %s quotes" % quote_type
+
+        elif not token.style:
+            is_extra_required = any(re.search(r, token.value)
+                                    for r in conf['extra-required'])
+            if is_extra_required:
+                msg = "string value is not quoted"
 
-    elif not token.plain:
+    elif conf['required'] == 'only-when-needed':
 
-        # Quotes are disallowed when not needed
-        if (tag == DEFAULT_SCALAR_TAG and token.value and
+        # Quotes are not strictly needed here
+        if (token.style and tag == DEFAULT_SCALAR_TAG and token.value and
                 not _quotes_are_needed(token.value)):
-            msg = "string value is redundantly quoted with %s quotes" % (
-                quote_type)
+            is_extra_required = any(re.search(r, token.value)
+                                    for r in conf['extra-required'])
+            is_extra_allowed = any(re.search(r, token.value)
+                                   for r in conf['extra-allowed'])
+            if not (is_extra_required or is_extra_allowed):
+                msg = "string value is redundantly quoted with %s quotes" % (
+                    quote_type)
 
         # But when used need to match config
         elif token.style and not _quote_match(quote_type, token.style):
-            msg = "string value is not quoted with %s quotes" % (quote_type)
+            msg = "string value is not quoted with %s quotes" % quote_type
+
+        elif not token.style:
+            is_extra_required = len(conf['extra-required']) and any(
+                re.search(r, token.value) for r in conf['extra-required'])
+            if is_extra_required:
+                msg = "string value is not quoted"
 
     if msg is not None:
         yield LintProblem(
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yamllint-1.22.1/yamllint.egg-info/PKG-INFO 
new/yamllint-1.23.0/yamllint.egg-info/PKG-INFO
--- old/yamllint-1.22.1/yamllint.egg-info/PKG-INFO      2020-04-15 
07:57:48.000000000 +0200
+++ new/yamllint-1.23.0/yamllint.egg-info/PKG-INFO      2020-04-17 
10:34:16.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.2
 Name: yamllint
-Version: 1.22.1
+Version: 1.23.0
 Summary: A linter for YAML files.
 Home-page: https://github.com/adrienverge/yamllint
 Author: Adrien Vergé


Reply via email to