PyYAML implements YAML spec version 1.1, not 1.2. Hence, values starting
with `0o` are not considered as numbers: they are just strings, so they
need quotes when `quoted-strings: {required: true}`.
>>> import yaml
>>> yaml.resolver.Resolver().resolve(yaml.nodes.ScalarNode, '100', (True, False))
'tag:yaml.org,2002:int'
>>> yaml.resolver.Resolver().resolve(yaml.nodes.ScalarNode, '0100', (True, False))
'tag:yaml.org,2002:int'
>>> yaml.resolver.Resolver().resolve(yaml.nodes.ScalarNode, '0o100', (True, False))
'tag:yaml.org,2002:str'
Let's try to prevent that.
Fixes https://github.com/adrienverge/yamllint/issues/351.
We'd like to disallow brackets and braces in our YAML, but there's a
catch: the only way to describe an empty array or hash in YAML is to
supply an empty one (`[]` or `{}`). Otherwise, the value will be null.
This commit adds a `non-empty` option to `forbid` for brackets and
braces. When it is set, all flow and sequence mappings will cause errors
_except_ for empty ones.
Using `python setup.py test` is now deprecated [1], users are encouraged
to be explicit about the test command.
Running yamllint tests using the Python standard library (`unittest`)
can be done using:
python -m unittest discover
Why not nose, tox or pytest? Because they would add a dependency, make
tests running more complicated and verbose for new users, and their
benefit is not worth for this simple project (only 2 runtime
dependencies: PyYAML and pathspec).
Resolves https://github.com/adrienverge/yamllint/issues/328.
[1]: https://github.com/pypa/setuptools/pull/1878
Quick PR to ignore the `/.eggs` folder, which appears to be generated every
time the `python setup.py test` command is run.
The content of the `./.eggs/README.txt` file:
> This directory contains eggs that were downloaded by setuptools to build,
> test, and run plug-ins.
>
> This directory caches those eggs to prevent repeated downloads.
>
> However, it is safe to delete this directory.
Fixes#325
The linter allows a directive to contain trailing whitespace characters like
\r, but does not trim them before iterating on the rules. As a result, the last
rule in the list contains the trailing whitespace characters and never matches
any existing rule.
I added the necessary trimming, as well as a test with 2 checks to go along
with it.
yamllint depends on pkg_resources.load_entry_point from setuptools to
make its command working, so this runtime dependency to setuptools is
necessary to be listed.
Add 'forbid' configuration parameters to the braces and brackets rules
to allow users to forbid the use of flow style collections, flow
mappings and flow sequences.
Move setuptools' packaging configuration from setup.py to setup.cfg to
simplify setup.py and make its packaging more dedeclarative.
Signed-off-by: Satoru SATOH <satoru.satoh@gmail.com>
Pound-signs followed by a lone CRLF should not
raise if require-starting-space is specified.
If require-starting-space is true, *and* either:
- new-lines: disbale, or
- newlines: type: dos
is specified, a line with `#\r` or `#\r\n` should
not raise a false positive.
This commit also uses a Set for O(1) membership testing
and uses the correct escape sequence for the nul byte.
If we find a CRLF when looking for Unix newlines, yamllint
should always raise, regardless of logic with
require-starting-space.
Closes: Issue #171.
Add ability to:
- require strings to be quoted if they match a pattern (PCRE regex)
- allow quoted strings if they match a pattern, while `require:
only-when-needed` is enforced.
Co-Authored-By: Leo Feyer (https://github.com/adrienverge/yamllint/pull/246)