Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0016390e78 | ||
|
|
9e90c777cb | ||
|
|
a2218988ee | ||
|
|
954fdd5e8f | ||
|
|
bbcad943b6 | ||
|
|
30c90dbf70 | ||
|
|
512fe17047 | ||
|
|
278a79f093 | ||
|
|
e98aacf62c | ||
|
|
94c0416f6b |
@@ -1,6 +1,14 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.24.0 (2020-07-15)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Specify config with environment variable ``YAMLLINT_CONFIG_FILE``
|
||||||
|
- Fix bug with CRLF in ``new-lines`` and ``require-starting-space``
|
||||||
|
- Do not run linter on directories whose names look like YAML files
|
||||||
|
- Add ``locale`` config option and make ``key-ordering`` locale-aware
|
||||||
|
|
||||||
1.23.0 (2020-04-17)
|
1.23.0 (2020-04-17)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
44
CONTRIBUTING.rst
Normal file
44
CONTRIBUTING.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
Pull requests are the best way to propose changes to the codebase.
|
||||||
|
Contributions are welcome, but they have to meet some criteria.
|
||||||
|
|
||||||
|
Pull Request Process
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
1. Fork this Git repository and create your branch from ``master``.
|
||||||
|
|
||||||
|
2. Make sure the tests pass:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
python setup.py test
|
||||||
|
|
||||||
|
3. If you add code that should be tested, add tests.
|
||||||
|
|
||||||
|
4. Make sure the linters pass:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
flake8 .
|
||||||
|
|
||||||
|
If you added/modified documentation:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
doc8 $(git ls-files '*.rst')
|
||||||
|
|
||||||
|
If you touched YAML files:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
yamllint --strict $(git ls-files '*.yaml' '*.yml')
|
||||||
|
|
||||||
|
5. If relevant, update documentation (either in ``docs`` directly or in rules
|
||||||
|
files themselves).
|
||||||
|
|
||||||
|
6. Write a `good commit message
|
||||||
|
<http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html>`_.
|
||||||
|
|
||||||
|
7. Then, open a pull request.
|
||||||
@@ -6,9 +6,9 @@ import sys
|
|||||||
import os
|
import os
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath('..')) # noqa
|
sys.path.insert(0, os.path.abspath('..'))
|
||||||
|
|
||||||
from yamllint import __copyright__, APP_NAME, APP_VERSION
|
from yamllint import __copyright__, APP_NAME, APP_VERSION # noqa
|
||||||
|
|
||||||
# -- General configuration ------------------------------------------------
|
# -- General configuration ------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ following locations (by order of preference):
|
|||||||
|
|
||||||
- ``.yamllint``, ``.yamllint.yaml`` or ``.yamllint.yml`` in the current working
|
- ``.yamllint``, ``.yamllint.yaml`` or ``.yamllint.yml`` in the current working
|
||||||
directory
|
directory
|
||||||
|
- the file referenced by ``$YAMLLINT_CONFIG_FILE``, if set
|
||||||
- ``$XDG_CONFIG_HOME/yamllint/config``
|
- ``$XDG_CONFIG_HOME/yamllint/config``
|
||||||
- ``~/.config/yamllint/config``
|
- ``~/.config/yamllint/config``
|
||||||
|
|
||||||
@@ -188,3 +189,22 @@ Here is a more complex example:
|
|||||||
ignore: |
|
ignore: |
|
||||||
*.ignore-trailing-spaces.yaml
|
*.ignore-trailing-spaces.yaml
|
||||||
ascii-art/*
|
ascii-art/*
|
||||||
|
|
||||||
|
Setting the locale
|
||||||
|
------------------
|
||||||
|
|
||||||
|
It is possible to set the ``locale`` option globally. This is passed to Python's
|
||||||
|
`locale.setlocale
|
||||||
|
<https://docs.python.org/3/library/locale.html#locale.setlocale>`_,
|
||||||
|
so an empty string ``""`` will use the system default locale, while e.g.
|
||||||
|
``"en_US.UTF-8"`` will use that. If unset, the default is ``"C.UTF-8"``.
|
||||||
|
|
||||||
|
Currently this only affects the ``key-ordering`` rule. The default will order
|
||||||
|
by Unicode code point number, while other locales will sort case and accents
|
||||||
|
properly as well.
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
locale: en_US.UTF-8
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ universal = 1
|
|||||||
[flake8]
|
[flake8]
|
||||||
import-order-style = pep8
|
import-order-style = pep8
|
||||||
application-import-names = yamllint
|
application-import-names = yamllint
|
||||||
|
ignore = W503,W504
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
all-files = 1
|
all-files = 1
|
||||||
|
|||||||
1
setup.py
1
setup.py
@@ -42,6 +42,7 @@ setup(
|
|||||||
'Programming Language :: Python :: 3.5',
|
'Programming Language :: Python :: 3.5',
|
||||||
'Programming Language :: Python :: 3.6',
|
'Programming Language :: Python :: 3.6',
|
||||||
'Programming Language :: Python :: 3.7',
|
'Programming Language :: Python :: 3.7',
|
||||||
|
'Programming Language :: Python :: 3.8',
|
||||||
'Topic :: Software Development',
|
'Topic :: Software Development',
|
||||||
'Topic :: Software Development :: Debuggers',
|
'Topic :: Software Development :: Debuggers',
|
||||||
'Topic :: Software Development :: Quality Assurance',
|
'Topic :: Software Development :: Quality Assurance',
|
||||||
|
|||||||
@@ -186,6 +186,27 @@ class CommentsTestCase(RuleTestCase):
|
|||||||
'inline: comment #\n'
|
'inline: comment #\n'
|
||||||
'foo: bar\n', conf)
|
'foo: bar\n', conf)
|
||||||
|
|
||||||
|
def test_empty_comment_crlf_dos_newlines(self):
|
||||||
|
conf = ('comments:\n'
|
||||||
|
' require-starting-space: true\n'
|
||||||
|
' min-spaces-from-content: 2\n'
|
||||||
|
'new-lines:\n'
|
||||||
|
' type: dos\n')
|
||||||
|
self.check('---\r\n'
|
||||||
|
'# This is paragraph 1.\r\n'
|
||||||
|
'#\r\n'
|
||||||
|
'# This is paragraph 2.\r\n', conf)
|
||||||
|
|
||||||
|
def test_empty_comment_crlf_disabled_newlines(self):
|
||||||
|
conf = ('comments:\n'
|
||||||
|
' require-starting-space: true\n'
|
||||||
|
' min-spaces-from-content: 2\n'
|
||||||
|
'new-lines: disable\n')
|
||||||
|
self.check('---\r\n'
|
||||||
|
'# This is paragraph 1.\r\n'
|
||||||
|
'#\r\n'
|
||||||
|
'# This is paragraph 2.\r\n', conf)
|
||||||
|
|
||||||
def test_first_line(self):
|
def test_first_line(self):
|
||||||
conf = ('comments:\n'
|
conf = ('comments:\n'
|
||||||
' require-starting-space: true\n'
|
' require-starting-space: true\n'
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import locale
|
||||||
|
|
||||||
from tests.common import RuleTestCase
|
from tests.common import RuleTestCase
|
||||||
|
|
||||||
|
|
||||||
@@ -103,10 +105,6 @@ class KeyOrderingTestCase(RuleTestCase):
|
|||||||
'haïr: true\n'
|
'haïr: true\n'
|
||||||
'hais: true\n', conf,
|
'hais: true\n', conf,
|
||||||
problem=(3, 1))
|
problem=(3, 1))
|
||||||
self.check('---\n'
|
|
||||||
'haïr: true\n'
|
|
||||||
'hais: true\n', conf,
|
|
||||||
problem=(3, 1))
|
|
||||||
|
|
||||||
def test_key_tokens_in_flow_sequences(self):
|
def test_key_tokens_in_flow_sequences(self):
|
||||||
conf = 'key-ordering: enable'
|
conf = 'key-ordering: enable'
|
||||||
@@ -114,3 +112,39 @@ class KeyOrderingTestCase(RuleTestCase):
|
|||||||
'[\n'
|
'[\n'
|
||||||
' key: value, mappings, in, flow: sequence\n'
|
' key: value, mappings, in, flow: sequence\n'
|
||||||
']\n', conf)
|
']\n', conf)
|
||||||
|
|
||||||
|
def test_locale_case(self):
|
||||||
|
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8')
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
|
except locale.Error:
|
||||||
|
self.skipTest('locale en_US.UTF-8 not available')
|
||||||
|
conf = ('key-ordering: enable')
|
||||||
|
self.check('---\n'
|
||||||
|
't-shirt: 1\n'
|
||||||
|
'T-shirt: 2\n'
|
||||||
|
't-shirts: 3\n'
|
||||||
|
'T-shirts: 4\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
't-shirt: 1\n'
|
||||||
|
't-shirts: 2\n'
|
||||||
|
'T-shirt: 3\n'
|
||||||
|
'T-shirts: 4\n', conf,
|
||||||
|
problem=(4, 1))
|
||||||
|
|
||||||
|
def test_locale_accents(self):
|
||||||
|
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8')
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
|
except locale.Error:
|
||||||
|
self.skipTest('locale en_US.UTF-8 not available')
|
||||||
|
conf = ('key-ordering: enable')
|
||||||
|
self.check('---\n'
|
||||||
|
'hair: true\n'
|
||||||
|
'haïr: true\n'
|
||||||
|
'hais: true\n'
|
||||||
|
'haïssable: true\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'hais: true\n'
|
||||||
|
'haïr: true\n', conf,
|
||||||
|
problem=(3, 1))
|
||||||
|
|||||||
@@ -40,6 +40,16 @@ class NewLinesTestCase(RuleTestCase):
|
|||||||
self.check('---\ntext\n', conf)
|
self.check('---\ntext\n', conf)
|
||||||
self.check('---\r\ntext\r\n', conf, problem=(1, 4))
|
self.check('---\r\ntext\r\n', conf, problem=(1, 4))
|
||||||
|
|
||||||
|
def test_unix_type_required_st_sp(self):
|
||||||
|
# If we find a CRLF when looking for Unix newlines, yamllint
|
||||||
|
# should always raise, regardless of logic with
|
||||||
|
# require-starting-space.
|
||||||
|
conf = ('new-line-at-end-of-file: disable\n'
|
||||||
|
'new-lines: {type: unix}\n'
|
||||||
|
'comments:\n'
|
||||||
|
' require-starting-space: true\n')
|
||||||
|
self.check('---\r\n#\r\n', conf, problem=(1, 4))
|
||||||
|
|
||||||
def test_dos_type(self):
|
def test_dos_type(self):
|
||||||
conf = ('new-line-at-end-of-file: disable\n'
|
conf = ('new-line-at-end-of-file: disable\n'
|
||||||
'new-lines: {type: dos}\n')
|
'new-lines: {type: dos}\n')
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import os
|
|||||||
import pty
|
import pty
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from tests.common import build_temp_workspace
|
from tests.common import build_temp_workspace
|
||||||
@@ -72,6 +73,9 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
# file in dir
|
# file in dir
|
||||||
'sub/ok.yaml': '---\n'
|
'sub/ok.yaml': '---\n'
|
||||||
'key: value\n',
|
'key: value\n',
|
||||||
|
# directory that looks like a yaml file
|
||||||
|
'sub/directory.yaml/not-yaml.txt': '',
|
||||||
|
'sub/directory.yaml/empty.yml': '',
|
||||||
# file in very nested dir
|
# file in very nested dir
|
||||||
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml': '---\n'
|
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml': '---\n'
|
||||||
'key: value\n'
|
'key: value\n'
|
||||||
@@ -91,6 +95,13 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
# dos line endings yaml
|
# dos line endings yaml
|
||||||
'dos.yml': '---\r\n'
|
'dos.yml': '---\r\n'
|
||||||
'dos: true',
|
'dos: true',
|
||||||
|
# different key-ordering by locale
|
||||||
|
'c.yaml': '---\n'
|
||||||
|
'A: true\n'
|
||||||
|
'a: true',
|
||||||
|
'en.yaml': '---\n'
|
||||||
|
'a: true\n'
|
||||||
|
'A: true'
|
||||||
})
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -104,9 +115,12 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively([self.wd], conf)),
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
[os.path.join(self.wd, 'a.yaml'),
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'c.yaml'),
|
||||||
os.path.join(self.wd, 'dos.yml'),
|
os.path.join(self.wd, 'dos.yml'),
|
||||||
os.path.join(self.wd, 'empty.yml'),
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'en.yaml'),
|
||||||
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
|
||||||
os.path.join(self.wd, 'sub/ok.yaml'),
|
os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
os.path.join(self.wd, 'warn.yaml')],
|
os.path.join(self.wd, 'warn.yaml')],
|
||||||
)
|
)
|
||||||
@@ -131,6 +145,7 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively(items, conf)),
|
sorted(cli.find_files_recursively(items, conf)),
|
||||||
[os.path.join(self.wd, '/etc/another/file'),
|
[os.path.join(self.wd, '/etc/another/file'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
|
||||||
os.path.join(self.wd, 'sub/ok.yaml')],
|
os.path.join(self.wd, 'sub/ok.yaml')],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -140,6 +155,8 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively([self.wd], conf)),
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
[os.path.join(self.wd, 'a.yaml'),
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'c.yaml'),
|
||||||
|
os.path.join(self.wd, 'en.yaml'),
|
||||||
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
||||||
os.path.join(self.wd, 'sub/ok.yaml'),
|
os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
os.path.join(self.wd, 'warn.yaml')]
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
@@ -151,7 +168,8 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively([self.wd], conf)),
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
[os.path.join(self.wd, 'dos.yml'),
|
[os.path.join(self.wd, 'dos.yml'),
|
||||||
os.path.join(self.wd, 'empty.yml')]
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/empty.yml')]
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = config.YamlLintConfig('extends: default\n'
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
@@ -168,11 +186,15 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively([self.wd], conf)),
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
[os.path.join(self.wd, 'a.yaml'),
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'c.yaml'),
|
||||||
os.path.join(self.wd, 'dos.yml'),
|
os.path.join(self.wd, 'dos.yml'),
|
||||||
os.path.join(self.wd, 'empty.yml'),
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'en.yaml'),
|
||||||
os.path.join(self.wd, 'no-yaml.json'),
|
os.path.join(self.wd, 'no-yaml.json'),
|
||||||
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
|
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
|
||||||
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
|
||||||
os.path.join(self.wd, 'sub/ok.yaml'),
|
os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
os.path.join(self.wd, 'warn.yaml')]
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
)
|
)
|
||||||
@@ -185,11 +207,15 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively([self.wd], conf)),
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
[os.path.join(self.wd, 'a.yaml'),
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'c.yaml'),
|
||||||
os.path.join(self.wd, 'dos.yml'),
|
os.path.join(self.wd, 'dos.yml'),
|
||||||
os.path.join(self.wd, 'empty.yml'),
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'en.yaml'),
|
||||||
os.path.join(self.wd, 'no-yaml.json'),
|
os.path.join(self.wd, 'no-yaml.json'),
|
||||||
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
|
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
|
||||||
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
|
||||||
os.path.join(self.wd, 'sub/ok.yaml'),
|
os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
os.path.join(self.wd, 'warn.yaml')]
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
)
|
)
|
||||||
@@ -285,6 +311,58 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
||||||
self.assertEqual(ctx.returncode, 1)
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
|
def test_run_with_user_yamllint_config_file_in_env(self):
|
||||||
|
self.addCleanup(os.environ.__delitem__, 'YAMLLINT_CONFIG_FILE')
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile('w') as f:
|
||||||
|
os.environ['YAMLLINT_CONFIG_FILE'] = f.name
|
||||||
|
f.write('rules: {trailing-spaces: disable}')
|
||||||
|
f.flush()
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
||||||
|
self.assertEqual(ctx.returncode, 0)
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile('w') as f:
|
||||||
|
os.environ['YAMLLINT_CONFIG_FILE'] = f.name
|
||||||
|
f.write('rules: {trailing-spaces: enable}')
|
||||||
|
f.flush()
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
||||||
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
|
def test_run_with_locale(self):
|
||||||
|
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8')
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
|
except locale.Error:
|
||||||
|
self.skipTest('locale en_US.UTF-8 not available')
|
||||||
|
|
||||||
|
# C + en.yaml should fail
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('-d', 'rules: { key-ordering: enable }',
|
||||||
|
os.path.join(self.wd, 'en.yaml')))
|
||||||
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
|
# en_US + en.yaml should pass
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('-d', 'locale: en_US.UTF-8\n'
|
||||||
|
'rules: { key-ordering: enable }',
|
||||||
|
os.path.join(self.wd, 'en.yaml')))
|
||||||
|
self.assertEqual(ctx.returncode, 0)
|
||||||
|
|
||||||
|
# en_US + c.yaml should fail
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('-d', 'locale: en_US.UTF-8\n'
|
||||||
|
'rules: { key-ordering: enable }',
|
||||||
|
os.path.join(self.wd, 'c.yaml')))
|
||||||
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
|
# C + c.yaml should pass
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('-d', 'rules: { key-ordering: enable }',
|
||||||
|
os.path.join(self.wd, 'c.yaml')))
|
||||||
|
self.assertEqual(ctx.returncode, 0)
|
||||||
|
|
||||||
def test_run_version(self):
|
def test_run_version(self):
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
cli.run(('--version', ))
|
cli.run(('--version', ))
|
||||||
@@ -343,15 +421,6 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
def test_run_non_ascii_file(self):
|
def test_run_non_ascii_file(self):
|
||||||
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
|
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
|
||||||
|
|
||||||
# Make sure the default localization conditions on this "system"
|
|
||||||
# support UTF-8 encoding.
|
|
||||||
loc = locale.getlocale()
|
|
||||||
try:
|
|
||||||
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
|
|
||||||
except locale.Error:
|
|
||||||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
|
||||||
self.addCleanup(locale.setlocale, locale.LC_ALL, loc)
|
|
||||||
|
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
cli.run(('-f', 'parsable', path))
|
cli.run(('-f', 'parsable', path))
|
||||||
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = 'yamllint'
|
APP_NAME = 'yamllint'
|
||||||
APP_VERSION = '1.23.0'
|
APP_VERSION = '1.24.0'
|
||||||
APP_DESCRIPTION = __doc__
|
APP_DESCRIPTION = __doc__
|
||||||
|
|
||||||
__author__ = u'Adrien Vergé'
|
__author__ = u'Adrien Vergé'
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import io
|
import io
|
||||||
|
import locale
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
@@ -144,8 +145,11 @@ def run(argv=None):
|
|||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
if 'YAMLLINT_CONFIG_FILE' in os.environ:
|
||||||
|
user_global_config = os.path.expanduser(
|
||||||
|
os.environ['YAMLLINT_CONFIG_FILE'])
|
||||||
# User-global config is supposed to be in ~/.config/yamllint/config
|
# User-global config is supposed to be in ~/.config/yamllint/config
|
||||||
if 'XDG_CONFIG_HOME' in os.environ:
|
elif 'XDG_CONFIG_HOME' in os.environ:
|
||||||
user_global_config = os.path.join(
|
user_global_config = os.path.join(
|
||||||
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
|
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
|
||||||
else:
|
else:
|
||||||
@@ -172,6 +176,8 @@ def run(argv=None):
|
|||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
locale.setlocale(locale.LC_ALL, conf.locale)
|
||||||
|
|
||||||
max_level = 0
|
max_level = 0
|
||||||
|
|
||||||
for file in find_files_recursively(args.files, conf):
|
for file in find_files_recursively(args.files, conf):
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class YamlLintConfig(object):
|
|||||||
self.yaml_files = pathspec.PathSpec.from_lines(
|
self.yaml_files = pathspec.PathSpec.from_lines(
|
||||||
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
|
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
|
||||||
|
|
||||||
|
self.locale = 'C.UTF-8'
|
||||||
|
|
||||||
if file is not None:
|
if file is not None:
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
@@ -46,7 +48,7 @@ class YamlLintConfig(object):
|
|||||||
return self.ignore and self.ignore.match_file(filepath)
|
return self.ignore and self.ignore.match_file(filepath)
|
||||||
|
|
||||||
def is_yaml_file(self, filepath):
|
def is_yaml_file(self, filepath):
|
||||||
return self.yaml_files.match_file(filepath)
|
return self.yaml_files.match_file(os.path.basename(filepath))
|
||||||
|
|
||||||
def enabled_rules(self, filepath):
|
def enabled_rules(self, filepath):
|
||||||
return [yamllint.rules.get(id) for id, val in self.rules.items()
|
return [yamllint.rules.get(id) for id, val in self.rules.items()
|
||||||
@@ -111,6 +113,12 @@ class YamlLintConfig(object):
|
|||||||
self.yaml_files = pathspec.PathSpec.from_lines('gitwildmatch',
|
self.yaml_files = pathspec.PathSpec.from_lines('gitwildmatch',
|
||||||
conf['yaml-files'])
|
conf['yaml-files'])
|
||||||
|
|
||||||
|
if 'locale' in conf:
|
||||||
|
if not isinstance(conf['locale'], str):
|
||||||
|
raise YamlLintConfigError(
|
||||||
|
'invalid config: locale should be a string')
|
||||||
|
self.locale = conf['locale']
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
for id in self.rules:
|
for id in self.rules:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -97,7 +97,9 @@ def check(conf, comment):
|
|||||||
comment.column_no == 1 and
|
comment.column_no == 1 and
|
||||||
re.match(r'^!\S', comment.buffer[text_start:])):
|
re.match(r'^!\S', comment.buffer[text_start:])):
|
||||||
return
|
return
|
||||||
elif comment.buffer[text_start] not in (' ', '\n', '\0'):
|
# We can test for both \r and \r\n just by checking first char
|
||||||
|
# \r itself is a valid newline on some older OS.
|
||||||
|
elif comment.buffer[text_start] not in {' ', '\n', '\r', '\x00'}:
|
||||||
column = comment.column_no + text_start - comment.pointer
|
column = comment.column_no + text_start - comment.pointer
|
||||||
yield LintProblem(comment.line_no,
|
yield LintProblem(comment.line_no,
|
||||||
column,
|
column,
|
||||||
|
|||||||
@@ -16,8 +16,10 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Use this rule to enforce alphabetical ordering of keys in mappings. The sorting
|
Use this rule to enforce alphabetical ordering of keys in mappings. The sorting
|
||||||
order uses the Unicode code point number. As a result, the ordering is
|
order uses the Unicode code point number as a default. As a result, the
|
||||||
case-sensitive and not accent-friendly (see examples below).
|
ordering is case-sensitive and not accent-friendly (see examples below).
|
||||||
|
This can be changed by setting the global ``locale`` option. This allows to
|
||||||
|
sort case and accents properly.
|
||||||
|
|
||||||
.. rubric:: Examples
|
.. rubric:: Examples
|
||||||
|
|
||||||
@@ -63,8 +65,24 @@ case-sensitive and not accent-friendly (see examples below).
|
|||||||
|
|
||||||
- haïr: true
|
- haïr: true
|
||||||
hais: true
|
hais: true
|
||||||
|
|
||||||
|
#. With global option ``locale: "en_US.UTF-8"`` and rule ``key-ordering: {}``
|
||||||
|
|
||||||
|
as opposed to before, the following code snippet would now **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
- t-shirt: 1
|
||||||
|
T-shirt: 2
|
||||||
|
t-shirts: 3
|
||||||
|
T-shirts: 4
|
||||||
|
- hair: true
|
||||||
|
haïr: true
|
||||||
|
hais: true
|
||||||
|
haïssable: true
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from locale import strcoll
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from yamllint.linter import LintProblem
|
from yamllint.linter import LintProblem
|
||||||
@@ -101,7 +119,8 @@ def check(conf, token, prev, next, nextnext, context):
|
|||||||
# This check is done because KeyTokens can be found inside flow
|
# This check is done because KeyTokens can be found inside flow
|
||||||
# sequences... strange, but allowed.
|
# sequences... strange, but allowed.
|
||||||
if len(context['stack']) > 0 and context['stack'][-1].type == MAP:
|
if len(context['stack']) > 0 and context['stack'][-1].type == MAP:
|
||||||
if any(next.value < key for key in context['stack'][-1].keys):
|
if any(strcoll(next.value, key) < 0
|
||||||
|
for key in context['stack'][-1].keys):
|
||||||
yield LintProblem(
|
yield LintProblem(
|
||||||
next.start_mark.line + 1, next.start_mark.column + 1,
|
next.start_mark.line + 1, next.start_mark.column + 1,
|
||||||
'wrong ordering of key "%s" in mapping' % next.value)
|
'wrong ordering of key "%s" in mapping' % next.value)
|
||||||
|
|||||||
Reference in New Issue
Block a user