Commit Graph

104 Commits (v1.12.0)

Author SHA1 Message Date
Guido Wischrop (mgm tp) aaa8777f1d Add quoted-strings rule
* taken from https://github.com/adrienverge/yamllint/pull/110 (submitted by @jurajseffer)
* small fixes for generic and multi-line strings
* fixes for comments from @adrienverge
6 years ago
Nick Burke 1b379628d7 key-duplicates: Handle merge keys (<<)
Merge keys are described here: http://yaml.org/type/merge.html
They shouldn't be considered as duplicated keys.

Fixes https://github.com/adrienverge/yamllint/issues/88
7 years ago
xieenlong 22e792a433 Feature: checking octal numbers 7 years ago
Adrien Vergé f713dc8be2 style: Fix E100 and E202 errors reported by pycodestyle 7 years ago
Adrien Vergé 501def327d tests: Use `sys.executable` instead of hard-coded 'python'
To test yamllint as a module, tests run commands like
`python -m yamllint`. But some environments (like continuous integration
of Debian or CentOS) don't always include the `python` executable (they
use `python3` instead).

Let's dynamically detect the Python executable path.
7 years ago
Adrien Vergé ed5d319df8 tests: Use en_US.UTF-8 locale when C.UTF-8 not available
Some operating systems don't have the `C.UTF-8` locale installed yet
(for instance, CentOS 7). In such a case, fallback to `en_US.UTF-8` so
that tests can be run.

This follows commit 92ff315.
7 years ago
Adrien Vergé c4475ece34 empty-values: Add `forbid-in-flow-mappings` conf
This allows preventing implicit `null` from empty values in flow
mappings.

For example:

    {a:}

    {a:, b: 2}

    {
      a: {
        b: ,
        c: {
          d: 4,
          e:
        }
      },
      f:
    }
7 years ago
Greg Dubicki 8537b0a164 Add rule: empty-values, to forbid implicit nulls
only in block mappings for now
7 years ago
Adrien Vergé d422274563 style: Fix E722 errors reported by pycodestyle
Since a few days ago pycodestyle (formerly called pep8) has a new check:
E722 warning for bare except clauses.

Let's fix our code.
7 years ago
Adrien Vergé 773bfc0f3c key-ordering: Add more test cases and documentation 7 years ago
Johannes F. Knauf 1543d0e435 New rule key-ordering
closes #67
7 years ago
Adrien Vergé f82346dac7 indentation: Add more test cases for key following empty list 7 years ago
Tim Wade ca540c113b Fix indentation rule for key following empty list
If a key-value pair follows an empty list, i.e.:

```yaml
a:
-
b: c
```

yamllint will complain:

```
warning  wrong indentation: expected 2 but found 0  (indentation)
```

This is because it is expecting the second key to be a continuation of
the block entry above:

```yaml
a:
-
  b: c
```

However, both are perfectly valid, though structurally different.
7 years ago
Adrien Vergé 1a961bd4b0 chore(tests): Also run tests on Python 2.6 8 years ago
Adrien Vergé df26cc0438 feat(config): Add support to ignore paths on per-rule basis
Example of configuration to use this feature:

    # 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/*

Closes #43.
8 years ago
Adrien Vergé 342d7b49dd tests(cli): Create a temp test workspace only once
Do not re-create it for every test in the class.
8 years ago
Adrien Vergé 7d638d47b9 tests(cli): Refactor temp test workspace recreation
Make it simpler and re-usable.
8 years ago
sedrubal 30dfa78923
Use argparse mutually_exclusive_group for --config-file and --config-data
This does the same as your solution 😉
8 years ago
Adrien Vergé d6a81f1b23 Add tests for `python -m yamllint` 8 years ago
Adrien Vergé ff1c9ad221 Merge pull request #38 from jhriggs/feature/empty_braces_brackets
Add min-spaces-inside-empty, max-spaces-inside-empty to braces and brackets
8 years ago
Jim Riggs 4b2b57aa32 Rules: Add min-spaces-inside-empty and max-spaces-inside-empty
Add min-spaces-inside-empty and max-spaces-inside-empty to braces and
brackets to allow separate handling for empty and non-empty objects.
8 years ago
Adrien Vergé 228c47ab77 fix(indentation): Fix seq indent detection with consistent spaces
In the case when the conf is as follows:

    indentation:
      spaces: consistent
      indent-sequences: true

