Commit Graph

154 Commits (d32d1f65ad9600d10f9f6c3fab915e25404b139c)

Author SHA1 Message Date
Adrien Vergé d32d1f65ad WIP - test by Adrien 4 years ago
Satoru SATOH 6abce4e9a9 enhancement: enable rules' plugin support
Enable rules' plugin support and add its test cases.
4 years ago
Satoru SATOH 1c15ad1adc enhancement: add lint rules plugin support
Add plugin support using setuptools (pkg_resources) plugin mechanism to
yamllint to allow users to add their own custom lint rule plugins,
together with an example plugin implementation and test cases.

Signed-off-by: Satoru SATOH <satoru.satoh@gmail.com>
4 years ago
Mathieu Couette 027d1b0a9a
directives: Fix DOS lines messing with rule IDs
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.
4 years ago
Andrew Imeson 67cb4eb24d Auto-change output format if GitHub Actions detected 4 years ago
Andrew Imeson 50c7453824 Add support for GitHub Annotations output format
Support the format used by GitHub Actions to annotate pull
requests with linter failures
4 years ago
Satoru SATOH 333ae52c78 Add 'forbid' configurations to the braces and brackets rules
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.
4 years ago
Julien Falque 0a88c55194
quoted-strings: Fix detecting strings with hashtag as requiring quotes 4 years ago
Julien Falque ac19d1e427
octal-values: Prevent detection of 8 and 9 as octal values 4 years ago
Wolfgang Walther b80997eba6
CI: Add build environment without UTF-8 locales to travis-ci
Preventing regressions like #285
5 years ago
Wolfgang Walther b5b436a3a4
Add global "locale" config option and make key-ordering rule locale-aware
Support sorting by locale with strcoll(). Properly handle case and accents.

Note: this is a second implementation, for context see:
https://github.com/adrienverge/yamllint/pull/280
https://github.com/adrienverge/yamllint/issues/285
https://github.com/adrienverge/yamllint/pull/288
5 years ago
Adrien Vergé 9403f1f3ec Revert "Add global "locale" config option"
This reverts commit 9e90c77, because it caused a bug that affected
different people just after being released:
https://github.com/adrienverge/yamllint/issues/285
https://github.com/adrienverge/yamllint/issues/286
5 years ago
Wolfgang Walther 9e90c777cb
Add global "locale" config option and make key-ordering rule locale-aware
Support sorting by locale with strcoll(). Properly handle case and accents.
5 years ago
Jonathan Sokolowski a2218988ee
config: Do no match directories that look like YAML files
Fixes #279
5 years ago
Brad Solomon 512fe17047
Fix bug with CRLF in new-lines and require-starting-space
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.
5 years ago
Will Badart 94c0416f6b
Specify config with environment variable YAMLLINT_CONFIG_FILE
Add option to specify config file with environment variable.
Add test case.
5 years ago
Adrien Vergé b711fd993e quoted-strings: Add options extra-required and extra-allowed
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)
5 years ago
Adrien Vergé fa87913566 quoted-strings: Fix only-when-needed on corner cases
Change implementation of `required: only-when-needed`, because
maintaining a list of `START_TOKENS` and just looking at the first
character of string values has proven to be partially broken.

Cf. discussion at
https://github.com/adrienverge/yamllint/pull/246#issuecomment-612354097.

Fixes https://github.com/adrienverge/yamllint/issues/242 and
https://github.com/adrienverge/yamllint/pull/244.
5 years ago
Adrien Vergé ce7d3fcc7b quoted-strings: Remove test_quotes_required()
It is exactly the same tests as `test_quote_type_any()`.
5 years ago
Adrien Vergé 0bffba1e13 quoted-strings: Remove test_single_quotes_required()
It is exactly the same tests as `test_quote_type_single()`.
5 years ago
Adrien Vergé 2d8639c3a1 quoted-strings: Fix broken rule for list items
The rule worked for values like:

    flow-map: {a: foo, b: "bar"}
    block-map:
      a: foo
      b: "bar"

But not for:

    flow-seq: [foo, "bar"]
    block-seq:
      - foo
      - "bar"

Also add tests to make sure there will be no regression.

Fixes: #208.
5 years ago
Adrien Vergé e284d74be1 quoted-strings: Rename tests names for clarity
And move only-when-needed tests at the end for readability.
5 years ago
Adrien Vergé 46ed0c02be truthy: Add missing test removed from PR
See https://github.com/adrienverge/yamllint/pull/247#discussion_r405421376.
5 years ago
ilyam8 6ce11dedb4 truthy: add `check-keys` option 5 years ago
Rui Pinge 3a6a09b7b6 Add support for redundant quotes in quoted-strings rule
Co-Authored-By: Adrien Vergé
5 years ago
Rui Pinge 15aea73fbe
Fix quoted-strings rules not working for string values matching scalars 5 years ago
Martin Packman 91763f5476 Fix new-lines rule on Python 3
Use io.open() when reading files in cli which has the same behaviour
in Python 2 and Python 3, and supply the newline='' parameter which
handles but does not translate line endings.

Add dos.yml test file with windows newlines.

Also add to file finding test expected output.

Add test for new-lines rule through the cli.

Validates files are read with the correct universal newlines setting.

Fixes adrienverge/yamllint#228
5 years ago
Martin Packman 5b049e4229 Add RunContext helper for cli tests
Single context manager that includes exit code and output streams.

