Compare commits
8 Commits
proto/fix-
...
v1.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e6e851c5b | ||
|
|
edd4cca02f | ||
|
|
867970258e | ||
|
|
d0cb5998c4 | ||
|
|
a5c97220e7 | ||
|
|
598e5e4370 | ||
|
|
03076ee214 | ||
|
|
eabd349902 |
@@ -82,7 +82,7 @@ Usage
|
||||
yamllint -d relaxed file.yaml
|
||||
|
||||
# Use a custom lint configuration
|
||||
yamllint -c ~/myconfig file.yml
|
||||
yamllint -c /path/to/myconfig file-to-lint.yaml
|
||||
|
||||
.. code:: bash
|
||||
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
Configuration
|
||||
=============
|
||||
|
||||
yamllint uses a set of *rules* to check sources 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.
|
||||
yamllint uses a set of :doc:`rules <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, either name it ``.yamllint`` in your working
|
||||
directory, or use the ``-c`` option:
|
||||
To use a custom configuration file, use the ``-c`` option:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
yamllint -c ~/myconfig file.yaml
|
||||
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``
|
||||
- ``$HOME/.config/yamllint/config``
|
||||
|
||||
Finally if no config file is found, the default configuration is applied.
|
||||
|
||||
Default configuration
|
||||
---------------------
|
||||
|
||||
@@ -78,6 +78,12 @@ class LineLengthTestCase(RuleTestCase):
|
||||
' # 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)
|
||||
|
||||
conf = 'line-length: {max: 20, allow-non-breakable-words: no}'
|
||||
self.check('---\n' + 30 * 'A' + '\n', conf, problem=(2, 21))
|
||||
@@ -94,3 +100,9 @@ class LineLengthTestCase(RuleTestCase):
|
||||
' # 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))
|
||||
|
||||
@@ -153,6 +153,49 @@ class CommandLineTestCase(unittest.TestCase):
|
||||
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:
|
||||
|
||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
||||
|
||||
|
||||
APP_NAME = 'yamllint'
|
||||
APP_VERSION = '1.2.1'
|
||||
APP_VERSION = '1.2.2'
|
||||
APP_DESCRIPTION = __doc__
|
||||
|
||||
__author__ = u'Adrien Vergé'
|
||||
|
||||
@@ -86,6 +86,15 @@ def run(argv=None):
|
||||
'simultaneously.', file=sys.stderr)
|
||||
sys.exit(-1)
|
||||
|
||||
# User-global config is supposed to be in ~/.config/yamllint/config
|
||||
user_global_config = None
|
||||
if 'XDG_CONFIG_HOME' in os.environ:
|
||||
user_global_config = os.path.join(
|
||||
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
|
||||
elif 'HOME' in os.environ:
|
||||
user_global_config = os.path.join(
|
||||
os.environ['HOME'], '.config', 'yamllint', 'config')
|
||||
|
||||
try:
|
||||
if args.config_data is not None:
|
||||
if args.config_data != '' and ':' not in args.config_data:
|
||||
@@ -95,6 +104,8 @@ def run(argv=None):
|
||||
conf = YamlLintConfig(file=args.config_file)
|
||||
elif os.path.isfile('.yamllint'):
|
||||
conf = YamlLintConfig(file='.yamllint')
|
||||
elif user_global_config and os.path.isfile(user_global_config):
|
||||
conf = YamlLintConfig(file=user_global_config)
|
||||
else:
|
||||
conf = YamlLintConfig('extends: default')
|
||||
except YamlLintConfigError as e:
|
||||
|
||||
@@ -62,7 +62,7 @@ CONF = {'max': 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 serie
|
||||
# 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
|
||||
|
||||
@@ -59,7 +59,7 @@ Use this rule to set a limit to lines length.
|
||||
the following code snippet would **FAIL**:
|
||||
::
|
||||
|
||||
- this line is waaaaaaaaaaaaaay too long but could be easily splitted...
|
||||
- this line is waaaaaaaaaaaaaay too long but could be easily split...
|
||||
|
||||
#. With ``line-length: {max: 60, allow-non-breakable-words: no}``
|
||||
|
||||
@@ -90,7 +90,7 @@ def check(conf, line):
|
||||
start += 1
|
||||
|
||||
if start != line.end:
|
||||
if line.buffer[start] == '#':
|
||||
if line.buffer[start] in ('#', '-'):
|
||||
start += 2
|
||||
|
||||
if line.buffer.find(' ', start, line.end) == -1:
|
||||
|
||||
Reference in New Issue
Block a user