and there is no indented block before the first block sequence, and this
block sequence is not indented, then the spaces number is computed as
zero (while it obviously shouldn't be).

This causes such a document to fail on 4th line, instead of 2nd:

    a:
    - b
    c:
      - d

This commit fixes that, and adds corresponding tests.

Fixes: #39
8 years ago
Adrien Vergé 21e81b6435 fix(rules): Use `true`/`false`, not `yes`/`no`
Although `yes` and `no` are recognized as booleans by the pyyaml parser,
the correct keywords are `true` and `false` (as highlighted by the newly
added `truthy` rule).

This commit replaces the use of `yes`/`no` by `true`/`false` and
advertise it in the docs, but also makes sure this change is
backward-compatible (so that `yes` and `no` still work).
8 years ago
Adrien Vergé b97b6ad19b style(tests): Fix new flake8 errors
This change fixes new errors detected by the last version of pycodestyle
(2.2.0), which is a dependency of flake8:

    ./tests/test_spec_examples.py:51:1: E305 expected 2 blank lines
    after class or function definition, found 1
    ./tests/test_spec_examples.py:139:1: E305 expected 2 blank lines
    after class or function definition, found 1

See pycodestyle changelog at 2.2.0 and
https://github.com/PyCQA/pycodestyle/pull/593.
8 years ago
Jonathan Sokolowski 03e0f5aa6b Add strict mode argument to CLI 8 years ago
Adrien Vergé 6dae8f5b6e feat(truthy): Allow explicit types
With this change, we don't require quotes for truthy values that are
explicitly typed. For instance, the following examples are all
considered valid:

    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
8 years ago
Peter Ericson 5294ff5552 truthy: Add tests for explicit booleans
From @adrienverge
8 years ago
Peter Ericson 1f472bc144 Add rule: truthy, to forbid truthy values that are not quoted 8 years ago
Adrien Vergé f656cf42d2 fix(line-length): Wrap token scanning securely
With `allow-non-breakable-inline-mappings` enabled, every long line is
passed through `loader.peek_token()`. Even lines that are not valid
YAML. For this reason, this code must be wrapped in a `try`/`except`
block.

Closes: #21
8 years ago
Adrien Vergé d3cd8ba332 line-length: Generalize ...-inline-mappings for corner cases
This commit refactors the `allow-non-breakable-inline-mappings` logic to
use YAML tokens and avoid crashes or erroneous reports on cases like:

```yaml
- {a: "http://localhost/very/very/very/very/very/very/long/url"
   }
```

```yaml
dict:
  {a: long long long long long long long, b: nospace}
```

```yaml
- long_line: http://localhost/very/very/long/url
```

```yaml
long_line: and+some+space+at+the+end       <-- extra spaces
```

For reference see:
https://github.com/adrienverge/yamllint/pull/17#issuecomment-247805799
8 years ago
Allan Lewis e56a7c788c line_length: Extract inline logic to new config option
This commit extracts the inline mappings logic defined in the previous
commit to a separate config option, as suggested by @adrienverge. I'll
squash this into the previous commit if the change is accepted. (I named
the option slightly differently to what was suggested as I think my
proposal reads better without consulting the docs: I'd be happy to
reconsider this.)
8 years ago
Allan Lewis d017631aff line_length: Allow mapping values with long unbreakable lines 8 years ago
Adrien Vergé 5b98cd2053 feat(comments): Allow comments with multiple hash chars
This change make the `comments` rule accept comments that start with
multiple pound signs, e.g.:

    ##############################
    ## This is some documentation

Closes: #12
9 years ago
Adrien Vergé a2c68fdf9b feat(cli): Colour output only on TTY
When piping yamllint output to a file, "coloured" characters aren't
interpreted and pollute text formatting with glyphs like:

  �[4m./global.yaml�[0m
    �[2m1439:52�[0m   �[31merror�[0m    no new line character...

With this commit, stdout is checked: if it's a TTY then output is
coloured, otherwise output is simple text.

Closes: #14
9 years ago
Adrien Vergé 92ff315fb4 Tests: Set proper LC_ALL when decoding UTF-8 is needed
Make sure the default localization conditions on the "test system"
support UTF-8 encoding.
9 years ago
Adrien Vergé f4cebdc054 Tests: Run with LC_ALL=C for uniform tests
Use default (C) locale in all tests to make sure the localization
conditions are the same wherever tests are run.
9 years ago
Adrien Vergé c8ba8f7e99 linter: Fix UnicodeError when parsing comments
And add tests when reading non-ASCII strings and comments (both from
Python strings and from files).

Fixes: #10
9 years ago
Adrien Vergé 0eb310e102 Allow disabling yamllint checks using comments
Implement problem report disabling with comments in YAML source, for
instance:

    # 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

or:

    # yamllint disable rule:colons
    - Lorem       : ipsum
      dolor       : sit amet,
      consectetur : adipiscing elit
    # yamllint enable rule:colons

Closes: #8
9 years ago
Adrien Vergé cdd094220c parser: Add tests for `Comment.is_inline()` 9 years ago
Adrien Vergé 7a7d98c96a parser: Iterate over lines + tokens + comments
Instead of iterating over lines and tokens (and find comments between
tokens in the comment rules), add a new `Comment` type and set rules
with `type = 'comment'`.
9 years ago
Michele Bariani 867970258e Patch allow-non-breakable-words on '-' 9 years ago
Adrien Vergé eabd349902 Config: Allow a user-global configuration file
Instead of just looking for `.yamllint` in the current working
directory, also look for `~/.config/yamllint/config` (using
`$XDG_CONFIG_HOME` or `$HOME`, see [1] and [2] for information).

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.6.html
[2]: https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

Closes: #6
9 years ago
Adrien Vergé 59d5bffbec Tests: cli: Detect and handle the `-d ''` case 9 years ago
Adrien Vergé 53da21934d Tests: Add many `cli.run` test cases 9 years ago
Adrien Vergé 88ebcbbb93 Tests: Test cli.find_files_recursively 9 years ago
Adrien Vergé 08615ec4f8 Tests: config: Check the non-valid-yaml-config case 9 years ago
Adrien Vergé 29aceb430a Tests: indentation: Increase coverage 9 years ago
Adrien Vergé 76f47e91ca Rules: indentation: Handle imbricated flows correctly
The following source -- although not loadable by pyyaml -- is valid
YAML:

    {{key}}: value

This was processed badly by yamllint. The same for `[[value]]`,
`{{{{{moustaches}}}}}` or:

    {[val,
      {{key: val,
        key2}}]}

This patch corrects it and add corresponding test cases.

Related-to: #3
9 years ago
Adrien Vergé 46e9108419 Rules: indentation: Add 'consistent' option for 'indent-sequences'
Using `indent-sequences: consistent` allows block sequences to be
indented or not to be, as long as it remains the same within the file.
9 years ago
Adrien Vergé 9a7eec34b1 Rules: indentation: Fix `spaces: consitent` with broken flows 9 years ago