Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce0336e430 | ||
|
|
063c854658 | ||
|
|
673bdbd324 | ||
|
|
cb5fe2c050 | ||
|
|
930c8eea94 |
@@ -1,6 +1,13 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.17.0 (2019-08-12)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Simplify installation instructions in the README
|
||||||
|
- Add OpenBSD installation instructions
|
||||||
|
- Make YAML file extensions configurable
|
||||||
|
|
||||||
1.16.0 (2019-06-07)
|
1.16.0 (2019-06-07)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
32
README.rst
32
README.rst
@@ -38,38 +38,16 @@ Screenshot
|
|||||||
Installation
|
Installation
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
On Fedora / CentOS (note: `EPEL <https://fedoraproject.org/wiki/EPEL>`_ is
|
Using pip, the Python package manager:
|
||||||
required on CentOS):
|
|
||||||
|
|
||||||
.. code:: bash
|
|
||||||
|
|
||||||
sudo dnf install yamllint
|
|
||||||
|
|
||||||
On Debian 8+ / Ubuntu 16.04+:
|
|
||||||
|
|
||||||
.. code:: bash
|
|
||||||
|
|
||||||
sudo apt-get install yamllint
|
|
||||||
|
|
||||||
On FreeBSD:
|
|
||||||
|
|
||||||
.. code:: sh
|
|
||||||
|
|
||||||
pkg install py27-yamllint
|
|
||||||
pkg install py36-yamllint
|
|
||||||
|
|
||||||
On Mac OS 10.11+:
|
|
||||||
|
|
||||||
.. code:: bash
|
|
||||||
|
|
||||||
brew install yamllint
|
|
||||||
|
|
||||||
Alternatively using pip, the Python package manager:
|
|
||||||
|
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
pip install --user yamllint
|
pip install --user yamllint
|
||||||
|
|
||||||
|
yamllint is also packaged for all major operating systems, see installation
|
||||||
|
examples (``dnf``, ``apt-get``...) `in the documentation
|
||||||
|
<https://yamllint.readthedocs.io/en/stable/quickstart.html>`_.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
^^^^^
|
^^^^^
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,21 @@ return code will be:
|
|||||||
* ``1`` if one or more errors occur
|
* ``1`` if one or more errors occur
|
||||||
* ``2`` if no errors occur, but one or more warnings occur
|
* ``2`` if no errors occur, but one or more warnings occur
|
||||||
|
|
||||||
|
YAML files extensions
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
To configure what yamllint should consider as YAML files, set ``yaml-files``
|
||||||
|
configuration option. The default is:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
yaml-files:
|
||||||
|
- '*.yaml'
|
||||||
|
- '*.yml'
|
||||||
|
|
||||||
|
The same rules as for ignoring paths apply (``.gitignore``-style path pattern,
|
||||||
|
see below).
|
||||||
|
|
||||||
Ignoring paths
|
Ignoring paths
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ Quickstart
|
|||||||
Installing yamllint
|
Installing yamllint
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
On Fedora / CentOS:
|
On Fedora / CentOS (note: `EPEL <https://fedoraproject.org/wiki/EPEL>`_ is
|
||||||
|
required on CentOS):
|
||||||
|
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
@@ -22,6 +23,18 @@ On Mac OS 10.11+:
|
|||||||
|
|
||||||
brew install yamllint
|
brew install yamllint
|
||||||
|
|
||||||
|
On FreeBSD:
|
||||||
|
|
||||||
|
.. code:: sh
|
||||||
|
|
||||||
|
pkg install py36-yamllint
|
||||||
|
|
||||||
|
On OpenBSD:
|
||||||
|
|
||||||
|
.. code:: sh
|
||||||
|
|
||||||
|
doas pkg_add py3-yamllint
|
||||||
|
|
||||||
Alternatively using pip, the Python package manager:
|
Alternatively using pip, the Python package manager:
|
||||||
|
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import unittest
|
|||||||
from tests.common import build_temp_workspace
|
from tests.common import build_temp_workspace
|
||||||
|
|
||||||
from yamllint import cli
|
from yamllint import cli
|
||||||
|
from yamllint import config
|
||||||
|
|
||||||
|
|
||||||
class CommandLineTestCase(unittest.TestCase):
|
class CommandLineTestCase(unittest.TestCase):
|
||||||
@@ -73,8 +74,9 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
shutil.rmtree(cls.wd)
|
shutil.rmtree(cls.wd)
|
||||||
|
|
||||||
def test_find_files_recursively(self):
|
def test_find_files_recursively(self):
|
||||||
|
conf = config.YamlLintConfig('extends: default')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively([self.wd])),
|
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, 'empty.yml'),
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
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'),
|
||||||
@@ -85,14 +87,14 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
items = [os.path.join(self.wd, 'sub/ok.yaml'),
|
items = [os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
os.path.join(self.wd, 'empty-dir')]
|
os.path.join(self.wd, 'empty-dir')]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively(items)),
|
sorted(cli.find_files_recursively(items, conf)),
|
||||||
[os.path.join(self.wd, 'sub/ok.yaml')],
|
[os.path.join(self.wd, 'sub/ok.yaml')],
|
||||||
)
|
)
|
||||||
|
|
||||||
items = [os.path.join(self.wd, 'empty.yml'),
|
items = [os.path.join(self.wd, 'empty.yml'),
|
||||||
os.path.join(self.wd, 's')]
|
os.path.join(self.wd, 's')]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively(items)),
|
sorted(cli.find_files_recursively(items, conf)),
|
||||||
[os.path.join(self.wd, 'empty.yml'),
|
[os.path.join(self.wd, 'empty.yml'),
|
||||||
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')],
|
||||||
)
|
)
|
||||||
@@ -100,11 +102,77 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
items = [os.path.join(self.wd, 'sub'),
|
items = [os.path.join(self.wd, 'sub'),
|
||||||
os.path.join(self.wd, '/etc/another/file')]
|
os.path.join(self.wd, '/etc/another/file')]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(cli.find_files_recursively(items)),
|
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/ok.yaml')],
|
os.path.join(self.wd, 'sub/ok.yaml')],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
|
'yaml-files:\n'
|
||||||
|
' - \'*.yaml\' \n')
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
|
[os.path.join(self.wd, 'a.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, 'warn.yaml')]
|
||||||
|
)
|
||||||
|
|
||||||
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
|
'yaml-files:\n'
|
||||||
|
' - \'*.yml\'\n')
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
|
[os.path.join(self.wd, 'empty.yml')]
|
||||||
|
)
|
||||||
|
|
||||||
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
|
'yaml-files:\n'
|
||||||
|
' - \'*.json\'\n')
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
|
[os.path.join(self.wd, 'no-yaml.json')]
|
||||||
|
)
|
||||||
|
|
||||||
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
|
'yaml-files:\n'
|
||||||
|
' - \'*\'\n')
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'no-yaml.json'),
|
||||||
|
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, 'sub/ok.yaml'),
|
||||||
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
|
)
|
||||||
|
|
||||||
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
|
'yaml-files:\n'
|
||||||
|
' - \'*.yaml\'\n'
|
||||||
|
' - \'*\'\n'
|
||||||
|
' - \'**\'\n')
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'no-yaml.json'),
|
||||||
|
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, 'sub/ok.yaml'),
|
||||||
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
|
)
|
||||||
|
|
||||||
|
conf = config.YamlLintConfig('extends: default\n'
|
||||||
|
'yaml-files:\n'
|
||||||
|
' - \'s/**\'\n'
|
||||||
|
' - \'**/utf-8\'\n')
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(cli.find_files_recursively([self.wd], conf)),
|
||||||
|
[os.path.join(self.wd, 'non-ascii/utf-8')]
|
||||||
|
)
|
||||||
|
|
||||||
def test_run_with_bad_arguments(self):
|
def test_run_with_bad_arguments(self):
|
||||||
sys.stdout, sys.stderr = StringIO(), StringIO()
|
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||||
with self.assertRaises(SystemExit) as ctx:
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = 'yamllint'
|
APP_NAME = 'yamllint'
|
||||||
APP_VERSION = '1.16.0'
|
APP_VERSION = '1.17.0'
|
||||||
APP_DESCRIPTION = __doc__
|
APP_DESCRIPTION = __doc__
|
||||||
|
|
||||||
__author__ = u'Adrien Vergé'
|
__author__ = u'Adrien Vergé'
|
||||||
|
|||||||
@@ -27,13 +27,14 @@ from yamllint.config import YamlLintConfig, YamlLintConfigError
|
|||||||
from yamllint.linter import PROBLEM_LEVELS
|
from yamllint.linter import PROBLEM_LEVELS
|
||||||
|
|
||||||
|
|
||||||
def find_files_recursively(items):
|
def find_files_recursively(items, conf):
|
||||||
for item in items:
|
for item in items:
|
||||||
if os.path.isdir(item):
|
if os.path.isdir(item):
|
||||||
for root, dirnames, filenames in os.walk(item):
|
for root, dirnames, filenames in os.walk(item):
|
||||||
for filename in [f for f in filenames
|
for f in filenames:
|
||||||
if f.endswith(('.yml', '.yaml'))]:
|
filepath = os.path.join(root, f)
|
||||||
yield os.path.join(root, filename)
|
if conf.is_yaml_file(filepath):
|
||||||
|
yield filepath
|
||||||
else:
|
else:
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ def run(argv=None):
|
|||||||
|
|
||||||
max_level = 0
|
max_level = 0
|
||||||
|
|
||||||
for file in find_files_recursively(args.files):
|
for file in find_files_recursively(args.files, conf):
|
||||||
filepath = file[2:] if file.startswith('./') else file
|
filepath = file[2:] if file.startswith('./') else file
|
||||||
try:
|
try:
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
yaml-files:
|
||||||
|
- '*.yaml'
|
||||||
|
- '*.yml'
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
braces: enable
|
braces: enable
|
||||||
brackets: enable
|
brackets: enable
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ class YamlLintConfig(object):
|
|||||||
|
|
||||||
self.ignore = None
|
self.ignore = None
|
||||||
|
|
||||||
|
self.yaml_files = pathspec.PathSpec.from_lines(
|
||||||
|
'gitwildmatch', ['*.yaml', '*.yml'])
|
||||||
|
|
||||||
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()
|
||||||
@@ -42,6 +45,9 @@ class YamlLintConfig(object):
|
|||||||
def is_file_ignored(self, filepath):
|
def is_file_ignored(self, filepath):
|
||||||
return self.ignore and self.ignore.match_file(filepath)
|
return self.ignore and self.ignore.match_file(filepath)
|
||||||
|
|
||||||
|
def is_yaml_file(self, filepath):
|
||||||
|
return self.yaml_files.match_file(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()
|
||||||
if val is not False and (
|
if val is not False and (
|
||||||
@@ -96,6 +102,15 @@ class YamlLintConfig(object):
|
|||||||
self.ignore = pathspec.PathSpec.from_lines(
|
self.ignore = pathspec.PathSpec.from_lines(
|
||||||
'gitwildmatch', conf['ignore'].splitlines())
|
'gitwildmatch', conf['ignore'].splitlines())
|
||||||
|
|
||||||
|
if 'yaml-files' in conf:
|
||||||
|
if not (isinstance(conf['yaml-files'], list)
|
||||||
|
and all(isinstance(i, str) for i in conf['yaml-files'])):
|
||||||
|
raise YamlLintConfigError(
|
||||||
|
'invalid config: yaml-files '
|
||||||
|
'should be a list of file patterns')
|
||||||
|
self.yaml_files = pathspec.PathSpec.from_lines('gitwildmatch',
|
||||||
|
conf['yaml-files'])
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
for id in self.rules:
|
for id in self.rules:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ from yamllint.linter import LintProblem
|
|||||||
|
|
||||||
TRUTHY = ['YES', 'Yes', 'yes',
|
TRUTHY = ['YES', 'Yes', 'yes',
|
||||||
'NO', 'No', 'no',
|
'NO', 'No', 'no',
|
||||||
'TRUE', 'True', 'true',
|
'TRUE', 'True', 'true',
|
||||||
'FALSE', 'False', 'false',
|
'FALSE', 'False', 'false',
|
||||||
'ON', 'On', 'on',
|
'ON', 'On', 'on',
|
||||||
'OFF', 'Off', 'off']
|
'OFF', 'Off', 'off']
|
||||||
|
|||||||
Reference in New Issue
Block a user