Use new RunContext throughout test_cli.

Largely non-functional change, saving some repetition of setup.

Also improve some failures by bundling multiple assertions into one.
5 years ago
Adrien Vergé 044c7f0248 cli: Test unicode chars in paths too 5 years ago
Sylvestre Ledru 43b95e99d1 Use 'syntax' as rule name upon syntax errors 5 years ago
ffapitalle 8fa9eb3ced Add --no-warnings option to suppress warning messages
Use `--no-warnings` option to hide warning messages. It only shows
problems marked as errors.
5 years ago
Joel Baranick fb400dc64b Allow disabling all checks for a file
Allow disabling of a file, even if it is invalid YAML (syntax error) by
including `# yamllint disable-file` in the first line.
5 years ago
Imran Iqbal 7359785ea0 fix(default.yaml): disable `empty-values` & `octal-values` by default
* Close #204
5 years ago
Adrien Vergé b62b424dd4 feat: Lint .yamllint by default 5 years ago
grzesuav 063c854658 feat: Make YAML file extensions configurable 6 years ago
Adrien Vergé 0ba193331b truthy: Validate options passed to 'allowed-values'
Make sure values passed in allowed values are correct ones. This is
possible thanks to previous commit, and should prevent users from
writing incorrect configurations.
6 years ago
Adrien Vergé f65553c4f7 config: Validate config options with list of enums
Allow rules to declare a list of valid values for an option.

For example, a rule like:

    CONF = {'allowed-values': list}

... allowed any value to be passed in the list (including bad ones).

It is now possible to declare:

    CONF = {'allowed-values': ['value1', 'value2', 'value3']}

... so that the list passed to the options must contain only values in
`['value1', 'value2', 'value3']`.
6 years ago
Ondrej Vaško 4ef7e05f3a truthy: Add allowed-values configuration option
Allows using key `allowed-values` for `truthy` section in configuration file (#150).

This allows to use configuration `truthy: allowed-values: ["yes", "no",
"..."]`, to set custom allowed truthy values.

This is especially useful for people using ansible, where values like
`yes` or `no` are valid and officially supported, but yamllint reports
them as illegal.

Implemented by difference of set of TRUTHY constants and configured
allowed values.

Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
6 years ago
Adrien Vergé fec2c2fba7 fix(parser): Correctly handle DOS new lines in 'line' rules
Do not consider the trailing `\r` of a line a part of it.
6 years ago
Miguel Barao 05dfcbc109 cli: Add command line option - to read from standard input
If YAML files are given as arguments, parses these files.
If yamllint is run with - option, stdin.
If no arguments are given, just fail.
6 years ago
Adrien Vergé b4740dc1fb comments: Fix ignore-shebangs option on corner cases 6 years ago
Mattias Bengtsson b77f78f677 Support ignoring shebangs
Some usages of YAML (like Ansible) supports running the file as a script.

Support (by default) an ignore-shebangs setting for the comments module.

Fixes #116 - comments rule with require-starting-space: true should special case shebang
6 years ago
Adrien Vergé 0f073f7a09 config: Do not require all rule options to be set
Before, it was required to specify all the options when customizing a
rule. For instance, one could use `empty-lines: enable` or `empty-lines:
{max: 1, max-start: 2, max-end: 2}`, but not just `empty-lines: {max:
1}` (it would fail with *invalid config: missing option "max-start" for
rule "empty-lines"*).

This was a minor problem for users, but it prevented the addition of new
options to existing rules, see [1] for an example. If a new option was
added, updating yamllint for all users that customize the rule would
produce a crash (*invalid config: missing option ...*).

To avoid that, let's embed default values inside the rules themselves,
instead of keeping them in `conf/default.yaml`.

This refactor should not have any impact on existing projects. I've
manually checked that it did not change the output of tests, on
different projects:
- ansible/ansible: `test/runner/ansible-test sanity --python 3.7 --test yamllint`
- ansible/molecule: `yamllint -s test/ molecule/`
- Neo23x0/sigma: `make test-yaml`
- markstory/lint-review: `yamllint .`

[1]: https://github.com/adrienverge/yamllint/pull/151
6 years ago
Hugo f4c56b8216 Upgrade Python syntax with pyupgrade
https://github.com/asottile/pyupgrade
6 years ago
Hugo 5852566ff0 Upgrade unit tests to use more useful asserts 6 years ago
Hugo 4a7986b4cf Remove redundant parentheses 6 years ago
Hugo c281d48507 Drop support for EOL Python 2.6 6 years ago
Adrien Vergé c8032c086b line-length: Add tests for lines containing unicode characters
Some unicode characters span accross multiple bytes. Python 3 is OK with
that, but Python 2 reports an incorrect number of characters.

Related to https://github.com/adrienverge/yamllint/issues/146
6 years ago
sedrubal 5062b91cac cli: Add -f colored to force colors
`-f standard` shows non-colored output,
`-f colored` shows colored output,
`-f auto` is the new default, it chooses `standard` or `colored`
depending on terminal capabilities.
6 years ago
Adrien Vergé 8354d50016 quoted-strings: Fix broken rule
Original implementation was completely broken. Documentation and actual
behavior were different. Numbers and booleans were detected as wrong, as
well as explicit types.

Fixes #136 and #130.
6 years ago