yamllint-1.10.0/0000755000232200023220000000000013177553503014001 5ustar debalancedebalanceyamllint-1.10.0/.pre-commit-hooks.yaml0000644000232200023220000000032613177553503020141 0ustar debalancedebalance--- # For use with pre-commit. # See usage instructions at http://pre-commit.com - id: yamllint name: yamllint description: This hook runs yamllint. entry: yamllint language: python types: [file, yaml] yamllint-1.10.0/README.rst0000644000232200023220000000554213177553503015476 0ustar debalancedebalanceyamllint ======== A linter for YAML files. yamllint does not only check for syntax validity, but for weirdnesses like key repetition and cosmetic problems such as lines length, trailing spaces, indentation, etc. .. image:: https://travis-ci.org/adrienverge/yamllint.svg?branch=master :target: https://travis-ci.org/adrienverge/yamllint :alt: CI tests status .. image:: https://coveralls.io/repos/github/adrienverge/yamllint/badge.svg?branch=master :target: https://coveralls.io/github/adrienverge/yamllint?branch=master :alt: Code coverage status .. image:: https://readthedocs.org/projects/yamllint/badge/?version=latest :target: https://yamllint.readthedocs.io/en/latest/?badge=latest :alt: Documentation status Written in Python (compatible with Python 2 & 3). Documentation ------------- https://yamllint.readthedocs.io/ Overview -------- Screenshot ^^^^^^^^^^ .. image:: docs/screenshot.png :alt: yamllint screenshot Installation ^^^^^^^^^^^^ On Fedora / CentOS: .. code:: bash sudo dnf install yamllint On Debian 8+ / Ubuntu 16.04+: .. code:: bash sudo apt-get install yamllint Alternatively using pip, the Python package manager: .. code:: bash sudo pip install yamllint Usage ^^^^^ .. code:: bash # Lint one or more files yamllint my_file.yml my_other_file.yaml ... .. code:: bash # Lint all YAML files in a directory yamllint . .. code:: bash # Use a pre-defined lint configuration yamllint -d relaxed file.yaml # Use a custom lint configuration yamllint -c /path/to/myconfig file-to-lint.yaml .. code:: bash # Output a parsable format (for syntax checking in editors like Vim, emacs...) yamllint -f parsable file.yaml `Read more in the complete documentation! `_ Features ^^^^^^^^ Here is a yamllint configuration file example: .. code:: yaml extends: default rules: # 80 chars should be enough, but don't fail if a line is longer line-length: max: 80 level: warning # don't bother me with this rule indentation: disable Within a YAML file, special comments can be used to disable checks for a single line: .. code:: yaml This line is waaaaaaaaaay too long # yamllint disable-line or for a whole block: .. code:: yaml # yamllint disable rule:colons - Lorem : ipsum dolor : sit amet, consectetur : adipiscing elit # yamllint enable Specific files can be ignored (totally or for some rules only) using a ``.gitignore``-style pattern: .. code:: yaml # For all rules ignore: | *.dont-lint-me.yaml /bin/ !/bin/*.lint-me-anyway.yaml rules: key-duplicates: ignore: | generated *.template.yaml trailing-spaces: ignore: | *.ignore-trailing-spaces.yaml /ascii-art/* `Read more in the complete documentation! `_ License ------- `GPL version 3 `_ yamllint-1.10.0/CHANGELOG.rst0000644000232200023220000000153613177553503016027 0ustar debalancedebalanceChangelog ========= 1.10.0 (2017-11-05) ------------------- - Fix colored output on Windows - Check documentation compilation on continuous integration - Add a new `empty-values` rule - Make sure test files are included in dist bundle - Tests: Use en_US.UTF-8 locale when C.UTF-8 not available - Tests: Dynamically detect Python executable path 1.9.0 (2017-10-16) ------------------ - Add a new `key-ordering` rule - Fix indentation rule for key following empty list 1.8.2 (2017-10-10) ------------------ - Be clearer about the `ignore` conf type - Update pre-commit hook file - Add documentation for pre-commit 1.8.1 (2017-07-04) ------------------ - Require pathspec >= 0.5.3 - Support Python 2.6 - Add a changelog 1.8.0 (2017-06-28) ------------------ - Refactor argparse with mutually_exclusive_group - Add support to ignore paths in configuration yamllint-1.10.0/tests/0000755000232200023220000000000013177553503015143 5ustar debalancedebalanceyamllint-1.10.0/tests/test_linter.py0000644000232200023220000000416513177553503020057 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import io import sys try: assert sys.version_info >= (2, 7) import unittest except AssertionError: import unittest2 as unittest from yamllint.config import YamlLintConfig from yamllint import linter class LinterTestCase(unittest.TestCase): def fake_config(self): return YamlLintConfig('extends: default') def test_run_on_string(self): linter.run('test: document', self.fake_config()) def test_run_on_bytes(self): linter.run(b'test: document', self.fake_config()) def test_run_on_unicode(self): linter.run(u'test: document', self.fake_config()) def test_run_on_stream(self): linter.run(io.StringIO(u'hello'), self.fake_config()) def test_run_on_int(self): self.assertRaises(TypeError, linter.run, 42, self.fake_config()) def test_run_on_list(self): self.assertRaises(TypeError, linter.run, ['h', 'e', 'l', 'l', 'o'], self.fake_config()) def test_run_on_non_ascii_chars(self): s = (u'- hétérogénéité\n' u'# 19.99 €\n') linter.run(s, self.fake_config()) linter.run(s.encode('utf-8'), self.fake_config()) linter.run(s.encode('iso-8859-15'), self.fake_config()) s = (u'- お早う御座います。\n' u'# الأَبْجَدِيَّة العَرَبِيَّة\n') linter.run(s, self.fake_config()) linter.run(s.encode('utf-8'), self.fake_config()) yamllint-1.10.0/tests/test_cli.py0000644000232200023220000003234013177553503017325 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . try: from cStringIO import StringIO except ImportError: from io import StringIO import fcntl import locale import os import pty import shutil import sys try: assert sys.version_info >= (2, 7) import unittest except AssertionError: import unittest2 as unittest from yamllint import cli from tests.common import build_temp_workspace @unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported') class CommandLineTestCase(unittest.TestCase): @classmethod def setUpClass(cls): super(CommandLineTestCase, cls).setUpClass() cls.wd = build_temp_workspace({ # .yaml file at root 'a.yaml': '---\n' '- 1 \n' '- 2', # file with only one warning 'warn.yaml': 'key: value\n', # .yml file at root 'empty.yml': '', # file in dir 'sub/ok.yaml': '---\n' 'key: value\n', # file in very nested dir 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml': '---\n' 'key: value\n' 'key: other value\n', # empty dir 'empty-dir': [], # non-YAML file 'no-yaml.json': '---\n' 'key: value\n', # non-ASCII chars 'non-ascii/utf-8': ( u'---\n' u'- hétérogénéité\n' u'# 19.99 €\n' u'- お早う御座います。\n' u'# الأَبْجَدِيَّة العَرَبِيَّة\n').encode('utf-8'), }) @classmethod def tearDownClass(cls): super(CommandLineTestCase, cls).tearDownClass() shutil.rmtree(cls.wd) def test_find_files_recursively(self): self.assertEqual( sorted(cli.find_files_recursively([self.wd])), [os.path.join(self.wd, 'a.yaml'), 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, 'sub/ok.yaml'), os.path.join(self.wd, 'warn.yaml')], ) items = [os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'empty-dir')] self.assertEqual( sorted(cli.find_files_recursively(items)), [os.path.join(self.wd, 'sub/ok.yaml')], ) items = [os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 's')] self.assertEqual( sorted(cli.find_files_recursively(items)), [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')], ) items = [os.path.join(self.wd, 'sub'), os.path.join(self.wd, '/etc/another/file')] self.assertEqual( sorted(cli.find_files_recursively(items)), [os.path.join(self.wd, '/etc/another/file'), os.path.join(self.wd, 'sub/ok.yaml')], ) def test_run_with_bad_arguments(self): sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(()) self.assertNotEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertRegexpMatches(err, r'^usage') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('--unknown-arg', )) self.assertNotEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertRegexpMatches(err, r'^usage') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-c', './conf.yaml', '-d', 'relaxed', 'file')) self.assertNotEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertRegexpMatches( err.splitlines()[-1], r'^yamllint: error: argument -d\/--config-data: ' r'not allowed with argument -c\/--config-file$' ) def test_run_with_bad_config(self): sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-d', 'rules: {a: b}', 'file')) self.assertEqual(ctx.exception.code, -1) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertRegexpMatches(err, r'^invalid config: no such rule') def test_run_with_empty_config(self): sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-d', '', 'file')) self.assertEqual(ctx.exception.code, -1) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertRegexpMatches(err, r'^invalid config: not a dict') def test_run_with_config_file(self): with open(os.path.join(self.wd, 'config'), 'w') as f: f.write('rules: {trailing-spaces: disable}') with self.assertRaises(SystemExit) as ctx: cli.run(('-c', f.name, os.path.join(self.wd, 'a.yaml'))) self.assertEqual(ctx.exception.code, 0) with open(os.path.join(self.wd, 'config'), 'w') as f: f.write('rules: {trailing-spaces: enable}') with self.assertRaises(SystemExit) as ctx: cli.run(('-c', f.name, os.path.join(self.wd, 'a.yaml'))) self.assertEqual(ctx.exception.code, 1) def test_run_with_user_global_config_file(self): home = os.path.join(self.wd, 'fake-home') os.mkdir(home) dir = os.path.join(home, '.config') os.mkdir(dir) dir = os.path.join(dir, 'yamllint') os.mkdir(dir) config = os.path.join(dir, 'config') temp = os.environ['HOME'] os.environ['HOME'] = home with open(config, 'w') as f: f.write('rules: {trailing-spaces: disable}') with self.assertRaises(SystemExit) as ctx: cli.run((os.path.join(self.wd, 'a.yaml'), )) self.assertEqual(ctx.exception.code, 0) with open(config, 'w') as f: f.write('rules: {trailing-spaces: enable}') with self.assertRaises(SystemExit) as ctx: cli.run((os.path.join(self.wd, 'a.yaml'), )) self.assertEqual(ctx.exception.code, 1) os.environ['HOME'] = temp def test_run_version(self): sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('--version', )) self.assertEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertRegexpMatches(out + err, r'yamllint \d+\.\d+') def test_run_non_existing_file(self): file = os.path.join(self.wd, 'i-do-not-exist.yaml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', file)) self.assertEqual(ctx.exception.code, -1) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertRegexpMatches(err, r'No such file or directory') def test_run_one_problem_file(self): file = os.path.join(self.wd, 'a.yaml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', file)) self.assertEqual(ctx.exception.code, 1) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, ( '%s:2:4: [error] trailing spaces (trailing-spaces)\n' '%s:3:4: [error] no new line character at the end of file ' '(new-line-at-end-of-file)\n') % (file, file)) self.assertEqual(err, '') def test_run_one_warning(self): file = os.path.join(self.wd, 'warn.yaml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', file)) self.assertEqual(ctx.exception.code, 0) def test_run_warning_in_strict_mode(self): file = os.path.join(self.wd, 'warn.yaml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', '--strict', file)) self.assertEqual(ctx.exception.code, 2) def test_run_one_ok_file(self): file = os.path.join(self.wd, 'sub', 'ok.yaml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', file)) self.assertEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertEqual(err, '') def test_run_empty_file(self): file = os.path.join(self.wd, 'empty.yml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', file)) self.assertEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertEqual(err, '') def test_run_non_ascii_file(self): file = 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') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(('-f', 'parsable', file)) locale.setlocale(locale.LC_ALL, loc) self.assertEqual(ctx.exception.code, 0) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') self.assertEqual(err, '') def test_run_multiple_files(self): items = [os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 's')] file = items[1] + '/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml' sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run(['-f', 'parsable'] + items) self.assertEqual(ctx.exception.code, 1) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, ( '%s:3:1: [error] duplication of key "key" in mapping ' '(key-duplicates)\n') % file) self.assertEqual(err, '') def test_run_piped_output_nocolor(self): file = os.path.join(self.wd, 'a.yaml') sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: cli.run((file, )) self.assertEqual(ctx.exception.code, 1) out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, ( '%s\n' ' 2:4 error trailing spaces (trailing-spaces)\n' ' 3:4 error no new line character at the end of file ' '(new-line-at-end-of-file)\n' '\n' % file)) self.assertEqual(err, '') def test_run_colored_output(self): file = os.path.join(self.wd, 'a.yaml') # Create a pseudo-TTY and redirect stdout to it master, slave = pty.openpty() sys.stdout = sys.stderr = os.fdopen(slave, 'w') with self.assertRaises(SystemExit) as ctx: cli.run((file, )) sys.stdout.flush() self.assertEqual(ctx.exception.code, 1) # Read output from TTY output = os.fdopen(master, 'r') flag = fcntl.fcntl(master, fcntl.F_GETFD) fcntl.fcntl(master, fcntl.F_SETFL, flag | os.O_NONBLOCK) out = output.read().replace('\r\n', '\n') sys.stdout.close() sys.stderr.close() output.close() self.assertEqual(out, ( '\033[4m%s\033[0m\n' ' \033[2m2:4\033[0m \033[31merror\033[0m ' 'trailing spaces \033[2m(trailing-spaces)\033[0m\n' ' \033[2m3:4\033[0m \033[31merror\033[0m ' 'no new line character at the end of file ' '\033[2m(new-line-at-end-of-file)\033[0m\n' '\n' % file)) yamllint-1.10.0/tests/test_module.py0000644000232200023220000000664413177553503020053 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2017 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import os import shutil import subprocess import tempfile import sys try: assert sys.version_info >= (2, 7) import unittest except AssertionError: import unittest2 as unittest PYTHON = sys.executable or 'python' @unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported') class ModuleTestCase(unittest.TestCase): def setUp(self): self.wd = tempfile.mkdtemp(prefix='yamllint-tests-') # file with only one warning with open(os.path.join(self.wd, 'warn.yaml'), 'w') as f: f.write('key: value\n') # file in dir os.mkdir(os.path.join(self.wd, 'sub')) with open(os.path.join(self.wd, 'sub', 'nok.yaml'), 'w') as f: f.write('---\n' 'list: [ 1, 1, 2, 3, 5, 8] \n') def tearDown(self): shutil.rmtree(self.wd) def test_run_module_no_args(self): with self.assertRaises(subprocess.CalledProcessError) as ctx: subprocess.check_output([PYTHON, '-m', 'yamllint'], stderr=subprocess.STDOUT) self.assertEqual(ctx.exception.returncode, 2) self.assertRegexpMatches(ctx.exception.output.decode(), r'^usage: yamllint') def test_run_module_on_bad_dir(self): with self.assertRaises(subprocess.CalledProcessError) as ctx: subprocess.check_output([PYTHON, '-m', 'yamllint', '/does/not/exist'], stderr=subprocess.STDOUT) self.assertRegexpMatches(ctx.exception.output.decode(), r'No such file or directory') def test_run_module_on_file(self): out = subprocess.check_output( [PYTHON, '-m', 'yamllint', os.path.join(self.wd, 'warn.yaml')]) lines = out.decode().splitlines() self.assertIn('/warn.yaml', lines[0]) self.assertEqual('\n'.join(lines[1:]), ' 1:1 warning missing document start "---"' ' (document-start)\n') def test_run_module_on_dir(self): with self.assertRaises(subprocess.CalledProcessError) as ctx: subprocess.check_output([PYTHON, '-m', 'yamllint', self.wd]) self.assertEqual(ctx.exception.returncode, 1) files = ctx.exception.output.decode().split('\n\n') self.assertIn( '/warn.yaml\n' ' 1:1 warning missing document start "---"' ' (document-start)', files[0]) self.assertIn( '/sub/nok.yaml\n' ' 2:9 error too many spaces inside brackets' ' (brackets)\n' ' 2:27 error trailing spaces (trailing-spaces)', files[1]) yamllint-1.10.0/tests/test_yamllint_directives.py0000644000232200023220000003057113177553503022634 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class YamllintDirectivesTestCase(RuleTestCase): conf = ('commas: disable\n' 'trailing-spaces: {}\n' 'colons: {max-spaces-before: 1}\n') def test_disable_directive(self): self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(4, 8, 'colons'), problem3=(6, 7, 'colons'), problem4=(6, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '# yamllint disable\n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem=(3, 18, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '# yamllint disable\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint enable\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(8, 7, 'colons'), problem2=(8, 26, 'trailing-spaces')) def test_disable_directive_with_rules(self): self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '# yamllint disable rule:trailing-spaces\n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(5, 8, 'colons'), problem3=(7, 7, 'colons')) self.check('---\n' '- [valid , YAML]\n' '# yamllint disable rule:trailing-spaces\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint enable rule:trailing-spaces\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(5, 8, 'colons'), problem2=(8, 7, 'colons'), problem3=(8, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '# yamllint disable rule:trailing-spaces\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint enable\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(5, 8, 'colons'), problem2=(8, 7, 'colons'), problem3=(8, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '# yamllint disable\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint enable rule:trailing-spaces\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem=(8, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '# yamllint disable rule:colons\n' '- trailing spaces \n' '# yamllint disable rule:trailing-spaces\n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint enable rule:colons\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(4, 18, 'trailing-spaces'), problem2=(9, 7, 'colons')) def test_disable_line_directive(self): self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '# yamllint disable-line\n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(7, 7, 'colons'), problem3=(7, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '- bad : colon # yamllint disable-line\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(6, 7, 'colons'), problem3=(6, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML] # yamllint disable-line\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(4, 8, 'colons'), problem3=(6, 7, 'colons'), problem4=(6, 26, 'trailing-spaces')) def test_disable_line_directive_with_rules(self): self.check('---\n' '- [valid , YAML]\n' '# yamllint disable-line rule:colons\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(4, 18, 'trailing-spaces'), problem2=(5, 8, 'colons'), problem3=(7, 7, 'colons'), problem4=(7, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces # yamllint disable-line rule:colons \n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 55, 'trailing-spaces'), problem2=(4, 8, 'colons'), problem3=(6, 7, 'colons'), problem4=(6, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '# yamllint disable-line rule:colons\n' '- bad : colon\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(7, 7, 'colons'), problem3=(7, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '- bad : colon # yamllint disable-line rule:colons\n' '- [valid , YAML]\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(6, 7, 'colons'), problem3=(6, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint disable-line rule:colons\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(4, 8, 'colons'), problem3=(7, 26, 'trailing-spaces')) self.check('---\n' '- [valid , YAML]\n' '- trailing spaces \n' '- bad : colon\n' '- [valid , YAML]\n' '# yamllint disable-line rule:colons rule:trailing-spaces\n' '- bad : colon and spaces \n' '- [valid , YAML]\n', self.conf, problem1=(3, 18, 'trailing-spaces'), problem2=(4, 8, 'colons')) def test_directive_on_last_line(self): conf = 'new-line-at-end-of-file: {}' self.check('---\n' 'no new line', conf, problem=(2, 12, 'new-line-at-end-of-file')) self.check('---\n' '# yamllint disable\n' 'no new line', conf) self.check('---\n' 'no new line # yamllint disable', conf) def test_indented_directive(self): conf = 'brackets: {min-spaces-inside: 0, max-spaces-inside: 0}' self.check('---\n' '- a: 1\n' ' b:\n' ' c: [ x]\n', conf, problem=(4, 12, 'brackets')) self.check('---\n' '- a: 1\n' ' b:\n' ' # yamllint disable-line rule:brackets\n' ' c: [ x]\n', conf) def test_directive_on_itself(self): conf = ('comments: {min-spaces-from-content: 2}\n' 'comments-indentation: {}\n') self.check('---\n' '- a: 1 # comment too close\n' ' b:\n' ' # wrong indentation\n' ' c: [x]\n', conf, problem1=(2, 8, 'comments'), problem2=(4, 2, 'comments-indentation')) self.check('---\n' '# yamllint disable\n' '- a: 1 # comment too close\n' ' b:\n' ' # wrong indentation\n' ' c: [x]\n', conf) self.check('---\n' '- a: 1 # yamllint disable-line\n' ' b:\n' ' # yamllint disable-line\n' ' # wrong indentation\n' ' c: [x]\n', conf) self.check('---\n' '- a: 1 # yamllint disable-line rule:comments\n' ' b:\n' ' # yamllint disable-line rule:comments-indentation\n' ' # wrong indentation\n' ' c: [x]\n', conf) self.check('---\n' '# yamllint disable\n' '- a: 1 # comment too close\n' ' # yamllint enable rule:comments-indentation\n' ' b:\n' ' # wrong indentation\n' ' c: [x]\n', conf, problem=(6, 2, 'comments-indentation')) yamllint-1.10.0/tests/test_spec_examples.py0000644000232200023220000001662013177553503021411 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from io import open import os from tests.common import RuleTestCase # This file checks examples from YAML 1.2 specification [1] against yamllint. # # [1]: http://www.yaml.org/spec/1.2/spec.html # # Example files generated with: # # from bs4 import BeautifulSoup # with open('spec.html', encoding='iso-8859-1') as f: # soup = BeautifulSoup(f, 'lxml') # for ex in soup.find_all('div', class_='example'): # title = ex.find('p', class_='title').find('b').get_text() # id = '-'.join(title.split('\xa0')[:2])[:-1].lower() # span = ex.find('span', class_='database') # for br in span.find_all("br"): # br.replace_with("\n") # text = text.replace('\u2193', '') # downwards arrow # text = text.replace('\u21d3', '') # double downwards arrow # text = text.replace('\u00b7', ' ') # visible space # text = text.replace('\u21d4', '') # byte order mark # text = text.replace('\u2192', '\t') # right arrow # text = text.replace('\u00b0', '') # empty scalar # with open('tests/yaml-1.2-spec-examples/%s' % id, 'w', # encoding='utf-8') as g: # g.write(text) class SpecificationTestCase(RuleTestCase): rule_id = None conf_general = ('document-start: disable\n' 'comments: {min-spaces-from-content: 1}\n' 'braces: {min-spaces-inside: 1, max-spaces-inside: 1}\n' 'brackets: {min-spaces-inside: 1, max-spaces-inside: 1}\n') conf_overrides = { 'example-2.2': ('colons: {max-spaces-after: 2}\n'), 'example-2.4': ('colons: {max-spaces-after: 3}\n'), 'example-2.5': ('empty-lines: {max-end: 2}\n' 'brackets: {min-spaces-inside: 0, max-spaces-inside: 2}\n' 'commas: {max-spaces-before: -1}\n'), 'example-2.6': ('braces: {min-spaces-inside: 0, max-spaces-inside: 0}\n' 'indentation: disable\n'), 'example-2.12': ('empty-lines: {max-end: 1}\n' 'colons: {max-spaces-before: -1}\n'), 'example-2.16': ('empty-lines: {max-end: 1}\n'), 'example-2.18': ('empty-lines: {max-end: 1}\n'), 'example-2.19': ('empty-lines: {max-end: 1}\n'), 'example-2.28': ('empty-lines: {max-end: 3}\n'), 'example-5.3': ('indentation: {indent-sequences: false}\n' 'colons: {max-spaces-before: 1}\n'), 'example-6.4': ('trailing-spaces: disable\n'), 'example-6.5': ('trailing-spaces: disable\n'), 'example-6.6': ('trailing-spaces: disable\n'), 'example-6.7': ('trailing-spaces: disable\n'), 'example-6.8': ('trailing-spaces: disable\n'), 'example-6.10': ('empty-lines: {max-end: 2}\n' 'trailing-spaces: disable\n' 'comments-indentation: disable\n'), 'example-6.11': ('empty-lines: {max-end: 1}\n' 'comments-indentation: disable\n'), 'example-6.13': ('comments-indentation: disable\n'), 'example-6.14': ('comments-indentation: disable\n'), 'example-6.23': ('colons: {max-spaces-before: 1}\n'), 'example-7.4': ('colons: {max-spaces-before: 1}\n' 'indentation: disable\n'), 'example-7.5': ('trailing-spaces: disable\n'), 'example-7.6': ('trailing-spaces: disable\n'), 'example-7.7': ('indentation: disable\n'), 'example-7.8': ('colons: {max-spaces-before: 1}\n' 'indentation: disable\n'), 'example-7.9': ('trailing-spaces: disable\n'), 'example-7.11': ('colons: {max-spaces-before: 1}\n' 'indentation: disable\n'), 'example-7.13': ('brackets: {min-spaces-inside: 0, max-spaces-inside: 1}\n' 'commas: {max-spaces-before: 1, min-spaces-after: 0}\n'), 'example-7.14': ('indentation: disable\n'), 'example-7.15': ('braces: {min-spaces-inside: 0, max-spaces-inside: 1}\n' 'commas: {max-spaces-before: 1, min-spaces-after: 0}\n' 'colons: {max-spaces-before: 1}\n'), 'example-7.16': ('indentation: disable\n'), 'example-7.17': ('indentation: disable\n'), 'example-7.18': ('indentation: disable\n'), 'example-7.19': ('indentation: disable\n'), 'example-7.20': ('colons: {max-spaces-before: 1}\n' 'indentation: disable\n'), 'example-8.1': ('empty-lines: {max-end: 1}\n'), 'example-8.2': ('trailing-spaces: disable\n'), 'example-8.5': ('comments-indentation: disable\n' 'trailing-spaces: disable\n'), 'example-8.6': ('empty-lines: {max-end: 1}\n'), 'example-8.7': ('empty-lines: {max-end: 1}\n'), 'example-8.8': ('trailing-spaces: disable\n'), 'example-8.9': ('empty-lines: {max-end: 1}\n'), 'example-8.14': ('colons: {max-spaces-before: 1}\n'), 'example-8.16': ('indentation: {spaces: 1}\n'), 'example-8.17': ('indentation: disable\n'), 'example-8.20': ('indentation: {indent-sequences: false}\n' 'colons: {max-spaces-before: 1}\n'), 'example-8.22': ('indentation: disable\n'), 'example-10.1': ('colons: {max-spaces-before: 2}\n'), 'example-10.2': ('indentation: {indent-sequences: false}\n'), 'example-10.8': ('truthy: disable\n'), 'example-10.9': ('truthy: disable\n'), } files = os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'yaml-1.2-spec-examples')) assert len(files) == 132 def _gen_test(buffer, conf): def test(self): self.check(buffer, conf) return test # The following tests are blacklisted (i.e. will not be checked against # yamllint), because pyyaml is currently not able to parse the contents # (using yaml.parse()). pyyaml_blacklist = ( 'example-2.11', 'example-2.23', 'example-2.24', 'example-2.27', 'example-5.10', 'example-5.12', 'example-5.13', 'example-5.14', 'example-5.6', 'example-6.1', 'example-6.12', 'example-6.15', 'example-6.17', 'example-6.18', 'example-6.19', 'example-6.2', 'example-6.20', 'example-6.21', 'example-6.22', 'example-6.24', 'example-6.25', 'example-6.26', 'example-6.27', 'example-6.3', 'example-7.1', 'example-7.10', 'example-7.12', 'example-7.17', 'example-7.2', 'example-7.21', 'example-7.22', 'example-7.3', 'example-8.18', 'example-8.19', 'example-8.21', 'example-8.3', 'example-9.3', 'example-9.4', 'example-9.5', ) for file in files: if file in pyyaml_blacklist: continue with open('tests/yaml-1.2-spec-examples/' + file, encoding='utf-8') as f: conf = conf_general + conf_overrides.get(file, '') setattr(SpecificationTestCase, 'test_' + file, _gen_test(f.read(), conf)) yamllint-1.10.0/tests/common.py0000644000232200023220000000460013177553503017005 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import os import tempfile import sys try: assert sys.version_info >= (2, 7) import unittest except AssertionError: import unittest2 as unittest import yaml from yamllint.config import YamlLintConfig from yamllint import linter class RuleTestCase(unittest.TestCase): def build_fake_config(self, conf): if conf is None: conf = {} else: conf = yaml.safe_load(conf) conf = {'extends': 'default', 'rules': conf} return YamlLintConfig(yaml.safe_dump(conf)) def check(self, source, conf, **kwargs): expected_problems = [] for key in kwargs: assert key.startswith('problem') if len(kwargs[key]) > 2: if kwargs[key][2] == 'syntax': rule_id = None else: rule_id = kwargs[key][2] else: rule_id = self.rule_id expected_problems.append(linter.LintProblem( kwargs[key][0], kwargs[key][1], rule=rule_id)) expected_problems.sort() real_problems = list(linter.run(source, self.build_fake_config(conf))) self.assertEqual(real_problems, expected_problems) def build_temp_workspace(files): tempdir = tempfile.mkdtemp(prefix='yamllint-tests-') for path, content in files.items(): path = os.path.join(tempdir, path) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) if type(content) is list: os.mkdir(path) else: mode = 'wb' if isinstance(content, bytes) else 'w' with open(path, mode) as f: f.write(content) return tempdir yamllint-1.10.0/tests/__init__.py0000644000232200023220000000135513177553503017260 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import locale locale.setlocale(locale.LC_ALL, 'C') yamllint-1.10.0/tests/yaml-1.2-spec-examples/0000755000232200023220000000000013177553503021147 5ustar debalancedebalanceyamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.40000644000232200023220000000010113177553503023075 0ustar debalancedebalance!!null null: value for null key key with null value: !!null null yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.140000644000232200023220000000007713177553503023113 0ustar debalancedebalance--- > Mark McGwire's year was crippled by a knee injury. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.230000644000232200023220000000004613177553503023114 0ustar debalancedebalance- [ a, b ] - { a: b } - "a" - 'b' - c yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.80000644000232200023220000000003413177553503023033 0ustar debalancedebalance" foo bar baz " yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.210000644000232200023220000000014513177553503023111 0ustar debalancedebalance%TAG !m! !my- --- # Bulb here !m!light fluorescent ... %TAG !m! !my- --- # Color here !m!light green yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.130000644000232200023220000000013113177553503023104 0ustar debalancedebalance"Fun with \\ \" \a \b \e \f \ \n \r \t \v \0 \ \  \_ \N \L \P \ \x41 \u0041 \U00000041" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.210000644000232200023220000000006013177553503023107 0ustar debalancedebalanceliteral: |2 value folded: !foo >1 value yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.80000644000232200023220000000007313177553503023037 0ustar debalancedebalance'implicit block key' : [ 'implicit flow key' : value, ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.140000644000232200023220000000005013177553503023110 0ustar debalancedebalanceblock sequence: - one - two : three yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.20000644000232200023220000000020213177553503023075 0ustar debalancedebalanceBlock style: !!seq - Clark Evans - Ingy döt Net - Oren Ben-Kiki Flow style: !!seq [ Clark Evans, Ingy döt Net, Oren Ben-Kiki ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.130000644000232200023220000000011513177553503023107 0ustar debalancedebalance%FOO bar baz # Should be ignored # with a warning. --- "foo" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.180000644000232200023220000000007613177553503023124 0ustar debalancedebalanceplain key: in-line value : # Both empty "quoted key": - entry yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.50000644000232200023220000000007413177553503023037 0ustar debalancedebalance%YAML 1.2 --- | %!PS-Adobe-2.0 ... %YAML1.2 --- # Empty ... yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.150000644000232200023220000000007413177553503023116 0ustar debalancedebalance- { one : two , three: four , } - {five: six,seven : eight} yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.100000644000232200023220000000017713177553503023110 0ustar debalancedebalance--- hr: - Mark McGwire # Following node labeled SS - &SS Sammy Sosa rbi: - *SS # Subsequent occurrence - Ken Griffey yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.30000644000232200023220000000005113177553503023027 0ustar debalancedebalance- | text - > text text - |2 text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.160000644000232200023220000000006313177553503023114 0ustar debalancedebalance%TAG !yaml! tag:yaml.org,2002: --- !yaml!str "foo" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.50000644000232200023220000000007713177553503023040 0ustar debalancedebalance"folded to a space, to a line feed, or \ \ non-content" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.30000644000232200023220000000003413177553503023026 0ustar debalancedebalance- foo: bar - - baz - baz yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.170000644000232200023220000000011213177553503023111 0ustar debalancedebalance{ unquoted : "separate", http://foo.com, omitted value:, : omitted key, } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.70000644000232200023220000000015713177553503023113 0ustar debalancedebalancenegative: !!float -1 zero: !!float 0 positive: !!float 2.3e4 infinity: !!float .inf not a number: !!float .nan yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.270000644000232200023220000000120413177553503023110 0ustar debalancedebalance--- ! invoice: 34843 date : 2001-01-23 bill-to: &id001 given : Chris family : Dumars address: lines: | 458 Walkman Dr. Suite #292 city : Royal Oak state : MI postal : 48046 ship-to: *id001 product: - sku : BL394D quantity : 4 description : Basketball price : 450.00 - sku : BL4438H quantity : 1 description : Super Hoop price : 2392.00 tax : 251.42 total: 4443.52 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.90000644000232200023220000000002113177553503023032 0ustar debalancedebalance> folded text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.200000644000232200023220000000015213177553503023102 0ustar debalancedebalancecanonical: 1.23015e+3 exponential: 12.3015e+02 fixed: 1230.15 negative infinity: -.inf not a number: .NaN yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.120000644000232200023220000000005613177553503023113 0ustar debalancedebalance1st non-empty 2nd non-empty 3rd non-empty yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.280000644000232200023220000000006713177553503023123 0ustar debalancedebalance# Assuming conventional resolution: - "12" - 12 - ! 12 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.280000644000232200023220000000063613177553503023121 0ustar debalancedebalance--- Time: 2001-11-23 15:01:42 -5 User: ed Warning: This is an error message for the log file --- Time: 2001-11-23 15:02:31 -5 User: ed Warning: A slightly different error message. --- Date: 2001-11-23 15:03:17 -5 User: ed Fatal: Unknown variable "bar" Stack: - file: TopClass.py line: 23 code: | x = MoreObject("345\n") - file: MoreClass.py line: 58 code: |- foo = bar yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.40000644000232200023220000000010613177553503023027 0ustar debalancedebalanceplain: text lines quoted: "text lines" block: | text lines yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.290000644000232200023220000000007313177553503023121 0ustar debalancedebalanceFirst occurrence: &anchor Value Second occurrence: *anchor yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.80000644000232200023220000000005313177553503023036 0ustar debalancedebalance| literal text # Comment yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.10000644000232200023220000000003313177553503023026 0ustar debalancedebalance# Comment # lines Document yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.60000644000232200023220000000005613177553503023034 0ustar debalancedebalanceanchored: !local &anchor value alias: *anchor yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.230000644000232200023220000000041113177553503023103 0ustar debalancedebalance--- not-date: !!str 2002-04-28 picture: !!binary | R0lGODlhDAAMAIQAAP//9/X 17unp5WZmZgAAAOfn515eXv Pz7Y6OjuDg4J+fn5OTk6enp 56enmleECcgggoBADs= application specific tag: !something | The semantics of the tag above may be different for different documents. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.140000644000232200023220000000013113177553503023107 0ustar debalancedebalance[ "double quoted", 'single quoted', plain text, [ nested ], single: pair, ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.10000644000232200023220000000005213177553503023020 0ustar debalancedebalance- Mark McGwire - Sammy Sosa - Ken Griffey yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.20000644000232200023220000000003413177553503023025 0ustar debalancedebalance? a : - b - - c - d yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.240000644000232200023220000000005513177553503023114 0ustar debalancedebalance! foo : ! baz yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.270000644000232200023220000000007213177553503023116 0ustar debalancedebalance%TAG !e! tag:example,2000:app/ --- - !e! foo - !h!bar baz yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.180000644000232200023220000000013613177553503023113 0ustar debalancedebalanceplain: This unquoted scalar spans many lines. quoted: "So does this quoted scalar.\n" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.30000644000232200023220000000013313177553503023101 0ustar debalancedebalanceBlock style: !!str |- String: just a theory. Flow style: !!str "String: just a theory." yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.130000644000232200023220000000012613177553503023113 0ustar debalancedebalance> folded line next line * bullet * list * line last line # Comment yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.40000644000232200023220000000007313177553503023031 0ustar debalancedebalancesequence: [ one, two, ] mapping: { sky: blue, sea: green } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.90000644000232200023220000000031313177553503023107 0ustar debalancedebalanceA null: null Also a null: # Empty Not a null: "" Booleans: [ true, True, false, FALSE ] Integers: [ 0, 0o7, 0x3A, -19 ] Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] Also floats: [ .inf, -.Inf, +.INF, .NAN ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.160000644000232200023220000000003313177553503023113 0ustar debalancedebalanceblock mapping: key: value yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.150000644000232200023220000000003013177553503023105 0ustar debalancedebalance%YAML 1.2 %YAML 1.1 foo yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.150000644000232200023220000000017013177553503023106 0ustar debalancedebalance> Sammy Sosa completed another fine season with great stats. 63 Home Runs 0.288 Batting Average What a year! yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.90000644000232200023220000000016313177553503023033 0ustar debalancedebalance--- hr: # 1998 hr ranking - Mark McGwire - Sammy Sosa rbi: # 1998 rbi ranking - Sammy Sosa - Ken Griffey yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.110000644000232200023220000000021613177553503023103 0ustar debalancedebalance? - Detroit Tigers - Chicago cubs : - 2001-07-23 ? [ New York Yankees, Atlanta Braves ] : [ 2001-07-02, 2001-08-12, 2001-08-14 ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.30000644000232200023220000000011213177553503023026 0ustar debalancedebalanceBare document ... # No document ... | %!PS-Adobe-2.0 # Not the first line yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.190000644000232200023220000000007713177553503023120 0ustar debalancedebalancecanonical: 12345 decimal: +12345 octal: 0o14 hexadecimal: 0xC yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.230000644000232200023220000000005313177553503023111 0ustar debalancedebalance!!str &a1 "foo": !!str bar &a2 baz : *a1 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.90000644000232200023220000000006213177553503023036 0ustar debalancedebalance' 1st non-empty 2nd non-empty 3rd non-empty ' yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.120000644000232200023220000000014113177553503023105 0ustar debalancedebalance{ first: Sammy, last: Sosa }: # Statistics: hr: # Home runs 65 avg: # Average 0.278 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.120000644000232200023220000000021013177553503023076 0ustar debalancedebalance--- # Products purchased - item : Super Hoop quantity: 1 - item : Basketball quantity: 4 - item : Big Shoes quantity: 1 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.20000644000232200023220000000010513177553503023026 0ustar debalancedebalance- | detected - > # detected - |1 explicit - > detected yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.180000644000232200023220000000012213177553503023112 0ustar debalancedebalance# Private !foo "bar" ... # Global %TAG ! tag:example.com,2000:app/ --- !foo "bar" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.170000644000232200023220000000026113177553503023111 0ustar debalancedebalanceunicode: "Sosa did fine.\u263A" control: "\b1998\t1999\t2000\n" hex esc: "\x0d\x0a is \r\n" single: '"Howdy!" he cried.' quoted: ' # Not a ''comment''.' tie-fighter: '|\-*-/|' yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.220000644000232200023220000000017313177553503023107 0ustar debalancedebalancecanonical: 2001-12-15T02:59:43.1Z iso8601: 2001-12-14t21:59:43.10-05:00 spaced: 2001-12-14 21:59:43.10 -5 date: 2002-12-14 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.10000644000232200023220000000002013177553503023016 0ustar debalancedebalance# Comment only. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.10000644000232200023220000000020413177553503023025 0ustar debalancedebalance- | # Empty header literal - >1 # Indentation indicator folded - |+ # Chomping indicator keep - >1- # Both indicators strip yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.110000644000232200023220000000006713177553503023114 0ustar debalancedebalanceimplicit block key : [ implicit flow key : value, ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.20000644000232200023220000000004413177553503023031 0ustar debalancedebalance%YAML 1.2 --- Document ... # Suffix yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.40000644000232200023220000000013613177553503023026 0ustar debalancedebalance- name: Mark McGwire hr: 65 avg: 0.278 - name: Sammy Sosa hr: 63 avg: 0.288 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.210000644000232200023220000000011213177553503023104 0ustar debalancedebalance- [ YAML : separate ] - [ : empty key entry ] - [ {JSON: like}:adjacent ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.80000644000232200023220000000022113177553503023104 0ustar debalancedebalanceA null: null Booleans: [ true, false ] Integers: [ 0, -0, 3, -19 ] Floats: [ 0., -0.0, 12e03, -2E+05 ] Invalid: [ True, Null, 0o7, 0x3A, +12.3 ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.50000644000232200023220000000011013177553503023076 0ustar debalancedebalanceYAML is a superset of JSON: !!bool true Pluto is a planet: !!bool false yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.190000644000232200023220000000001513177553503023115 0ustar debalancedebalance[ foo: bar ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.160000644000232200023220000000005213177553503023113 0ustar debalancedebalance{ ? explicit: entry, implicit: entry, ? } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.50000644000232200023220000000023013177553503023030 0ustar debalancedebalance # Strip # Comments: strip: |- # text # Clip # comments: clip: | # text # Keep # comments: keep: |+ # text # Trail # comments. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.40000644000232200023220000000005313177553503023033 0ustar debalancedebalance--- { matches % : 20 } ... --- # Empty ... yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.80000644000232200023220000000017513177553503023035 0ustar debalancedebalance--- time: 20:03:20 player: Sammy Sosa action: strike (miss) ... --- time: 20:03:47 player: Sammy Sosa action: grand slam ... yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.140000644000232200023220000000003313177553503023106 0ustar debalancedebalanceBad escapes: "\c \xq-" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.60000644000232200023220000000012013177553503023021 0ustar debalancedebalanceMark McGwire: {hr: 65, avg: 0.278} Sammy Sosa: { hr: 63, avg: 0.288 } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.60000644000232200023220000000004013177553503023026 0ustar debalancedebalance>- trimmed as space yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.260000644000232200023220000000023713177553503023114 0ustar debalancedebalance# Ordered maps are represented as # A sequence of mappings, with # each mapping having one key --- !!omap - Mark McGwire: 65 - Sammy Sosa: 63 - Ken Griffy: 58 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.10000644000232200023220000000015413177553503023030 0ustar debalancedebalanceFirst occurrence: &anchor Foo Second occurrence: *anchor Override anchor: &anchor Bar Reuse anchor: *anchor yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.50000644000232200023220000000012213177553503023026 0ustar debalancedebalanceFolding: "Empty line as a line feed" Chomping: | Clipped empty lines yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.200000644000232200023220000000006413177553503023110 0ustar debalancedebalance%TAG !e! tag:example.com,2000:app/ --- !e!foo "bar" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.190000644000232200023220000000011213177553503023112 0ustar debalancedebalance%TAG !! tag:example.com,2000:app/ --- !!int 1 - 3 # Interval, not integer yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.40000644000232200023220000000007313177553503023033 0ustar debalancedebalance"implicit block key" : [ "implicit flow key" : value, ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.120000644000232200023220000000014013177553503023103 0ustar debalancedebalance# Tabs and spaces quoted: "Quoted " block: | void main() { printf("Hello, world!\n"); } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.260000644000232200023220000000012013177553503023107 0ustar debalancedebalance%TAG !e! tag:example.com,2000:app/ --- - !local foo - !!str bar - !e!tag%21 baz yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.20000644000232200023220000000004213177553503023025 0ustar debalancedebalance{ foo : !!str, !!str : bar, } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.100000644000232200023220000000013013177553503023103 0ustar debalancedebalance> folded line next line * bullet * list * lines last line # Comment yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.40000644000232200023220000000006013177553503023030 0ustar debalancedebalancestrip: |- text clip: | text keep: |+ text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.90000644000232200023220000000003513177553503023035 0ustar debalancedebalancekey: # Comment valueeof yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.70000644000232200023220000000002313177553503023032 0ustar debalancedebalance| literal text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.190000644000232200023220000000005613177553503023123 0ustar debalancedebalance- sun: yellow - ? earth: blue : moon: white yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.170000644000232200023220000000003413177553503023113 0ustar debalancedebalance%TAG ! !foo %TAG ! !foo bar yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.110000644000232200023220000000013013177553503023104 0ustar debalancedebalance> folded line next line * bullet * list * lines last line # Comment yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.140000644000232200023220000000010213177553503023104 0ustar debalancedebalance%YAML 1.3 # Attempt parsing # with a warning --- "foo" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.30000644000232200023220000000007613177553503023033 0ustar debalancedebalancesequence: - one - two mapping: ? sky : blue sea : green yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.100000644000232200023220000000033213177553503023106 0ustar debalancedebalance# Outside flow collection: - ::vector - ": - ()" - Up, up, and away! - -123 - http://example.com/foo#bar # Inside flow collection: - [ ::vector, ": - ()", "Up, up and away!", -123, http://example.com/foo#bar ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.50000644000232200023220000000002013177553503023022 0ustar debalancedebalance# Comment only. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.100000644000232200023220000000005113177553503023102 0ustar debalancedebalancecommercial-at: @text grave-accent: `text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.120000644000232200023220000000012713177553503023113 0ustar debalancedebalance> folded line next line * bullet * list * line last line # Comment yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.70000644000232200023220000000002713177553503023035 0ustar debalancedebalance 'here''s to "quotes"' yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.250000644000232200023220000000003013177553503023106 0ustar debalancedebalance- ! foo - !<$:?> bar yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.60000644000232200023220000000006213177553503023033 0ustar debalancedebalance" 1st non-empty 2nd non-empty 3rd non-empty " yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.250000644000232200023220000000021113177553503023103 0ustar debalancedebalance# Sets are represented as a # Mapping where each key is # associated with a null value --- !!set ? Mark McGwire ? Sammy Sosa ? Ken Griff yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.70000644000232200023220000000006113177553503023031 0ustar debalancedebalanceliteral: | some text folded: > some text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.220000644000232200023220000000007613177553503023116 0ustar debalancedebalance[ foo bar: invalid, "foo...>1K characters...bar": invalid ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.70000644000232200023220000000003213177553503023030 0ustar debalancedebalance> foo bar baz yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.200000644000232200023220000000011513177553503023107 0ustar debalancedebalance- "flow in block" - > Block scalar - !!map # Block collection foo : bar yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.10000644000232200023220000000021513177553503023100 0ustar debalancedebalanceBlock style: !!map Clark : Evans Ingy : döt Net Oren : Ben-Kiki Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.20000644000232200023220000000012013177553503023015 0ustar debalancedebalancehr: 65 # Home runs avg: 0.278 # Batting average rbi: 147 # Runs Batted In yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.150000644000232200023220000000013413177553503023114 0ustar debalancedebalance- # Empty - | block node - - one # Compact - two # sequence - one: two # Compact mapping yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.200000644000232200023220000000002513177553503023106 0ustar debalancedebalance[ ? foo bar : baz ] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.60000644000232200023220000000003613177553503023035 0ustar debalancedebalancestrip: >- clip: > keep: |+ yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.170000644000232200023220000000013613177553503023120 0ustar debalancedebalance? explicit key # Empty value ? | block key : - one # Explicit compact - two # block value yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.240000644000232200023220000000045213177553503023111 0ustar debalancedebalance%TAG ! tag:clarkevans.com,2002: --- !shape # Use the ! handle for presenting # tag:clarkevans.com,2002:circle - !circle center: &ORIGIN {x: 73, y: 129} radius: 7 - !line start: *ORIGIN finish: { x: 89, y: 102 } - !label start: *ORIGIN color: 0xFFEEBB text: Pretty vector drawing. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.10000644000232200023220000000045513177553503023033 0ustar debalancedebalance # Leading comment line spaces are # neither content nor indentation. Not indented: By one space: | By four spaces Flow style: [ # Leading spaces By two, # in flow style Also by two, # are neither Still by two # content nor ] # indentation. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.160000644000232200023220000000021313177553503023105 0ustar debalancedebalancename: Mark McGwire accomplishment: > Mark set a major league home run record in 1998. stats: | 65 Home Runs 0.278 Batting Average yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.30000644000232200023220000000020513177553503023022 0ustar debalancedebalanceamerican: - Boston Red Sox - Detroit Tigers - New York Yankees national: - New York Mets - Chicago Cubs - Atlanta Braves yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.20000644000232200023220000000005313177553503023025 0ustar debalancedebalance- Invalid use of BOM - Inside a document. yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.60000644000232200023220000000006513177553503023040 0ustar debalancedebalanceDocument --- # Empty ... %YAML 1.2 --- matches %: 20 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.240000644000232200023220000000006213177553503023113 0ustar debalancedebalance- !!str "a" - 'b' - &anchor "c" - *anchor - !!str yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.60000644000232200023220000000006513177553503023110 0ustar debalancedebalancenegative: !!int -12 zero: !!int 0 positive: !!int 34 yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.90000644000232200023220000000002313177553503023031 0ustar debalancedebalance%YAML 1.2 --- text yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.130000644000232200023220000000005413177553503023105 0ustar debalancedebalance# ASCII Art --- | \//||\/|| // || ||__ yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.220000644000232200023220000000006613177553503023114 0ustar debalancedebalance%TAG !e! tag:example.com,2000:app/ --- - !e!foo "bar" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.50000644000232200023220000000012613177553503023026 0ustar debalancedebalance- [name , hr, avg ] - [Mark McGwire, 65, 0.278] - [Sammy Sosa , 63, 0.288] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.100000644000232200023220000000002113177553503023100 0ustar debalancedebalance # Comment yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.210000644000232200023220000000006113177553503023102 0ustar debalancedebalancenull: booleans: [ true, false ] string: '012345' yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.180000644000232200023220000000006213177553503023116 0ustar debalancedebalance{ "adjacent":value, "readable": value, "empty": } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.220000644000232200023220000000010313177553503023106 0ustar debalancedebalancesequence: !!seq - entry - !!seq - nested mapping: !!map foo: bar yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.80000644000232200023220000000003613177553503023034 0ustar debalancedebalancesingle: 'text' double: "text" yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.110000644000232200023220000000006113177553503023104 0ustar debalancedebalance| Line break (no glyph) Line break (glyphed) yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.30000644000232200023220000000003013177553503023023 0ustar debalancedebalance{ ? foo :, : bar, } yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.70000644000232200023220000000020213177553503023023 0ustar debalancedebalance# Ranking of 1998 home runs --- - Mark McGwire - Sammy Sosa - Ken Griffey # Team ranking --- - Chicago Cubs - St Louis Cardinals yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.130000644000232200023220000000004013177553503023105 0ustar debalancedebalance- [ one, two, ] - [three ,four] yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.110000644000232200023220000000005313177553503023106 0ustar debalancedebalancekey: # Comment # lines value yamllint-1.10.0/tests/test_syntax_errors.py0000644000232200023220000000607513177553503021506 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class YamlLintTestCase(RuleTestCase): rule_id = None # syntax error def test_syntax_errors(self): self.check('---\n' 'this is not: valid: YAML\n', None, problem=(2, 19)) self.check('---\n' 'this is: valid YAML\n' '\n' 'this is an error: [\n' '\n' '...\n', None, problem=(6, 1)) self.check('%YAML 1.2\n' '%TAG ! tag:clarkevans.com,2002:\n' 'doc: ument\n' '...\n', None, problem=(3, 1)) def test_empty_flows(self): self.check('---\n' '- []\n' '- {}\n' '- [\n' ']\n' '- {\n' '}\n' '...\n', None) def test_explicit_mapping(self): self.check('---\n' '? key\n' ': - value 1\n' ' - value 2\n' '...\n', None) self.check('---\n' '?\n' ' key\n' ': {a: 1}\n' '...\n', None) self.check('---\n' '?\n' ' key\n' ':\n' ' val\n' '...\n', None) def test_mapping_between_sequences(self): # This is valid YAML. See http://www.yaml.org/spec/1.2/spec.html, # example 2.11 self.check('---\n' '? - Detroit Tigers\n' ' - Chicago cubs\n' ':\n' ' - 2001-07-23\n' '\n' '? [New York Yankees,\n' ' Atlanta Braves]\n' ': [2001-07-02, 2001-08-12,\n' ' 2001-08-14]\n', None) def test_sets(self): self.check('---\n' '? key one\n' '? key two\n' '? [non, scalar, key]\n' '? key with value\n' ': value\n' '...\n', None) self.check('---\n' '? - multi\n' ' - line\n' ' - keys\n' '? in:\n' ' a:\n' ' set\n' '...\n', None) yamllint-1.10.0/tests/test_parser.py0000644000232200023220000001517213177553503020056 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys try: assert sys.version_info >= (2, 7) import unittest except AssertionError: import unittest2 as unittest import yaml from yamllint.parser import (line_generator, token_or_comment_generator, token_or_comment_or_line_generator, Line, Token, Comment) class ParserTestCase(unittest.TestCase): def test_line_generator(self): e = list(line_generator('')) self.assertEqual(len(e), 1) self.assertEqual(e[0].line_no, 1) self.assertEqual(e[0].start, 0) self.assertEqual(e[0].end, 0) e = list(line_generator('\n')) self.assertEqual(len(e), 2) e = list(line_generator(' \n')) self.assertEqual(len(e), 2) self.assertEqual(e[0].line_no, 1) self.assertEqual(e[0].start, 0) self.assertEqual(e[0].end, 1) e = list(line_generator('\n\n')) self.assertEqual(len(e), 3) e = list(line_generator('---\n' 'this is line 1\n' 'line 2\n' '\n' '3\n')) self.assertEqual(len(e), 6) self.assertEqual(e[0].line_no, 1) self.assertEqual(e[0].content, '---') self.assertEqual(e[2].content, 'line 2') self.assertEqual(e[3].content, '') self.assertEqual(e[5].line_no, 6) e = list(line_generator('test with\n' 'no newline\n' 'at the end')) self.assertEqual(len(e), 3) self.assertEqual(e[2].line_no, 3) self.assertEqual(e[2].content, 'at the end') def test_token_or_comment_generator(self): e = list(token_or_comment_generator('')) self.assertEqual(len(e), 2) self.assertEqual(e[0].prev, None) self.assertIsInstance(e[0].curr, yaml.Token) self.assertIsInstance(e[0].next, yaml.Token) self.assertEqual(e[1].prev, e[0].curr) self.assertEqual(e[1].curr, e[0].next) self.assertEqual(e[1].next, None) e = list(token_or_comment_generator('---\n' 'k: v\n')) self.assertEqual(len(e), 9) self.assertIsInstance(e[3].curr, yaml.KeyToken) self.assertIsInstance(e[5].curr, yaml.ValueToken) e = list(token_or_comment_generator('# start comment\n' '- a\n' '- key: val # key=val\n' '# this is\n' '# a block \n' '# comment\n' '- c\n' '# end comment\n')) self.assertEqual(len(e), 21) self.assertIsInstance(e[1], Comment) self.assertEqual(e[1], Comment(1, 1, '# start comment', 0)) self.assertEqual(e[11], Comment(3, 13, '# key=val', 0)) self.assertEqual(e[12], Comment(4, 1, '# this is', 0)) self.assertEqual(e[13], Comment(5, 1, '# a block ', 0)) self.assertEqual(e[14], Comment(6, 1, '# comment', 0)) self.assertEqual(e[18], Comment(8, 1, '# end comment', 0)) e = list(token_or_comment_generator('---\n' '# no newline char')) self.assertEqual(e[2], Comment(2, 1, '# no newline char', 0)) e = list(token_or_comment_generator('# just comment')) self.assertEqual(e[1], Comment(1, 1, '# just comment', 0)) e = list(token_or_comment_generator('\n' ' # indented comment\n')) self.assertEqual(e[1], Comment(2, 4, '# indented comment', 0)) e = list(token_or_comment_generator('\n' '# trailing spaces \n')) self.assertEqual(e[1], Comment(2, 1, '# trailing spaces ', 0)) e = [c for c in token_or_comment_generator('# block\n' '# comment\n' '- data # inline comment\n' '# block\n' '# comment\n' '- k: v # inline comment\n' '- [ l, ist\n' '] # inline comment\n' '- { m: ap\n' '} # inline comment\n' '# block comment\n' '- data # inline comment\n') if isinstance(c, Comment)] self.assertEqual(len(e), 10) self.assertFalse(e[0].is_inline()) self.assertFalse(e[1].is_inline()) self.assertTrue(e[2].is_inline()) self.assertFalse(e[3].is_inline()) self.assertFalse(e[4].is_inline()) self.assertTrue(e[5].is_inline()) self.assertTrue(e[6].is_inline()) self.assertTrue(e[7].is_inline()) self.assertFalse(e[8].is_inline()) self.assertTrue(e[9].is_inline()) def test_token_or_comment_or_line_generator(self): e = list(token_or_comment_or_line_generator('---\n' 'k: v # k=v\n')) self.assertEqual(len(e), 13) self.assertIsInstance(e[0], Token) self.assertIsInstance(e[0].curr, yaml.StreamStartToken) self.assertIsInstance(e[1], Token) self.assertIsInstance(e[1].curr, yaml.DocumentStartToken) self.assertIsInstance(e[2], Line) self.assertIsInstance(e[3].curr, yaml.BlockMappingStartToken) self.assertIsInstance(e[4].curr, yaml.KeyToken) self.assertIsInstance(e[6].curr, yaml.ValueToken) self.assertIsInstance(e[8], Comment) self.assertIsInstance(e[9], Line) self.assertIsInstance(e[12], Line) yamllint-1.10.0/tests/rules/0000755000232200023220000000000013177553503016275 5ustar debalancedebalanceyamllint-1.10.0/tests/rules/test_indentation.py0000644000232200023220000023065113177553503022231 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase from yamllint.parser import token_or_comment_generator, Comment from yamllint.rules.indentation import check class IndentationStackTestCase(RuleTestCase): # This test suite checks that the "indentation stack" built by the # indentation rule is valid. It is important, since everything else in the # rule relies on this stack. maxDiff = None def format_stack(self, stack): """Transform the stack at a given moment into a printable string like: B_MAP:0 KEY:0 VAL:5 """ return ' '.join(map(str, stack[1:])) def full_stack(self, source): conf = {'spaces': 2, 'indent-sequences': True, 'check-multi-line-strings': False} context = {} output = '' for elem in [t for t in token_or_comment_generator(source) if not isinstance(t, Comment)]: list(check(conf, elem.curr, elem.prev, elem.next, elem.nextnext, context)) token_type = (elem.curr.__class__.__name__ .replace('Token', '') .replace('Block', 'B').replace('Flow', 'F') .replace('Sequence', 'Seq') .replace('Mapping', 'Map')) if token_type in ('StreamStart', 'StreamEnd'): continue output += '%9s %s\n' % (token_type, self.format_stack(context['stack'])) return output def test_simple_mapping(self): self.assertMultiLineEqual( self.full_stack('key: val\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:5\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack(' key: val\n'), 'BMapStart B_MAP:5\n' ' Key B_MAP:5 KEY:5\n' ' Scalar B_MAP:5 KEY:5\n' ' Value B_MAP:5 KEY:5 VAL:10\n' ' Scalar B_MAP:5\n' ' BEnd \n') def test_simple_sequence(self): self.assertMultiLineEqual( self.full_stack('- 1\n' '- 2\n' '- 3\n'), 'BSeqStart B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Scalar B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Scalar B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Scalar B_SEQ:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('key:\n' ' - 1\n' ' - 2\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' 'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n' ' BEnd B_MAP:0\n' ' BEnd \n') def test_non_indented_sequences(self): # There seems to be a bug in pyyaml: depending on the indentation, a # sequence does not produce the same tokens. More precisely, the # following YAML: # usr: # - lib # produces a BlockSequenceStartToken and a BlockEndToken around the # "lib" sequence, whereas the following: # usr: # - lib # does not (both two tokens are omitted). # So, yamllint must create fake 'B_SEQ'. This test makes sure it does. self.assertMultiLineEqual( self.full_stack('usr:\n' ' - lib\n' 'var: cache\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' 'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n' ' BEnd B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:5\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('usr:\n' '- lib\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' # missing BSeqStart here ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' ' Scalar B_MAP:0\n' # missing BEnd here ' BEnd \n') self.assertMultiLineEqual( self.full_stack('usr:\n' '- lib\n' 'var: cache\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' # missing BSeqStart here ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' ' Scalar B_MAP:0\n' # missing BEnd here ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:5\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('usr:\n' '- []\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' # missing BSeqStart here ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' 'FSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 F_SEQ:3\n' ' FSeqEnd B_MAP:0\n' # missing BEnd here ' BEnd \n') self.assertMultiLineEqual( self.full_stack('usr:\n' '- k:\n' ' v\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' # missing BSeqStart here ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' 'BMapStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2\n' ' Key B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n' ' Value B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2 VAL:4\n' # noqa ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2\n' ' BEnd B_MAP:0\n' # missing BEnd here ' BEnd \n') def test_flows(self): self.assertMultiLineEqual( self.full_stack('usr: [\n' ' {k:\n' ' v}\n' ' ]\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:5\n' 'FSeqStart B_MAP:0 KEY:0 VAL:5 F_SEQ:2\n' 'FMapStart B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3\n' ' Key B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3 KEY:3\n' ' Scalar B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3 KEY:3\n' ' Value B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3 KEY:3 VAL:5\n' ' Scalar B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3\n' ' FMapEnd B_MAP:0 KEY:0 VAL:5 F_SEQ:2\n' ' FSeqEnd B_MAP:0\n' ' BEnd \n') def test_anchors(self): self.assertMultiLineEqual( self.full_stack('key: &anchor value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:5\n' ' Anchor B_MAP:0 KEY:0 VAL:5\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('key: &anchor\n' ' value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' ' Anchor B_MAP:0 KEY:0 VAL:2\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('- &anchor value\n'), 'BSeqStart B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Anchor B_SEQ:0 B_ENT:2\n' ' Scalar B_SEQ:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('- &anchor\n' ' value\n'), 'BSeqStart B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Anchor B_SEQ:0 B_ENT:2\n' ' Scalar B_SEQ:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('- &anchor\n' ' - 1\n' ' - 2\n'), 'BSeqStart B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Anchor B_SEQ:0 B_ENT:2\n' 'BSeqStart B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEntry B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEntry B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEnd B_SEQ:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('&anchor key:\n' ' value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Anchor B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('pre:\n' ' &anchor1 0\n' '&anchor2 key:\n' ' value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' ' Anchor B_MAP:0 KEY:0 VAL:2\n' ' Scalar B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Anchor B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('sequence: &anchor\n' '- entry\n' '- &anchor\n' ' - nested\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' ' Anchor B_MAP:0 KEY:0 VAL:2\n' # missing BSeqStart here ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' ' Anchor B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' 'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEnd B_MAP:0\n' # missing BEnd here ' BEnd \n') def test_tags(self): self.assertMultiLineEqual( self.full_stack('key: !!tag value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:5\n' ' Tag B_MAP:0 KEY:0 VAL:5\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('- !!map # Block collection\n' ' foo : bar\n'), 'BSeqStart B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Tag B_SEQ:0 B_ENT:2\n' 'BMapStart B_SEQ:0 B_ENT:2 B_MAP:2\n' ' Key B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n' ' Scalar B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n' ' Value B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2 VAL:8\n' ' Scalar B_SEQ:0 B_ENT:2 B_MAP:2\n' ' BEnd B_SEQ:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('- !!seq\n' ' - nested item\n'), 'BSeqStart B_SEQ:0\n' ' BEntry B_SEQ:0 B_ENT:2\n' ' Tag B_SEQ:0 B_ENT:2\n' 'BSeqStart B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEntry B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEnd B_SEQ:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('sequence: !!seq\n' '- entry\n' '- !!seq\n' ' - nested\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' ' Scalar B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:2\n' ' Tag B_MAP:0 KEY:0 VAL:2\n' # missing BSeqStart here ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' ' Tag B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n' 'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n' ' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n' ' BEnd B_MAP:0\n' # missing BEnd here ' BEnd \n') def test_flows_imbrication(self): self.assertMultiLineEqual( self.full_stack('[[val]]\n'), 'FSeqStart F_SEQ:1\n' 'FSeqStart F_SEQ:1 F_SEQ:2\n' ' Scalar F_SEQ:1 F_SEQ:2\n' ' FSeqEnd F_SEQ:1\n' ' FSeqEnd \n') self.assertMultiLineEqual( self.full_stack('[[val], [val2]]\n'), 'FSeqStart F_SEQ:1\n' 'FSeqStart F_SEQ:1 F_SEQ:2\n' ' Scalar F_SEQ:1 F_SEQ:2\n' ' FSeqEnd F_SEQ:1\n' ' FEntry F_SEQ:1\n' 'FSeqStart F_SEQ:1 F_SEQ:9\n' ' Scalar F_SEQ:1 F_SEQ:9\n' ' FSeqEnd F_SEQ:1\n' ' FSeqEnd \n') self.assertMultiLineEqual( self.full_stack('{{key}}\n'), 'FMapStart F_MAP:1\n' 'FMapStart F_MAP:1 F_MAP:2\n' ' Scalar F_MAP:1 F_MAP:2\n' ' FMapEnd F_MAP:1\n' ' FMapEnd \n') self.assertMultiLineEqual( self.full_stack('[key]: value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' 'FSeqStart B_MAP:0 KEY:0 F_SEQ:1\n' ' Scalar B_MAP:0 KEY:0 F_SEQ:1\n' ' FSeqEnd B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:7\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('[[key]]: value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' 'FSeqStart B_MAP:0 KEY:0 F_SEQ:1\n' 'FSeqStart B_MAP:0 KEY:0 F_SEQ:1 F_SEQ:2\n' ' Scalar B_MAP:0 KEY:0 F_SEQ:1 F_SEQ:2\n' ' FSeqEnd B_MAP:0 KEY:0 F_SEQ:1\n' ' FSeqEnd B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:9\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('{key}: value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' 'FMapStart B_MAP:0 KEY:0 F_MAP:1\n' ' Scalar B_MAP:0 KEY:0 F_MAP:1\n' ' FMapEnd B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:7\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('{key: value}: value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' 'FMapStart B_MAP:0 KEY:0 F_MAP:1\n' ' Key B_MAP:0 KEY:0 F_MAP:1 KEY:1\n' ' Scalar B_MAP:0 KEY:0 F_MAP:1 KEY:1\n' ' Value B_MAP:0 KEY:0 F_MAP:1 KEY:1 VAL:6\n' ' Scalar B_MAP:0 KEY:0 F_MAP:1\n' ' FMapEnd B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:14\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('{{key}}: value\n'), 'BMapStart B_MAP:0\n' ' Key B_MAP:0 KEY:0\n' 'FMapStart B_MAP:0 KEY:0 F_MAP:1\n' 'FMapStart B_MAP:0 KEY:0 F_MAP:1 F_MAP:2\n' ' Scalar B_MAP:0 KEY:0 F_MAP:1 F_MAP:2\n' ' FMapEnd B_MAP:0 KEY:0 F_MAP:1\n' ' FMapEnd B_MAP:0 KEY:0\n' ' Value B_MAP:0 KEY:0 VAL:9\n' ' Scalar B_MAP:0\n' ' BEnd \n') self.assertMultiLineEqual( self.full_stack('{{key}: val, {key2}: {val2}}\n'), 'FMapStart F_MAP:1\n' ' Key F_MAP:1 KEY:1\n' 'FMapStart F_MAP:1 KEY:1 F_MAP:2\n' ' Scalar F_MAP:1 KEY:1 F_MAP:2\n' ' FMapEnd F_MAP:1 KEY:1\n' ' Value F_MAP:1 KEY:1 VAL:8\n' ' Scalar F_MAP:1\n' ' FEntry F_MAP:1\n' ' Key F_MAP:1 KEY:1\n' 'FMapStart F_MAP:1 KEY:1 F_MAP:14\n' ' Scalar F_MAP:1 KEY:1 F_MAP:14\n' ' FMapEnd F_MAP:1 KEY:1\n' ' Value F_MAP:1 KEY:1 VAL:21\n' 'FMapStart F_MAP:1 KEY:1 VAL:21 F_MAP:22\n' ' Scalar F_MAP:1 KEY:1 VAL:21 F_MAP:22\n' ' FMapEnd F_MAP:1\n' ' FMapEnd \n') self.assertMultiLineEqual( self.full_stack('{[{{[val]}}, [{[key]: val2}]]}\n'), 'FMapStart F_MAP:1\n' 'FSeqStart F_MAP:1 F_SEQ:2\n' 'FMapStart F_MAP:1 F_SEQ:2 F_MAP:3\n' 'FMapStart F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4\n' 'FSeqStart F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4 F_SEQ:5\n' ' Scalar F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4 F_SEQ:5\n' ' FSeqEnd F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4\n' ' FMapEnd F_MAP:1 F_SEQ:2 F_MAP:3\n' ' FMapEnd F_MAP:1 F_SEQ:2\n' ' FEntry F_MAP:1 F_SEQ:2\n' 'FSeqStart F_MAP:1 F_SEQ:2 F_SEQ:14\n' 'FMapStart F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15\n' ' Key F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15\n' 'FSeqStart F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15 F_SEQ:16\n' ' Scalar F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15 F_SEQ:16\n' ' FSeqEnd F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15\n' ' Value F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15 VAL:22\n' ' Scalar F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15\n' ' FMapEnd F_MAP:1 F_SEQ:2 F_SEQ:14\n' ' FSeqEnd F_MAP:1 F_SEQ:2\n' ' FSeqEnd F_MAP:1\n' ' FMapEnd \n') class IndentationTestCase(RuleTestCase): rule_id = 'indentation' def test_disabled(self): conf = 'indentation: disable' self.check('---\n' 'object:\n' ' k1: v1\n' 'obj2:\n' ' k2:\n' ' - 8\n' ' k3:\n' ' val\n' '...\n', conf) self.check('---\n' ' o:\n' ' k1: v1\n' ' p:\n' ' k3:\n' ' val\n' '...\n', conf) self.check('---\n' ' - o:\n' ' k1: v1\n' ' - p: kdjf\n' ' - q:\n' ' k3:\n' ' - val\n' '...\n', conf) def test_one_space(self): conf = 'indentation: {spaces: 1, indent-sequences: false}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) conf = 'indentation: {spaces: 1, indent-sequences: true}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) def test_two_spaces(self): conf = 'indentation: {spaces: 2, indent-sequences: false}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' ' k4:\n' ' -\n' ' k5: v3\n' '...\n', conf) conf = 'indentation: {spaces: 2, indent-sequences: true}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) def test_three_spaces(self): conf = 'indentation: {spaces: 3, indent-sequences: false}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) conf = 'indentation: {spaces: 3, indent-sequences: true}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) def test_consistent_spaces(self): conf = ('indentation: {spaces: consistent,\n' ' indent-sequences: whatever}\n' 'document-start: disable\n') self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf) self.check('first is not indented:\n' ' value is indented\n', conf) self.check('first is not indented:\n' ' value:\n' ' is indented\n', conf) self.check('- first is already indented:\n' ' value is indented too\n', conf) self.check('- first is already indented:\n' ' value:\n' ' is indented too\n', conf) self.check('- first is already indented:\n' ' value:\n' ' is indented too\n', conf, problem=(3, 14)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem=(7, 5)) self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf) def test_consistent_spaces_and_indent_sequences(self): conf = 'indentation: {spaces: consistent, indent-sequences: true}' self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(3, 1)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(7, 5)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf, problem1=(7, 1)) conf = 'indentation: {spaces: consistent, indent-sequences: false}' self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(7, 5)) self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(7, 3)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf, problem1=(3, 3)) conf = ('indentation: {spaces: consistent,\n' ' indent-sequences: consistent}') self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(7, 5)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf, problem1=(7, 1)) self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(7, 5)) conf = 'indentation: {spaces: consistent, indent-sequences: whatever}' self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf) self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem1=(7, 5)) def test_indent_sequences_whatever(self): conf = 'indentation: {spaces: 4, indent-sequences: whatever}' self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem=(3, 3)) self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem=(7, 3)) self.check('---\n' 'list:\n' ' - 1\n' ' - 2\n' ' - 3\n' '- a\n' '- b\n' '- c\n', conf, problem=(6, 1, 'syntax')) def test_indent_sequences_consistent(self): conf = 'indentation: {spaces: 4, indent-sequences: consistent}' self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list:\n' ' two:\n' ' - a\n' ' - b\n' ' - c\n', conf) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list:\n' ' two:\n' ' - a\n' ' - b\n' ' - c\n', conf) self.check('---\n' 'list one:\n' '- 1\n' '- 2\n' '- 3\n' 'list two:\n' ' - a\n' ' - b\n' ' - c\n', conf, problem=(7, 5)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf, problem=(7, 1)) self.check('---\n' 'list one:\n' ' - 1\n' ' - 2\n' ' - 3\n' 'list two:\n' '- a\n' '- b\n' '- c\n', conf, problem1=(3, 2), problem2=(7, 1)) def test_direct_flows(self): # flow: [ ... # ] conf = 'indentation: {spaces: consistent}' self.check('---\n' 'a: {x: 1,\n' ' y,\n' ' z: 1}\n', conf) self.check('---\n' 'a: {x: 1,\n' ' y,\n' ' z: 1}\n', conf, problem=(3, 4)) self.check('---\n' 'a: {x: 1,\n' ' y,\n' ' z: 1}\n', conf, problem=(3, 6)) self.check('---\n' 'a: {x: 1,\n' ' y, z: 1}\n', conf, problem=(3, 3)) self.check('---\n' 'a: {x: 1,\n' ' y, z: 1\n' '}\n', conf) self.check('---\n' 'a: {x: 1,\n' ' y, z: 1\n' '}\n', conf, problem=(3, 3)) self.check('---\n' 'a: [x,\n' ' y,\n' ' z]\n', conf) self.check('---\n' 'a: [x,\n' ' y,\n' ' z]\n', conf, problem=(3, 4)) self.check('---\n' 'a: [x,\n' ' y,\n' ' z]\n', conf, problem=(3, 6)) self.check('---\n' 'a: [x,\n' ' y, z]\n', conf, problem=(3, 3)) self.check('---\n' 'a: [x,\n' ' y, z\n' ']\n', conf) self.check('---\n' 'a: [x,\n' ' y, z\n' ']\n', conf, problem=(3, 3)) def test_broken_flows(self): # flow: [ # ... # ] conf = 'indentation: {spaces: consistent}' self.check('---\n' 'a: {\n' ' x: 1,\n' ' y, z: 1\n' '}\n', conf) self.check('---\n' 'a: {\n' ' x: 1,\n' ' y, z: 1}\n', conf) self.check('---\n' 'a: {\n' ' x: 1,\n' ' y, z: 1\n' '}\n', conf, problem=(4, 3)) self.check('---\n' 'a: {\n' ' x: 1,\n' ' y, z: 1\n' ' }\n', conf, problem=(5, 3)) self.check('---\n' 'a: [\n' ' x,\n' ' y, z\n' ']\n', conf) self.check('---\n' 'a: [\n' ' x,\n' ' y, z]\n', conf) self.check('---\n' 'a: [\n' ' x,\n' ' y, z\n' ']\n', conf, problem=(4, 3)) self.check('---\n' 'a: [\n' ' x,\n' ' y, z\n' ' ]\n', conf, problem=(5, 3)) self.check('---\n' 'obj: {\n' ' a: 1,\n' ' b: 2,\n' ' c: 3\n' '}\n', conf, problem1=(4, 4), problem2=(5, 2)) self.check('---\n' 'list: [\n' ' 1,\n' ' 2,\n' ' 3\n' ']\n', conf, problem1=(4, 4), problem2=(5, 2)) self.check('---\n' 'top:\n' ' rules: [\n' ' 1, 2,\n' ' ]\n', conf) self.check('---\n' 'top:\n' ' rules: [\n' ' 1, 2,\n' ']\n' ' rulez: [\n' ' 1, 2,\n' ' ]\n', conf, problem1=(5, 1), problem2=(8, 5)) self.check('---\n' 'top:\n' ' rules:\n' ' here: {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf) self.check('---\n' 'top:\n' ' rules:\n' ' here: {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n' ' there: {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf, problem1=(7, 7), problem2=(11, 3)) conf = 'indentation: {spaces: 2}' self.check('---\n' 'a: {\n' ' x: 1,\n' ' y, z: 1\n' '}\n', conf, problem=(3, 4)) self.check('---\n' 'a: [\n' ' x,\n' ' y, z\n' ']\n', conf, problem=(3, 4)) def test_cleared_flows(self): # flow: # [ # ... # ] conf = 'indentation: {spaces: consistent}' self.check('---\n' 'top:\n' ' rules:\n' ' {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf) self.check('---\n' 'top:\n' ' rules:\n' ' {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf, problem=(5, 8)) self.check('---\n' 'top:\n' ' rules:\n' ' {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf, problem=(4, 4)) self.check('---\n' 'top:\n' ' rules:\n' ' {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf, problem=(7, 4)) self.check('---\n' 'top:\n' ' rules:\n' ' {\n' ' foo: 1,\n' ' bar: 2\n' ' }\n', conf, problem=(7, 6)) self.check('---\n' 'top:\n' ' [\n' ' a, b, c\n' ' ]\n', conf) self.check('---\n' 'top:\n' ' [\n' ' a, b, c\n' ' ]\n', conf, problem=(4, 6)) self.check('---\n' 'top:\n' ' [\n' ' a, b, c\n' ' ]\n', conf, problem=(4, 6)) self.check('---\n' 'top:\n' ' [\n' ' a, b, c\n' ' ]\n', conf, problem=(5, 4)) self.check('---\n' 'top:\n' ' rules: [\n' ' {\n' ' foo: 1\n' ' },\n' ' {\n' ' foo: 2,\n' ' bar: [\n' ' a, b, c\n' ' ],\n' ' },\n' ' ]\n', conf) self.check('---\n' 'top:\n' ' rules: [\n' ' {\n' ' foo: 1\n' ' },\n' ' {\n' ' foo: 2,\n' ' bar: [\n' ' a, b, c\n' ' ],\n' ' },\n' ']\n', conf, problem1=(5, 6), problem2=(6, 6), problem3=(9, 9), problem4=(11, 7), problem5=(13, 1)) def test_under_indented(self): conf = 'indentation: {spaces: 2, indent-sequences: consistent}' self.check('---\n' 'object:\n' ' val: 1\n' '...\n', conf, problem=(3, 2)) self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' '...\n', conf, problem=(4, 4)) self.check('---\n' 'object:\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' '...\n', conf, problem=(5, 6, 'syntax')) conf = 'indentation: {spaces: 4, indent-sequences: consistent}' self.check('---\n' 'object:\n' ' val: 1\n' '...\n', conf, problem=(3, 4)) self.check('---\n' '- el1\n' '- el2:\n' ' - subel\n' '...\n', conf, problem=(4, 4)) self.check('---\n' 'object:\n' ' k3:\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf, problem=(5, 10, 'syntax')) conf = 'indentation: {spaces: 2, indent-sequences: true}' self.check('---\n' 'a:\n' '-\n' # empty list 'b: c\n' '...\n', conf, problem=(3, 1)) conf = 'indentation: {spaces: 2, indent-sequences: consistent}' self.check('---\n' 'a:\n' ' -\n' # empty list 'b:\n' '-\n' 'c: d\n' '...\n', conf, problem=(5, 1)) def test_over_indented(self): conf = 'indentation: {spaces: 2, indent-sequences: consistent}' self.check('---\n' 'object:\n' ' val: 1\n' '...\n', conf, problem=(3, 4)) self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' '...\n', conf, problem=(4, 6)) self.check('---\n' 'object:\n' ' k3:\n' ' - name: Unix\n' ' date: 1969\n' '...\n', conf, problem=(5, 12, 'syntax')) conf = 'indentation: {spaces: 4, indent-sequences: consistent}' self.check('---\n' 'object:\n' ' val: 1\n' '...\n', conf, problem=(3, 6)) self.check('---\n' ' object:\n' ' val: 1\n' '...\n', conf, problem=(2, 2)) self.check('---\n' '- el1\n' '- el2:\n' ' - subel\n' '...\n', conf, problem=(4, 6)) self.check('---\n' '- el1\n' '- el2:\n' ' - subel\n' '...\n', conf, problem=(4, 15)) self.check('---\n' ' - el1\n' ' - el2:\n' ' - subel\n' '...\n', conf, problem=(2, 3)) self.check('---\n' 'object:\n' ' k3:\n' ' - name: Linux\n' ' date: 1991\n' '...\n', conf, problem=(5, 16, 'syntax')) conf = 'indentation: {spaces: 4, indent-sequences: whatever}' self.check('---\n' ' - el1\n' ' - el2:\n' ' - subel\n' '...\n', conf, problem=(2, 3)) conf = 'indentation: {spaces: 2, indent-sequences: false}' self.check('---\n' 'a:\n' ' -\n' # empty list 'b: c\n' '...\n', conf, problem=(3, 3)) conf = 'indentation: {spaces: 2, indent-sequences: consistent}' self.check('---\n' 'a:\n' '-\n' # empty list 'b:\n' ' -\n' 'c: d\n' '...\n', conf, problem=(5, 3)) def test_multi_lines(self): conf = 'indentation: {spaces: consistent, indent-sequences: true}' self.check('---\n' 'long_string: >\n' ' bla bla blah\n' ' blah bla bla\n' '...\n', conf) self.check('---\n' '- long_string: >\n' ' bla bla blah\n' ' blah bla bla\n' '...\n', conf) self.check('---\n' 'obj:\n' ' - long_string: >\n' ' bla bla blah\n' ' blah bla bla\n' '...\n', conf) def test_empty_value(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' 'key1:\n' 'key2: not empty\n' 'key3:\n' '...\n', conf) self.check('---\n' '-\n' '- item 2\n' '-\n' '...\n', conf) def test_nested_collections(self): conf = 'indentation: {spaces: 2}' self.check('---\n' '- o:\n' ' k1: v1\n' '...\n', conf) self.check('---\n' '- o:\n' ' k1: v1\n' '...\n', conf, problem=(3, 2, 'syntax')) self.check('---\n' '- o:\n' ' k1: v1\n' '...\n', conf, problem=(3, 4)) conf = 'indentation: {spaces: 4}' self.check('---\n' '- o:\n' ' k1: v1\n' '...\n', conf) self.check('---\n' '- o:\n' ' k1: v1\n' '...\n', conf, problem=(3, 6)) self.check('---\n' '- o:\n' ' k1: v1\n' '...\n', conf, problem=(3, 8)) self.check('---\n' '- - - - item\n' ' - elem 1\n' ' - elem 2\n' ' - - - - - very nested: a\n' ' key: value\n' '...\n', conf) self.check('---\n' ' - - - - item\n' ' - elem 1\n' ' - elem 2\n' ' - - - - - very nested: a\n' ' key: value\n' '...\n', conf, problem=(2, 2)) def test_return(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' 'a:\n' ' b:\n' ' c:\n' ' d:\n' ' e:\n' ' f:\n' 'g:\n' '...\n', conf) self.check('---\n' 'a:\n' ' b:\n' ' c:\n' ' d:\n' '...\n', conf, problem=(5, 4, 'syntax')) self.check('---\n' 'a:\n' ' b:\n' ' c:\n' ' d:\n' '...\n', conf, problem=(5, 2, 'syntax')) def test_first_line(self): conf = ('indentation: {spaces: consistent}\n' 'document-start: disable\n') self.check(' a: 1\n', conf, problem=(1, 3)) def test_explicit_block_mappings(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' 'object:\n' ' ? key\n' ' : value\n', conf) self.check('---\n' 'object:\n' ' ? key\n' ' :\n' ' value\n' '...\n', conf) self.check('---\n' 'object:\n' ' ?\n' ' key\n' ' : value\n', conf) self.check('---\n' 'object:\n' ' ?\n' ' key\n' ' :\n' ' value\n' '...\n', conf) self.check('---\n' '- ? key\n' ' : value\n', conf) self.check('---\n' '- ? key\n' ' :\n' ' value\n' '...\n', conf) self.check('---\n' '- ?\n' ' key\n' ' : value\n', conf) self.check('---\n' '- ?\n' ' key\n' ' :\n' ' value\n' '...\n', conf) self.check('---\n' 'object:\n' ' ? key\n' ' :\n' ' value\n' '...\n', conf, problem=(5, 8)) self.check('---\n' '- - ?\n' ' key\n' ' :\n' ' value\n' '...\n', conf, problem=(5, 7)) self.check('---\n' 'object:\n' ' ?\n' ' key\n' ' :\n' ' value\n' '...\n', conf, problem1=(4, 8), problem2=(6, 10)) self.check('---\n' 'object:\n' ' ?\n' ' key\n' ' :\n' ' value\n' '...\n', conf, problem1=(4, 10), problem2=(6, 8)) def test_clear_sequence_item(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' '-\n' ' string\n' '-\n' ' map: ping\n' '-\n' ' - sequence\n' ' -\n' ' nested\n' ' -\n' ' >\n' ' multi\n' ' line\n' '...\n', conf) self.check('---\n' '-\n' ' string\n' '-\n' ' string\n', conf, problem=(5, 4)) self.check('---\n' '-\n' ' map: ping\n' '-\n' ' map: ping\n', conf, problem=(5, 4)) self.check('---\n' '-\n' ' - sequence\n' '-\n' ' - sequence\n', conf, problem=(5, 4)) self.check('---\n' '-\n' ' -\n' ' nested\n' ' -\n' ' nested\n', conf, problem1=(4, 4), problem2=(6, 6)) self.check('---\n' '-\n' ' -\n' ' >\n' ' multi\n' ' line\n' '...\n', conf, problem=(4, 6)) conf = 'indentation: {spaces: 2}' self.check('---\n' '-\n' ' string\n' '-\n' ' string\n', conf, problem1=(3, 2), problem2=(5, 4)) self.check('---\n' '-\n' ' map: ping\n' '-\n' ' map: ping\n', conf, problem1=(3, 2), problem2=(5, 4)) self.check('---\n' '-\n' ' - sequence\n' '-\n' ' - sequence\n', conf, problem1=(3, 2), problem2=(5, 4)) self.check('---\n' '-\n' ' -\n' ' nested\n' ' -\n' ' nested\n', conf, problem1=(4, 4), problem2=(6, 6)) def test_anchors(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' 'key: &anchor value\n', conf) self.check('---\n' 'key: &anchor\n' ' value\n', conf) self.check('---\n' '- &anchor value\n', conf) self.check('---\n' '- &anchor\n' ' value\n', conf) self.check('---\n' 'key: &anchor [1,\n' ' 2]\n', conf) self.check('---\n' 'key: &anchor\n' ' [1,\n' ' 2]\n', conf) self.check('---\n' 'key: &anchor\n' ' - 1\n' ' - 2\n', conf) self.check('---\n' '- &anchor [1,\n' ' 2]\n', conf) self.check('---\n' '- &anchor\n' ' [1,\n' ' 2]\n', conf) self.check('---\n' '- &anchor\n' ' - 1\n' ' - 2\n', conf) self.check('---\n' 'key:\n' ' &anchor1\n' ' value\n', conf) self.check('---\n' 'pre:\n' ' &anchor1 0\n' '&anchor2 key:\n' ' value\n', conf) self.check('---\n' 'machine0:\n' ' /etc/hosts: &ref-etc-hosts\n' ' content:\n' ' - 127.0.0.1: localhost\n' ' - ::1: localhost\n' ' mode: 0644\n' 'machine1:\n' ' /etc/hosts: *ref-etc-hosts\n', conf) self.check('---\n' 'list:\n' ' - k: v\n' ' - &a truc\n' ' - &b\n' ' truc\n' ' - k: *a\n', conf) def test_tags(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' '-\n' ' "flow in block"\n' '- >\n' ' Block scalar\n' '- !!map # Block collection\n' ' foo: bar\n', conf) conf = 'indentation: {spaces: consistent, indent-sequences: false}' self.check('---\n' 'sequence: !!seq\n' '- entry\n' '- !!seq\n' ' - nested\n', conf) self.check('---\n' 'mapping: !!map\n' ' foo: bar\n' 'Block style: !!map\n' ' Clark: Evans\n' ' Ingy: döt Net\n' ' Oren: Ben-Kiki\n', conf) self.check('---\n' 'Flow style: !!map {Clark: Evans, Ingy: döt Net}\n' 'Block style: !!seq\n' '- Clark Evans\n' '- Ingy döt Net\n', conf) def test_flows_imbrication(self): conf = 'indentation: {spaces: consistent}' self.check('---\n' '[val]: value\n', conf) self.check('---\n' '{key}: value\n', conf) self.check('---\n' '{key: val}: value\n', conf) self.check('---\n' '[[val]]: value\n', conf) self.check('---\n' '{{key}}: value\n', conf) self.check('---\n' '{{key: val1}: val2}: value\n', conf) self.check('---\n' '- [val, {{key: val}: val}]: value\n' '- {[val,\n' ' {{key: val}: val}]}\n' '- {[val,\n' ' {{key: val,\n' ' key2}}]}\n' '- {{{{{moustaches}}}}}\n' '- {{{{{moustache,\n' ' moustache},\n' ' moustache}},\n' ' moustache}}\n', conf) self.check('---\n' '- {[val,\n' ' {{key: val}: val}]}\n', conf, problem=(3, 6)) self.check('---\n' '- {[val,\n' ' {{key: val,\n' ' key2}}]}\n', conf, problem=(4, 6)) self.check('---\n' '- {{{{{moustache,\n' ' moustache},\n' ' moustache}},\n' ' moustache}}\n', conf, problem1=(4, 8), problem2=(5, 4)) class ScalarIndentationTestCase(RuleTestCase): rule_id = 'indentation' def test_basics_plain(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: false}\n' 'document-start: disable\n') self.check('multi\n' 'line\n', conf) self.check('multi\n' ' line\n', conf) self.check('- multi\n' ' line\n', conf) self.check('- multi\n' ' line\n', conf) self.check('a key: multi\n' ' line\n', conf) self.check('a key: multi\n' ' line\n', conf) self.check('a key: multi\n' ' line\n', conf) self.check('a key:\n' ' multi\n' ' line\n', conf) self.check('- C code: void main() {\n' ' printf("foo");\n' ' }\n', conf) self.check('- C code:\n' ' void main() {\n' ' printf("foo");\n' ' }\n', conf) def test_check_multi_line_plain(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('multi\n' ' line\n', conf, problem=(2, 2)) self.check('- multi\n' ' line\n', conf, problem=(2, 4)) self.check('a key: multi\n' ' line\n', conf, problem=(2, 3)) self.check('a key: multi\n' ' line\n', conf, problem=(2, 9)) self.check('a key:\n' ' multi\n' ' line\n', conf, problem=(3, 4)) self.check('- C code: void main() {\n' ' printf("foo");\n' ' }\n', conf, problem=(2, 15)) self.check('- C code:\n' ' void main() {\n' ' printf("foo");\n' ' }\n', conf, problem=(3, 9)) def test_basics_quoted(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: false}\n' 'document-start: disable\n') self.check('"multi\n' ' line"\n', conf) self.check('- "multi\n' ' line"\n', conf) self.check('a key: "multi\n' ' line"\n', conf) self.check('a key:\n' ' "multi\n' ' line"\n', conf) self.check('- jinja2: "{% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}"\n', conf) self.check('- jinja2:\n' ' "{% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}"\n', conf) self.check('["this is a very long line\n' ' that needs to be split",\n' ' "other line"]\n', conf) self.check('["multi\n' ' line 1", "multi\n' ' line 2"]\n', conf) def test_check_multi_line_quoted(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('"multi\n' 'line"\n', conf, problem=(2, 1)) self.check('"multi\n' ' line"\n', conf, problem=(2, 3)) self.check('- "multi\n' ' line"\n', conf, problem=(2, 3)) self.check('- "multi\n' ' line"\n', conf, problem=(2, 5)) self.check('a key: "multi\n' ' line"\n', conf, problem=(2, 3)) self.check('a key: "multi\n' ' line"\n', conf, problem=(2, 8)) self.check('a key: "multi\n' ' line"\n', conf, problem=(2, 10)) self.check('a key:\n' ' "multi\n' ' line"\n', conf, problem=(3, 3)) self.check('a key:\n' ' "multi\n' ' line"\n', conf, problem=(3, 5)) self.check('- jinja2: "{% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}"\n', conf, problem1=(2, 14), problem2=(4, 14)) self.check('- jinja2:\n' ' "{% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}"\n', conf, problem1=(3, 8), problem2=(5, 8)) self.check('["this is a very long line\n' ' that needs to be split",\n' ' "other line"]\n', conf) self.check('["this is a very long line\n' ' that needs to be split",\n' ' "other line"]\n', conf, problem=(2, 2)) self.check('["this is a very long line\n' ' that needs to be split",\n' ' "other line"]\n', conf, problem=(2, 4)) self.check('["multi\n' ' line 1", "multi\n' ' line 2"]\n', conf) self.check('["multi\n' ' line 1", "multi\n' ' line 2"]\n', conf, problem=(3, 12)) self.check('["multi\n' ' line 1", "multi\n' ' line 2"]\n', conf, problem=(3, 14)) def test_basics_folded_style(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: false}\n' 'document-start: disable\n') self.check('>\n' ' multi\n' ' line\n', conf) self.check('- >\n' ' multi\n' ' line\n', conf) self.check('- key: >\n' ' multi\n' ' line\n', conf) self.check('- key:\n' ' >\n' ' multi\n' ' line\n', conf) self.check('- ? >\n' ' multi-line\n' ' key\n' ' : >\n' ' multi-line\n' ' value\n', conf) self.check('- ?\n' ' >\n' ' multi-line\n' ' key\n' ' :\n' ' >\n' ' multi-line\n' ' value\n', conf) self.check('- jinja2: >\n' ' {% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}\n', conf) def test_check_multi_line_folded_style(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('>\n' ' multi\n' ' line\n', conf, problem=(3, 4)) self.check('- >\n' ' multi\n' ' line\n', conf, problem=(3, 6)) self.check('- key: >\n' ' multi\n' ' line\n', conf, problem=(3, 6)) self.check('- key:\n' ' >\n' ' multi\n' ' line\n', conf, problem=(4, 8)) self.check('- ? >\n' ' multi-line\n' ' key\n' ' : >\n' ' multi-line\n' ' value\n', conf, problem1=(3, 8), problem2=(6, 8)) self.check('- ?\n' ' >\n' ' multi-line\n' ' key\n' ' :\n' ' >\n' ' multi-line\n' ' value\n', conf, problem1=(4, 8), problem2=(8, 8)) self.check('- jinja2: >\n' ' {% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}\n', conf, problem1=(3, 7), problem2=(5, 7)) def test_basics_literal_style(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: false}\n' 'document-start: disable\n') self.check('|\n' ' multi\n' ' line\n', conf) self.check('- |\n' ' multi\n' ' line\n', conf) self.check('- key: |\n' ' multi\n' ' line\n', conf) self.check('- key:\n' ' |\n' ' multi\n' ' line\n', conf) self.check('- ? |\n' ' multi-line\n' ' key\n' ' : |\n' ' multi-line\n' ' value\n', conf) self.check('- ?\n' ' |\n' ' multi-line\n' ' key\n' ' :\n' ' |\n' ' multi-line\n' ' value\n', conf) self.check('- jinja2: |\n' ' {% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}\n', conf) def test_check_multi_line_literal_style(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('|\n' ' multi\n' ' line\n', conf, problem=(3, 4)) self.check('- |\n' ' multi\n' ' line\n', conf, problem=(3, 6)) self.check('- key: |\n' ' multi\n' ' line\n', conf, problem=(3, 6)) self.check('- key:\n' ' |\n' ' multi\n' ' line\n', conf, problem=(4, 8)) self.check('- ? |\n' ' multi-line\n' ' key\n' ' : |\n' ' multi-line\n' ' value\n', conf, problem1=(3, 8), problem2=(6, 8)) self.check('- ?\n' ' |\n' ' multi-line\n' ' key\n' ' :\n' ' |\n' ' multi-line\n' ' value\n', conf, problem1=(4, 8), problem2=(8, 8)) self.check('- jinja2: |\n' ' {% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' ' {{ chef }}\n' ' {% endif %}\n', conf, problem1=(3, 7), problem2=(5, 7)) # The following "paragraph" examples are inspired from # http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines def test_paragraph_plain(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('- long text: very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf) self.check('- long text: very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf, problem1=(2, 5), problem2=(4, 5), problem3=(5, 5)) self.check('- long text:\n' ' very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf) def test_paragraph_double_quoted(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('- long text: "very \\"long\\"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces."\n', conf) self.check('- long text: "very \\"long\\"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces."\n', conf, problem1=(2, 5), problem2=(4, 5), problem3=(5, 5)) self.check('- long text: "very \\"long\\"\n' '\'string\' with\n' '\n' 'paragraph gap, \\n and\n' 'spaces."\n', conf, problem1=(2, 1), problem2=(4, 1), problem3=(5, 1)) self.check('- long text:\n' ' "very \\"long\\"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces."\n', conf) def test_paragraph_single_quoted(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('- long text: \'very "long"\n' ' \'\'string\'\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\'\n', conf) self.check('- long text: \'very "long"\n' ' \'\'string\'\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\'\n', conf, problem1=(2, 5), problem2=(4, 5), problem3=(5, 5)) self.check('- long text: \'very "long"\n' '\'\'string\'\' with\n' '\n' 'paragraph gap, \\n and\n' 'spaces.\'\n', conf, problem1=(2, 1), problem2=(4, 1), problem3=(5, 1)) self.check('- long text:\n' ' \'very "long"\n' ' \'\'string\'\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\'\n', conf) def test_paragraph_folded(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('- long text: >\n' ' very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf) self.check('- long text: >\n' ' very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf, problem1=(3, 6), problem2=(5, 7), problem3=(6, 8)) def test_paragraph_literal(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('- long text: |\n' ' very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf) self.check('- long text: |\n' ' very "long"\n' ' \'string\' with\n' '\n' ' paragraph gap, \\n and\n' ' spaces.\n', conf, problem1=(3, 6), problem2=(5, 7), problem3=(6, 8)) def test_consistent(self): conf = ('indentation: {spaces: consistent,\n' ' check-multi-line-strings: true}\n' 'document-start: disable\n') self.check('multi\n' 'line\n', conf) self.check('multi\n' ' line\n', conf, problem=(2, 2)) self.check('- multi\n' ' line\n', conf) self.check('- multi\n' ' line\n', conf, problem=(2, 4)) self.check('a key: multi\n' ' line\n', conf, problem=(2, 3)) self.check('a key: multi\n' ' line\n', conf, problem=(2, 9)) self.check('a key:\n' ' multi\n' ' line\n', conf, problem=(3, 4)) self.check('- C code: void main() {\n' ' printf("foo");\n' ' }\n', conf, problem=(2, 15)) self.check('- C code:\n' ' void main() {\n' ' printf("foo");\n' ' }\n', conf, problem=(3, 9)) self.check('>\n' ' multi\n' ' line\n', conf) self.check('>\n' ' multi\n' ' line\n', conf) self.check('>\n' ' multi\n' ' line\n', conf, problem=(3, 7)) yamllint-1.10.0/tests/rules/test_comments.py0000644000232200023220000001451413177553503021540 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class CommentsTestCase(RuleTestCase): rule_id = 'comments' def test_disabled(self): conf = ('comments: disable\n' 'comments-indentation: disable\n') self.check('---\n' '#comment\n' '\n' 'test: # description\n' ' - foo # bar\n' ' - hello #world\n' '\n' '# comment 2\n' '#comment 3\n' ' #comment 3 bis\n' ' # comment 3 ter\n' '\n' '################################\n' '## comment 4\n' '##comment 5\n' '\n' 'string: "Une longue phrase." # this is French\n', conf) def test_starting_space(self): conf = ('comments:\n' ' require-starting-space: true\n' ' min-spaces-from-content: -1\n' 'comments-indentation: disable\n') self.check('---\n' '# comment\n' '\n' 'test: # description\n' ' - foo # bar\n' ' - hello # world\n' '\n' '# comment 2\n' '# comment 3\n' ' # comment 3 bis\n' ' # comment 3 ter\n' '\n' '################################\n' '## comment 4\n' '## comment 5\n', conf) self.check('---\n' '#comment\n' '\n' 'test: # description\n' ' - foo # bar\n' ' - hello #world\n' '\n' '# comment 2\n' '#comment 3\n' ' #comment 3 bis\n' ' # comment 3 ter\n' '\n' '################################\n' '## comment 4\n' '##comment 5\n', conf, problem1=(2, 2), problem2=(6, 13), problem3=(9, 2), problem4=(10, 4), problem5=(15, 3)) def test_spaces_from_content(self): conf = ('comments:\n' ' require-starting-space: false\n' ' min-spaces-from-content: 2\n') self.check('---\n' '# comment\n' '\n' 'test: # description\n' ' - foo # bar\n' ' - hello #world\n' '\n' 'string: "Une longue phrase." # this is French\n', conf) self.check('---\n' '# comment\n' '\n' 'test: # description\n' ' - foo # bar\n' ' - hello #world\n' '\n' 'string: "Une longue phrase." # this is French\n', conf, problem1=(4, 7), problem2=(6, 11), problem3=(8, 30)) def test_both(self): conf = ('comments:\n' ' require-starting-space: true\n' ' min-spaces-from-content: 2\n' 'comments-indentation: disable\n') self.check('---\n' '#comment\n' '\n' 'test: # description\n' ' - foo # bar\n' ' - hello #world\n' '\n' '# comment 2\n' '#comment 3\n' ' #comment 3 bis\n' ' # comment 3 ter\n' '\n' '################################\n' '## comment 4\n' '##comment 5\n' '\n' 'string: "Une longue phrase." # this is French\n', conf, problem1=(2, 2), problem2=(4, 7), problem3=(6, 11), problem4=(6, 12), problem5=(9, 2), problem6=(10, 4), problem7=(15, 3), problem8=(17, 30)) def test_empty_comment(self): conf = ('comments:\n' ' require-starting-space: true\n' ' min-spaces-from-content: 2\n') self.check('---\n' '# This is paragraph 1.\n' '#\n' '# This is paragraph 2.\n', conf) self.check('---\n' 'inline: comment #\n' 'foo: bar\n', conf) def test_first_line(self): conf = ('comments:\n' ' require-starting-space: true\n' ' min-spaces-from-content: 2\n') self.check('# comment\n', conf) def test_last_line(self): conf = ('comments:\n' ' require-starting-space: true\n' ' min-spaces-from-content: 2\n' 'new-line-at-end-of-file: disable\n') self.check('# comment with no newline char:\n' '#', conf) def test_multi_line_scalar(self): conf = ('comments:\n' ' require-starting-space: true\n' ' min-spaces-from-content: 2\n' 'trailing-spaces: disable\n') self.check('---\n' 'string: >\n' ' this is plain text\n' '\n' '# comment\n', conf) self.check('---\n' '- string: >\n' ' this is plain text\n' ' \n' ' # comment\n', conf) yamllint-1.10.0/tests/rules/test_braces.py0000644000232200023220000002465713177553503021163 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class ColonTestCase(RuleTestCase): rule_id = 'braces' def test_disabled(self): conf = 'braces: disable' self.check('---\n' 'dict1: {}\n' 'dict2: { }\n' 'dict3: { a: 1, b}\n' 'dict4: {a: 1, b, c: 3 }\n' 'dict5: {a: 1, b, c: 3 }\n' 'dict6: { a: 1, b, c: 3 }\n' 'dict7: { a: 1, b, c: 3 }\n', conf) def test_min_spaces(self): conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 0\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: {}\n', conf) conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: {}\n', conf, problem=(2, 8)) self.check('---\n' 'dict: { }\n', conf) self.check('---\n' 'dict: {a: 1, b}\n', conf, problem1=(2, 8), problem2=(2, 15)) self.check('---\n' 'dict: { a: 1, b }\n', conf) self.check('---\n' 'dict: {\n' ' a: 1,\n' ' b\n' '}\n', conf) conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 3\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: { a: 1, b }\n', conf, problem1=(2, 9), problem2=(2, 17)) self.check('---\n' 'dict: { a: 1, b }\n', conf) def test_max_spaces(self): conf = ('braces:\n' ' max-spaces-inside: 0\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: {}\n', conf) self.check('---\n' 'dict: { }\n', conf, problem=(2, 8)) self.check('---\n' 'dict: {a: 1, b}\n', conf) self.check('---\n' 'dict: { a: 1, b }\n', conf, problem1=(2, 8), problem2=(2, 16)) self.check('---\n' 'dict: { a: 1, b }\n', conf, problem1=(2, 10), problem2=(2, 20)) self.check('---\n' 'dict: {\n' ' a: 1,\n' ' b\n' '}\n', conf) conf = ('braces:\n' ' max-spaces-inside: 3\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: { a: 1, b }\n', conf) self.check('---\n' 'dict: { a: 1, b }\n', conf, problem1=(2, 11), problem2=(2, 23)) def test_min_and_max_spaces(self): conf = ('braces:\n' ' max-spaces-inside: 0\n' ' min-spaces-inside: 0\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: {}\n', conf) self.check('---\n' 'dict: { }\n', conf, problem=(2, 8)) self.check('---\n' 'dict: { a: 1, b}\n', conf, problem=(2, 10)) conf = ('braces:\n' ' max-spaces-inside: 1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: {a: 1, b, c: 3 }\n', conf, problem=(2, 8)) conf = ('braces:\n' ' max-spaces-inside: 2\n' ' min-spaces-inside: 0\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'dict: {a: 1, b, c: 3 }\n', conf) self.check('---\n' 'dict: { a: 1, b, c: 3 }\n', conf) self.check('---\n' 'dict: { a: 1, b, c: 3 }\n', conf, problem=(2, 10)) def test_min_spaces_empty(self): conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 0\n' ' min-spaces-inside-empty: 0\n') self.check('---\n' 'array: {}\n', conf) conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: {}\n', conf, problem=(2, 9)) self.check('---\n' 'array: { }\n', conf) conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: 3\n') self.check('---\n' 'array: {}\n', conf, problem=(2, 9)) self.check('---\n' 'array: { }\n', conf) def test_max_spaces_empty(self): conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 0\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: {}\n', conf) self.check('---\n' 'array: { }\n', conf, problem=(2, 9)) conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: {}\n', conf) self.check('---\n' 'array: { }\n', conf) self.check('---\n' 'array: { }\n', conf, problem=(2, 10)) conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 3\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: {}\n', conf) self.check('---\n' 'array: { }\n', conf) self.check('---\n' 'array: { }\n', conf, problem=(2, 12)) def test_min_and_max_spaces_empty(self): conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 2\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: {}\n', conf, problem=(2, 9)) self.check('---\n' 'array: { }\n', conf) self.check('---\n' 'array: { }\n', conf) self.check('---\n' 'array: { }\n', conf, problem=(2, 11)) def test_mixed_empty_nonempty(self): conf = ('braces:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: 0\n' ' min-spaces-inside-empty: 0\n') self.check('---\n' 'array: { a: 1, b }\n', conf) self.check('---\n' 'array: {a: 1, b}\n', conf, problem1=(2, 9), problem2=(2, 16)) self.check('---\n' 'array: {}\n', conf) self.check('---\n' 'array: { }\n', conf, problem1=(2, 9)) conf = ('braces:\n' ' max-spaces-inside: 0\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: { a: 1, b }\n', conf, problem1=(2, 9), problem2=(2, 17)) self.check('---\n' 'array: {a: 1, b}\n', conf) self.check('---\n' 'array: {}\n', conf, problem1=(2, 9)) self.check('---\n' 'array: { }\n', conf) conf = ('braces:\n' ' max-spaces-inside: 2\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: { a: 1, b }\n', conf) self.check('---\n' 'array: {a: 1, b }\n', conf, problem1=(2, 9), problem2=(2, 18)) self.check('---\n' 'array: {}\n', conf, problem1=(2, 9)) self.check('---\n' 'array: { }\n', conf) self.check('---\n' 'array: { }\n', conf, problem1=(2, 11)) conf = ('braces:\n' ' max-spaces-inside: 1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: { a: 1, b }\n', conf) self.check('---\n' 'array: {a: 1, b}\n', conf, problem1=(2, 9), problem2=(2, 16)) self.check('---\n' 'array: {}\n', conf, problem1=(2, 9)) self.check('---\n' 'array: { }\n', conf) yamllint-1.10.0/tests/rules/test_brackets.py0000644000232200023220000002456613177553503021521 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class ColonTestCase(RuleTestCase): rule_id = 'brackets' def test_disabled(self): conf = 'brackets: disable' self.check('---\n' 'array1: []\n' 'array2: [ ]\n' 'array3: [ a, b]\n' 'array4: [a, b, c ]\n' 'array5: [a, b, c ]\n' 'array6: [ a, b, c ]\n' 'array7: [ a, b, c ]\n', conf) def test_min_spaces(self): conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 0\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf) conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf, problem=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) self.check('---\n' 'array: [a, b]\n', conf, problem1=(2, 9), problem2=(2, 13)) self.check('---\n' 'array: [ a, b ]\n', conf) self.check('---\n' 'array: [\n' ' a,\n' ' b\n' ']\n', conf) conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 3\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: [ a, b ]\n', conf, problem1=(2, 10), problem2=(2, 15)) self.check('---\n' 'array: [ a, b ]\n', conf) def test_max_spaces(self): conf = ('brackets:\n' ' max-spaces-inside: 0\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem=(2, 9)) self.check('---\n' 'array: [a, b]\n', conf) self.check('---\n' 'array: [ a, b ]\n', conf, problem1=(2, 9), problem2=(2, 14)) self.check('---\n' 'array: [ a, b ]\n', conf, problem1=(2, 11), problem2=(2, 18)) self.check('---\n' 'array: [\n' ' a,\n' ' b\n' ']\n', conf) conf = ('brackets:\n' ' max-spaces-inside: 3\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: [ a, b ]\n', conf) self.check('---\n' 'array: [ a, b ]\n', conf, problem1=(2, 12), problem2=(2, 21)) def test_min_and_max_spaces(self): conf = ('brackets:\n' ' max-spaces-inside: 0\n' ' min-spaces-inside: 0\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem=(2, 9)) self.check('---\n' 'array: [ a, b]\n', conf, problem=(2, 11)) conf = ('brackets:\n' ' max-spaces-inside: 1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: [a, b, c ]\n', conf, problem=(2, 9)) conf = ('brackets:\n' ' max-spaces-inside: 2\n' ' min-spaces-inside: 0\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: [a, b, c ]\n', conf) self.check('---\n' 'array: [ a, b, c ]\n', conf) self.check('---\n' 'array: [ a, b, c ]\n', conf, problem=(2, 11)) def test_min_spaces_empty(self): conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 0\n' ' min-spaces-inside-empty: 0\n') self.check('---\n' 'array: []\n', conf) conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: []\n', conf, problem=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: -1\n' ' min-spaces-inside-empty: 3\n') self.check('---\n' 'array: []\n', conf, problem=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) def test_max_spaces_empty(self): conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 0\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem=(2, 9)) conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf) self.check('---\n' 'array: [ ]\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem=(2, 10)) conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 3\n' ' min-spaces-inside-empty: -1\n') self.check('---\n' 'array: []\n', conf) self.check('---\n' 'array: [ ]\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem=(2, 12)) def test_min_and_max_spaces_empty(self): conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 2\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: []\n', conf, problem=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) self.check('---\n' 'array: [ ]\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem=(2, 11)) def test_mixed_empty_nonempty(self): conf = ('brackets:\n' ' max-spaces-inside: -1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: 0\n' ' min-spaces-inside-empty: 0\n') self.check('---\n' 'array: [ a, b ]\n', conf) self.check('---\n' 'array: [a, b]\n', conf, problem1=(2, 9), problem2=(2, 13)) self.check('---\n' 'array: []\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem1=(2, 9)) conf = ('brackets:\n' ' max-spaces-inside: 0\n' ' min-spaces-inside: -1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: [ a, b ]\n', conf, problem1=(2, 9), problem2=(2, 14)) self.check('---\n' 'array: [a, b]\n', conf) self.check('---\n' 'array: []\n', conf, problem1=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) conf = ('brackets:\n' ' max-spaces-inside: 2\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: [ a, b ]\n', conf) self.check('---\n' 'array: [a, b ]\n', conf, problem1=(2, 9), problem2=(2, 15)) self.check('---\n' 'array: []\n', conf, problem1=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) self.check('---\n' 'array: [ ]\n', conf, problem1=(2, 11)) conf = ('brackets:\n' ' max-spaces-inside: 1\n' ' min-spaces-inside: 1\n' ' max-spaces-inside-empty: 1\n' ' min-spaces-inside-empty: 1\n') self.check('---\n' 'array: [ a, b ]\n', conf) self.check('---\n' 'array: [a, b]\n', conf, problem1=(2, 9), problem2=(2, 13)) self.check('---\n' 'array: []\n', conf, problem1=(2, 9)) self.check('---\n' 'array: [ ]\n', conf) yamllint-1.10.0/tests/rules/test_line_length.py0000644000232200023220000001457113177553503022206 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class LineLengthTestCase(RuleTestCase): rule_id = 'line-length' def test_disabled(self): conf = ('line-length: disable\n' 'empty-lines: disable\n' 'new-line-at-end-of-file: disable\n' 'document-start: disable\n') self.check('', conf) self.check('\n', conf) self.check('---\n', conf) self.check(81 * 'a', conf) self.check('---\n' + 81 * 'a' + '\n', conf) self.check(1000 * 'b', conf) self.check('---\n' + 1000 * 'b' + '\n', conf) self.check('content: |\n' ' {% this line is' + 99 * ' really' + ' long %}\n', conf) def test_default(self): conf = ('line-length: {max: 80}\n' 'empty-lines: disable\n' 'new-line-at-end-of-file: disable\n' 'document-start: disable\n') self.check('', conf) self.check('\n', conf) self.check('---\n', conf) self.check(80 * 'a', conf) self.check('---\n' + 80 * 'a' + '\n', conf) self.check(16 * 'aaaa ' + 'z', conf, problem=(1, 81)) self.check('---\n' + 16 * 'aaaa ' + 'z' + '\n', conf, problem=(2, 81)) self.check(1000 * 'word ' + 'end', conf, problem=(1, 81)) self.check('---\n' + 1000 * 'word ' + 'end\n', conf, problem=(2, 81)) def test_max_length_10(self): conf = ('line-length: {max: 10}\n' 'new-line-at-end-of-file: disable\n') self.check('---\nABCD EFGHI', conf) self.check('---\nABCD EFGHIJ', conf, problem=(2, 11)) self.check('---\nABCD EFGHIJ\n', conf, problem=(2, 11)) def test_spaces(self): conf = ('line-length: {max: 80}\n' 'new-line-at-end-of-file: disable\n' 'trailing-spaces: disable\n') self.check('---\n' + 81 * ' ', conf, problem=(2, 81)) self.check('---\n' + 81 * ' ' + '\n', conf, problem=(2, 81)) def test_non_breakable_word(self): conf = 'line-length: {max: 20, allow-non-breakable-words: true}' self.check('---\n' + 30 * 'A' + '\n', conf) self.check('---\n' 'this:\n' ' is:\n' ' - a:\n' ' http://localhost/very/long/url\n' '...\n', conf) self.check('---\n' 'this:\n' ' is:\n' ' - a:\n' ' # http://localhost/very/long/url\n' ' comment\n' '...\n', conf) self.check('---\n' 'this:\n' 'is:\n' 'another:\n' ' - https://localhost/very/very/long/url\n' '...\n', conf) self.check('---\n' 'long_line: http://localhost/very/very/long/url\n', conf, problem=(2, 21)) conf = 'line-length: {max: 20, allow-non-breakable-words: false}' self.check('---\n' + 30 * 'A' + '\n', conf, problem=(2, 21)) self.check('---\n' 'this:\n' ' is:\n' ' - a:\n' ' http://localhost/very/long/url\n' '...\n', conf, problem=(5, 21)) self.check('---\n' 'this:\n' ' is:\n' ' - a:\n' ' # http://localhost/very/long/url\n' ' comment\n' '...\n', conf, problem=(5, 21)) self.check('---\n' 'this:\n' 'is:\n' 'another:\n' ' - https://localhost/very/very/long/url\n' '...\n', conf, problem=(5, 21)) self.check('---\n' 'long_line: http://localhost/very/very/long/url\n' '...\n', conf, problem=(2, 21)) conf = ('line-length: {max: 20, allow-non-breakable-words: true}\n' 'trailing-spaces: disable') self.check('---\n' 'loooooooooong+word+and+some+space+at+the+end \n', conf, problem=(2, 21)) def test_non_breakable_inline_mappings(self): conf = 'line-length: {max: 20, ' \ 'allow-non-breakable-inline-mappings: true}' self.check('---\n' 'long_line: http://localhost/very/very/long/url\n' 'long line: http://localhost/very/very/long/url\n', conf) self.check('---\n' '- long line: http://localhost/very/very/long/url\n', conf) self.check('---\n' 'long_line: http://localhost/short/url + word\n' 'long line: http://localhost/short/url + word\n', conf, problem1=(2, 21), problem2=(3, 21)) conf = ('line-length: {max: 20,' ' allow-non-breakable-inline-mappings: true}\n' 'trailing-spaces: disable') self.check('---\n' 'long_line: and+some+space+at+the+end \n', conf, problem=(2, 21)) self.check('---\n' 'long line: and+some+space+at+the+end \n', conf, problem=(2, 21)) self.check('---\n' '- long line: and+some+space+at+the+end \n', conf, problem=(2, 21)) # See https://github.com/adrienverge/yamllint/issues/21 conf = 'line-length: {allow-non-breakable-inline-mappings: true}' self.check('---\n' 'content: |\n' ' {% this line is' + 99 * ' really' + ' long %}\n', conf, problem=(3, 81)) yamllint-1.10.0/tests/rules/test_trailing_spaces.py0000644000232200023220000000334513177553503023062 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class TrailingSpacesTestCase(RuleTestCase): rule_id = 'trailing-spaces' def test_disabled(self): conf = 'trailing-spaces: disable' self.check('', conf) self.check('\n', conf) self.check(' \n', conf) self.check('---\n' 'some: text \n', conf) def test_enabled(self): conf = 'trailing-spaces: enable' self.check('', conf) self.check('\n', conf) self.check(' \n', conf, problem=(1, 1)) self.check('\t\t\t\n', conf, problem=(1, 1, 'syntax')) self.check('---\n' 'some: text \n', conf, problem=(2, 11)) self.check('---\n' 'some: text\t\n', conf, problem=(2, 11, 'syntax')) def test_with_dos_new_lines(self): conf = ('trailing-spaces: enable\n' 'new-lines: {type: dos}\n') self.check('---\r\n' 'some: text\r\n', conf) self.check('---\r\n' 'some: text \r\n', conf, problem=(2, 11)) yamllint-1.10.0/tests/rules/test_new_line_at_end_of_file.py0000644000232200023220000000302313177553503024501 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class NewLineAtEndOfFileTestCase(RuleTestCase): rule_id = 'new-line-at-end-of-file' def test_disabled(self): conf = ('new-line-at-end-of-file: disable\n' 'empty-lines: disable\n' 'document-start: disable\n') self.check('', conf) self.check('\n', conf) self.check('word', conf) self.check('Sentence.\n', conf) def test_enabled(self): conf = ('new-line-at-end-of-file: enable\n' 'empty-lines: disable\n' 'document-start: disable\n') self.check('', conf) self.check('\n', conf) self.check('word', conf, problem=(1, 5)) self.check('Sentence.\n', conf) self.check('---\n' 'yaml: document\n' '...', conf, problem=(3, 4)) yamllint-1.10.0/tests/rules/test_document_end.py0000644000232200023220000000473313177553503022361 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class DocumentEndTestCase(RuleTestCase): rule_id = 'document-end' def test_disabled(self): conf = 'document-end: disable' self.check('---\n' 'with:\n' ' document: end\n' '...\n', conf) self.check('---\n' 'without:\n' ' document: end\n', conf) def test_required(self): conf = 'document-end: {present: true}' self.check('', conf) self.check('\n', conf) self.check('---\n' 'with:\n' ' document: end\n' '...\n', conf) self.check('---\n' 'without:\n' ' document: end\n', conf, problem=(3, 1)) def test_forbidden(self): conf = 'document-end: {present: false}' self.check('---\n' 'with:\n' ' document: end\n' '...\n', conf, problem=(4, 1)) self.check('---\n' 'without:\n' ' document: end\n', conf) def test_multiple_documents(self): conf = ('document-end: {present: true}\n' 'document-start: disable\n') self.check('---\n' 'first: document\n' '...\n' '---\n' 'second: document\n' '...\n' '---\n' 'third: document\n' '...\n', conf) self.check('---\n' 'first: document\n' '...\n' '---\n' 'second: document\n' '---\n' 'third: document\n' '...\n', conf, problem=(6, 1)) yamllint-1.10.0/tests/rules/__init__.py0000644000232200023220000000000013177553503020374 0ustar debalancedebalanceyamllint-1.10.0/tests/rules/test_empty_values.py0000644000232200023220000002357013177553503022432 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2017 Greg Dubicki # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class EmptyValuesTestCase(RuleTestCase): rule_id = 'empty-values' def test_disabled(self): conf = ('empty-values: disable\n' 'braces: disable\n' 'commas: disable\n') self.check('---\n' 'foo:\n', conf) self.check('---\n' 'foo:\n' ' bar:\n', conf) self.check('---\n' '{a:}\n', conf) self.check('---\n' 'foo: {a:}\n', conf) self.check('---\n' '- {a:}\n' '- {a:, b: 2}\n' '- {a: 1, b:}\n' '- {a: 1, b: , }\n', conf) self.check('---\n' '{a: {b: , c: {d: 4, e:}}, f:}\n', conf) def test_in_block_mappings_disabled(self): conf = ('empty-values: {forbid-in-block-mappings: false,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n', conf) self.check('---\n' 'foo:\n' 'bar: aaa\n', conf) def test_in_block_mappings_single_line(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'implicitly-null:\n', conf, problem1=(2, 17)) self.check('---\n' 'implicitly-null:with-colons:in-key:\n', conf, problem1=(2, 36)) self.check('---\n' 'implicitly-null:with-colons:in-key2:\n', conf, problem1=(2, 37)) def test_in_block_mappings_all_lines(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n' 'bar:\n' 'foobar:\n', conf, problem1=(2, 5), problem2=(3, 5), problem3=(4, 8)) def test_in_block_mappings_explicit_end_of_document(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n' '...\n', conf, problem1=(2, 5)) def test_in_block_mappings_not_end_of_document(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n' 'bar:\n' ' aaa\n', conf, problem1=(2, 5)) def test_in_block_mappings_different_level(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n' ' bar:\n' 'aaa: bbb\n', conf, problem1=(3, 6)) def test_in_block_mappings_empty_flow_mapping(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n' 'braces: disable\n' 'commas: disable\n') self.check('---\n' 'foo: {a:}\n', conf) self.check('---\n' '- {a:, b: 2}\n' '- {a: 1, b:}\n' '- {a: 1, b: , }\n', conf) def test_in_block_mappings_empty_block_sequence(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n' ' -\n', conf) def test_in_block_mappings_not_empty_or_explicit_null(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'foo:\n' ' bar:\n' ' aaa\n', conf) self.check('---\n' 'explicitly-null: null\n', conf) self.check('---\n' 'explicitly-null:with-colons:in-key: null\n', conf) self.check('---\n' 'false-null: nulL\n', conf) self.check('---\n' 'empty-string: \'\'\n', conf) self.check('---\n' 'nullable-boolean: false\n', conf) self.check('---\n' 'nullable-int: 0\n', conf) self.check('---\n' 'First occurrence: &anchor Foo\n' 'Second occurrence: *anchor\n', conf) def test_in_block_mappings_various_explicit_null(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n') self.check('---\n' 'null-alias: ~\n', conf) self.check('---\n' 'null-key1: {?: val}\n', conf) self.check('---\n' 'null-key2: {? !!null "": val}\n', conf) def test_in_block_mappings_comments(self): conf = ('empty-values: {forbid-in-block-mappings: true,\n' ' forbid-in-flow-mappings: false}\n' 'comments: disable\n') self.check('---\n' 'empty: # comment\n' 'foo:\n' ' bar: # comment\n', conf, problem1=(2, 7), problem2=(4, 7)) def test_in_flow_mappings_disabled(self): conf = ('empty-values: {forbid-in-block-mappings: false,\n' ' forbid-in-flow-mappings: false}\n' 'braces: disable\n' 'commas: disable\n') self.check('---\n' '{a:}\n', conf) self.check('---\n' 'foo: {a:}\n', conf) self.check('---\n' '- {a:}\n' '- {a:, b: 2}\n' '- {a: 1, b:}\n' '- {a: 1, b: , }\n', conf) self.check('---\n' '{a: {b: , c: {d: 4, e:}}, f:}\n', conf) def test_in_flow_mappings_single_line(self): conf = ('empty-values: {forbid-in-block-mappings: false,\n' ' forbid-in-flow-mappings: true}\n' 'braces: disable\n' 'commas: disable\n') self.check('---\n' '{a:}\n', conf, problem=(2, 4)) self.check('---\n' 'foo: {a:}\n', conf, problem=(2, 9)) self.check('---\n' '- {a:}\n' '- {a:, b: 2}\n' '- {a: 1, b:}\n' '- {a: 1, b: , }\n', conf, problem1=(2, 6), problem2=(3, 6), problem3=(4, 12), problem4=(5, 12)) self.check('---\n' '{a: {b: , c: {d: 4, e:}}, f:}\n', conf, problem1=(2, 8), problem2=(2, 23), problem3=(2, 29)) def test_in_flow_mappings_multi_line(self): conf = ('empty-values: {forbid-in-block-mappings: false,\n' ' forbid-in-flow-mappings: true}\n' 'braces: disable\n' 'commas: disable\n') self.check('---\n' 'foo: {\n' ' a:\n' '}\n', conf, problem=(3, 5)) self.check('---\n' '{\n' ' a: {\n' ' b: ,\n' ' c: {\n' ' d: 4,\n' ' e:\n' ' }\n' ' },\n' ' f:\n' '}\n', conf, problem1=(4, 7), problem2=(7, 9), problem3=(10, 5)) def test_in_flow_mappings_various_explicit_null(self): conf = ('empty-values: {forbid-in-block-mappings: false,\n' ' forbid-in-flow-mappings: true}\n' 'braces: disable\n' 'commas: disable\n') self.check('---\n' '{explicit-null: null}\n', conf) self.check('---\n' '{null-alias: ~}\n', conf) self.check('---\n' 'null-key1: {?: val}\n', conf) self.check('---\n' 'null-key2: {? !!null "": val}\n', conf) def test_in_flow_mappings_comments(self): conf = ('empty-values: {forbid-in-block-mappings: false,\n' ' forbid-in-flow-mappings: true}\n' 'braces: disable\n' 'commas: disable\n' 'comments: disable\n') self.check('---\n' '{\n' ' a: {\n' ' b: , # comment\n' ' c: {\n' ' d: 4, # comment\n' ' e: # comment\n' ' }\n' ' },\n' ' f: # comment\n' '}\n', conf, problem1=(4, 7), problem2=(7, 9), problem3=(10, 5)) yamllint-1.10.0/tests/rules/test_hyphens.py0000644000232200023220000000724713177553503021376 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class HyphenTestCase(RuleTestCase): rule_id = 'hyphens' def test_disabled(self): conf = 'hyphens: disable' self.check('---\n' '- elem1\n' '- elem2\n', conf) self.check('---\n' '- elem1\n' '- elem2\n', conf) self.check('---\n' '- elem1\n' '- elem2\n', conf) self.check('---\n' '- elem1\n' '- elem2\n', conf) self.check('---\n' 'object:\n' ' - elem1\n' ' - elem2\n', conf) self.check('---\n' 'object:\n' ' - elem1\n' ' - elem2\n', conf) self.check('---\n' 'object:\n' ' subobject:\n' ' - elem1\n' ' - elem2\n', conf) self.check('---\n' 'object:\n' ' subobject:\n' ' - elem1\n' ' - elem2\n', conf) def test_enabled(self): conf = 'hyphens: {max-spaces-after: 1}' self.check('---\n' '- elem1\n' '- elem2\n', conf) self.check('---\n' '- elem1\n' '- elem2\n', conf, problem=(3, 3)) self.check('---\n' '- elem1\n' '- elem2\n', conf, problem1=(2, 3), problem2=(3, 3)) self.check('---\n' '- elem1\n' '- elem2\n', conf, problem=(2, 3)) self.check('---\n' 'object:\n' ' - elem1\n' ' - elem2\n', conf, problem=(4, 5)) self.check('---\n' 'object:\n' ' - elem1\n' ' - elem2\n', conf, problem1=(3, 5), problem2=(4, 5)) self.check('---\n' 'object:\n' ' subobject:\n' ' - elem1\n' ' - elem2\n', conf, problem=(5, 7)) self.check('---\n' 'object:\n' ' subobject:\n' ' - elem1\n' ' - elem2\n', conf, problem1=(4, 7), problem2=(5, 7)) def test_max_3(self): conf = 'hyphens: {max-spaces-after: 3}' self.check('---\n' '- elem1\n' '- elem2\n', conf) self.check('---\n' '- elem1\n' '- elem2\n', conf, problem=(2, 5)) self.check('---\n' 'a:\n' ' b:\n' ' - elem1\n' ' - elem2\n', conf) self.check('---\n' 'a:\n' ' b:\n' ' - elem1\n' ' - elem2\n', conf, problem1=(4, 9), problem2=(5, 9)) yamllint-1.10.0/tests/rules/test_truthy.py0000644000232200023220000000466613177553503021261 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Peter Ericson # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class TruthyTestCase(RuleTestCase): rule_id = 'truthy' def test_disabled(self): conf = 'truthy: disable' self.check('---\n' '1: True\n', conf) self.check('---\n' 'True: 1\n', conf) def test_enabled(self): conf = 'truthy: enable\n' self.check('---\n' '1: True\n' 'True: 1\n', conf, problem1=(2, 4), problem2=(3, 1)) self.check('---\n' '1: "True"\n' '"True": 1\n', conf) self.check('---\n' '[\n' ' true, false,\n' ' "false", "FALSE",\n' ' "true", "True",\n' ' True, FALSE,\n' ' on, OFF,\n' ' NO, Yes\n' ']\n', conf, problem1=(6, 3), problem2=(6, 9), problem3=(7, 3), problem4=(7, 7), problem5=(8, 3), problem6=(8, 7)) def test_explicit_types(self): conf = 'truthy: enable\n' self.check('---\n' 'string1: !!str True\n' 'string2: !!str yes\n' 'string3: !!str off\n' 'encoded: !!binary |\n' ' True\n' ' OFF\n' ' pad==\n' # this decodes as 'N\xbb\x9e8Qii' 'boolean1: !!bool true\n' 'boolean2: !!bool "false"\n' 'boolean3: !!bool FALSE\n' 'boolean4: !!bool True\n' 'boolean5: !!bool off\n' 'boolean6: !!bool NO\n', conf) yamllint-1.10.0/tests/rules/test_commas.py0000644000232200023220000002351713177553503021175 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class CommaTestCase(RuleTestCase): rule_id = 'commas' def test_disabled(self): conf = 'commas: disable' self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e , f: [g, h]}\n' 'array: [\n' ' elem ,\n' ' key: val ,\n' ']\n' 'map: {\n' ' key1: val1 ,\n' ' key2: val2,\n' '}\n' '...\n', conf) self.check('---\n' '- [one, two , three,four]\n' '- {five,six , seven, eight}\n' '- [\n' ' nine, ten\n' ' , eleven\n' ' ,twelve\n' ']\n' '- {\n' ' thirteen: 13, fourteen\n' ' , fifteen: 15\n' ' ,sixteen: 16\n' '}\n', conf) def test_before_max(self): conf = ('commas:\n' ' max-spaces-before: 0\n' ' min-spaces-after: 0\n' ' max-spaces-after: -1\n') self.check('---\n' 'array: [1, 2, 3, 4]\n' '...\n', conf) self.check('---\n' 'array: [1, 2 , 3, 4]\n' '...\n', conf, problem=(2, 13)) self.check('---\n' 'array: [1 , 2, 3 , 4]\n' '...\n', conf, problem1=(2, 10), problem2=(2, 23)) self.check('---\n' 'dict: {a: b, c: "1 2 3", d: e, f: [g, h]}\n' '...\n', conf) self.check('---\n' 'dict: {a: b, c: "1 2 3" , d: e, f: [g, h]}\n' '...\n', conf, problem=(2, 24)) self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e, f: [g , h]}\n' '...\n', conf, problem1=(2, 12), problem2=(2, 42)) self.check('---\n' 'array: [\n' ' elem,\n' ' key: val,\n' ']\n', conf) self.check('---\n' 'array: [\n' ' elem ,\n' ' key: val,\n' ']\n', conf, problem=(3, 7)) self.check('---\n' 'map: {\n' ' key1: val1,\n' ' key2: val2,\n' '}\n', conf) self.check('---\n' 'map: {\n' ' key1: val1,\n' ' key2: val2 ,\n' '}\n', conf, problem=(4, 13)) def test_before_max_with_comma_on_new_line(self): conf = ('commas:\n' ' max-spaces-before: 0\n' ' min-spaces-after: 0\n' ' max-spaces-after: -1\n') self.check('---\n' 'flow-seq: [1, 2, 3\n' ' , 4, 5, 6]\n' '...\n', conf, problem=(3, 11)) self.check('---\n' 'flow-map: {a: 1, b: 2\n' ' , c: 3}\n' '...\n', conf, problem=(3, 11)) conf = ('commas:\n' ' max-spaces-before: 0\n' ' min-spaces-after: 0\n' ' max-spaces-after: -1\n' 'indentation: disable\n') self.check('---\n' 'flow-seq: [1, 2, 3\n' ' , 4, 5, 6]\n' '...\n', conf, problem=(3, 9)) self.check('---\n' 'flow-map: {a: 1, b: 2\n' ' , c: 3}\n' '...\n', conf, problem=(3, 9)) self.check('---\n' '[\n' '1,\n' '2\n' ', 3\n' ']\n', conf, problem=(5, 1)) self.check('---\n' '{\n' 'a: 1,\n' 'b: 2\n' ', c: 3\n' '}\n', conf, problem=(5, 1)) def test_before_max_3(self): conf = ('commas:\n' ' max-spaces-before: 3\n' ' min-spaces-after: 0\n' ' max-spaces-after: -1\n') self.check('---\n' 'array: [1 , 2, 3 , 4]\n' '...\n', conf) self.check('---\n' 'array: [1 , 2, 3 , 4]\n' '...\n', conf, problem=(2, 20)) self.check('---\n' 'array: [\n' ' elem1 ,\n' ' elem2 ,\n' ' key: val,\n' ']\n', conf, problem=(4, 11)) def test_after_min(self): conf = ('commas:\n' ' max-spaces-before: -1\n' ' min-spaces-after: 1\n' ' max-spaces-after: -1\n') self.check('---\n' '- [one, two , three,four]\n' '- {five,six , seven, eight}\n' '- [\n' ' nine, ten\n' ' , eleven\n' ' ,twelve\n' ']\n' '- {\n' ' thirteen: 13, fourteen\n' ' , fifteen: 15\n' ' ,sixteen: 16\n' '}\n', conf, problem1=(2, 21), problem2=(3, 9), problem3=(7, 4), problem4=(12, 4)) def test_after_max(self): conf = ('commas:\n' ' max-spaces-before: -1\n' ' min-spaces-after: 0\n' ' max-spaces-after: 1\n') self.check('---\n' 'array: [1, 2, 3, 4]\n' '...\n', conf) self.check('---\n' 'array: [1, 2, 3, 4]\n' '...\n', conf, problem=(2, 15)) self.check('---\n' 'array: [1, 2, 3, 4]\n' '...\n', conf, problem1=(2, 12), problem2=(2, 22)) self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n' '...\n', conf) self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n' '...\n', conf, problem=(2, 27)) self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n' '...\n', conf, problem1=(2, 15), problem2=(2, 44)) self.check('---\n' 'array: [\n' ' elem,\n' ' key: val,\n' ']\n', conf) self.check('---\n' 'array: [\n' ' elem, key: val,\n' ']\n', conf, problem=(3, 9)) self.check('---\n' 'map: {\n' ' key1: val1, key2: [val2, val3]\n' '}\n', conf, problem1=(3, 16), problem2=(3, 30)) def test_after_max_3(self): conf = ('commas:\n' ' max-spaces-before: -1\n' ' min-spaces-after: 1\n' ' max-spaces-after: 3\n') self.check('---\n' 'array: [1, 2, 3, 4]\n' '...\n', conf) self.check('---\n' 'array: [1, 2, 3, 4]\n' '...\n', conf, problem=(2, 21)) self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n' '...\n', conf, problem1=(2, 31), problem2=(2, 49)) def test_both_before_and_after(self): conf = ('commas:\n' ' max-spaces-before: 0\n' ' min-spaces-after: 1\n' ' max-spaces-after: 1\n') self.check('---\n' 'dict: {a: b , c: "1 2 3", d: e , f: [g, h]}\n' 'array: [\n' ' elem ,\n' ' key: val ,\n' ']\n' 'map: {\n' ' key1: val1 ,\n' ' key2: val2,\n' '}\n' '...\n', conf, problem1=(2, 12), problem2=(2, 16), problem3=(2, 31), problem4=(2, 36), problem5=(2, 50), problem6=(4, 8), problem7=(5, 11), problem8=(8, 13)) conf = ('commas:\n' ' max-spaces-before: 0\n' ' min-spaces-after: 1\n' ' max-spaces-after: 1\n' 'indentation: disable\n') self.check('---\n' '- [one, two , three,four]\n' '- {five,six , seven, eight}\n' '- [\n' ' nine, ten\n' ' , eleven\n' ' ,twelve\n' ']\n' '- {\n' ' thirteen: 13, fourteen\n' ' , fifteen: 15\n' ' ,sixteen: 16\n' '}\n', conf, problem1=(2, 12), problem2=(2, 21), problem3=(3, 9), problem4=(3, 12), problem5=(5, 9), problem6=(6, 2), problem7=(7, 2), problem8=(7, 4), problem9=(10, 17), problem10=(11, 2), problem11=(12, 2), problem12=(12, 4)) yamllint-1.10.0/tests/rules/test_key_duplicates.py0000644000232200023220000001326313177553503022720 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class KeyDuplicatesTestCase(RuleTestCase): rule_id = 'key-duplicates' def test_disabled(self): conf = 'key-duplicates: disable' self.check('---\n' 'block mapping:\n' ' key: a\n' ' otherkey: b\n' ' key: c\n', conf) self.check('---\n' 'flow mapping:\n' ' {key: a, otherkey: b, key: c}\n', conf) self.check('---\n' 'duplicated twice:\n' ' - k: a\n' ' ok: b\n' ' k: c\n' ' k: d\n', conf) self.check('---\n' 'duplicated twice:\n' ' - {k: a, ok: b, k: c, k: d}\n', conf) self.check('---\n' 'multiple duplicates:\n' ' a: 1\n' ' b: 2\n' ' c: 3\n' ' d: 4\n' ' d: 5\n' ' b: 6\n', conf) self.check('---\n' 'multiple duplicates:\n' ' {a: 1, b: 2, c: 3, d: 4, d: 5, b: 6}\n', conf) self.check('---\n' 'at: root\n' 'multiple: times\n' 'at: root\n', conf) self.check('---\n' 'nested but OK:\n' ' a: {a: {a: 1}}\n' ' b:\n' ' b: 2\n' ' c: 3\n', conf) self.check('---\n' 'nested duplicates:\n' ' a: {a: 1, a: 1}\n' ' b:\n' ' c: 3\n' ' d: 4\n' ' d: 4\n' ' b: 2\n', conf) self.check('---\n' 'duplicates with many styles: 1\n' '"duplicates with many styles": 1\n' '\'duplicates with many styles\': 1\n' '? duplicates with many styles\n' ': 1\n' '? >-\n' ' duplicates with\n' ' many styles\n' ': 1\n', conf) def test_enabled(self): conf = 'key-duplicates: enable' self.check('---\n' 'block mapping:\n' ' key: a\n' ' otherkey: b\n' ' key: c\n', conf, problem=(5, 3)) self.check('---\n' 'flow mapping:\n' ' {key: a, otherkey: b, key: c}\n', conf, problem=(3, 25)) self.check('---\n' 'duplicated twice:\n' ' - k: a\n' ' ok: b\n' ' k: c\n' ' k: d\n', conf, problem1=(5, 5), problem2=(6, 5)) self.check('---\n' 'duplicated twice:\n' ' - {k: a, ok: b, k: c, k: d}\n', conf, problem1=(3, 19), problem2=(3, 25)) self.check('---\n' 'multiple duplicates:\n' ' a: 1\n' ' b: 2\n' ' c: 3\n' ' d: 4\n' ' d: 5\n' ' b: 6\n', conf, problem1=(7, 3), problem2=(8, 3)) self.check('---\n' 'multiple duplicates:\n' ' {a: 1, b: 2, c: 3, d: 4, d: 5, b: 6}\n', conf, problem1=(3, 28), problem2=(3, 34)) self.check('---\n' 'at: root\n' 'multiple: times\n' 'at: root\n', conf, problem=(4, 1)) self.check('---\n' 'nested but OK:\n' ' a: {a: {a: 1}}\n' ' b:\n' ' b: 2\n' ' c: 3\n', conf) self.check('---\n' 'nested duplicates:\n' ' a: {a: 1, a: 1}\n' ' b:\n' ' c: 3\n' ' d: 4\n' ' d: 4\n' ' b: 2\n', conf, problem1=(3, 13), problem2=(7, 5), problem3=(8, 3)) self.check('---\n' 'duplicates with many styles: 1\n' '"duplicates with many styles": 1\n' '\'duplicates with many styles\': 1\n' '? duplicates with many styles\n' ': 1\n' '? >-\n' ' duplicates with\n' ' many styles\n' ': 1\n', conf, problem1=(3, 1), problem2=(4, 1), problem3=(5, 3), problem4=(7, 3)) def test_key_tokens_in_flow_sequences(self): conf = 'key-duplicates: enable' self.check('---\n' '[\n' ' flow: sequence, with, key: value, mappings\n' ']\n', conf) yamllint-1.10.0/tests/rules/test_document_start.py0000644000232200023220000000672213177553503022750 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class DocumentStartTestCase(RuleTestCase): rule_id = 'document-start' def test_disabled(self): conf = 'document-start: disable' self.check('', conf) self.check('key: val\n', conf) self.check('---\n' 'key: val\n', conf) def test_required(self): conf = ('document-start: {present: true}\n' 'empty-lines: disable\n') self.check('', conf) self.check('\n', conf) self.check('key: val\n', conf, problem=(1, 1)) self.check('\n' '\n' 'key: val\n', conf, problem=(3, 1)) self.check('---\n' 'key: val\n', conf) self.check('\n' '\n' '---\n' 'key: val\n', conf) def test_forbidden(self): conf = ('document-start: {present: false}\n' 'empty-lines: disable\n') self.check('', conf) self.check('key: val\n', conf) self.check('\n' '\n' 'key: val\n', conf) self.check('---\n' 'key: val\n', conf, problem=(1, 1)) self.check('\n' '\n' '---\n' 'key: val\n', conf, problem=(3, 1)) self.check('first: document\n' '---\n' 'key: val\n', conf, problem=(2, 1)) def test_multiple_documents(self): conf = 'document-start: {present: true}' self.check('---\n' 'first: document\n' '...\n' '---\n' 'second: document\n' '...\n' '---\n' 'third: document\n', conf) self.check('---\n' 'first: document\n' '---\n' 'second: document\n' '---\n' 'third: document\n', conf) self.check('---\n' 'first: document\n' '...\n' 'second: document\n' '---\n' 'third: document\n', conf, problem=(4, 1, 'syntax')) def test_directives(self): conf = 'document-start: {present: true}' self.check('%YAML 1.2\n' '---\n' 'doc: ument\n' '...\n', conf) self.check('%YAML 1.2\n' '%TAG ! tag:clarkevans.com,2002:\n' '---\n' 'doc: ument\n' '...\n', conf) self.check('---\n' 'doc: 1\n' '...\n' '%YAML 1.2\n' '---\n' 'doc: 2\n' '...\n', conf) yamllint-1.10.0/tests/rules/test_key_ordering.py0000644000232200023220000000755313177553503022401 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2017 Johannes F. Knauf # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class KeyOrderingTestCase(RuleTestCase): rule_id = 'key-ordering' def test_disabled(self): conf = 'key-ordering: disable' self.check('---\n' 'block mapping:\n' ' secondkey: a\n' ' firstkey: b\n', conf) self.check('---\n' 'flow mapping:\n' ' {secondkey: a, firstkey: b}\n', conf) self.check('---\n' 'second: before_first\n' 'at: root\n', conf) self.check('---\n' 'nested but OK:\n' ' second: {first: 1}\n' ' third:\n' ' second: 2\n', conf) def test_enabled(self): conf = 'key-ordering: enable' self.check('---\n' 'block mapping:\n' ' secondkey: a\n' ' firstkey: b\n', conf, problem=(4, 3)) self.check('---\n' 'flow mapping:\n' ' {secondkey: a, firstkey: b}\n', conf, problem=(3, 18)) self.check('---\n' 'second: before_first\n' 'at: root\n', conf, problem=(3, 1)) self.check('---\n' 'nested but OK:\n' ' second: {first: 1}\n' ' third:\n' ' second: 2\n', conf) def test_word_length(self): conf = 'key-ordering: enable' self.check('---\n' 'a: 1\n' 'ab: 1\n' 'abc: 1\n', conf) self.check('---\n' 'a: 1\n' 'abc: 1\n' 'ab: 1\n', conf, problem=(4, 1)) def test_key_duplicates(self): conf = ('key-duplicates: disable\n' 'key-ordering: enable') self.check('---\n' 'key: 1\n' 'key: 2\n', conf) def test_case(self): conf = 'key-ordering: enable' self.check('---\n' 'T-shirt: 1\n' 'T-shirts: 2\n' 't-shirt: 3\n' 't-shirts: 4\n', conf) self.check('---\n' 'T-shirt: 1\n' 't-shirt: 2\n' 'T-shirts: 3\n' 't-shirts: 4\n', conf, problem=(4, 1)) def test_accents(self): conf = 'key-ordering: enable' self.check('---\n' 'hair: true\n' 'hais: true\n' 'haïr: true\n' 'haïssable: true\n', conf) self.check('---\n' 'haïr: true\n' 'hais: true\n', conf, 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): conf = 'key-ordering: enable' self.check('---\n' '[\n' ' key: value, mappings, in, flow: sequence\n' ']\n', conf) yamllint-1.10.0/tests/rules/test_new_lines.py0000644000232200023220000000323513177553503021674 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class NewLinesTestCase(RuleTestCase): rule_id = 'new-lines' def test_disabled(self): conf = ('new-line-at-end-of-file: disable\n' 'new-lines: disable\n') self.check('', conf) self.check('\n', conf) self.check('\r', conf) self.check('\r\n', conf) self.check('---\ntext\n', conf) self.check('---\r\ntext\r\n', conf) def test_unix_type(self): conf = 'new-lines: {type: unix}' self.check('', conf) self.check('\n', conf) self.check('\r\n', conf, problem=(1, 1)) self.check('---\ntext\n', conf) self.check('---\r\ntext\r\n', conf, problem=(1, 4)) def test_dos_type(self): conf = 'new-lines: {type: dos}\n' self.check('', conf) self.check('\n', conf, problem=(1, 1)) self.check('\r\n', conf) self.check('---\ntext\n', conf, problem=(1, 4)) self.check('---\r\ntext\r\n', conf) yamllint-1.10.0/tests/rules/test_empty_lines.py0000644000232200023220000000646313177553503022247 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class EmptyLinesTestCase(RuleTestCase): rule_id = 'empty-lines' def test_disabled(self): conf = ('empty-lines: disable\n' 'new-line-at-end-of-file: disable\n' 'document-start: disable\n') self.check('', conf) self.check('\n', conf) self.check('\n\n', conf) self.check('\n\n\n\n\n\n\n\n\n', conf) self.check('some text\n\n\n\n\n\n\n\n\n', conf) self.check('\n\n\n\n\n\n\n\n\nsome text', conf) self.check('\n\n\nsome text\n\n\n', conf) def test_empty_document(self): conf = ('empty-lines: {max: 0, max-start: 0, max-end: 0}\n' 'new-line-at-end-of-file: disable\n' 'document-start: disable\n') self.check('', conf) self.check('\n', conf) def test_0_empty_lines(self): conf = ('empty-lines: {max: 0, max-start: 0, max-end: 0}\n' 'new-line-at-end-of-file: disable\n') self.check('---\n', conf) self.check('---\ntext\n\ntext', conf, problem=(3, 1)) self.check('---\ntext\n\ntext\n', conf, problem=(3, 1)) def test_10_empty_lines(self): conf = 'empty-lines: {max: 10, max-start: 0, max-end: 0}' self.check('---\nintro\n\n\n\n\n\n\n\n\n\n\nconclusion\n', conf) self.check('---\nintro\n\n\n\n\n\n\n\n\n\n\n\nconclusion\n', conf, problem=(13, 1)) def test_spaces(self): conf = ('empty-lines: {max: 1, max-start: 0, max-end: 0}\n' 'trailing-spaces: disable\n') self.check('---\nintro\n\n \n\nconclusion\n', conf) self.check('---\nintro\n\n \n\n\nconclusion\n', conf, problem=(6, 1)) def test_empty_lines_at_start(self): conf = ('empty-lines: {max: 2, max-start: 4, max-end: 0}\n' 'document-start: disable\n') self.check('\n\n\n\nnon empty\n', conf) self.check('\n\n\n\n\nnon empty\n', conf, problem=(5, 1)) conf = ('empty-lines: {max: 2, max-start: 0, max-end: 0}\n' 'document-start: disable\n') self.check('non empty\n', conf) self.check('\nnon empty\n', conf, problem=(1, 1)) def test_empty_lines_at_end(self): conf = ('empty-lines: {max: 2, max-start: 0, max-end: 4}\n' 'document-start: disable\n') self.check('non empty\n\n\n\n\n', conf) self.check('non empty\n\n\n\n\n\n', conf, problem=(6, 1)) conf = ('empty-lines: {max: 2, max-start: 0, max-end: 0}\n' 'document-start: disable\n') self.check('non empty\n', conf) self.check('non empty\n\n', conf, problem=(2, 1)) yamllint-1.10.0/tests/rules/test_common.py0000644000232200023220000000315513177553503021202 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import unittest import yaml from yamllint.rules.common import get_line_indent class CommonTestCase(unittest.TestCase): def test_get_line_indent(self): tokens = list(yaml.scan('a: 1\n' 'b:\n' ' - c: [2, 3, {d: 4}]\n')) self.assertEqual(tokens[3].value, 'a') self.assertEqual(tokens[5].value, '1') self.assertEqual(tokens[7].value, 'b') self.assertEqual(tokens[13].value, 'c') self.assertEqual(tokens[16].value, '2') self.assertEqual(tokens[18].value, '3') self.assertEqual(tokens[22].value, 'd') self.assertEqual(tokens[24].value, '4') for i in (3, 5): self.assertEqual(get_line_indent(tokens[i]), 0) for i in (7,): self.assertEqual(get_line_indent(tokens[i]), 0) for i in (13, 16, 18, 22, 24): self.assertEqual(get_line_indent(tokens[i]), 2) yamllint-1.10.0/tests/rules/test_colons.py0000644000232200023220000002210213177553503021200 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class ColonTestCase(RuleTestCase): rule_id = 'colons' def test_disabled(self): conf = 'colons: disable' self.check('---\n' 'object:\n' ' k1 : v1\n' 'obj2:\n' ' k2 :\n' ' - 8\n' ' k3:\n' ' val\n' ' property : value\n' ' prop2 : val2\n' ' propriété : [valeur]\n' ' o:\n' ' k1: [v1, v2]\n' ' p:\n' ' - k3: >\n' ' val\n' ' - o: {k1: v1}\n' ' - p: kdjf\n' ' - q: val0\n' ' - q2:\n' ' - val1\n' '...\n', conf) self.check('---\n' 'object:\n' ' k1: v1\n' 'obj2:\n' ' k2:\n' ' - 8\n' ' k3:\n' ' val\n' ' property: value\n' ' prop2: val2\n' ' propriété: [valeur]\n' ' o:\n' ' k1: [v1, v2]\n', conf) self.check('---\n' 'obj:\n' ' p:\n' ' - k1: >\n' ' val\n' ' - k3: >\n' ' val\n' ' - o: {k1: v1}\n' ' - o: {k1: v1}\n' ' - q2:\n' ' - val1\n' '...\n', conf) self.check('---\n' 'a: {b: {c: d, e : f}}\n', conf) def test_before_enabled(self): conf = 'colons: {max-spaces-before: 0, max-spaces-after: -1}' self.check('---\n' 'object:\n' ' k1:\n' ' - a\n' ' - b\n' ' k2: v2\n' '...\n', conf) self.check('---\n' 'object:\n' ' k1 :\n' ' - a\n' ' - b\n' ' k2: v2\n' '...\n', conf, problem=(3, 5)) self.check('---\n' 'lib :\n' ' - var\n' '...\n', conf, problem=(2, 4)) self.check('---\n' '- lib :\n' ' - var\n' '...\n', conf, problem=(2, 6)) self.check('---\n' 'a: {b: {c : d, e : f}}\n', conf, problem1=(2, 10), problem2=(2, 17)) def test_before_max(self): conf = 'colons: {max-spaces-before: 3, max-spaces-after: -1}' self.check('---\n' 'object :\n' ' k1 :\n' ' - a\n' ' - b\n' ' k2 : v2\n' '...\n', conf) self.check('---\n' 'object :\n' ' k1 :\n' ' - a\n' ' - b\n' ' k2 : v2\n' '...\n', conf, problem=(3, 8)) def test_before_with_explicit_block_mappings(self): conf = 'colons: {max-spaces-before: 0, max-spaces-after: 1}' self.check('---\n' 'object:\n' ' ? key\n' ' : value\n' '...\n', conf) self.check('---\n' 'object :\n' ' ? key\n' ' : value\n' '...\n', conf, problem=(2, 7)) self.check('---\n' '? >\n' ' multi-line\n' ' key\n' ': >\n' ' multi-line\n' ' value\n' '...\n', conf) self.check('---\n' '- ? >\n' ' multi-line\n' ' key\n' ' : >\n' ' multi-line\n' ' value\n' '...\n', conf) self.check('---\n' '- ? >\n' ' multi-line\n' ' key\n' ' : >\n' ' multi-line\n' ' value\n' '...\n', conf, problem=(5, 5)) def test_after_enabled(self): conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}' self.check('---\n' 'key: value\n', conf) self.check('---\n' 'key: value\n', conf, problem=(2, 6)) self.check('---\n' 'object:\n' ' k1: [a, b]\n' ' k2: string\n', conf, problem=(3, 7)) self.check('---\n' 'object:\n' ' k1: [a, b]\n' ' k2: string\n', conf, problem=(4, 7)) self.check('---\n' 'object:\n' ' other: {key: value}\n' '...\n', conf, problem=(3, 16)) self.check('---\n' 'a: {b: {c: d, e : f}}\n', conf, problem1=(2, 12), problem2=(2, 20)) def test_after_enabled_question_mark(self): conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}' self.check('---\n' '? key\n' ': value\n', conf) self.check('---\n' '? key\n' ': value\n', conf, problem=(2, 3)) self.check('---\n' '? key\n' ': value\n', conf, problem1=(2, 3), problem2=(3, 3)) self.check('---\n' '- ? key\n' ' : value\n', conf, problem1=(2, 5), problem2=(3, 5)) def test_after_max(self): conf = 'colons: {max-spaces-before: -1, max-spaces-after: 3}' self.check('---\n' 'object:\n' ' k1: [a, b]\n', conf) self.check('---\n' 'object:\n' ' k1: [a, b]\n', conf, problem=(3, 9)) self.check('---\n' 'object:\n' ' k2: string\n', conf) self.check('---\n' 'object:\n' ' k2: string\n', conf, problem=(3, 9)) self.check('---\n' 'object:\n' ' other: {key: value}\n' '...\n', conf) self.check('---\n' 'object:\n' ' other: {key: value}\n' '...\n', conf, problem=(3, 18)) def test_after_with_explicit_block_mappings(self): conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}' self.check('---\n' 'object:\n' ' ? key\n' ' : value\n' '...\n', conf) self.check('---\n' 'object:\n' ' ? key\n' ' : value\n' '...\n', conf, problem=(4, 5)) def test_after_do_not_confound_with_trailing_space(self): conf = ('colons: {max-spaces-before: 1, max-spaces-after: 1}\n' 'trailing-spaces: disable\n') self.check('---\n' 'trailing: \n' ' - spaces\n', conf) def test_both_before_and_after(self): conf = 'colons: {max-spaces-before: 0, max-spaces-after: 1}' self.check('---\n' 'obj:\n' ' string: text\n' ' k:\n' ' - 8\n' ' k3:\n' ' val\n' ' property: [value]\n', conf) self.check('---\n' 'object:\n' ' k1 : v1\n', conf, problem1=(3, 5), problem2=(3, 8)) self.check('---\n' 'obj:\n' ' string: text\n' ' k :\n' ' - 8\n' ' k3:\n' ' val\n' ' property: {a: 1, b: 2, c : 3}\n', conf, problem1=(3, 11), problem2=(4, 4), problem3=(8, 23), problem4=(8, 28)) yamllint-1.10.0/tests/rules/test_comments_indentation.py0000644000232200023220000001237413177553503024136 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tests.common import RuleTestCase class CommentsIndentationTestCase(RuleTestCase): rule_id = 'comments-indentation' def test_disable(self): conf = 'comments-indentation: disable' self.check('---\n' ' # line 1\n' '# line 2\n' ' # line 3\n' ' # line 4\n' '\n' 'obj:\n' ' # these\n' ' # are\n' ' # [good]\n' '# bad\n' ' # comments\n' ' a: b\n' '\n' 'obj1:\n' ' a: 1\n' ' # comments\n' '\n' 'obj2:\n' ' b: 2\n' '\n' '# empty\n' '#\n' '# comment\n' '...\n', conf) def test_enabled(self): conf = 'comments-indentation: enable' self.check('---\n' '# line 1\n' '# line 2\n', conf) self.check('---\n' ' # line 1\n' '# line 2\n', conf, problem=(2, 2)) self.check('---\n' ' # line 1\n' ' # line 2\n', conf, problem1=(2, 3)) self.check('---\n' 'obj:\n' ' # normal\n' ' a: b\n', conf) self.check('---\n' 'obj:\n' ' # bad\n' ' a: b\n', conf, problem=(3, 2)) self.check('---\n' 'obj:\n' '# bad\n' ' a: b\n', conf, problem=(3, 1)) self.check('---\n' 'obj:\n' ' # bad\n' ' a: b\n', conf, problem=(3, 4)) self.check('---\n' 'obj:\n' ' # these\n' ' # are\n' ' # [good]\n' '# bad\n' ' # comments\n' ' a: b\n', conf, problem1=(3, 2), problem2=(4, 4), problem3=(6, 1), problem4=(7, 7)) self.check('---\n' 'obj1:\n' ' a: 1\n' ' # the following line is disabled\n' ' # b: 2\n', conf) self.check('---\n' 'obj1:\n' ' a: 1\n' ' # b: 2\n' '\n' 'obj2:\n' ' b: 2\n', conf) self.check('---\n' 'obj1:\n' ' a: 1\n' ' # b: 2\n' '# this object is useless\n' 'obj2: "no"\n', conf) self.check('---\n' 'obj1:\n' ' a: 1\n' '# this object is useless\n' ' # b: 2\n' 'obj2: "no"\n', conf, problem=(5, 3)) self.check('---\n' 'obj1:\n' ' a: 1\n' ' # comments\n' ' b: 2\n', conf) self.check('---\n' 'my list for today:\n' ' - todo 1\n' ' - todo 2\n' ' # commented for now\n' ' # - todo 3\n' '...\n', conf) def test_first_line(self): conf = 'comments-indentation: enable' self.check('# comment\n', conf) self.check(' # comment\n', conf, problem=(1, 3)) def test_no_newline_at_end(self): conf = ('comments-indentation: enable\n' 'new-line-at-end-of-file: disable\n') self.check('# comment', conf) self.check(' # comment', conf, problem=(1, 3)) def test_empty_comment(self): conf = 'comments-indentation: enable' self.check('---\n' '# hey\n' '# normal\n' '#\n', conf) self.check('---\n' '# hey\n' '# normal\n' ' #\n', conf, problem=(4, 2)) def test_inline_comment(self): conf = 'comments-indentation: enable' self.check('---\n' '- a # inline\n' '# ok\n', conf) self.check('---\n' '- a # inline\n' ' # not ok\n', conf, problem=(3, 2)) self.check('---\n' ' # not ok\n' '- a # inline\n', conf, problem=(2, 2)) yamllint-1.10.0/tests/test_config.py0000644000232200023220000004027713177553503020033 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . try: from cStringIO import StringIO except ImportError: from io import StringIO import os import shutil import sys try: assert sys.version_info >= (2, 7) import unittest except AssertionError: import unittest2 as unittest from yamllint import cli from yamllint import config from tests.common import build_temp_workspace class SimpleConfigTestCase(unittest.TestCase): def test_parse_config(self): new = config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 0\n' ' max-spaces-after: 1\n') self.assertEqual(list(new.rules.keys()), ['colons']) self.assertEqual(new.rules['colons']['max-spaces-before'], 0) self.assertEqual(new.rules['colons']['max-spaces-after'], 1) self.assertEqual(len(new.enabled_rules(None)), 1) def test_invalid_conf(self): with self.assertRaises(config.YamlLintConfigError): config.YamlLintConfig('not: valid: yaml') def test_unknown_rule(self): with self.assertRaisesRegexp( config.YamlLintConfigError, 'invalid config: no such rule: "this-one-does-not-exist"'): config.YamlLintConfig('rules:\n' ' this-one-does-not-exist: enable\n') def test_missing_option(self): with self.assertRaisesRegexp( config.YamlLintConfigError, 'invalid config: missing option "max-spaces-before" ' 'for rule "colons"'): config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-after: 1\n') def test_unknown_option(self): with self.assertRaisesRegexp( config.YamlLintConfigError, 'invalid config: unknown option "abcdef" for rule "colons"'): config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 0\n' ' max-spaces-after: 1\n' ' abcdef: yes\n') def test_yes_no_for_booleans(self): c = config.YamlLintConfig('rules:\n' ' indentation:\n' ' spaces: 2\n' ' indent-sequences: true\n' ' check-multi-line-strings: false\n') self.assertEqual(c.rules['indentation']['indent-sequences'], True) self.assertEqual(c.rules['indentation']['check-multi-line-strings'], False) c = config.YamlLintConfig('rules:\n' ' indentation:\n' ' spaces: 2\n' ' indent-sequences: yes\n' ' check-multi-line-strings: false\n') self.assertEqual(c.rules['indentation']['indent-sequences'], True) self.assertEqual(c.rules['indentation']['check-multi-line-strings'], False) c = config.YamlLintConfig('rules:\n' ' indentation:\n' ' spaces: 2\n' ' indent-sequences: whatever\n' ' check-multi-line-strings: false\n') self.assertEqual(c.rules['indentation']['indent-sequences'], 'whatever') self.assertEqual(c.rules['indentation']['check-multi-line-strings'], False) with self.assertRaisesRegexp( config.YamlLintConfigError, 'invalid config: option "indent-sequences" of "indentation" ' 'should be in '): c = config.YamlLintConfig('rules:\n' ' indentation:\n' ' spaces: 2\n' ' indent-sequences: YES!\n' ' check-multi-line-strings: false\n') def test_validate_rule_conf(self): class Rule(object): ID = 'fake' self.assertEqual(config.validate_rule_conf(Rule, False), False) self.assertEqual(config.validate_rule_conf(Rule, 'disable'), False) self.assertEqual(config.validate_rule_conf(Rule, {}), {'level': 'error'}) self.assertEqual(config.validate_rule_conf(Rule, 'enable'), {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'warning'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'level': 'warn'}) Rule.CONF = {'length': int} config.validate_rule_conf(Rule, {'length': 8}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'height': 8}) Rule.CONF = {'a': bool, 'b': int} config.validate_rule_conf(Rule, {'a': True, 'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'a': True}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'a': 1, 'b': 0}) Rule.CONF = {'choice': (True, 88, 'str')} config.validate_rule_conf(Rule, {'choice': True}) config.validate_rule_conf(Rule, {'choice': 88}) config.validate_rule_conf(Rule, {'choice': 'str'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 99}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'}) Rule.CONF = {'choice': (int, 'hardcoded')} config.validate_rule_conf(Rule, {'choice': 42}) config.validate_rule_conf(Rule, {'choice': 'hardcoded'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'}) class ExtendedConfigTestCase(unittest.TestCase): def test_extend_add_rule(self): old = config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 0\n' ' max-spaces-after: 1\n') new = config.YamlLintConfig('rules:\n' ' hyphens:\n' ' max-spaces-after: 2\n') new.extend(old) self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens']) self.assertEqual(new.rules['colons']['max-spaces-before'], 0) self.assertEqual(new.rules['colons']['max-spaces-after'], 1) self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2) self.assertEqual(len(new.enabled_rules(None)), 2) def test_extend_remove_rule(self): old = config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 0\n' ' max-spaces-after: 1\n' ' hyphens:\n' ' max-spaces-after: 2\n') new = config.YamlLintConfig('rules:\n' ' colons: disable\n') new.extend(old) self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens']) self.assertEqual(new.rules['colons'], False) self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2) self.assertEqual(len(new.enabled_rules(None)), 1) def test_extend_edit_rule(self): old = config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 0\n' ' max-spaces-after: 1\n' ' hyphens:\n' ' max-spaces-after: 2\n') new = config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 3\n' ' max-spaces-after: 4\n') new.extend(old) self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens']) self.assertEqual(new.rules['colons']['max-spaces-before'], 3) self.assertEqual(new.rules['colons']['max-spaces-after'], 4) self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2) self.assertEqual(len(new.enabled_rules(None)), 2) def test_extend_reenable_rule(self): old = config.YamlLintConfig('rules:\n' ' colons:\n' ' max-spaces-before: 0\n' ' max-spaces-after: 1\n' ' hyphens: disable\n') new = config.YamlLintConfig('rules:\n' ' hyphens:\n' ' max-spaces-after: 2\n') new.extend(old) self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens']) self.assertEqual(new.rules['colons']['max-spaces-before'], 0) self.assertEqual(new.rules['colons']['max-spaces-after'], 1) self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2) self.assertEqual(len(new.enabled_rules(None)), 2) class ExtendedLibraryConfigTestCase(unittest.TestCase): def test_extend_config_disable_rule(self): old = config.YamlLintConfig('extends: default') new = config.YamlLintConfig('extends: default\n' 'rules:\n' ' trailing-spaces: disable\n') old.rules['trailing-spaces'] = False self.assertEqual(sorted(new.rules.keys()), sorted(old.rules.keys())) for rule in new.rules: self.assertEqual(new.rules[rule], old.rules[rule]) def test_extend_config_override_whole_rule(self): old = config.YamlLintConfig('extends: default') new = config.YamlLintConfig('extends: default\n' 'rules:\n' ' empty-lines:\n' ' max: 42\n' ' max-start: 43\n' ' max-end: 44\n') old.rules['empty-lines']['max'] = 42 old.rules['empty-lines']['max-start'] = 43 old.rules['empty-lines']['max-end'] = 44 self.assertEqual(sorted(new.rules.keys()), sorted(old.rules.keys())) for rule in new.rules: self.assertEqual(new.rules[rule], old.rules[rule]) def test_extend_config_override_rule_partly(self): old = config.YamlLintConfig('extends: default') new = config.YamlLintConfig('extends: default\n' 'rules:\n' ' empty-lines:\n' ' max-start: 42\n') old.rules['empty-lines']['max-start'] = 42 self.assertEqual(sorted(new.rules.keys()), sorted(old.rules.keys())) for rule in new.rules: self.assertEqual(new.rules[rule], old.rules[rule]) class IgnorePathConfigTestCase(unittest.TestCase): @classmethod def setUpClass(cls): super(IgnorePathConfigTestCase, cls).setUpClass() bad_yaml = ('---\n' '- key: val1\n' ' key: val2\n' '- trailing space \n' '- lonely hyphen\n') cls.wd = build_temp_workspace({ 'bin/file.lint-me-anyway.yaml': bad_yaml, 'bin/file.yaml': bad_yaml, 'file-at-root.yaml': bad_yaml, 'file.dont-lint-me.yaml': bad_yaml, 'ign-dup/file.yaml': bad_yaml, 'ign-dup/sub/dir/file.yaml': bad_yaml, 'ign-trail/file.yaml': bad_yaml, 'include/ign-dup/sub/dir/file.yaml': bad_yaml, 's/s/ign-trail/file.yaml': bad_yaml, 's/s/ign-trail/s/s/file.yaml': bad_yaml, 's/s/ign-trail/s/s/file2.lint-me-anyway.yaml': bad_yaml, '.yamllint': 'ignore: |\n' ' *.dont-lint-me.yaml\n' ' /bin/\n' ' !/bin/*.lint-me-anyway.yaml\n' '\n' 'extends: default\n' '\n' 'rules:\n' ' key-duplicates:\n' ' ignore: |\n' ' /ign-dup\n' ' trailing-spaces:\n' ' ignore: |\n' ' ign-trail\n' ' !*.lint-me-anyway.yaml\n', }) cls.backup_wd = os.getcwd() os.chdir(cls.wd) @classmethod def tearDownClass(cls): super(IgnorePathConfigTestCase, cls).tearDownClass() os.chdir(cls.backup_wd) shutil.rmtree(cls.wd) @unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported') def test_run_with_ignored_path(self): sys.stdout = StringIO() with self.assertRaises(SystemExit): cli.run(('-f', 'parsable', '.')) out = sys.stdout.getvalue() out = '\n'.join(sorted(out.splitlines())) keydup = '[error] duplication of key "key" in mapping (key-duplicates)' trailing = '[error] trailing spaces (trailing-spaces)' hyphen = '[error] too many spaces after hyphen (hyphens)' self.assertEqual(out, '\n'.join(( './bin/file.lint-me-anyway.yaml:3:3: ' + keydup, './bin/file.lint-me-anyway.yaml:4:17: ' + trailing, './bin/file.lint-me-anyway.yaml:5:5: ' + hyphen, './file-at-root.yaml:3:3: ' + keydup, './file-at-root.yaml:4:17: ' + trailing, './file-at-root.yaml:5:5: ' + hyphen, './ign-dup/file.yaml:4:17: ' + trailing, './ign-dup/file.yaml:5:5: ' + hyphen, './ign-dup/sub/dir/file.yaml:4:17: ' + trailing, './ign-dup/sub/dir/file.yaml:5:5: ' + hyphen, './ign-trail/file.yaml:3:3: ' + keydup, './ign-trail/file.yaml:5:5: ' + hyphen, './include/ign-dup/sub/dir/file.yaml:3:3: ' + keydup, './include/ign-dup/sub/dir/file.yaml:4:17: ' + trailing, './include/ign-dup/sub/dir/file.yaml:5:5: ' + hyphen, './s/s/ign-trail/file.yaml:3:3: ' + keydup, './s/s/ign-trail/file.yaml:5:5: ' + hyphen, './s/s/ign-trail/s/s/file.yaml:3:3: ' + keydup, './s/s/ign-trail/s/s/file.yaml:5:5: ' + hyphen, './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:3:3: ' + keydup, './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:4:17: ' + trailing, './s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:5:5: ' + hyphen, ))) yamllint-1.10.0/docs/0000755000232200023220000000000013177553503014731 5ustar debalancedebalanceyamllint-1.10.0/docs/rules.rst0000644000232200023220000000331613177553503016620 0ustar debalancedebalanceRules ===== When linting a document with yamllint, a series of rules (such as ``line-length``, ``trailing-spaces``, etc.) are checked against. A :doc:`configuration file ` can be used to enable or disable these rules, to set their level (*error* or *warning*), but also to tweak their options. This page describes the rules and their options. .. contents:: List of rules :local: :depth: 1 braces ------ .. automodule:: yamllint.rules.braces brackets -------- .. automodule:: yamllint.rules.brackets colons ------ .. automodule:: yamllint.rules.colons commas ------ .. automodule:: yamllint.rules.commas comments -------- .. automodule:: yamllint.rules.comments comments-indentation -------------------- .. automodule:: yamllint.rules.comments_indentation document-end ------------ .. automodule:: yamllint.rules.document_end document-start -------------- .. automodule:: yamllint.rules.document_start empty-lines ----------- .. automodule:: yamllint.rules.empty_lines empty-values ------------ .. automodule:: yamllint.rules.empty_values hyphens ------- .. automodule:: yamllint.rules.hyphens indentation ----------- .. automodule:: yamllint.rules.indentation key-duplicates -------------- .. automodule:: yamllint.rules.key_duplicates key-ordering -------------- .. automodule:: yamllint.rules.key_ordering line-length ----------- .. automodule:: yamllint.rules.line_length new-line-at-end-of-file ----------------------- .. automodule:: yamllint.rules.new_line_at_end_of_file new-lines --------- .. automodule:: yamllint.rules.new_lines trailing-spaces --------------- .. automodule:: yamllint.rules.trailing_spaces truthy --------------- .. automodule:: yamllint.rules.truthy yamllint-1.10.0/docs/index.rst0000644000232200023220000000071213177553503016572 0ustar debalancedebalanceyamllint documentation ====================== .. automodule:: yamllint Screenshot ---------- .. image:: screenshot.png :alt: yamllint screenshot .. note:: The default output format is inspired by `eslint `_, a great linting tool for Javascript. Table of contents ----------------- .. toctree:: :maxdepth: 2 quickstart configuration rules disable_with_comments development text_editors integration yamllint-1.10.0/docs/text_editors.rst0000644000232200023220000000230613177553503020201 0ustar debalancedebalanceIntegration with text editors ============================= Most text editors support syntax checking and highlighting, to visually report syntax errors and warnings to the user. yamllint can be used to syntax-check YAML source, but a bit of configuration is required depending on your favorite text editor. Vim --- Assuming that the `ALE `_ plugin is installed, yamllint is supported by default. It is automatically enabled when editing YAML files. If you instead use the `syntastic `_ plugin, add this to your ``.vimrc``: :: let g:syntastic_yaml_checkers = ['yamllint'] Neovim ------ Assuming that the `neomake `_ plugin is installed, yamllint is supported by default. It is automatically enabled when editing YAML files. Emacs ----- If you are `flycheck `_ user, you can use `flycheck-yamllint `_ integration. Other text editors ------------------ .. rubric:: Help wanted! Your favorite text editor is not listed here? Help us improve by adding a section (by opening a pull-request or issue on GitHub). yamllint-1.10.0/docs/screenshot.png0000644000232200023220000012140113177553503017613 0ustar debalancedebalancePNG  IHDRuhtIME&4k- IDATx{XW8 \7DQ"uFh(M,*DM&J;A֘YDc$Hh." DPX⊀Bff{yz`NWשStwun#aaaڥaaa8qfaaNaagaaęaaa8qfnCDUG:= vOçʽ46zaac~FFF֑6pYYFKKNӟԧ'^=m0 0]8!sK=Ow&=}Mt '}3qW' 0}~w@u-ؼHwdOAAfϞ-(ӧeAAA8vQ]] J/++ 555شi<vفikP]],ڪcO?2V|[[-444]g}hjjByy9y(lmmZTWWu/O`a!'&FFbAݒ:ijї?V} ʔJ%mܸQPva9s&ѠA(!!Z/9sFN+bt#"*(( oooR(4dJKKL?Rt[GLF~w'K."$BA'Oz'$%ߥĐhxb!{{{JNNFwXXXXXzǙ'wdݓXLО-C׃@f @WJsXXXXPMM %ξ@9*Ovg„ TQQA#RIт1T*rrr"\zUJ́;g-qDss&K!O`aaaa%hY!hWs /ȑ#~7͝;Wd}}}$#}%7n cc5HON՘={Ʃ~Þ8^6ǹ/SO=E?-;z(Đ5Y[[ӂ L_M$ɴ#FG_sII -Zú {:DdnnN4|/ڝFKOۓ'|Μ9CP(hҤITTTD!!!KLKaOK{} '=F ц Ԗ=CSMM Snn.M2E烤RKKw{:K}ZoVVjjji&p5Aaa{~%U]Z0 0 sgj0 0 0>!`aaNaagaasرce} .Nhzݟ~Nbܹ1hڟfgg DW;FPPar`ފ+=,54L&C@@222zt*L ##E[ˉMpirss_` J9=8;;ʕ+(++1>+9$k)++CMM ƍ`8K[Ν;=o@^>^p!!uC:QWOiM ""333<Ӻ<((ǎCcc#R`cc^㫷7rrrp5TWW#++ K(--Œ%K$fkkm۶ÿo̙3GQZZFaٲejpGCC***b v ЀJDDDHY߸!//}`G$aeekBRa׮]h]Xddd`׮]Xf  :{1BNNNAZZvڅ(XYY Nddd 11SN웕V\$#55/&L gڴiHLLDFF0m45[bb8qDaϞ=HNN5ډǞ={m6Jǎ;rCJvv(mzW(I |R4 }yh(Yt@/H}dv>fXWO-v~Zx1ؐ=%''.?|0͜9hРA@YYY:'Ɵ ۛ  2(33Ug֬YTZZڪA#999ؘ~?:|b"BA&M"(AAATYYIf" rtt;w lQmm-%Qqq1JYOÆ _l5=S7l@cǎӀ(44TR6l''''255Rdd$]Uٙ[uN[ny摵5d2$ڰaRI#Gl+!!Ə/Q ]]]i۶mLr BǏ'JEdffFÆ #RIƍqppx>^z^MFM*9q ZԦl @okIfv`=XWoMD۴nKevvvTUUѣ4gάY$'uuu4jԨ={Z]Gü<7o^Rdd, 8 g}J%q>}z(55gAd'&&&L qvvOMM|C?ꊉ×_~&N:jۗ _^wdRb`1M#""|@ڦ牰M!mgN9xrlڴ x [(t'Otcƌ_-o$oÉ'pIj?Vѣ%p>$E c^RRR$OP__[NXP(  8&&&>ϝ;']WWKK-=ٳgNV'Gii)***p%={V͖>>(,,lC֭[eXjdu`pWy(-Eػ'.x/SSSqܹshhh^m޸qC:ann1Q[[駟իW*ܸqrwqܬq~޽Ɂ#0vX>wC}pǎjew'R|677GCCghIr;^Pc. qc#y&qM?,;2cƌN%YrK?<==q2l;wNpe$Sp]pNL O:ooo|GZ}?NO`ggn LS Fš5kpڵ߷1ct &&&:޷\#F888}Ȑ!$#F\wpphaEEFoV/eeex뭷PWWi޾10uo`.o'rue3c< ܹsX`I=y$`mm kkk,X@6{v{[lقDx{{CPd;ǎChh(~acXt){Rɓ[R*-[ƬY`aa#F`͛7###0775ϟ/B &Q+R@@@  <<<|r}>+SSS888'l'66>>>4hd2lll0uTTTT0rֺJ|08;;C.cjwF݋?ppp) &N7JΉ]ii)݉J~9[3 Yl` lH,{aO򔅥K"!!|r|W:mm}ؽ{7mۦQ)vΝ;裏x饗&ׯGdd$|M?>̟?_t<@||<>I1O`ll-[`̘1tbbb:t---뇼T})>L;[[[:chiiq~Jgʔ)@uu5~7#444;w.\/7hKtt4^b ; ,'|rHOOsQ*Xz5{llقO?ǏǠAl2,^X1}#> +I}FF O@܋k8>sCСC[ۙ:u*كMMM(,,Ċ+?tvvƕ+WPVV֮2`ܸq}#q677Gxx8v܉`%R܋xH`?Z *#҉zxG4.{GPYY)(#""333<ӺgEyy9P^^.Xvg}oooڵkFVVlmmzK.EQQQZZ%K|;h[.ƟPeee S444| ±c؈jT*HQ|٧|Ӆ;`Ν]vw|rEEEXl`GCC***b O;K8oߎ5kڵk:EXXԄb5G.Zi%fYm]1RQQM4 yyyQIIRpp0YZZ ܇3g 4(++K|kWK׾[upp0}ԿE &MDEEE' Yf9::Ν;%r]L]bơXywEb jC~#oH7n:tmeDžx6lΟoΦxrrr"SSS8p EFFڵk[u\]])!!N4rHR*Ǐ'JEdffFÆ #RIƍTiÆ 4vX߿? 0BCCLԩS)!!F!hNrpp>!=z4T*T«/;}UvM֒^{:5$Jձ W7x UWWӀzjGXXF['N$|`}wwwUUU>z(͙3G3k֬.K;'77WcK:ptM",--NT_"&hȐ!t3g<ٳgGJ+//͛שK8#ӧOt)=6q;$oHm;R(]v\PT]gA266VIv,pqqKǨRSS8oٲEc_}U5`RT?qNLLThtIxe1l&KK2;HDM@mr] 2j(ꫯ](""55j{m֒ښjkk뛘{PrD֮uiȐ!x񢤺$666T*_z0mii{⬯>՗Wun޼ISN[vYYY˗%U__O666N%fmYx8c!UO&LGR?dJ5J"sssrB!IOOرCR]br'BAaaaH{iN^ggmm;.LsGpy+R&N__ʴ=rYzr/ݙ3g#WFdd$֮]wy<Μ9/ҩ:oܸ!y|x#>`tեmIMMŕ+WsΡzj#}K,b 'N? 777|WlO .};l0l߾۷oWë#?rnnWg}7Ԅ'Obɒ%7 IDATv.iannީ}JssseEc߱cGvT~i\zqqq7 ˱{nwbenn. ɝW)0 [q.ݦl 8~DO?4w-[SNIzHٳpwF%%%|駟f8}Z&M$;;; DWݼyƚ}||3gδ,g̘!َ!T_+BCC1~xEV1BIu:u ޝS1ubOBۊ'bxW\Q{`NS_ck}:PRRB-xѣCdmmM ,2vA_} ==(&e OOO:s YXX=6y1VXXHAAAjp#h}o/%f{hM1{Njvv6<@4uTXL{Čg1>k!F:D#BGi}(+dժUةO0nJZ;v,EGG( 8q"mܸQ'J%M<맶,&&IP>(َ8x{{֭[[>|8%$$Д)StjWPP9Μ8N&P@]8 OZwND Ƈ_::?Ot :wZ-6Z|9PSSҢEIi"՟0*..&*++˗̘19BW^k׮.xKsܹT^^Njz!z)77L"َO8sZZ毽޽[!rjjjzꩧ$?RAA5665/%f2q^|9QSSShh@ޞ˭c[XW{Čg1>sёL:>cK~(266c„ iU4ԤoT*)33iڴij:cƌ7ݻ)--i:%nnnDYYYj>ZnT*JOOXrttlGL|hܹL,8iڮ80aBLYXXtCRqq1ǂKcaaYJJWұt888PJJ^Դ'60O FRǎK.]{r9ҥKhԨQz׹[7Q/NJfffD9EGGC{T{Gso-Ϟ!:C3lذFdjjʉ3=8rM222Sqgי}y/]_ث B믿=]t`1dW9qξgVl٢ =rs{;w@:<,Т` Wp@D%>pߐNՓ Eqq1QVV0Q#]|9JKK؈"L󑟟TTT`Ŋj:AAA8vQ]] Jz:S?>,Ԅr<3j6k׮YYYgL:M{{{8,/((ٳe^^^8}t>悔y1L:8pznM۾};֬Yk׮ϫ0668kPSSM6Ahh}ھtRXdINpssC^^(ӧ#&&ւrWWWcϞ=ضm|}},(9r$z-@T"##>})wgggcڴiHLLDFF0mڴNOĉ={ 99Y;1EFFvڅ5k@Ph ۫ʕ+t⥗^„ l;v nnn;U#%%222(99֭[GCmW_ۙի)**םB&t _h@tJh6@ tzqY:S$00hҤIP(ˋJJJD]jS\\L^^^P(hҤITTTD~~~zD4k, GGGڹsÇi̙dffF һ?K."$BA'Oz'7) 2dQffSYȈhdjj*Z &KKKrssbmYj۷OR7v˝1c^#sss@ǎ ]zU:w_1PrrrY_cϏ|}}ߟ|||̙3w1()ζ}֬YTZZڪA]z >>^맴FFFdzD3~xRTIfff4l0R*4nܸV{{9zaaapBIRBB >LMMiȑT*9|R#G) >hzJ۶m#ggg4dP۰a;O PA'1}C#kkkddiiIaᄅ֭Ç YYYm߾&N(ѣIR5'd@ڔMm-쵧[CB>T)+Hr$C$γg,5k=zTj^^͛7Or[---N8qBc ;;;1u3q677}ы/uDFF -,,z`x"999uKB'fֹ̋ǏcǎQ~Y:ӧOݷͣr-qǘ'"$K죤:GҜ9sYRр&s5ƪBׯo-IRMc2d$_cccIdQYٙbbb8˒<dffFaR/q [o%iD<'ο1l,dvY,Se:%mXYY˗׷ )J*++ׯZZZ m{FVL]L򨤤^x}hccC/^ر:2~n.fmn]q#]MNiiڕvܹ믿% N1_.f%e?ٶ_rEpQN]]8Xvv6ˤT*^HOO;vi7ln*JvK֎9ڵKszz:)vU(FgϞֶkڞ?b={PLL ? >\냣ud/={Vmn`G!<<jly3i(kѢ{Yzr/_KKN뙘ׯ{+HMMŕ+WsΡzjƍnZ~=Ξ=Ǐ~ŋ;W)))ꫯb…:')cHcСC3l0l߾۷oWKE!)) s߭Pc3ۻ}.1]xׯ_ָdff_~+?otvءqN:t=OOOct-z駟իW*ܸqrwlػw/rrr;;;;!!!377GCCz-q~GP]]-iM)uhU6^ӧOyk٤I:W\-Z\\\lyzz rrwwGaaƝ\.׺vĩS퍏>H~am-1cFݛ7o7om =<@[n%WWW:_yQp)<<\`R(&&&jT*iC "LF666OPllj[_a9Γ&MW^yIR͛EjpܾL(ro'ғ q6h@ @T;=Q¨/_.ySvv6]|)77JaaaT^^NMMMTRRBO=RKKƏ8hn?TPP@tyz!z)Sh<(͝;˩Y'矧 q;wNJ"U3zĉdff&8@9r^J׮]?\[ i|[Iј+tijll~Ia}t?1h ِ]>Jھ|r*))&*--EQSSSm&LsҖ-[ecƌ7ݻ)--5ԔRSSӧRLJLLiӦ (ڵkSll,999%ӧO$$RI3f![RVVZ<67ݝ)##o߮V}G֭#J곣QRRFŨQhݺuCJjⴾlGDXeё#Qݽ:t(w˗-oзƎ/0 e/0>S>(J%T*U܌#$$˷w___,^8|WY <>***tz) K_DNׯSqq1dllcMW^n0 0 0L;T aaęaaa8qfaa8cٲeHNNFFFz-L80%=ӵIZCIq "t~oss"::dgg })>mFPPPOMLLi&`XlJOvzMazN.Ldddp"tI|zR322L cC8 .`׮]e;1`> d8Ό4qq0`B7ǧ 5557nN< \qg}&DT; ߧy}kЀ XBMgEyy9P^^gyFlڴ DMM BCC%@PP ЀJDDD퍜\v ʂ@U,%6>Gb} Eqq1QVV05[싎볾OaaaɁvr;5Tr;.8q"g$''cj:HJJBff&vLJ… K/ARG">>{mVbbb]v!** VVVs;9rJ$%%!==x饗0a1VJHLLϝbcc]va͚5P(tcLL رcpss#wwwz7hϞ=@dddݚ^-ν$VO}|: dd56yz^=6 4@hZ?$7o^'>侧#;c@Y3j(U6WVVҬY‚iΝKRQQyzzBɓ'SII =/9sFRpp0YZZNAAy{{B!CPZZeffbts`` ѤIHPl/%gtG{ڋ32228ڽ{7JnSC!S)m6rvv&\NC ԩS)!!FA4rHR*%8?ƍG4a=z4mݺUIR'ѰaHTҸqvɉLMMiIk׮17oY[[L&#KKK 6#b|vuu>| w4d|І hرԿ0`RTT]Ѧ'vmwf 3++^y_netOi"\~[tkufoלL՞l%hĹ#;IM'q5s^^͛7]'Nor9rtrss)22RPW@@8p@`]cggGUUU]8wT:q\>mӐ}!.1>:q677}ы/s  JJE и_[l$fwW_}UԘtI:4gA]...~zډUG ]jj*=jccc5n&133T'bǘv 0T*h9MMM:xwO?v"=oߚ_Z6@k kɝ[Q{%5ޑ?<T*)xǏGNNN:Çlj'q:~#F544off&I-AY۹Z.]%1.1$ߍ!BL]b|64 A7.Co/Cob133C}}e>( ]ٳg1x`Aٍ7߿$Cb֭uj*Aٹs`ii)).| QZZ \t gϞٳg5N5]v>1wc( I#}#vmW}}=r$qŋe  -v"VϜ IDAT lM5/oWrKo@lS 4;4۽_ul֏:ٹOj;E1d]m<{B_tTX qY?~uaOu;annWmyUd{"''رc> wtܖ|*>O?4^8TUUƍj1$benn.h%<XRR|PP6x`\r[E `[u5 8[ @n%ԳV~ ,=k:u9{,e())ѻ?6HWܼy]{,%>G OVyҤIb3Wa/?y!%%Ǐvvi`ggqYEEF+;h/z H۫R 999?x j .yQF!55?s 1ctsG{ۣg'ĪUFxx8 ڞj^`߾[{8fѭ֓J`lJD- )0lٲo6f͚ 1۷o$&&߆ &MR Rw6oތ ֘?cܹsX`Avb!%>G qqqP*pwwBɓ5d_KϒPw}իW㣏>UC_1Ӷӻ-GGG>rFxx@ ajjÇ#,, ׿޽{?055BĉqFO<<<Яz*  42 666:u****e",,#GT{!SQQ( ( xxx`AcQm rJ[VV{OQSS/;}Js9pCJ+qޜ][WK*׿?m_wo)uGཏWܚvr @*'[l1cp%taoo, 2/^DRRR|@СChiiA||<Я_?^s=ddd_~]N^)?moA[_CZZ .`x/%g)DFFbضmGQt~Ç?ƴipuŰ;WONb…d C=:|W3<Dnn}ADXd ###࣏>LZBCCvZ \dffbΜ9XlLMMQSSh{Rx@ zA?@4 4KǺzKRQQyzzBɓ'SII =tGDDO>>>tÇi̙dffF=,+_2\"!qE" 4!@L|Mu!؍3f5*b (7ÚB D33k9}N`JNNl"%LFAYYY:K,C rZ~$hժUdmmMzzz4dzg)77WOII M2d2M4)((HR¨fΜI&&&D~FPPSdd$;P``$JW>Kr1hôpB$kkkJKK41~Ĭw1ui;ږ$ɡ$rvv&4h-[/_ޮ3c z뭷y r5j#%''HP7=r;v$;qqq4g ]]]233#///Zn'%%UKG]fAdjj*~vv6HdggG6m~2w42>P̆wa3=*kXף8;wN)8 gJ뇡! 766v?333jhh :jjjP]]ѡjrvvsCCtٮYf fΜINԮӧOӜ9s:O~~RVHH9rDϚʃ>k+pӮvbbb=hcYbv1v- B1+''e=CCCR(diiއ;v [[[q 7$OgVJ5Yz$;4|pQcjjJ /8Ӯ]詧l?##C~2 z gj"gu:'2ypx\eT__/IG[ZZ\.2jjjܹsGe;wAӟtз~+֭[G͔Gr/_N^^^J>?t5Ijlll2Icc oZbD Ŵۃ6Ə..1m6eاjكW_}"""999͛􍍍eƴ{nIuݻ $X.hǎS|_NPk"]Ӓ_033Chh(,--SSS4vikΝxW0`̛7OZmܸصk'Ob]w%jAp]]lll&B[tծݡ'O..1mcG455X򶶶.m?~сw9ӝv>_(''Ge>~Wv8+V 77\]]~zhnn69ں@jV,Y.-즎T NR5lmm%===ѩf2UAm]q_Bp]]};wRuu55J+DRvG@ϗ.1yyydeemň\lJiWwjkYbvM;ձOUyBBM8vAÆ S ƎKꊋS;|9ǙS58ϙ3hĉeoo߾8p`{sW mh4@R's0@sorɂA$p.--竼M /ŋK0)**JSNQ\\YXXEDDPYYƁŋR (::HOOlllhӦMTPP4Il$ӓ.\@aaa#G̘1?NdllL4w\:q$ňqC1zsgGzS?yɒ% ߟRSSWqrmݺUpS+]d2yxx&sO~~~4x`%KKKZ` ︽xp,%(]-/&[ qob͛)33RRR(""BmYvP@zr:Ч-&T^^NmmmJZZr%UVVRkk+UTTPlldmO>$s̞=[K/˗/֭[(..Ƌ/dvܹsQXXfTVV_ViͨҥK%,%%%O񧫫;wb YYYGmm@W?b.Y̘vmqi=<ѪUښhȐ!Rnn2e d24iSPPvQUU͜9LLLɉ>C H233#www*))@I>]_"1cQ#":|0-\,--ښ4GYb|3浵]h[ԦiL8mFƍ#CCCK tNJ4rH200QF\.)Sknnn4vXɡѣi֭tкuՕHM+Vh_Gs! %333u֩|vRR_dT cccёܜLB۷oJ |@M0ޅt'a]R|9"((Ξ=+IGdhh(̨A`S3tPimbbBuuudccsH::T]]MΒ|nhh .5k,A̙3ԩSui3gNϧe˖ BBBȑ#|T+??_?bƢ1FDq1BbƼ mBP{ٴiSdz;vMC/w^I:ȈEԔ U,8VJ\]]i˖-=Z;ڵzG~edEtNd^&u=Js}}= ,,,^T?}$\NeeeDs@___vر?=oVr߭[)//r9-_}ڵkHH2KKK]uuu31"j?!ҤĈu!g1c^[ۅej'ݻd2YL& Ҏǵ|dC)))~{233)..bbb(88Nxs.]uٟf6uHLLĞ={zC 'R5V^Mƍ####222"WWW4}tO3geeeĉO4 {~P>t1&ޛ,a]}MJKKi*o tEL-j:u‚,,,(""꣋4ŋSyy9}7 Ptt4ّЦM@iɓI&']p$ i#G۷ 1c?~<==ؘ,,,hܹt I>]_5{lI@D1YT rru!gmj?ږ%KPhhɁ666ꫯ t|}}i֭HHT8$LF2(%%EO~~~4x`%KKKZ`ǫ\JJ&Mw}K 6nH&L]եj}y'z<ғ{ pE>,@hvSyy9)hutthʕTYYITQQAu8?tAF'gLF *g΋iӦсDeeeLC QV^^N---TZZT1@< ѭ[ʕ+*O'O7n͛7رc'xYz饗l^ IDATZZZ%#&2ƺ әt.YѦ?8{zzRRR۷oNJNiiiEiiiImO<ƒB{R||<999 t\\\(66>#̤&333%&&sY8pfaay<~vUrrr̰Hv7:88Yxr 0:::Xt)Q\\0hkkÇX{…8|0x08y30  t6ɧ0 0  0 0 T aaaaa8pfaaaagaaaaa8pfaaaaaaa8pfaaaagaaaaa8pfaaaaaaa8pfaaaagaaaaa8pfaaFyy9ܹOUD$Bm0 0Lw興#yҥKxב;wh_n_OSaaUaa?]j(//GKK o(Wn"//7oDmm-aee% CQQQUUK 謬z*%&($"궧i<跶RĶ30k,Aٔ)S+UPP[n 6egg6lѣGQWWhaa!ɢEI&ɓ,XKwKBDTTTD$֖222(++]'(()22ݝJJJ(00PÇ… Ғ)--:kKguWRՙ,Y:$(~zAYnn. <);;[kPPQpp0ŋ5H/c :~8yzz1YXXܹsĉ=BTߴtRm.tH1QWŋeN8 2Q],,,,,,,,_C+WJjmm UN֦ ?>>]qtuu?! 0 0/`Ɇ 0 peUUU7o aaaao1aaa8pfaaaaήHHHPzò.ͧ'SxUc/'<<k׮Dzڵk4"""w>caOG"$$x' }}!44<zUц wgZo3n8\~eeeL;eeeرcqyG>㜓÷$rp3`eO]~)n?'?~0)/5趻3m8.]mU3k2/fzL!;;uuuذa=:DGG+UXYYa۶m(//Gcc#cْtEDE^^n޼ZdggJh"֭[|2y2FGGnBYYbbbt|Mx7tΝB477/RԵW CQQQUUKJÎ렫ubֻغPPP[n * YYYGmmm:VOVrCJJ OTdee!55!!!J:HLLDff&Ҕ;~v,+P(0oU}yWv<ǀ_{Q`` ]xQu͞=[3sLR~~ vs9:gϞm}i3g핲iٲe!!!tI}SzZ544պXEPe~`XRki&`ଯO{~c„ zj҉64|(==]ӧw.SSSR(gg}{@On:NοwʀMl Կ+W3ߪJWT]pB =BܬH͛7/Ĺspy̙38{$<7?cȐ!njM=z4Ν;'#g~;::9rdo7770aϟ/ӧsNI}----abذa0444ѣ}6>זNobddFˆ˗;K. ~[[[ԱiO… Z񷵵UF[ SRR%K***`ffO:DFFO˗/?3.]ԏ]! &`РAtꫯ׍(hÁs?Gz0 -ޟ^~Vm-!pljQ_6>>OnƍȀl߾u49B ;w<~JuuumѤ{jl!==ׯ_Ghh(*** ܸqC?g1cO[:ISSU7ve[ڴg@A8<899aСpuuETTbϞ=7n 11555hmmZn$yWpJ "ե`Qݫϗ{Eyo.Ltm+8gohN***WbPXX(h8rH{d;=<==qرI& t.]R___|'j~:PSS^6a>։۷{tltU/=zܩСCU?7ݑ9:: t~'%IOee%\\\_ƍ077GCCC{~;)++Ö-[vC[[tuuhe[[[$&&*_7ol/3fLZk OG|] ,pޝg-Oi0`b|W܁?DveV, Cww՗)((@tt4젧,Z_$mB&_$ILL\.'d2&O \.III|///d2L4 r\>3g΄ F۷ 8q7oưa`llS"--M7nľ} cccXXX`ܹ8qAoDDW:d2xxx`^^^0@#>>~~~C'Y  t$ @׀ƎT=ѮwM]Hf'6~GL]uMFׯSSSQrr2 2DL@/RKK ]|ϟO---(&&JJJ襗^ԥC+WJjmm U3PQQݺu\4SښrrrڵkH+zuO'O7n͛7رc$Pxx8S[[FĬw1u=tAk>b?^0A>}:rʢ6mCᔖFYYYFaaaJv<==)))G۷o'r Zb޽K49h̘1~zڳgeddڵkMDNѱŅbcc飏>LJIIh233TOICegLq^쬁 OXX1j(\r >OcaaaF{p0 0 p0 0 083 0 0L /"-- Ö-[!Ɇ>"##L 22R5HHH0 "ӽ>k\R ../_FSS._8m}yX3Css3[̞=};zW ڵke_V&e}]aaaE__?ŋiСGO=ے,^V^MOÆ wy^~eކ hrEz}WҲT:r999!5>L)))ܴim߾GϮ?ӌ3А&}wwwwz*S=r_z10ZlY޽,--e> $9pBgϞU &(6lԨgjjJ4bĈ1>ܹS͎V`gɹs(88W0aBoD|T1p@ G(^^^?)V]= 4"='%QypgT7zS-E^^n޼ZdggJ"477 K.ؗz7Q^^7HG[tU>\hq-\|?pdgg;wܹi]>sTTTH믿Fll,=Nyԩ8z@ȑ#\ܹsQXXfTVV_VG. p-BPRez Ƒ;],v-w法mۆr466ԙ#<>>rtt$rttO>6lؠR^JGoAgϞ۷oѣG)**%ond2ݸqCŪ*9s&@1R@@)99UÇ… Ғ)--M1>R|ˣUV5ѐ!Cg\%;_0))׈w7U#''ٙ hРAl2Z|y) &###'\Ncǎ^1uyܸqҮH[nUYwWW ^񝔔WTlzwwvvvi& dGOO֯_XIOOgv42>P̆wa3=*kXW ===eC"WJa #Ghs)ăi btz1}x)={@g̙O\6p@:y$uĉ4p@K.of_%BA/綶60`3gPAA 0$zi3gNcuJ̨A>>hGbƳm3D>^i{0a^Z끳61n8"P(8}猌 էz%O>9pfɁk\Ճ >S89 ɃrMꏁ;V)gZ>ד‚%?bdaat04p}Tٙ Ņ>suuu奵1E&W&Wh]XZZ\.2jjjjܹ666*cGbƳm3׭[G͔Gr/_v Skkkd3mΪ訿w^4hXݱc;`w峘GL&,766(phOz#Ղdgʔ)E}}=۶mᅬ>n|k"]Ӓ_uڥ΃TF|>ݸq~Ҳ W^\p111ol2ndd$pn ,… agg"##C|1}F+WJ\ZZÇ/ IDATF' P u`4aWI_655аGw>xPSS{o߆n߾ҥK< tՇڪテ79")WoRQu~woj[o  xQ+̎>c֬Y988yyyꫯO>[vvv_{Ď;۾-WTT&:99P)pGeeekjj0tN疖kt+2lٲ Zיڪ~ȑ#qy XWWW`#Z;0S5=%K^}U8qBgϞk[[[cذaXt)Μ9k.Lu^l[I_~׈nձqF۷066ΝvsPsJJ >xyyA&aҤItՇڪ+!!)))L&'hN \v!޽000Q477#77Wc?^x߿O>$f͚Lf1>F@@ 0c "%%E0sL`ȑؾ}dϟ?+V֭[{Ď;۾- ::vvvӃ -ZZIΝaYY:թ 蹰@&ׯ^g>k?/r6^xA W /_栨镜ڼy3effRJJ EDD͙Rd``@?@MڃcqVLEN.\;w(6vD>wO'O7n͛7رcT^^NmmmJʕ+Z[[BٽbtՇbۇ/RKK ]|ϟO---v21%%%Qyy9577Syy9%$$Dsq,P֭[w)M+< ѭ[ʕ+xb'R]]566R~~>ogybt峘KʶܙӦMש(99 _-,8?8֭[);;[阫Yl1chgȠkגƓo,.>O6r9eeeQJJ M|QQQ?G! >F•+WP(﫜0 L8 ,ap5|baJ:{I7Yu!}}}zjϰΦ_M:ٙ;Fk׮Uz<y, Pm4K,0Aٜ9sW_}$v,8p(KHHڷ&*++I&=~_B:::Jo 矕tϝ;ko؛0aBo{$ =G(ꫯeϟs!8 05zxIDIyՍR[Нݚ7Q^^7HG?٨Æ pQ!::Zܺu P(E^^n޼Zdggʪ]f؝2e {~Ġ ---())ALLFCR[^^{t KesXX܌*,]T)eb۶m(//Gcc#cdgg]nnn۷_͛75믿Flll~ʕJ===%#<APfnnN~>LOO=7Ԕ ,fFKK Xf ֮]֭[|O@$NR!: 5ET$o u=*8::ܹs3g`ȑt܌fw##喖(++CSS 055UJ}?!Cߐŋiŋ}>sٳg"ɆǏǘ1c̓.y„ 8tp:}7oތ/yyyX|94 *ڵ WO?wŘ1ctR̝;ܹ< _\՘)بrو#pYAYII {V ?6ҥKJ.yriiܼy:MɊ ugff&?S$%%!..111ahh# ȵk`ee~ ׮]$TQb֋/#==ׯ_Ghh(*** ܸqC;w{AΝ;]WƥKpoC]gb|7n܈ HHH+٧7n\eioo۷cr"`,\vvv8x 222$ۙ?>RSS1{l|*u͕LOcccرCL['sHvq[8tgGFFJuU8pyyyprrСCꊨ(Ğ={366n(0\\\\q  &htqB]? WI_޾}zzz}ҲK.S[///J~~~/^v*TΟ?#""ѣG{zzdCCC/m_`Μ98r*++&#K - sϡS U:'''j8WTT^e*8$h~뭷`!77>cWi;W_͛1sLճGeee7jjj0tPsYYl٢F)*Oڠ6 & 7nا:)}XSS#vlmm8[[[w1Ij_qȑ#3g\]]WWWȑ#*^@k=P~+F\ eEE""",%%| 0i$rrI:Xb,,,`aalݺUc{;w|:hdC.cɐd\.Gbb_hv_~'|:Y[lܸ탧'aaasĉ:`ccE_||||ztz~<䓘5k2335 ~ml۶ QQQJiA㣔6Փe8882 X~zbbb0j(111*˫ӫǎCLL ~7\zUWUUO+bӇ KKKL:Uɓ._#^<3qDڲe ۷6o;{x<voTL؃Ɂ"@tw1Q]_hEXO"WGkeUҴ۴E?*E(B?~Z̭?m PBU0 O̞u^{357aՊEP ;wߏ۷o#;;[\`9spl6tuu+VpO. NХڜł>fhZQQQy&?~lgHveo8Cn_^x=zK.!11qUVGww7, 1cƌ[RRū/gܸqv  77Ν瑓# ٱjqqq8~8.Q]]t:u*F#6m4EhL:67iPdggٳ^V]3UelRݻw1dʔ)?]IhɁ4iFJpp0ٻj0 Q(Emmm 2梨":z踩ӑ#Gرc5Y=O6nm۶Q]] #>>g:}4N]IDDthD4Q=HD2uEDo(+m~~JVj'|2")TWWfCO6ZH/55`0ZrJ2L#jooj ijjQ˗/c600JJJjRWWuvv?@֭ٓA;Rss3ر./W""ڰaݸqzzzΝ;sN455QOORVVlCΞZH *HՒl^X,)}Il6;,݁TUUE.~xb˙ԹzHSUUt:s:Ӿ}`0Й3g(99yŋS~~>UVVҙ3g?$ADyDGGSAAUTTЉ'xb*,, *))x{n:~8h/"##jll(U(P:>߿Q:VeODH7PL"U" $"\ B8H#,k 8۷K. XlZZZuVY:RHLLD||< )) uHXf bTWWijjʕ+!fϞϣjPg޽x(_N\Y6L&|g5k&O3fw˗Ef,_ `ɒ%hnnFbbzk׮ŴiӧOHLLDGGl???DEEl6#>>^\{f,Y `hiiKiuԧum6j̚5 'NJ ]SSNyaԩ;w.h"`{T*ڵk",, |}}jEŋQRRxyyapB ,]x7>CRAT1118xc fOt[oJ53DxoH "g6E~s/#qey|5;"11?,vxyyKk)GшtfΜ{i`"B@[[ϟ/NWBB(mڵr劬z]zׯ|Ǣd|wlv/㬬RG nff=]`ӱ/""B|qqqh|aDGG{M~~>֭['J[hF$|}}a0bay,9zn(s#8Dg6@LӆS|>Z-mٲv16,--Ckkkitez!Qnn5 >>>qK3/"*0]Q8 X:Le?&O,9T#!!ePw8?$"BZZS}W3׮]CJJ 0o|hN||豾zIydo28j9,)+{]k2\j}I<>u~3\]=]Iaa!U .#//Oָf4fDH ˳{ EM;w.8pr[8Qg JN98ID%‚'Þ,L'sKK {=T}ܺu 111EPt8_ryyyPTPTظq#,ˈ]vj_~YPc#Z-^uL<AAA8|0-[ @͛HMMU|M>>PTذa~'Y6HY=LJJ͛7hfZ_G}:4F֕J݋IQTTHYZ^^lA bbbE ]={ CNN1uThт|"N\yIDAT Jj[nujW ;.ge$:8/D(# OeqVa?_D>&iiiZ 8;woFvvlw9s `ՅXbĎ t*^Z >aXP\\3f-ZCKKhG"";hjjBoo/|WF}}=/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/yamllint.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/yamllint.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/yamllint" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/yamllint" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." yamllint-1.10.0/docs/configuration.rst0000644000232200023220000001036213177553503020334 0ustar debalancedebalanceConfiguration ============= yamllint uses a set of :doc:`rules ` to check source files for problems. Each rule is independent from the others, and can be enabled, disabled or tweaked. All these settings can be gathered in a configuration file. To use a custom configuration file, use the ``-c`` option: .. code:: bash yamllint -c /path/to/myconfig file-to-lint.yaml If ``-c`` is not provided, yamllint will look for a configuration file in the following locations (by order of preference): - ``.yamllint`` in the current working directory - ``$XDG_CONFIG_HOME/yamllint/config`` - ``~/.config/yamllint/config`` Finally if no config file is found, the default configuration is applied. Default configuration --------------------- Unless told otherwise, yamllint uses its ``default`` configuration: .. literalinclude:: ../yamllint/conf/default.yaml :language: yaml Details on rules can be found on :doc:`the rules page `. There is another pre-defined configuration named ``relaxed``. As its name suggests, it is more tolerant: .. literalinclude:: ../yamllint/conf/relaxed.yaml :language: yaml It can be chosen using: .. code:: bash yamllint -d relaxed file.yml Extending the default configuration ----------------------------------- When writing a custom configuration file, you don't need to redefine every rule. Just extend the ``default`` configuration (or any already-existing configuration file). For instance, if you just want to disable the ``comments-indentation`` rule, your file could look like this: .. code-block:: yaml # This is my first, very own configuration file for yamllint! # It extends the default conf by adjusting some options. extends: default rules: comments-indentation: disable # don't bother me with this rule Similarly, if you want to set the ``line-length`` rule as a warning and be less strict on block sequences indentation: .. code-block:: yaml extends: default rules: # 80 chars should be enough, but don't fail if a line is longer line-length: max: 80 level: warning # accept both key: # - item # # and key: # - item indentation: indent-sequences: whatever Custom configuration without a config file ------------------------------------------ It is possible -- although not recommended -- to pass custom configuration options to yamllint with the ``-d`` (short for ``--config-data``) option. Its content can either be the name of a pre-defined conf (example: ``default`` or ``relaxed``) or a serialized YAML object describing the configuration. For instance: .. code:: bash yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" file.yaml Errors and warnings ------------------- Problems detected by yamllint can be raised either as errors or as warnings. The CLI will output them (with different colors when using the ``standard`` output format). By default the script will exit with a return code ``1`` *only when* there is one or more error(s). However if strict mode is enabled with the ``-s`` (or ``--strict``) option, the return code will be: * ``0`` if no errors or warnings occur * ``1`` if one or more errors occur * ``2`` if no errors occur, but one or more warnings occur Ignoring paths -------------- It is possible to exclude specific files or directories, so that the linter doesn't process them. You can either totally ignore files (they won't be looked at): .. code-block:: yaml extends: default ignore: | /this/specific/file.yaml /all/this/directory/ *.template.yaml or ignore paths only for specific rules: .. code-block:: yaml extends: default rules: trailing-spaces: ignore: | /this-file-has-trailing-spaces-but-it-is-OK.yaml /generated/*.yaml Note that this ``.gitignore``-style path pattern allows complex path exclusion/inclusion, see the `pathspec README file `_ for more details. Here is a more complex example: .. code-block:: yaml # For all rules ignore: | *.dont-lint-me.yaml /bin/ !/bin/*.lint-me-anyway.yaml extends: default rules: key-duplicates: ignore: | generated *.template.yaml trailing-spaces: ignore: | *.ignore-trailing-spaces.yaml /ascii-art/* yamllint-1.10.0/docs/disable_with_comments.rst0000644000232200023220000000424713177553503022035 0ustar debalancedebalanceDisable with comments ===================== Disabling checks for a specific line ------------------------------------ To prevent yamllint from reporting problems for a specific line, add a directive comment (``# yamllint disable-line ...``) on that line, or on the line above. For instance: .. code-block:: yaml # The following mapping contains the same key twice, # but I know what I'm doing: key: value 1 key: value 2 # yamllint disable-line rule:key-duplicates - This line is waaaaaaaaaay too long but yamllint will not report anything about it. # yamllint disable-line rule:line-length This line will be checked by yamllint. or: .. code-block:: yaml # The following mapping contains the same key twice, # but I know what I'm doing: key: value 1 # yamllint disable-line rule:key-duplicates key: value 2 # yamllint disable-line rule:line-length - This line is waaaaaaaaaay too long but yamllint will not report anything about it. This line will be checked by yamllint. It is possible, although not recommend, to disabled **all** rules for a specific line: .. code-block:: yaml # yamllint disable-line - { all : rules ,are disabled for this line} If you need to disable multiple rules, it is allowed to chain rules like this: ``# yamllint disable-line rule:hyphens rule:commas rule:indentation``. Disabling checks for all (or part of) the file ---------------------------------------------- To prevent yamllint from reporting problems for the whole file, or for a block of lines within the file, use ``# yamllint disable ...`` and ``# yamllint enable ...`` directive comments. For instance: .. code-block:: yaml # yamllint disable rule:colons - Lorem : ipsum dolor : sit amet, consectetur : adipiscing elit # yamllint enable rule:colons - rest of the document... It is possible, although not recommend, to disabled **all** rules: .. code-block:: yaml # yamllint disable - Lorem : ipsum: dolor : [ sit,amet] - consectetur : adipiscing elit # yamllint enable If you need to disable multiple rules, it is allowed to chain rules like this: ``# yamllint disable rule:hyphens rule:commas rule:indentation``. yamllint-1.10.0/docs/quickstart.rst0000644000232200023220000000445313177553503017663 0ustar debalancedebalanceQuickstart ========== Installing yamllint ------------------- On Fedora / CentOS: .. code:: bash sudo dnf install yamllint On Debian 8+ / Ubuntu 16.04+: .. code:: bash sudo apt-get install yamllint On older Debian / Ubuntu versions: .. code:: bash sudo add-apt-repository -y ppa:adrienverge/ppa && sudo apt-get update sudo apt-get install yamllint Alternatively using pip, the Python package manager: .. code:: bash sudo pip install yamllint If you prefer installing from source, you can run, from the source directory: .. code:: bash python setup.py sdist sudo pip install dist/yamllint-*.tar.gz Running yamllint ---------------- Basic usage: .. code:: bash yamllint file.yml other-file.yaml You can also lint all YAML files in a whole directory: .. code:: bash yamllint . The output will look like (colors are not displayed here): :: file.yml 1:4 error trailing spaces (trailing-spaces) 4:4 error wrong indentation: expected 4 but found 3 (indentation) 5:4 error duplication of key "id-00042" in mapping (key-duplicates) 6:6 warning comment not indented like content (comments-indentation) 12:6 error too many spaces after hyphen (hyphens) 15:12 error too many spaces before comma (commas) other-file.yaml 1:1 warning missing document start "---" (document-start) 6:81 error line too long (87 > 80 characters) (line-length) 10:1 error too many blank lines (4 > 2) (empty-lines) 11:4 error too many spaces inside braces (braces) Add the ``-f parsable`` arguments if you need an output format parsable by a machine (for instance for :doc:`syntax highlighting in text editors `). The output will then look like: :: file.yml:6:2: [warning] missing starting space in comment (comments) file.yml:57:1: [error] trailing spaces (trailing-spaces) file.yml:60:3: [error] wrong indentation: expected 4 but found 2 (indentation) If you have a custom linting configuration file (see :doc:`how to configure yamllint `), it can be passed to yamllint using the ``-c`` option: .. code:: bash yamllint -c ~/myconfig file.yaml .. note:: If you have a ``.yamllint`` file in your working directory, it will be automatically loaded as configuration by yamllint. yamllint-1.10.0/docs/development.rst0000644000232200023220000000026413177553503020007 0ustar debalancedebalanceDevelopment =========== yamllint provides both a script and a Python module. The latter can be used to write your own linting tools: .. automodule:: yamllint.linter :members: yamllint-1.10.0/docs/conf.py0000644000232200023220000000237013177553503016232 0ustar debalancedebalance# -*- coding: utf-8 -*- # yamllint documentation build configuration file, created by # sphinx-quickstart on Thu Jan 21 21:18:52 2016. import sys import os from unittest.mock import MagicMock sys.path.insert(0, os.path.abspath('..')) # noqa from yamllint import __copyright__, APP_NAME, APP_VERSION # -- General configuration ------------------------------------------------ extensions = [ 'sphinx.ext.autodoc', ] source_suffix = '.rst' master_doc = 'index' project = APP_NAME copyright = __copyright__ version = APP_VERSION release = APP_VERSION pygments_style = 'sphinx' # -- Options for HTML output ---------------------------------------------- html_theme = 'default' htmlhelp_basename = 'yamllintdoc' # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'yamllint', '', [u'Adrien Vergé'], 1) ] # -- Build with sphinx automodule without needing to install third-party libs class Mock(MagicMock): @classmethod def __getattr__(cls, name): return MagicMock() MOCK_MODULES = ['pathspec', 'yaml'] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) yamllint-1.10.0/docs/integration.rst0000644000232200023220000000073013177553503020006 0ustar debalancedebalanceIntegration with other software =============================== Integration with pre-commit --------------------------- You can integrate yamllint in `pre-commit `_ tool. Here is an example, to add in your .pre-commit-config.yaml .. code:: yaml --- # Update the sha variable with the release version that you want, from the yamllint repo - repo: https://github.com/adrienverge/yamllint.git sha: v1.8.1 hooks: - id: yamllint yamllint-1.10.0/MANIFEST.in0000644000232200023220000000016513177553503015541 0ustar debalancedebalanceinclude LICENSE include README.rst include docs/* include tests/*.py tests/rules/*.py tests/yaml-1.2-spec-examples/* yamllint-1.10.0/yamllint/0000755000232200023220000000000013177553503015632 5ustar debalancedebalanceyamllint-1.10.0/yamllint/cli.py0000644000232200023220000001467213177553503016765 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from __future__ import print_function import os import sys import platform import argparse from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint.config import YamlLintConfig, YamlLintConfigError from yamllint.linter import PROBLEM_LEVELS from yamllint import linter def find_files_recursively(items): for item in items: if os.path.isdir(item): for root, dirnames, filenames in os.walk(item): for filename in [f for f in filenames if f.endswith(('.yml', '.yaml'))]: yield os.path.join(root, filename) else: yield item def supports_color(): supported_platform = not (platform.system() == 'Windows' and not ('ANSICON' in os.environ or ('TERM' in os.environ and os.environ['TERM'] == 'ANSI'))) return (supported_platform and hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()) class Format(object): @staticmethod def parsable(problem, filename): return ('%(file)s:%(line)s:%(column)s: [%(level)s] %(message)s' % {'file': filename, 'line': problem.line, 'column': problem.column, 'level': problem.level, 'message': problem.message}) @staticmethod def standard(problem, filename): line = ' %d:%d' % (problem.line, problem.column) line += max(12 - len(line), 0) * ' ' line += problem.level line += max(21 - len(line), 0) * ' ' line += problem.desc if problem.rule: line += ' (%s)' % problem.rule return line @staticmethod def standard_color(problem, filename): line = ' \033[2m%d:%d\033[0m' % (problem.line, problem.column) line += max(20 - len(line), 0) * ' ' if problem.level == 'warning': line += '\033[33m%s\033[0m' % problem.level else: line += '\033[31m%s\033[0m' % problem.level line += max(38 - len(line), 0) * ' ' line += problem.desc if problem.rule: line += ' \033[2m(%s)\033[0m' % problem.rule return line def run(argv=None): parser = argparse.ArgumentParser(prog=APP_NAME, description=APP_DESCRIPTION) parser.add_argument('files', metavar='FILE_OR_DIR', nargs='+', help='files to check') config_group = parser.add_mutually_exclusive_group() config_group.add_argument('-c', '--config-file', dest='config_file', action='store', help='path to a custom configuration') config_group.add_argument('-d', '--config-data', dest='config_data', action='store', help='custom configuration (as YAML source)') parser.add_argument('-f', '--format', choices=('parsable', 'standard'), default='standard', help='format for parsing output') parser.add_argument('-s', '--strict', action='store_true', help='return non-zero exit code on warnings ' 'as well as errors') parser.add_argument('-v', '--version', action='version', version='%s %s' % (APP_NAME, APP_VERSION)) # TODO: read from stdin when no filename? args = parser.parse_args(argv) # User-global config is supposed to be in ~/.config/yamllint/config if 'XDG_CONFIG_HOME' in os.environ: user_global_config = os.path.join( os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config') else: user_global_config = os.path.expanduser('~/.config/yamllint/config') try: if args.config_data is not None: if args.config_data != '' and ':' not in args.config_data: args.config_data = 'extends: ' + args.config_data conf = YamlLintConfig(content=args.config_data) elif args.config_file is not None: conf = YamlLintConfig(file=args.config_file) elif os.path.isfile('.yamllint'): conf = YamlLintConfig(file='.yamllint') elif os.path.isfile(user_global_config): conf = YamlLintConfig(file=user_global_config) else: conf = YamlLintConfig('extends: default') except YamlLintConfigError as e: print(e, file=sys.stderr) sys.exit(-1) max_level = 0 for file in find_files_recursively(args.files): filepath = file[2:] if file.startswith('./') else file try: first = True with open(file) as f: for problem in linter.run(f, conf, filepath): if args.format == 'parsable': print(Format.parsable(problem, file)) elif supports_color(): if first: print('\033[4m%s\033[0m' % file) first = False print(Format.standard_color(problem, file)) else: if first: print(file) first = False print(Format.standard(problem, file)) max_level = max(max_level, PROBLEM_LEVELS[problem.level]) if not first and args.format != 'parsable': print('') except EnvironmentError as e: print(e, file=sys.stderr) sys.exit(-1) if max_level == PROBLEM_LEVELS['error']: return_code = 1 elif max_level == PROBLEM_LEVELS['warning']: return_code = 2 if args.strict else 0 else: return_code = 0 sys.exit(return_code) yamllint-1.10.0/yamllint/conf/0000755000232200023220000000000013177553503016557 5ustar debalancedebalanceyamllint-1.10.0/yamllint/conf/relaxed.yaml0000644000232200023220000000077113177553503021074 0ustar debalancedebalance--- extends: default rules: braces: level: warning max-spaces-inside: 1 brackets: level: warning max-spaces-inside: 1 colons: level: warning commas: level: warning comments: disable comments-indentation: disable document-start: disable empty-lines: level: warning hyphens: level: warning indentation: level: warning indent-sequences: consistent line-length: level: warning allow-non-breakable-inline-mappings: true truthy: disable yamllint-1.10.0/yamllint/conf/default.yaml0000644000232200023220000000223213177553503021066 0ustar debalancedebalance--- rules: braces: min-spaces-inside: 0 max-spaces-inside: 0 min-spaces-inside-empty: -1 max-spaces-inside-empty: -1 brackets: min-spaces-inside: 0 max-spaces-inside: 0 min-spaces-inside-empty: -1 max-spaces-inside-empty: -1 colons: max-spaces-before: 0 max-spaces-after: 1 commas: max-spaces-before: 0 min-spaces-after: 1 max-spaces-after: 1 comments: level: warning require-starting-space: true min-spaces-from-content: 2 comments-indentation: level: warning document-end: disable document-start: level: warning present: true empty-lines: max: 2 max-start: 0 max-end: 0 empty-values: forbid-in-block-mappings: false forbid-in-flow-mappings: false hyphens: max-spaces-after: 1 indentation: spaces: consistent indent-sequences: true check-multi-line-strings: false key-duplicates: enable key-ordering: disable line-length: max: 80 allow-non-breakable-words: true allow-non-breakable-inline-mappings: false new-line-at-end-of-file: enable new-lines: type: unix trailing-spaces: enable truthy: level: warning yamllint-1.10.0/yamllint/__main__.py0000644000232200023220000000010313177553503017716 0ustar debalancedebalancefrom yamllint.cli import run if __name__ == '__main__': run() yamllint-1.10.0/yamllint/__init__.py0000644000232200023220000000211213177553503017737 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """A linter for YAML files. yamllint does not only check for syntax validity, but for weirdnesses like key repetition and cosmetic problems such as lines length, trailing spaces, indentation, etc.""" APP_NAME = 'yamllint' APP_VERSION = '1.10.0' APP_DESCRIPTION = __doc__ __author__ = u'Adrien Vergé' __copyright__ = u'Copyright 2016, Adrien Vergé' __license__ = 'GPLv3' __version__ = APP_VERSION yamllint-1.10.0/yamllint/linter.py0000644000232200023220000002065113177553503017505 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import re import yaml from yamllint import parser PROBLEM_LEVELS = { 0: None, 1: 'warning', 2: 'error', None: 0, 'warning': 1, 'error': 2, } class LintProblem(object): """Represents a linting problem found by yamllint.""" def __init__(self, line, column, desc='', rule=None): #: Line on which the problem was found (starting at 1) self.line = line #: Column on which the problem was found (starting at 1) self.column = column #: Human-readable description of the problem self.desc = desc #: Identifier of the rule that detected the problem self.rule = rule self.level = None @property def message(self): if self.rule is not None: return '%s (%s)' % (self.desc, self.rule) return self.desc def __eq__(self, other): return (self.line == other.line and self.column == other.column and self.rule == other.rule) def __lt__(self, other): return (self.line < other.line or (self.line == other.line and self.column < other.column)) def __repr__(self): return '%d:%d: %s' % (self.line, self.column, self.message) def get_cosmetic_problems(buffer, conf, filepath): rules = conf.enabled_rules(filepath) # Split token rules from line rules token_rules = [r for r in rules if r.TYPE == 'token'] comment_rules = [r for r in rules if r.TYPE == 'comment'] line_rules = [r for r in rules if r.TYPE == 'line'] context = {} for rule in token_rules: context[rule.ID] = {} class DisableDirective(): def __init__(self): self.rules = set() self.all_rules = set([r.ID for r in rules]) def process_comment(self, comment): try: comment = str(comment) except UnicodeError: return # this certainly wasn't a yamllint directive comment if re.match(r'^# yamllint disable( rule:\S+)*\s*$', comment): rules = [item[5:] for item in comment[18:].split(' ')][1:] if len(rules) == 0: self.rules = self.all_rules.copy() else: for id in rules: if id in self.all_rules: self.rules.add(id) elif re.match(r'^# yamllint enable( rule:\S+)*\s*$', comment): rules = [item[5:] for item in comment[17:].split(' ')][1:] if len(rules) == 0: self.rules.clear() else: for id in rules: self.rules.discard(id) def is_disabled_by_directive(self, problem): return problem.rule in self.rules class DisableLineDirective(DisableDirective): def process_comment(self, comment): try: comment = str(comment) except UnicodeError: return # this certainly wasn't a yamllint directive comment if re.match(r'^# yamllint disable-line( rule:\S+)*\s*$', comment): rules = [item[5:] for item in comment[23:].split(' ')][1:] if len(rules) == 0: self.rules = self.all_rules.copy() else: for id in rules: if id in self.all_rules: self.rules.add(id) # Use a cache to store problems and flush it only when a end of line is # found. This allows the use of yamllint directive to disable some rules on # some lines. cache = [] disabled = DisableDirective() disabled_for_line = DisableLineDirective() disabled_for_next_line = DisableLineDirective() for elem in parser.token_or_comment_or_line_generator(buffer): if isinstance(elem, parser.Token): for rule in token_rules: rule_conf = conf.rules[rule.ID] for problem in rule.check(rule_conf, elem.curr, elem.prev, elem.next, elem.nextnext, context[rule.ID]): problem.rule = rule.ID problem.level = rule_conf['level'] cache.append(problem) elif isinstance(elem, parser.Comment): for rule in comment_rules: rule_conf = conf.rules[rule.ID] for problem in rule.check(rule_conf, elem): problem.rule = rule.ID problem.level = rule_conf['level'] cache.append(problem) disabled.process_comment(elem) if elem.is_inline(): disabled_for_line.process_comment(elem) else: disabled_for_next_line.process_comment(elem) elif isinstance(elem, parser.Line): for rule in line_rules: rule_conf = conf.rules[rule.ID] for problem in rule.check(rule_conf, elem): problem.rule = rule.ID problem.level = rule_conf['level'] cache.append(problem) # This is the last token/comment/line of this line, let's flush the # problems found (but filter them according to the directives) for problem in cache: if not (disabled_for_line.is_disabled_by_directive(problem) or disabled.is_disabled_by_directive(problem)): yield problem disabled_for_line = disabled_for_next_line disabled_for_next_line = DisableLineDirective() cache = [] def get_syntax_error(buffer): try: list(yaml.parse(buffer, Loader=yaml.BaseLoader)) except yaml.error.MarkedYAMLError as e: problem = LintProblem(e.problem_mark.line + 1, e.problem_mark.column + 1, 'syntax error: ' + e.problem) problem.level = 'error' return problem def _run(buffer, conf, filepath): assert hasattr(buffer, '__getitem__'), \ '_run() argument must be a buffer, not a stream' # If the document contains a syntax error, save it and yield it at the # right line syntax_error = get_syntax_error(buffer) for problem in get_cosmetic_problems(buffer, conf, filepath): # Insert the syntax error (if any) at the right place... if (syntax_error and syntax_error.line <= problem.line and syntax_error.column <= problem.column): yield syntax_error # If there is already a yamllint error at the same place, discard # it as it is probably redundant (and maybe it's just a 'warning', # in which case the script won't even exit with a failure status). if (syntax_error.line == problem.line and syntax_error.column == problem.column): syntax_error = None continue syntax_error = None yield problem if syntax_error: yield syntax_error def run(input, conf, filepath=None): """Lints a YAML source. Returns a generator of LintProblem objects. :param input: buffer, string or stream to read from :param conf: yamllint configuration object """ if conf.is_file_ignored(filepath): return () if type(input) in (type(b''), type(u'')): # compat with Python 2 & 3 return _run(input, conf, filepath) elif hasattr(input, 'read'): # Python 2's file or Python 3's io.IOBase # We need to have everything in memory to parse correctly content = input.read() return _run(content, conf, filepath) else: raise TypeError('input should be a string or a stream') yamllint-1.10.0/yamllint/config.py0000644000232200023220000001345713177553503017463 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import os.path import pathspec import yaml import yamllint.rules class YamlLintConfigError(Exception): pass class YamlLintConfig(object): def __init__(self, content=None, file=None): assert (content is None) ^ (file is None) self.ignore = None if file is not None: with open(file) as f: content = f.read() self.parse(content) self.validate() def is_file_ignored(self, filepath): return self.ignore and self.ignore.match_file(filepath) def enabled_rules(self, filepath): return [yamllint.rules.get(id) for id, val in self.rules.items() if val is not False and ( filepath is None or 'ignore' not in val or not val['ignore'].match_file(filepath))] def extend(self, base_config): assert isinstance(base_config, YamlLintConfig) for rule in self.rules: if (type(self.rules[rule]) == dict and rule in base_config.rules and base_config.rules[rule] is not False): base_config.rules[rule].update(self.rules[rule]) else: base_config.rules[rule] = self.rules[rule] self.rules = base_config.rules if base_config.ignore is not None: self.ignore = base_config.ignore def parse(self, raw_content): try: conf = yaml.safe_load(raw_content) except Exception as e: raise YamlLintConfigError('invalid config: %s' % e) if type(conf) != dict: raise YamlLintConfigError('invalid config: not a dict') self.rules = conf.get('rules', {}) # Does this conf override another conf that we need to load? if 'extends' in conf: path = get_extended_config_file(conf['extends']) base = YamlLintConfig(file=path) try: self.extend(base) except Exception as e: raise YamlLintConfigError('invalid config: %s' % e) if 'ignore' in conf: if type(conf['ignore']) != str: raise YamlLintConfigError( 'invalid config: ignore should contain file patterns') self.ignore = pathspec.PathSpec.from_lines( 'gitwildmatch', conf['ignore'].splitlines()) def validate(self): for id in self.rules: try: rule = yamllint.rules.get(id) except Exception as e: raise YamlLintConfigError('invalid config: %s' % e) self.rules[id] = validate_rule_conf(rule, self.rules[id]) def validate_rule_conf(rule, conf): if conf is False or conf == 'disable': return False elif conf == 'enable': conf = {} if type(conf) == dict: if ('ignore' in conf and type(conf['ignore']) != pathspec.pathspec.PathSpec): if type(conf['ignore']) != str: raise YamlLintConfigError( 'invalid config: ignore should contain file patterns') conf['ignore'] = pathspec.PathSpec.from_lines( 'gitwildmatch', conf['ignore'].splitlines()) if 'level' not in conf: conf['level'] = 'error' elif conf['level'] not in ('error', 'warning'): raise YamlLintConfigError( 'invalid config: level should be "error" or "warning"') options = getattr(rule, 'CONF', {}) for optkey in conf: if optkey in ('ignore', 'level'): continue if optkey not in options: raise YamlLintConfigError( 'invalid config: unknown option "%s" for rule "%s"' % (optkey, rule.ID)) if type(options[optkey]) == tuple: if (conf[optkey] not in options[optkey] and type(conf[optkey]) not in options[optkey]): raise YamlLintConfigError( 'invalid config: option "%s" of "%s" should be in %s' % (optkey, rule.ID, options[optkey])) else: if type(conf[optkey]) != options[optkey]: raise YamlLintConfigError( 'invalid config: option "%s" of "%s" should be %s' % (optkey, rule.ID, options[optkey].__name__)) for optkey in options: if optkey not in conf: raise YamlLintConfigError( 'invalid config: missing option "%s" for rule "%s"' % (optkey, rule.ID)) else: raise YamlLintConfigError(('invalid config: rule "%s": should be ' 'either "enable", "disable" or a dict') % rule.ID) return conf def get_extended_config_file(name): # Is it a standard conf shipped with yamllint... if '/' not in name: std_conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf', name + '.yaml') if os.path.isfile(std_conf): return std_conf # or a custom conf on filesystem? return name yamllint-1.10.0/yamllint/rules/0000755000232200023220000000000013177553503016764 5ustar debalancedebalanceyamllint-1.10.0/yamllint/rules/truthy.py0000644000232200023220000000466713177553503020712 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Peter Ericson # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to forbid truthy values that are not quoted nor explicitly typed. This would prevent YAML parsers from transforming ``[yes, FALSE, Off]`` into ``[true, false, false]`` or ``{y: 1, yes: 2, on: 3, true: 4, True: 5}`` into ``{y: 1, true: 5}``. .. rubric:: Examples #. With ``truthy: {}`` the following code snippet would **PASS**: :: boolean: true object: {"True": 1, 1: "True"} "yes": 1 "on": 2 "true": 3 "True": 4 explicit: string1: !!str True string2: !!str yes string3: !!str off encoded: !!binary | True OFF pad== # this decodes as 'N\xbb\x9e8Qii' boolean1: !!bool true boolean2: !!bool "false" boolean3: !!bool FALSE boolean4: !!bool True boolean5: !!bool off boolean6: !!bool NO the following code snippet would **FAIL**: :: object: {True: 1, 1: True} the following code snippet would **FAIL**: :: yes: 1 on: 2 true: 3 True: 4 """ import yaml from yamllint.linter import LintProblem ID = 'truthy' TYPE = 'token' CONF = {} TRUTHY = ['YES', 'Yes', 'yes', 'NO', 'No', 'no', 'TRUE', 'True', # 'true' is a boolean 'FALSE', 'False', # 'false' is a boolean 'ON', 'On', 'on', 'OFF', 'Off', 'off'] def check(conf, token, prev, next, nextnext, context): if prev and isinstance(prev, yaml.tokens.TagToken): return if isinstance(token, yaml.tokens.ScalarToken): if token.value in TRUTHY and token.style is None: yield LintProblem(token.start_mark.line + 1, token.start_mark.column + 1, "truthy value is not quoted") yamllint-1.10.0/yamllint/rules/trailing_spaces.py0000644000232200023220000000314213177553503022505 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to forbid trailing spaces at the end of lines. .. rubric:: Examples #. With ``trailing-spaces: {}`` the following code snippet would **PASS**: :: this document doesn't contain any trailing spaces the following code snippet would **FAIL**: :: this document contains """ """ trailing spaces on lines 1 and 3 """ """ """ import string from yamllint.linter import LintProblem ID = 'trailing-spaces' TYPE = 'line' def check(conf, line): if line.end == 0: return # YAML recognizes two white space characters: space and tab. # http://yaml.org/spec/1.2/spec.html#id2775170 pos = line.end while line.buffer[pos - 1] in string.whitespace and pos > line.start: pos -= 1 if pos != line.end and line.buffer[pos] in ' \t': yield LintProblem(line.line_no, pos - line.start + 1, 'trailing spaces') yamllint-1.10.0/yamllint/rules/indentation.py0000644000232200023220000004477513177553503021673 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the indentation. .. rubric:: Options * ``spaces`` defines the indentation width, in spaces. Set either to an integer (e.g. ``2`` or ``4``, representing the number of spaces in an indentation level) or to ``consistent`` to allow any number, as long as it remains the same within the file. * ``indent-sequences`` defines whether block sequences should be indented or not (when in a mapping, this indentation is not mandatory -- some people perceive the ``-`` as part of the indentation). Possible values: ``true``, ``false``, ``whatever`` and ``consistent``. ``consistent`` requires either all block sequences to be indented, or none to be. ``whatever`` means either indenting or not indenting individual block sequences is OK. * ``check-multi-line-strings`` defines whether to lint indentation in multi-line strings. Set to ``true`` to enable, ``false`` to disable. .. rubric:: Examples #. With ``indentation: {spaces: 1}`` the following code snippet would **PASS**: :: history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle #. With ``indentation: {spaces: 4}`` the following code snippet would **PASS**: :: history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle the following code snippet would **FAIL**: :: history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle #. With ``indentation: {spaces: consistent}`` the following code snippet would **PASS**: :: history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle the following code snippet would **FAIL**: :: some: Russian: dolls #. With ``indentation: {spaces: 2, indent-sequences: false}`` the following code snippet would **PASS**: :: list: - flying - spaghetti - monster the following code snippet would **FAIL**: :: list: - flying - spaghetti - monster #. With ``indentation: {spaces: 2, indent-sequences: whatever}`` the following code snippet would **PASS**: :: list: - flying: - spaghetti - monster - not flying: - spaghetti - sauce #. With ``indentation: {spaces: 2, indent-sequences: consistent}`` the following code snippet would **PASS**: :: - flying: - spaghetti - monster - not flying: - spaghetti - sauce the following code snippet would **FAIL**: :: - flying: - spaghetti - monster - not flying: - spaghetti - sauce #. With ``indentation: {spaces: 4, check-multi-line-strings: true}`` the following code snippet would **PASS**: :: Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte. the following code snippet would **PASS**: :: Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte. the following code snippet would **FAIL**: :: Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte. the following code snippet would **FAIL**: :: C code: void main() { printf("foo"); } the following code snippet would **PASS**: :: C code: void main() { printf("bar"); } """ import yaml from yamllint.linter import LintProblem from yamllint.rules.common import is_explicit_key, get_real_end_line ID = 'indentation' TYPE = 'token' CONF = {'spaces': (int, 'consistent'), 'indent-sequences': (bool, 'whatever', 'consistent'), 'check-multi-line-strings': bool} ROOT, B_MAP, F_MAP, B_SEQ, F_SEQ, B_ENT, KEY, VAL = range(8) labels = ('ROOT', 'B_MAP', 'F_MAP', 'B_SEQ', 'F_SEQ', 'B_ENT', 'KEY', 'VAL') class Parent(object): def __init__(self, type, indent, line_indent=None): self.type = type self.indent = indent self.line_indent = line_indent self.explicit_key = False self.implicit_block_seq = False def __repr__(self): return '%s:%d' % (labels[self.type], self.indent) def check_scalar_indentation(conf, token, context): if token.start_mark.line == token.end_mark.line: return def compute_expected_indent(found_indent): def detect_indent(base_indent): if type(context['spaces']) is not int: context['spaces'] = found_indent - base_indent return base_indent + context['spaces'] if token.plain: return token.start_mark.column elif token.style in ('"', "'"): return token.start_mark.column + 1 elif token.style in ('>', '|'): if context['stack'][-1].type == B_ENT: # - > # multi # line return detect_indent(token.start_mark.column) elif context['stack'][-1].type == KEY: assert context['stack'][-1].explicit_key # - ? > # multi-line # key # : > # multi-line # value return detect_indent(token.start_mark.column) elif context['stack'][-1].type == VAL: if token.start_mark.line + 1 > context['cur_line']: # - key: # > # multi # line return detect_indent(context['stack'][-1].indent) elif context['stack'][-2].explicit_key: # - ? key # : > # multi-line # value return detect_indent(token.start_mark.column) else: # - key: > # multi # line return detect_indent(context['stack'][-2].indent) else: return detect_indent(context['stack'][-1].indent) expected_indent = None line_no = token.start_mark.line + 1 line_start = token.start_mark.pointer while True: line_start = token.start_mark.buffer.find( '\n', line_start, token.end_mark.pointer - 1) + 1 if line_start == 0: break line_no += 1 indent = 0 while token.start_mark.buffer[line_start + indent] == ' ': indent += 1 if token.start_mark.buffer[line_start + indent] == '\n': continue if expected_indent is None: expected_indent = compute_expected_indent(indent) if indent != expected_indent: yield LintProblem(line_no, indent + 1, 'wrong indentation: expected %d but found %d' % (expected_indent, indent)) def _check(conf, token, prev, next, nextnext, context): if 'stack' not in context: context['stack'] = [Parent(ROOT, 0)] context['cur_line'] = -1 context['spaces'] = conf['spaces'] context['indent-sequences'] = conf['indent-sequences'] # Step 1: Lint is_visible = ( not isinstance(token, (yaml.StreamStartToken, yaml.StreamEndToken)) and not isinstance(token, yaml.BlockEndToken) and not (isinstance(token, yaml.ScalarToken) and token.value == '')) first_in_line = (is_visible and token.start_mark.line + 1 > context['cur_line']) def detect_indent(base_indent, next): if type(context['spaces']) is not int: context['spaces'] = next.start_mark.column - base_indent return base_indent + context['spaces'] if first_in_line: found_indentation = token.start_mark.column expected = context['stack'][-1].indent if isinstance(token, (yaml.FlowMappingEndToken, yaml.FlowSequenceEndToken)): expected = context['stack'][-1].line_indent elif (context['stack'][-1].type == KEY and context['stack'][-1].explicit_key and not isinstance(token, yaml.ValueToken)): expected = detect_indent(expected, token) if found_indentation != expected: yield LintProblem(token.start_mark.line + 1, found_indentation + 1, 'wrong indentation: expected %d but found %d' % (expected, found_indentation)) if (isinstance(token, yaml.ScalarToken) and conf['check-multi-line-strings']): for problem in check_scalar_indentation(conf, token, context): yield problem # Step 2.a: if is_visible: context['cur_line'] = get_real_end_line(token) if first_in_line: context['cur_line_indent'] = found_indentation # Step 2.b: Update state if isinstance(token, yaml.BlockMappingStartToken): # - a: 1 # or # - ? a # : 1 # or # - ? # a # : 1 assert isinstance(next, yaml.KeyToken) assert next.start_mark.line == token.start_mark.line indent = token.start_mark.column context['stack'].append(Parent(B_MAP, indent)) elif isinstance(token, yaml.FlowMappingStartToken): if next.start_mark.line == token.start_mark.line: # - {a: 1, b: 2} indent = next.start_mark.column else: # - { # a: 1, b: 2 # } indent = detect_indent(context['cur_line_indent'], next) context['stack'].append(Parent(F_MAP, indent, line_indent=context['cur_line_indent'])) elif isinstance(token, yaml.BlockSequenceStartToken): # - - a # - b assert isinstance(next, yaml.BlockEntryToken) assert next.start_mark.line == token.start_mark.line indent = token.start_mark.column context['stack'].append(Parent(B_SEQ, indent)) elif (isinstance(token, yaml.BlockEntryToken) and # in case of an empty entry not isinstance(next, (yaml.BlockEntryToken, yaml.BlockEndToken))): # It looks like pyyaml doesn't issue BlockSequenceStartTokens when the # list is not indented. We need to compensate that. if context['stack'][-1].type != B_SEQ: context['stack'].append(Parent(B_SEQ, token.start_mark.column)) context['stack'][-1].implicit_block_seq = True if next.start_mark.line == token.end_mark.line: # - item 1 # - item 2 indent = next.start_mark.column elif next.start_mark.column == token.start_mark.column: # - # key: value indent = next.start_mark.column else: # - # item 1 # - # key: # value indent = detect_indent(token.start_mark.column, next) context['stack'].append(Parent(B_ENT, indent)) elif isinstance(token, yaml.FlowSequenceStartToken): if next.start_mark.line == token.start_mark.line: # - [a, b] indent = next.start_mark.column else: # - [ # a, b # ] indent = detect_indent(context['cur_line_indent'], next) context['stack'].append(Parent(F_SEQ, indent, line_indent=context['cur_line_indent'])) elif isinstance(token, yaml.KeyToken): indent = context['stack'][-1].indent context['stack'].append(Parent(KEY, indent)) context['stack'][-1].explicit_key = is_explicit_key(token) elif isinstance(token, yaml.ValueToken): assert context['stack'][-1].type == KEY # Special cases: # key: &anchor # value # and: # key: !!tag # value if isinstance(next, (yaml.AnchorToken, yaml.TagToken)): if (next.start_mark.line == prev.start_mark.line and next.start_mark.line < nextnext.start_mark.line): next = nextnext # Only if value is not empty if not isinstance(next, (yaml.BlockEndToken, yaml.FlowMappingEndToken, yaml.FlowSequenceEndToken, yaml.KeyToken)): if context['stack'][-1].explicit_key: # ? k # : value # or # ? k # : # value indent = detect_indent(context['stack'][-1].indent, next) elif next.start_mark.line == prev.start_mark.line: # k: value indent = next.start_mark.column elif isinstance(next, (yaml.BlockSequenceStartToken, yaml.BlockEntryToken)): # NOTE: We add BlockEntryToken in the test above because # sometimes BlockSequenceStartToken are not issued. Try # yaml.scan()ning this: # '- lib:\n' # ' - var\n' if context['indent-sequences'] is False: indent = context['stack'][-1].indent elif context['indent-sequences'] is True: if (context['spaces'] == 'consistent' and next.start_mark.column - context['stack'][-1].indent == 0): # In this case, the block sequence item is not indented # (while it should be), but we don't know yet the # indentation it should have (because `spaces` is # `consistent` and its value has not been computed yet # -- this is probably the beginning of the document). # So we choose an arbitrary value (2). indent = 2 else: indent = detect_indent(context['stack'][-1].indent, next) else: # 'whatever' or 'consistent' if next.start_mark.column == context['stack'][-1].indent: # key: # - e1 # - e2 if context['indent-sequences'] == 'consistent': context['indent-sequences'] = False indent = context['stack'][-1].indent else: if context['indent-sequences'] == 'consistent': context['indent-sequences'] = True # key: # - e1 # - e2 indent = detect_indent(context['stack'][-1].indent, next) else: # k: # value indent = detect_indent(context['stack'][-1].indent, next) context['stack'].append(Parent(VAL, indent)) consumed_current_token = False while True: if (context['stack'][-1].type == F_SEQ and isinstance(token, yaml.FlowSequenceEndToken) and not consumed_current_token): context['stack'].pop() consumed_current_token = True elif (context['stack'][-1].type == F_MAP and isinstance(token, yaml.FlowMappingEndToken) and not consumed_current_token): context['stack'].pop() consumed_current_token = True elif (context['stack'][-1].type in (B_MAP, B_SEQ) and isinstance(token, yaml.BlockEndToken) and not context['stack'][-1].implicit_block_seq and not consumed_current_token): context['stack'].pop() consumed_current_token = True elif (context['stack'][-1].type == B_ENT and not isinstance(token, yaml.BlockEntryToken) and context['stack'][-2].implicit_block_seq and not isinstance(token, (yaml.AnchorToken, yaml.TagToken)) and not isinstance(next, yaml.BlockEntryToken)): context['stack'].pop() context['stack'].pop() elif (context['stack'][-1].type == B_ENT and isinstance(next, (yaml.BlockEntryToken, yaml.BlockEndToken))): context['stack'].pop() elif (context['stack'][-1].type == VAL and not isinstance(token, yaml.ValueToken) and not isinstance(token, (yaml.AnchorToken, yaml.TagToken))): assert context['stack'][-2].type == KEY context['stack'].pop() context['stack'].pop() elif (context['stack'][-1].type == KEY and isinstance(next, (yaml.BlockEndToken, yaml.FlowMappingEndToken, yaml.FlowSequenceEndToken, yaml.KeyToken))): # A key without a value: it's part of a set. Let's drop this key # and leave room for the next one. context['stack'].pop() else: break def check(conf, token, prev, next, nextnext, context): try: for problem in _check(conf, token, prev, next, nextnext, context): yield problem except AssertionError: yield LintProblem(token.start_mark.line + 1, token.start_mark.column + 1, 'cannot infer indentation: unexpected token') yamllint-1.10.0/yamllint/rules/new_line_at_end_of_file.py0000644000232200023220000000251513177553503024136 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to require a new line character (``\\n``) at the end of files. The POSIX standard `requires the last line to end with a new line character `_. All UNIX tools expect a new line at the end of files. Most text editors use this convention too. """ from yamllint.linter import LintProblem ID = 'new-line-at-end-of-file' TYPE = 'line' def check(conf, line): if line.end == len(line.buffer) and line.end > line.start: yield LintProblem(line.line_no, line.end - line.start + 1, 'no new line character at the end of file') yamllint-1.10.0/yamllint/rules/hyphens.py0000644000232200023220000000364413177553503021023 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the number of spaces after hyphens (``-``). .. rubric:: Options * ``max-spaces-after`` defines the maximal number of spaces allowed after hyphens. .. rubric:: Examples #. With ``hyphens: {max-spaces-after: 1}`` the following code snippet would **PASS**: :: - first list: - a - b - - 1 - 2 - 3 the following code snippet would **FAIL**: :: - first list: - a - b the following code snippet would **FAIL**: :: - - 1 - 2 - 3 #. With ``hyphens: {max-spaces-after: 3}`` the following code snippet would **PASS**: :: - key - key2 - key42 the following code snippet would **FAIL**: :: - key - key2 - key42 """ import yaml from yamllint.rules.common import spaces_after ID = 'hyphens' TYPE = 'token' CONF = {'max-spaces-after': int} def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.BlockEntryToken): problem = spaces_after(token, prev, next, max=conf['max-spaces-after'], max_desc='too many spaces after hyphen') if problem is not None: yield problem yamllint-1.10.0/yamllint/rules/key_duplicates.py0000644000232200023220000000533013177553503022344 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to prevent multiple entries with the same key in mappings. .. rubric:: Examples #. With ``key-duplicates: {}`` the following code snippet would **PASS**: :: - key 1: v key 2: val key 3: value - {a: 1, b: 2, c: 3} the following code snippet would **FAIL**: :: - key 1: v key 2: val key 1: value the following code snippet would **FAIL**: :: - {a: 1, b: 2, b: 3} the following code snippet would **FAIL**: :: duplicated key: 1 "duplicated key": 2 other duplication: 1 ? >- other duplication : 2 """ import yaml from yamllint.linter import LintProblem ID = 'key-duplicates' TYPE = 'token' CONF = {} MAP, SEQ = range(2) class Parent(object): def __init__(self, type): self.type = type self.keys = [] def check(conf, token, prev, next, nextnext, context): if 'stack' not in context: context['stack'] = [] if isinstance(token, (yaml.BlockMappingStartToken, yaml.FlowMappingStartToken)): context['stack'].append(Parent(MAP)) elif isinstance(token, (yaml.BlockSequenceStartToken, yaml.FlowSequenceStartToken)): context['stack'].append(Parent(SEQ)) elif isinstance(token, (yaml.BlockEndToken, yaml.FlowMappingEndToken, yaml.FlowSequenceEndToken)): context['stack'].pop() elif (isinstance(token, yaml.KeyToken) and isinstance(next, yaml.ScalarToken)): # This check is done because KeyTokens can be found inside flow # sequences... strange, but allowed. if len(context['stack']) > 0 and context['stack'][-1].type == MAP: if next.value in context['stack'][-1].keys: yield LintProblem( next.start_mark.line + 1, next.start_mark.column + 1, 'duplication of key "%s" in mapping' % next.value) else: context['stack'][-1].keys.append(next.value) yamllint-1.10.0/yamllint/rules/colons.py0000644000232200023220000000530513177553503020636 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the number of spaces before and after colons (``:``). .. rubric:: Options * ``max-spaces-before`` defines the maximal number of spaces allowed before colons (use ``-1`` to disable). * ``max-spaces-after`` defines the maximal number of spaces allowed after colons (use ``-1`` to disable). .. rubric:: Examples #. With ``colons: {max-spaces-before: 0, max-spaces-after: 1}`` the following code snippet would **PASS**: :: object: - a - b key: value #. With ``colons: {max-spaces-before: 1}`` the following code snippet would **PASS**: :: object : - a - b the following code snippet would **FAIL**: :: object : - a - b #. With ``colons: {max-spaces-after: 2}`` the following code snippet would **PASS**: :: first: 1 second: 2 third: 3 the following code snippet would **FAIL**: :: first: 1 2nd: 2 third: 3 """ import yaml from yamllint.rules.common import spaces_after, spaces_before, is_explicit_key ID = 'colons' TYPE = 'token' CONF = {'max-spaces-before': int, 'max-spaces-after': int} def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.ValueToken): problem = spaces_before(token, prev, next, max=conf['max-spaces-before'], max_desc='too many spaces before colon') if problem is not None: yield problem problem = spaces_after(token, prev, next, max=conf['max-spaces-after'], max_desc='too many spaces after colon') if problem is not None: yield problem if isinstance(token, yaml.KeyToken) and is_explicit_key(token): problem = spaces_after(token, prev, next, max=conf['max-spaces-after'], max_desc='too many spaces after question mark') if problem is not None: yield problem yamllint-1.10.0/yamllint/rules/brackets.py0000644000232200023220000001051513177553503021136 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the number of spaces inside brackets (``[`` and ``]``). .. rubric:: Options * ``min-spaces-inside`` defines the minimal number of spaces required inside brackets. * ``max-spaces-inside`` defines the maximal number of spaces allowed inside brackets. * ``min-spaces-inside-empty`` defines the minimal number of spaces required inside empty brackets. * ``max-spaces-inside-empty`` defines the maximal number of spaces allowed inside empty brackets. .. rubric:: Examples #. With ``brackets: {min-spaces-inside: 0, max-spaces-inside: 0}`` the following code snippet would **PASS**: :: object: [1, 2, abc] the following code snippet would **FAIL**: :: object: [ 1, 2, abc ] #. With ``brackets: {min-spaces-inside: 1, max-spaces-inside: 3}`` the following code snippet would **PASS**: :: object: [ 1, 2, abc ] the following code snippet would **PASS**: :: object: [ 1, 2, abc ] the following code snippet would **FAIL**: :: object: [ 1, 2, abc ] the following code snippet would **FAIL**: :: object: [1, 2, abc ] #. With ``brackets: {min-spaces-inside-empty: 0, max-spaces-inside-empty: 0}`` the following code snippet would **PASS**: :: object: [] the following code snippet would **FAIL**: :: object: [ ] #. With ``brackets: {min-spaces-inside-empty: 1, max-spaces-inside-empty: -1}`` the following code snippet would **PASS**: :: object: [ ] the following code snippet would **FAIL**: :: object: [] """ import yaml from yamllint.rules.common import spaces_after, spaces_before ID = 'brackets' TYPE = 'token' CONF = {'min-spaces-inside': int, 'max-spaces-inside': int, 'min-spaces-inside-empty': int, 'max-spaces-inside-empty': int} def check(conf, token, prev, next, nextnext, context): if (isinstance(token, yaml.FlowSequenceStartToken) and isinstance(next, yaml.FlowSequenceEndToken)): problem = spaces_after(token, prev, next, min=(conf['min-spaces-inside-empty'] if conf['min-spaces-inside-empty'] != -1 else conf['min-spaces-inside']), max=(conf['max-spaces-inside-empty'] if conf['max-spaces-inside-empty'] != -1 else conf['max-spaces-inside']), min_desc='too few spaces inside empty brackets', max_desc=('too many spaces inside empty ' 'brackets')) if problem is not None: yield problem elif isinstance(token, yaml.FlowSequenceStartToken): problem = spaces_after(token, prev, next, min=conf['min-spaces-inside'], max=conf['max-spaces-inside'], min_desc='too few spaces inside brackets', max_desc='too many spaces inside brackets') if problem is not None: yield problem elif (isinstance(token, yaml.FlowSequenceEndToken) and (prev is None or not isinstance(prev, yaml.FlowSequenceStartToken))): problem = spaces_before(token, prev, next, min=conf['min-spaces-inside'], max=conf['max-spaces-inside'], min_desc='too few spaces inside brackets', max_desc='too many spaces inside brackets') if problem is not None: yield problem yamllint-1.10.0/yamllint/rules/key_ordering.py0000644000232200023220000000602513177553503022022 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2017 Johannes F. Knauf # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ 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 case-sensitive and not accent-friendly (see examples below). .. rubric:: Examples #. With ``key-ordering: {}`` the following code snippet would **PASS**: :: - key 1: v key 2: val key 3: value - {a: 1, b: 2, c: 3} - T-shirt: 1 T-shirts: 2 t-shirt: 3 t-shirts: 4 - hair: true hais: true haïr: true haïssable: true the following code snippet would **FAIL**: :: - key 2: v key 1: val the following code snippet would **FAIL**: :: - {b: 1, a: 2} the following code snippet would **FAIL**: :: - T-shirt: 1 t-shirt: 2 T-shirts: 3 t-shirts: 4 the following code snippet would **FAIL**: :: - haïr: true hais: true """ import yaml from yamllint.linter import LintProblem ID = 'key-ordering' TYPE = 'token' CONF = {} MAP, SEQ = range(2) class Parent(object): def __init__(self, type): self.type = type self.keys = [] def check(conf, token, prev, next, nextnext, context): if 'stack' not in context: context['stack'] = [] if isinstance(token, (yaml.BlockMappingStartToken, yaml.FlowMappingStartToken)): context['stack'].append(Parent(MAP)) elif isinstance(token, (yaml.BlockSequenceStartToken, yaml.FlowSequenceStartToken)): context['stack'].append(Parent(SEQ)) elif isinstance(token, (yaml.BlockEndToken, yaml.FlowMappingEndToken, yaml.FlowSequenceEndToken)): context['stack'].pop() elif (isinstance(token, yaml.KeyToken) and isinstance(next, yaml.ScalarToken)): # This check is done because KeyTokens can be found inside flow # sequences... strange, but allowed. if len(context['stack']) > 0 and context['stack'][-1].type == MAP: if any(next.value < key for key in context['stack'][-1].keys): yield LintProblem( next.start_mark.line + 1, next.start_mark.column + 1, 'wrong ordering of key "%s" in mapping' % next.value) else: context['stack'][-1].keys.append(next.value) yamllint-1.10.0/yamllint/rules/common.py0000644000232200023220000000623213177553503020631 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import string import yaml from yamllint.linter import LintProblem def spaces_after(token, prev, next, min=-1, max=-1, min_desc=None, max_desc=None): if next is not None and token.end_mark.line == next.start_mark.line: spaces = next.start_mark.pointer - token.end_mark.pointer if max != - 1 and spaces > max: return LintProblem(token.start_mark.line + 1, next.start_mark.column, max_desc) elif min != - 1 and spaces < min: return LintProblem(token.start_mark.line + 1, next.start_mark.column + 1, min_desc) def spaces_before(token, prev, next, min=-1, max=-1, min_desc=None, max_desc=None): if (prev is not None and prev.end_mark.line == token.start_mark.line and # Discard tokens (only scalars?) that end at the start of next line (prev.end_mark.pointer == 0 or prev.end_mark.buffer[prev.end_mark.pointer - 1] != '\n')): spaces = token.start_mark.pointer - prev.end_mark.pointer if max != - 1 and spaces > max: return LintProblem(token.start_mark.line + 1, token.start_mark.column, max_desc) elif min != - 1 and spaces < min: return LintProblem(token.start_mark.line + 1, token.start_mark.column + 1, min_desc) def get_line_indent(token): """Finds the indent of the line the token starts in.""" start = token.start_mark.buffer.rfind('\n', 0, token.start_mark.pointer) + 1 content = start while token.start_mark.buffer[content] == ' ': content += 1 return content - start def get_real_end_line(token): """Finds the line on which the token really ends. With pyyaml, scalar tokens often end on a next line. """ end_line = token.end_mark.line + 1 if not isinstance(token, yaml.ScalarToken): return end_line pos = token.end_mark.pointer - 1 while (pos >= token.start_mark.pointer - 1 and token.end_mark.buffer[pos] in string.whitespace): if token.end_mark.buffer[pos] == '\n': end_line -= 1 pos -= 1 return end_line def is_explicit_key(token): # explicit key: # ? key # : v # or # ? # key # : v return (token.start_mark.pointer < token.end_mark.pointer and token.start_mark.buffer[token.start_mark.pointer] == '?') yamllint-1.10.0/yamllint/rules/__init__.py0000644000232200023220000000342413177553503021100 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from yamllint.rules import ( braces, brackets, colons, commas, comments, comments_indentation, document_end, document_start, empty_lines, empty_values, hyphens, indentation, key_duplicates, key_ordering, line_length, new_line_at_end_of_file, new_lines, trailing_spaces, truthy, ) _RULES = { braces.ID: braces, brackets.ID: brackets, colons.ID: colons, commas.ID: commas, comments.ID: comments, comments_indentation.ID: comments_indentation, document_end.ID: document_end, document_start.ID: document_start, empty_lines.ID: empty_lines, empty_values.ID: empty_values, hyphens.ID: hyphens, indentation.ID: indentation, key_duplicates.ID: key_duplicates, key_ordering.ID: key_ordering, line_length.ID: line_length, new_line_at_end_of_file.ID: new_line_at_end_of_file, new_lines.ID: new_lines, trailing_spaces.ID: trailing_spaces, truthy.ID: truthy, } def get(id): if id not in _RULES: raise ValueError('no such rule: "%s"' % id) return _RULES[id] yamllint-1.10.0/yamllint/rules/empty_values.py0000644000232200023220000000472013177553503022056 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2017 Greg Dubicki # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to prevent nodes with empty content, that implicitly result in ``null`` values. .. rubric:: Options * Use ``forbid-in-block-mappings`` to prevent empty values in block mappings. * Use ``forbid-in-flow-mappings`` to prevent empty values in flow mappings. .. rubric:: Examples #. With ``empty-values: {forbid-in-block-mappings: true}`` the following code snippets would **PASS**: :: some-mapping: sub-element: correctly indented :: explicitly-null: null the following code snippets would **FAIL**: :: some-mapping: sub-element: incorrectly indented :: implicitly-null: #. With ``empty-values: {forbid-in-flow-mappings: true}`` the following code snippet would **PASS**: :: {prop: null} {a: 1, b: 2, c: 3} the following code snippets would **FAIL**: :: {prop: } :: {a: 1, b:, c: 3} """ import yaml from yamllint.linter import LintProblem ID = 'empty-values' TYPE = 'token' CONF = {'forbid-in-block-mappings': bool, 'forbid-in-flow-mappings': bool} def check(conf, token, prev, next, nextnext, context): if conf['forbid-in-block-mappings']: if isinstance(token, yaml.ValueToken) and isinstance(next, ( yaml.KeyToken, yaml.BlockEndToken)): yield LintProblem(token.start_mark.line + 1, token.end_mark.column + 1, 'empty value in block mapping') if conf['forbid-in-flow-mappings']: if isinstance(token, yaml.ValueToken) and isinstance(next, ( yaml.FlowEntryToken, yaml.FlowMappingEndToken)): yield LintProblem(token.start_mark.line + 1, token.end_mark.column + 1, 'empty value in flow mapping') yamllint-1.10.0/yamllint/rules/new_lines.py0000644000232200023220000000304213177553503021320 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to force the type of new line characters. .. rubric:: Options * Set ``type`` to ``unix`` to use UNIX-typed new line characters (``\\n``), or ``dos`` to use DOS-typed new line characters (``\\r\\n``). """ from yamllint.linter import LintProblem ID = 'new-lines' TYPE = 'line' CONF = {'type': ('unix', 'dos')} def check(conf, line): if line.start == 0 and len(line.buffer) > line.end: if conf['type'] == 'dos': if line.buffer[line.end - 1:line.end + 1] != '\r\n': yield LintProblem(1, line.end - line.start + 1, 'wrong new line character: expected \\r\\n') else: if line.end > 0 and line.buffer[line.end - 1] == '\r': yield LintProblem(1, line.end - line.start, 'wrong new line character: expected \\n') yamllint-1.10.0/yamllint/rules/comments_indentation.py0000644000232200023220000000654113177553503023565 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to force comments to be indented like content. .. rubric:: Examples #. With ``comments-indentation: {}`` the following code snippet would **PASS**: :: # Fibonacci [0, 1, 1, 2, 3, 5] the following code snippet would **FAIL**: :: # Fibonacci [0, 1, 1, 2, 3, 5] the following code snippet would **PASS**: :: list: - 2 - 3 # - 4 - 5 the following code snippet would **FAIL**: :: list: - 2 - 3 # - 4 - 5 the following code snippet would **PASS**: :: # This is the first object obj1: - item A # - item B # This is the second object obj2: [] the following code snippet would **PASS**: :: # This sentence # is a block comment the following code snippet would **FAIL**: :: # This sentence # is a block comment """ import yaml from yamllint.linter import LintProblem from yamllint.rules.common import get_line_indent ID = 'comments-indentation' TYPE = 'comment' # Case A: # # prev: line: # # commented line # current: line # # Case B: # # prev: line # # commented line 1 # # commented line 2 # current: line def check(conf, comment): # Only check block comments if (not isinstance(comment.token_before, yaml.StreamStartToken) and comment.token_before.end_mark.line + 1 == comment.line_no): return next_line_indent = comment.token_after.start_mark.column if isinstance(comment.token_after, yaml.StreamEndToken): next_line_indent = 0 if isinstance(comment.token_before, yaml.StreamStartToken): prev_line_indent = 0 else: prev_line_indent = get_line_indent(comment.token_before) # In the following case only the next line indent is valid: # list: # # comment # - 1 # - 2 if prev_line_indent <= next_line_indent: prev_line_indent = next_line_indent # If two indents are valid but a previous comment went back to normal # indent, for the next ones to do the same. In other words, avoid this: # list: # - 1 # # comment on valid indent (0) # # comment on valid indent (4) # other-list: # - 2 if (comment.comment_before is not None and not comment.comment_before.is_inline()): prev_line_indent = comment.comment_before.column_no - 1 if (comment.column_no - 1 != prev_line_indent and comment.column_no - 1 != next_line_indent): yield LintProblem(comment.line_no, comment.column_no, 'comment not indented like content') yamllint-1.10.0/yamllint/rules/comments.py0000644000232200023220000000533413177553503021170 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the position and formatting of comments. .. rubric:: Options * Use ``require-starting-space`` to require a space character right after the ``#``. Set to ``true`` to enable, ``false`` to disable. * ``min-spaces-from-content`` is used to visually separate inline comments from content. It defines the minimal required number of spaces between a comment and its preceding content. .. rubric:: Examples #. With ``comments: {require-starting-space: true}`` the following code snippet would **PASS**: :: # This sentence # is a block comment the following code snippet would **PASS**: :: ############################## ## This is some documentation the following code snippet would **FAIL**: :: #This sentence #is a block comment #. With ``comments: {min-spaces-from-content: 2}`` the following code snippet would **PASS**: :: x = 2 ^ 127 - 1 # Mersenne prime number the following code snippet would **FAIL**: :: x = 2 ^ 127 - 1 # Mersenne prime number """ from yamllint.linter import LintProblem ID = 'comments' TYPE = 'comment' CONF = {'require-starting-space': bool, 'min-spaces-from-content': int} def check(conf, comment): if (conf['min-spaces-from-content'] != -1 and comment.is_inline() and comment.pointer - comment.token_before.end_mark.pointer < conf['min-spaces-from-content']): yield LintProblem(comment.line_no, comment.column_no, 'too few spaces before comment') if conf['require-starting-space']: text_start = comment.pointer + 1 while (comment.buffer[text_start] == '#' and text_start < len(comment.buffer)): text_start += 1 if (text_start < len(comment.buffer) and comment.buffer[text_start] not in (' ', '\n', '\0')): yield LintProblem(comment.line_no, comment.column_no + text_start - comment.pointer, 'missing starting space in comment') yamllint-1.10.0/yamllint/rules/commas.py0000644000232200023220000000706213177553503020622 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the number of spaces before and after commas (``,``). .. rubric:: Options * ``max-spaces-before`` defines the maximal number of spaces allowed before commas (use ``-1`` to disable). * ``min-spaces-after`` defines the minimal number of spaces required after commas. * ``max-spaces-after`` defines the maximal number of spaces allowed after commas (use ``-1`` to disable). .. rubric:: Examples #. With ``commas: {max-spaces-before: 0}`` the following code snippet would **PASS**: :: strange var: [10, 20, 30, {x: 1, y: 2}] the following code snippet would **FAIL**: :: strange var: [10, 20 , 30, {x: 1, y: 2}] #. With ``commas: {max-spaces-before: 2}`` the following code snippet would **PASS**: :: strange var: [10 , 20 , 30, {x: 1 , y: 2}] #. With ``commas: {max-spaces-before: -1}`` the following code snippet would **PASS**: :: strange var: [10, 20 , 30 , {x: 1, y: 2}] #. With ``commas: {min-spaces-after: 1, max-spaces-after: 1}`` the following code snippet would **PASS**: :: strange var: [10, 20,30, {x: 1, y: 2}] the following code snippet would **FAIL**: :: strange var: [10, 20,30, {x: 1, y: 2}] #. With ``commas: {min-spaces-after: 1, max-spaces-after: 3}`` the following code snippet would **PASS**: :: strange var: [10, 20, 30, {x: 1, y: 2}] #. With ``commas: {min-spaces-after: 0, max-spaces-after: 1}`` the following code snippet would **PASS**: :: strange var: [10, 20,30, {x: 1, y: 2}] """ import yaml from yamllint.linter import LintProblem from yamllint.rules.common import spaces_after, spaces_before ID = 'commas' TYPE = 'token' CONF = {'max-spaces-before': int, 'min-spaces-after': int, 'max-spaces-after': int} def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.FlowEntryToken): if (prev is not None and conf['max-spaces-before'] != -1 and prev.end_mark.line < token.start_mark.line): yield LintProblem(token.start_mark.line + 1, max(1, token.start_mark.column), 'too many spaces before comma') else: problem = spaces_before(token, prev, next, max=conf['max-spaces-before'], max_desc='too many spaces before comma') if problem is not None: yield problem problem = spaces_after(token, prev, next, min=conf['min-spaces-after'], max=conf['max-spaces-after'], min_desc='too few spaces after comma', max_desc='too many spaces after comma') if problem is not None: yield problem yamllint-1.10.0/yamllint/rules/document_end.py0000644000232200023220000000514213177553503022004 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to require or forbid the use of document end marker (``...``). .. rubric:: Options * Set ``present`` to ``true`` when the document end marker is required, or to ``false`` when it is forbidden. .. rubric:: Examples #. With ``document-end: {present: true}`` the following code snippet would **PASS**: :: --- this: is: [a, document] ... --- - this - is: another one ... the following code snippet would **FAIL**: :: --- this: is: [a, document] --- - this - is: another one ... #. With ``document-end: {present: false}`` the following code snippet would **PASS**: :: --- this: is: [a, document] --- - this - is: another one the following code snippet would **FAIL**: :: --- this: is: [a, document] ... --- - this - is: another one """ import yaml from yamllint.linter import LintProblem ID = 'document-end' TYPE = 'token' CONF = {'present': bool} def check(conf, token, prev, next, nextnext, context): if conf['present']: if (isinstance(token, yaml.StreamEndToken) and not (isinstance(prev, yaml.DocumentEndToken) or isinstance(prev, yaml.StreamStartToken))): yield LintProblem(token.start_mark.line, 1, 'missing document end "..."') elif (isinstance(token, yaml.DocumentStartToken) and not (isinstance(prev, yaml.DocumentEndToken) or isinstance(prev, yaml.StreamStartToken))): yield LintProblem(token.start_mark.line + 1, 1, 'missing document end "..."') else: if isinstance(token, yaml.DocumentEndToken): yield LintProblem(token.start_mark.line + 1, token.start_mark.column + 1, 'found forbidden document end "..."') yamllint-1.10.0/yamllint/rules/document_start.py0000644000232200023220000000455113177553503022376 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to require or forbid the use of document start marker (``---``). .. rubric:: Options * Set ``present`` to ``true`` when the document start marker is required, or to ``false`` when it is forbidden. .. rubric:: Examples #. With ``document-start: {present: true}`` the following code snippet would **PASS**: :: --- this: is: [a, document] --- - this - is: another one the following code snippet would **FAIL**: :: this: is: [a, document] --- - this - is: another one #. With ``document-start: {present: false}`` the following code snippet would **PASS**: :: this: is: [a, document] ... the following code snippet would **FAIL**: :: --- this: is: [a, document] ... """ import yaml from yamllint.linter import LintProblem ID = 'document-start' TYPE = 'token' CONF = {'present': bool} def check(conf, token, prev, next, nextnext, context): if conf['present']: if (isinstance(prev, (yaml.StreamStartToken, yaml.DocumentEndToken, yaml.DirectiveToken)) and not isinstance(token, (yaml.DocumentStartToken, yaml.DirectiveToken, yaml.StreamEndToken))): yield LintProblem(token.start_mark.line + 1, 1, 'missing document start "---"') else: if isinstance(token, yaml.DocumentStartToken): yield LintProblem(token.start_mark.line + 1, token.start_mark.column + 1, 'found forbidden document start "---"') yamllint-1.10.0/yamllint/rules/empty_lines.py0000644000232200023220000000537013177553503021673 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to set a maximal number of allowed consecutive blank lines. .. rubric:: Options * ``max`` defines the maximal number of empty lines allowed in the document. * ``max-start`` defines the maximal number of empty lines allowed at the beginning of the file. This option takes precedence over ``max``. * ``max-end`` defines the maximal number of empty lines allowed at the end of the file. This option takes precedence over ``max``. .. rubric:: Examples #. With ``empty-lines: {max: 1}`` the following code snippet would **PASS**: :: - foo: - 1 - 2 - bar: [3, 4] the following code snippet would **FAIL**: :: - foo: - 1 - 2 - bar: [3, 4] """ from yamllint.linter import LintProblem ID = 'empty-lines' TYPE = 'line' CONF = {'max': int, 'max-start': int, 'max-end': int} def check(conf, line): if line.start == line.end and line.end < len(line.buffer): # Only alert on the last blank line of a series if (line.end < len(line.buffer) - 1 and line.buffer[line.end + 1] == '\n'): return blank_lines = 0 while (line.start > blank_lines and line.buffer[line.start - blank_lines - 1] == '\n'): blank_lines += 1 max = conf['max'] # Special case: start of document if line.start - blank_lines == 0: blank_lines += 1 # first line doesn't have a preceding \n max = conf['max-start'] # Special case: end of document # NOTE: The last line of a file is always supposed to end with a new # line. See POSIX definition of a line at: if line.end == len(line.buffer) - 1 and line.buffer[line.end] == '\n': # Allow the exception of the one-byte file containing '\n' if line.end == 0: return max = conf['max-end'] if blank_lines > max: yield LintProblem(line.line_no, 1, 'too many blank lines (%d > %d)' % (blank_lines, max)) yamllint-1.10.0/yamllint/rules/line_length.py0000644000232200023220000001061513177553503021631 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to set a limit to lines length. .. rubric:: Options * ``max`` defines the maximal (inclusive) length of lines. * ``allow-non-breakable-words`` is used to allow non breakable words (without spaces inside) to overflow the limit. This is useful for long URLs, for instance. Use ``true`` to allow, ``false`` to forbid. * ``allow-non-breakable-inline-mappings`` implies ``allow-non-breakable-words`` and extends it to also allow non-breakable words in inline mappings. .. rubric:: Examples #. With ``line-length: {max: 70}`` the following code snippet would **PASS**: :: long sentence: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. the following code snippet would **FAIL**: :: long sentence: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. #. With ``line-length: {max: 60, allow-non-breakable-words: true}`` the following code snippet would **PASS**: :: this: is: - a: http://localhost/very/very/very/very/very/very/very/very/long/url # this comment is too long, # but hard to split: # http://localhost/another/very/very/very/very/very/very/very/very/long/url the following code snippet would **FAIL**: :: - this line is waaaaaaaaaaaaaay too long but could be easily split... and the following code snippet would also **FAIL**: :: - foobar: http://localhost/very/very/very/very/very/very/very/very/long/url #. With ``line-length: {max: 60, allow-non-breakable-words: true, allow-non-breakable-inline-mappings: true}`` the following code snippet would **PASS**: :: - foobar: http://localhost/very/very/very/very/very/very/very/very/long/url #. With ``line-length: {max: 60, allow-non-breakable-words: false}`` the following code snippet would **FAIL**: :: this: is: - a: http://localhost/very/very/very/very/very/very/very/very/long/url """ import yaml from yamllint.linter import LintProblem ID = 'line-length' TYPE = 'line' CONF = {'max': int, 'allow-non-breakable-words': bool, 'allow-non-breakable-inline-mappings': bool} def check_inline_mapping(line): loader = yaml.SafeLoader(line.content) try: while loader.peek_token(): if isinstance(loader.get_token(), yaml.BlockMappingStartToken): while loader.peek_token(): if isinstance(loader.get_token(), yaml.ValueToken): t = loader.get_token() if isinstance(t, yaml.ScalarToken): return ( ' ' not in line.content[t.start_mark.column:]) except yaml.scanner.ScannerError: pass return False def check(conf, line): if line.end - line.start > conf['max']: conf['allow-non-breakable-words'] |= \ conf['allow-non-breakable-inline-mappings'] if conf['allow-non-breakable-words']: start = line.start while start < line.end and line.buffer[start] == ' ': start += 1 if start != line.end: if line.buffer[start] in ('#', '-'): start += 2 if line.buffer.find(' ', start, line.end) == -1: return if (conf['allow-non-breakable-inline-mappings'] and check_inline_mapping(line)): return yield LintProblem(line.line_no, conf['max'] + 1, 'line too long (%d > %d characters)' % (line.end - line.start, conf['max'])) yamllint-1.10.0/yamllint/rules/braces.py0000644000232200023220000001044413177553503020600 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Use this rule to control the number of spaces inside braces (``{`` and ``}``). .. rubric:: Options * ``min-spaces-inside`` defines the minimal number of spaces required inside braces. * ``max-spaces-inside`` defines the maximal number of spaces allowed inside braces. * ``min-spaces-inside-empty`` defines the minimal number of spaces required inside empty braces. * ``max-spaces-inside-empty`` defines the maximal number of spaces allowed inside empty braces. .. rubric:: Examples #. With ``braces: {min-spaces-inside: 0, max-spaces-inside: 0}`` the following code snippet would **PASS**: :: object: {key1: 4, key2: 8} the following code snippet would **FAIL**: :: object: { key1: 4, key2: 8 } #. With ``braces: {min-spaces-inside: 1, max-spaces-inside: 3}`` the following code snippet would **PASS**: :: object: { key1: 4, key2: 8 } the following code snippet would **PASS**: :: object: { key1: 4, key2: 8 } the following code snippet would **FAIL**: :: object: { key1: 4, key2: 8 } the following code snippet would **FAIL**: :: object: {key1: 4, key2: 8 } #. With ``braces: {min-spaces-inside-empty: 0, max-spaces-inside-empty: 0}`` the following code snippet would **PASS**: :: object: {} the following code snippet would **FAIL**: :: object: { } #. With ``braces: {min-spaces-inside-empty: 1, max-spaces-inside-empty: -1}`` the following code snippet would **PASS**: :: object: { } the following code snippet would **FAIL**: :: object: {} """ import yaml from yamllint.rules.common import spaces_after, spaces_before ID = 'braces' TYPE = 'token' CONF = {'min-spaces-inside': int, 'max-spaces-inside': int, 'min-spaces-inside-empty': int, 'max-spaces-inside-empty': int} def check(conf, token, prev, next, nextnext, context): if (isinstance(token, yaml.FlowMappingStartToken) and isinstance(next, yaml.FlowMappingEndToken)): problem = spaces_after(token, prev, next, min=(conf['min-spaces-inside-empty'] if conf['min-spaces-inside-empty'] != -1 else conf['min-spaces-inside']), max=(conf['max-spaces-inside-empty'] if conf['max-spaces-inside-empty'] != -1 else conf['max-spaces-inside']), min_desc='too few spaces inside empty braces', max_desc='too many spaces inside empty braces') if problem is not None: yield problem elif isinstance(token, yaml.FlowMappingStartToken): problem = spaces_after(token, prev, next, min=conf['min-spaces-inside'], max=conf['max-spaces-inside'], min_desc='too few spaces inside braces', max_desc='too many spaces inside braces') if problem is not None: yield problem elif (isinstance(token, yaml.FlowMappingEndToken) and (prev is None or not isinstance(prev, yaml.FlowMappingStartToken))): problem = spaces_before(token, prev, next, min=conf['min-spaces-inside'], max=conf['max-spaces-inside'], min_desc='too few spaces inside braces', max_desc='too many spaces inside braces') if problem is not None: yield problem yamllint-1.10.0/yamllint/parser.py0000644000232200023220000001160113177553503017477 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import yaml class Line(object): def __init__(self, line_no, buffer, start, end): self.line_no = line_no self.start = start self.end = end self.buffer = buffer @property def content(self): return self.buffer[self.start:self.end] class Token(object): def __init__(self, line_no, curr, prev, next, nextnext): self.line_no = line_no self.curr = curr self.prev = prev self.next = next self.nextnext = nextnext class Comment(object): def __init__(self, line_no, column_no, buffer, pointer, token_before=None, token_after=None, comment_before=None): self.line_no = line_no self.column_no = column_no self.buffer = buffer self.pointer = pointer self.token_before = token_before self.token_after = token_after self.comment_before = comment_before def __str__(self): end = self.buffer.find('\n', self.pointer) if end == -1: end = self.buffer.find('\0', self.pointer) if end != -1: return self.buffer[self.pointer:end] return self.buffer[self.pointer:] def __eq__(self, other): return (isinstance(other, Comment) and self.line_no == other.line_no and self.column_no == other.column_no and str(self) == str(other)) def is_inline(self): return ( not isinstance(self.token_before, yaml.StreamStartToken) and self.line_no == self.token_before.end_mark.line + 1 and # sometimes token end marks are on the next line self.buffer[self.token_before.end_mark.pointer - 1] != '\n' ) def line_generator(buffer): line_no = 1 cur = 0 next = buffer.find('\n') while next != -1: yield Line(line_no, buffer, start=cur, end=next) cur = next + 1 next = buffer.find('\n', cur) line_no += 1 yield Line(line_no, buffer, start=cur, end=len(buffer)) def comments_between_tokens(token1, token2): """Find all comments between two tokens""" if token2 is None: buf = token1.end_mark.buffer[token1.end_mark.pointer:] elif (token1.end_mark.line == token2.start_mark.line and not isinstance(token1, yaml.StreamStartToken) and not isinstance(token2, yaml.StreamEndToken)): return else: buf = token1.end_mark.buffer[token1.end_mark.pointer: token2.start_mark.pointer] line_no = token1.end_mark.line + 1 column_no = token1.end_mark.column + 1 pointer = token1.end_mark.pointer comment_before = None for line in buf.split('\n'): pos = line.find('#') if pos != -1: comment = Comment(line_no, column_no + pos, token1.end_mark.buffer, pointer + pos, token1, token2, comment_before) yield comment comment_before = comment pointer += len(line) + 1 line_no += 1 column_no = 1 def token_or_comment_generator(buffer): yaml_loader = yaml.BaseLoader(buffer) try: prev = None curr = yaml_loader.get_token() while curr is not None: next = yaml_loader.get_token() nextnext = yaml_loader.peek_token() yield Token(curr.start_mark.line + 1, curr, prev, next, nextnext) for comment in comments_between_tokens(curr, next): yield comment prev = curr curr = next except yaml.scanner.ScannerError: pass def token_or_comment_or_line_generator(buffer): """Generator that mixes tokens and lines, ordering them by line number""" tok_or_com_gen = token_or_comment_generator(buffer) line_gen = line_generator(buffer) tok_or_com = next(tok_or_com_gen, None) line = next(line_gen, None) while tok_or_com is not None or line is not None: if tok_or_com is None or (line is not None and tok_or_com.line_no > line.line_no): yield line line = next(line_gen, None) else: yield tok_or_com tok_or_com = next(tok_or_com_gen, None) yamllint-1.10.0/.travis.yml0000644000232200023220000000104613177553503016113 0ustar debalancedebalance--- language: python python: - 2.6 - 2.7 - 3.3 - 3.4 - 3.5 - 3.6 - nightly install: - pip install pyyaml flake8 flake8-import-order coveralls sphinx - if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pip install unittest2; fi - pip install . script: - if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then flake8 .; fi - yamllint --strict $(git ls-files '*.yaml' '*.yml') - coverage run --source=yamllint setup.py test - if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then python setup.py build_sphinx; fi after_success: coveralls yamllint-1.10.0/setup.cfg0000644000232200023220000000023513177553503015622 0ustar debalancedebalance[bdist_wheel] universal = 1 [flake8] import-order-style = pep8 [build_sphinx] all-files = 1 source-dir = docs build-dir = docs/_build warning-is-error = 1 yamllint-1.10.0/setup.py0000644000232200023220000000362513177553503015521 0ustar debalancedebalance# -*- coding: utf-8 -*- # Copyright (C) 2016 Adrien Vergé # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from setuptools import setup, find_packages from yamllint import (__author__, __license__, APP_NAME, APP_VERSION, APP_DESCRIPTION) setup( name=APP_NAME, version=APP_VERSION, author=__author__, description=APP_DESCRIPTION.split('\n')[0], long_description=APP_DESCRIPTION, license=__license__, keywords=['yaml', 'lint', 'linter', 'syntax', 'checker'], url='https://github.com/adrienverge/yamllint', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'Topic :: Software Development', 'Topic :: Software Development :: Debuggers', 'Topic :: Software Development :: Quality Assurance', 'Topic :: Software Development :: Testing', ], packages=find_packages(exclude=['tests', 'tests.*']), entry_points={'console_scripts': ['yamllint=yamllint.cli:run']}, package_data={'yamllint': ['conf/*.yaml']}, install_requires=['pathspec >=0.5.3', 'pyyaml'], test_suite='tests', ) yamllint-1.10.0/LICENSE0000644000232200023220000010451313177553503015012 0ustar debalancedebalance GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .