Commit Graph

114 Commits (404656394cc0fd1f3f962a143ab738673037ea40)

Author SHA1 Message Date
Greg Dubicki 8537b0a164 Add rule: empty-values, to forbid implicit nulls
only in block mappings for now
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é 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é 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é 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é 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
Adrien Vergé 5b62548ece Tests: indentation: Use 'spaces: consistent' by default 9 years ago
Adrien Vergé 8fca8a7a33 Config: Allow 'enable' keyword for rules
In the same manner as 'disable', 'enable' allows setting a rule on
without worrying about its options.
9 years ago
Adrien Vergé 5693b1dddf Rules: indentation: Add 'consistent' option for 'spaces'
Using `spaces: consistent` allows any number of spaces, as long as it
remains the same within the file.
9 years ago
Adrien Vergé 647d84ff94 Rules: indentation: Handle tags 9 years ago
Adrien Vergé 4bc3d5a01c Rules: indentation: Handle anchors 9 years ago
Adrien Vergé 48c7d65c54 parser: Provide nextnext for token rules
Because the indentation rule sometimes needs to look two tokens forward
(in case of anchors for instance).
9 years ago
Adrien Vergé 62fa4cbe39 Tests: indentation: Test the indent stack
The "indentation stack" is iteratively built by the `check()` function
of the indentation rule. It is important, since everything in the rule
relies on it.

This patch adds tests to make sure the stack is correctly built for some
known structures.
9 years ago
Adrien Vergé 9a82b99d4b Rules: indentation: Fix multi-line flows
To detect this as correct indentations:

    top:
      rules: [
        {
          foo: 1
        },
        {
          foo: 2
          bar: [
            a, b, c
          ],
        },
      ]
9 years ago
Adrien Vergé f6bab05e8a Rules: Add the 'key-duplicates' rule 9 years ago
Adrien Vergé 6b5948c06b Tests: Reorganize common and global tests 9 years ago
Adrien Vergé dd163ed551 Rules: indentation: Fix flow sequences with multi-line scalars
Typically sequences like this:

    ["multi
      line 1", "multi
                line 2"]
9 years ago
Adrien Vergé 14c99da2bb Tests: Add test cases for empty flows 9 years ago
Adrien Vergé cae100071a Rules: indentation: Add support for cleared sequence entries
The following construction is valid YAML, and its indentation should be
correctly handled:

    - this is
    -
      a
    -
      sequence:
        with cleared entries
9 years ago
Adrien Vergé 7cb7b4f669 Rules: commas: Add 'min-spaces-after'
Since such constructions are allowed and valid YAML:

    - [one,two, three,four]

this commit adds a `min-spaces-after` option that defaults to 1.
9 years ago
Adrien Vergé 4410bc3e23 Rules: indentation: Fix check-multi-line-strings
For strings that continue on next line at a lower indentation level:

    Blaise Pascal: Je vous écris une longue lettre parce que
      je n'ai pas le temps d'en écrire une courte.
9 years ago
Adrien Vergé 97c446907c Rules: line-length: Add option `allow-non-breakable-words` 9 years ago
Adrien Vergé 5ed496f471 Distribution: Remove unneeded `setup_requires`
With the new project layout, `pyyaml` is not needed anymore for parsing
setup.py.
9 years ago
Adrien Vergé fc108e7cee Config: Refactor to use YamlLintConfig objects 9 years ago
Adrien Vergé 1bfd18097a Rules: indentation: Add 'check-multi-line-strings' option
This options allows the user to control whether to lint indentation
inside multi-line scalars or not.

When enabled, such YAML source will be detected as a problem:

    - C code: void main() {
                  printf("foo");
              }

whereas this one would not:

    - C code: void main() {
              printf("foo");
              }
9 years ago
Adrien Vergé 67d13d60ae Rules: indentation: Check multi-line scalars 9 years ago
Adrien Vergé 96465008ab Rules: Fix `spaces_before` when prev is multi-line scalar
YAML content like the following one produced an error, because the
multi-line ScalarToken ends at the beginning of the 4th line (the one
with the value):

    ? >
        multi-line
        key
    : value
9 years ago
Adrien Vergé 847f7e3fff Rules: comments: Fix bug when multi-line scalar
YAML content like the following one produced an error, because the
ScalarToken associated whose value is "this is plain text" ends at the
beginning of the 5th line (the one with the comment):

    ---
    string: >
      this is plain text

    # comment
9 years ago
Adrien Vergé 6a24781f96 Tests: indentation: Add explicit keys test cases 9 years ago
Adrien Vergé 0b0251bacc Rules: indentation: Add the 'indent-sequences' option
Using either 'yes', 'no' or 'whatever', the user will be able to choose
whether to force block sequence items to be indented, to force them not
to be indented, or don't care, respectively.
9 years ago
Adrien Vergé 8288a6f331 Rules: colons: Apply to '?' also 9 years ago
Adrien Vergé 9d8b0d4d2c Rules: commas: Don't allow a comma on a new line
Forbid such constructions:

    [ a, b, c
      , d, e ]
9 years ago
Adrien Vergé 39c878c819 Rules: indentation: Rewrite the algorithm (again)
Use a new, better thought algorithm that keeps an history stack with all
the parents indentations.
9 years ago
Adrien Vergé 222f7a27c1 Make syntax errors prevail over all yamllint problems 9 years ago
Adrien Vergé effb4db3b4 Tests: Rules: Remove unused `line` and `column` args
Now that every test case use the `problem=(x, y)` syntax.
9 years ago
Adrien Vergé f09aef4f89 Rules: comments-indentation: Allow two levels
Previously only comments that were indented like the following content
line were allowed, e.g.:

    prev: line:
      # commented line
      current: line

With this change, such new cases are also allowed:

      prev: line
      # commented line 1
    # commented line 2
    current: line
9 years ago
Adrien Vergé 97e2210ec9 Don't treat non-importable YAML as syntax error
`yaml.load()` exceptions are not necessarily syntax errors. For
instance, the following YAML source cannot be `load()`ed into a Python
object, but is valid nonetheless:

    ? - Detroit Tigers
      - Chicago cubs
    :
      - 2001-07-23

    ? [ New York Yankees,
        Atlanta Braves ]
    : [ 2001-07-02, 2001-08-12,
        2001-08-14 ]

This commit detects syntax errors from `yaml.parse()` exceptions rather
than `yaml.load_all()`.
9 years ago
Adrien Vergé 233a70adb3 Rules: Add the 'comments-indentation' rule 9 years ago
Adrien Vergé e81b73c111 Rules: indentation: Rewrite algorithm 9 years ago
Adrien Vergé 3989a09d32 Rules: comments: Allow empty comments 9 years ago
Adrien Vergé 5cc900f2a8 Rules: document-start: Allow directives 9 years ago
Adrien Vergé 851b9ac42c Rules: Add the 'comments' rule 9 years ago
Adrien Vergé 5c4c208b98 Rules: Add the 'braces' rule 9 years ago
Adrien Vergé d08eb22081 Rules: Add the 'brackets' rule 9 years ago
Adrien Vergé a5b384ab21 Rules: Add the 'commas' rule 9 years ago
Adrien Vergé 07c5b4177c Rewrite syntax errors handling and test them
If a syntax errors occurs at the same place than a regular yamllint rule
error, only the yamllint one is issued.
9 years ago
Adrien Vergé 350213b165 Initial commit 9 years ago