Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: interpreting GitHub actions "on:" as a truthy value #430

Closed
jamesbraza opened this issue Dec 23, 2021 · 16 comments
Closed

Comments

@jamesbraza
Copy link

Here is part of a GitHub action workflow foo.yml:

---
name: Foo

on:
  push:

Currently, yamllint==v1.26.3 invoked via pre-commit==v4.0.1 with --strict raises the following warning:

yamllint......................................................................Failed
- hook id: yamllint
- exit code: 2

.github/workflows/lint.yml
  4:1       warning  truthy value should be one of [false, true]  (truthy)

I believe yamllint's perception of on: being a truthy value is incorrect, and thus is a false positive warning.

For now, I am using this workaround:

---
name: Foo

on:  # yamllint disable-line rule:truthy
  push:
@adrienverge
Copy link
Owner

Before opening a new issue:

@jamesbraza
Copy link
Author

Ha you're right, I guess it didn't even occur to me that an on key could be considered truthy, and thus this'd be a dup. Thanks for your patience :)

After reviewing all the issues and docs linked, I think the one-line disable is the most desirable.

on:  # yamllint disable-line rule:truthy

I wish that check-keys: false or allowed-values: ['true', 'false', 'on'] didn't apply to all files. By accommodating GitHub Action's Workflow choice in using the key on, I have to relax a rule for all yaml files in my repo, something I don't want to do. I think the allowed-keys proposed here #344 (comment) was a useful idea, but it still has the problem of applying to all yaml files.

Is it possible to extend a .yamllint config twice? The first extends would be making the default .yamllint config for the entire repo, and the second extends would be making an exception that applies specifically to the .github/workflows subdirectory.

@mvz
Copy link

mvz commented Apr 23, 2022

I'm running into this problem as well. Has anyone tried to see if github actions accepts using

"on":
  push:

Update: I've tried and it seems to work fine.

@adrienverge
Copy link
Owner

adrienverge commented May 12, 2022

In response to message (deleted in the meantime by its author named "Error 404"):

@mvz Using "on" works but I think using "foo" is not a good idea because we use a linter (in many cases) to help us to keep our code with a consistent/homogeneous style. If you will use "key": value (with quotes) in one line and uses key: value (without quotes) in other lines then your code will not have a homogeneous style.

I think we should not modify our code, not adding # yamllint disable-line rule:truth or adding "on" because the code is ok, the issue is in the linter. While the bug is fixed we could configure our workflows to let us decide if a linter warning/error is actually an error or a false positive.

As already stated, this issue is a multi-duplicate, and the described behavior is not a false positive. Again, the option check-keys is probably what you're looking for.

@mvz
Copy link

mvz commented May 12, 2022

I think many people are not aware that on being truthy also applies to keys, in addition to values. I certainly wasn't.

@trallnag
Copy link

Interesting. I wonder how GitHub processes it internally. I've heard that they are using a custom YAML parser which ignores many parts of the YAML standard

trallnag added a commit to trallnag/ansible-role-aws-cli that referenced this issue Jun 30, 2022
Why? Making yamllint happy. It complains about it being a truthy
value which is correct.

See this issue as an example: <adrienverge/yamllint#430>
kaffarell pushed a commit to kaffarell/prometheus that referenced this issue Oct 3, 2022
Currently all the github actions return warnings because the "on"
keyword in the yaml files are being interpreted as a "truthy" value by
yamllint. To ignore this behavior I added a rule which ignores the "on".
See adrienverge/yamllint#430.

Signed-off-by: Gabriel Goller <gabriel.goller@acs.it>
roidelapluie pushed a commit to prometheus/prometheus that referenced this issue Oct 3, 2022
Currently all the github actions return warnings because the "on"
keyword in the yaml files are being interpreted as a "truthy" value by
yamllint. To ignore this behavior I added a rule which ignores the "on".
See adrienverge/yamllint#430.

Signed-off-by: Gabriel Goller <gabriel.goller@acs.it>

Signed-off-by: Gabriel Goller <gabriel.goller@acs.it>
Co-authored-by: Gabriel Goller <gabriel.goller@acs.it>
@adrienverge
Copy link
Owner

1.2 has been out there for quite a while.

True.
We could also decide that from a future version (say, 1.35), yamllint would treat input files as YAML 1.2 by default (in particular, yes and on would stop triggering errors). This would be a slight breaking change, but yamllint always tried to be 1.2-compatible.
@perlpunk what do you think?

@perlpunk
Copy link

perlpunk commented Jan 18, 2024

@adrienverge I wouldn't make the 1.2 behaviour the default. That could break too much I think. edit: but that's of course something you can decide better.

I am currently also thinking about how this could be configured in yamltidy, and I'm leaning towards a schema: key, that in my case (since yamltidy is new) would default to the 1.2 Core schema. But I would also like to allow additional things, for example it's possible that someone is using YAML 1.2 with the optional merge key, so yamltidy should know to not unquote a "<<" string. Not sure how the config for such extra things would look like yet.

@adrienverge
Copy link
Owner

yamltidy

That's cool!!

and I'm leaning towards a schema: key

This certainly is a good idea. In the yamllint case, it could be a configurable option in .yamllint conf, that would default to either 1.1 or 1.2 (to be decided). I propose that we use the same name (e.g. schema), for consistency between tools.

adrienverge added a commit that referenced this issue Jan 31, 2024
Specification of YAML ≤ 1.1 has 18 boolean values:

    true  | True  | TRUE | false | False | FALSE
    yes   | Yes   | YES  | no    | No    | NO
    on    | On    | ON   | off   | Off   | OFF

Whereas YAML 1.2 spec recognizes only 6:

    true  | True  | TRUE | false | False | FALSE

For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.

In the future, we should:
- implement a configuration option to declare the default YAML spec
  version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
  slight breaking change, but yamllint always tried to be
  1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].

Solves: #587

Related to: #559 #540 #430 #344 #247 #232 #158

[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge added a commit that referenced this issue Jan 31, 2024
Specification of YAML ≤ 1.1 has 18 boolean values:

    true  | True  | TRUE | false | False | FALSE
    yes   | Yes   | YES  | no    | No    | NO
    on    | On    | ON   | off   | Off   | OFF

Whereas YAML 1.2 spec recognizes only 6 [^1]:

    true  | True  | TRUE | false | False | FALSE

For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.

In the future, we should:
- implement a configuration option to declare the default YAML spec
  version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
  slight breaking change, but yamllint always tried to be
  1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].

Solves: #587

Related to: #559 #540 #430 #344 #247 #232 #158

[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
@adrienverge
Copy link
Owner

@perlpunk see #650 (for info I would find default-yaml-spec-version: 1.1 | 1.2 a good option name for yamllint configuration, I like the fact that it's explicit).

adrienverge added a commit that referenced this issue Feb 4, 2024
Specification of YAML ≤ 1.1 has 22 boolean values:

    y     | Y            | n     | N
    yes   | Yes   | YES  | no    | No    | NO
    true  | True  | TRUE | false | False | FALSE
    on    | On    | ON   | off   | Off   | OFF

Whereas YAML 1.2 spec recognizes only 6 [^1]:

    true  | True  | TRUE | false | False | FALSE

For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.

In the future, we should:
- implement a configuration option to declare the default YAML spec
  version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
  slight breaking change, but yamllint always tried to be
  1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].

Solves: #587

Related to: #559 #540 #430 #344 #247 #232 #158

[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge added a commit that referenced this issue Feb 6, 2024
Specification of YAML ≤ 1.1 has 22 boolean values:

    y     | Y            | n     | N
    yes   | Yes   | YES  | no    | No    | NO
    true  | True  | TRUE | false | False | FALSE
    on    | On    | ON   | off   | Off   | OFF

Whereas YAML 1.2 spec recognizes only 6 [^1]:

    true  | True  | TRUE | false | False | FALSE

For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.

In the future, we should:
- implement a configuration option to declare the default YAML spec
  version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
  slight breaking change, but yamllint always tried to be
  1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].

Solves: #587

Related to: #559 #540 #430 #344 #247 #232 #158

[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge added a commit that referenced this issue Feb 6, 2024
Specification of YAML ≤ 1.1 has 22 boolean values:

    y     | Y            | n     | N
    yes   | Yes   | YES  | no    | No    | NO
    true  | True  | TRUE | false | False | FALSE
    on    | On    | ON   | off   | Off   | OFF

Whereas YAML 1.2 spec recognizes only 6 [^1]:

    true  | True  | TRUE | false | False | FALSE

For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.

In the future, we should:
- implement a configuration option to declare the default YAML spec
  version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
  slight breaking change, but yamllint always tried to be
  1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].

Solves: #587

Related to: #559 #540 #430 #344 #247 #232 #158

[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)

Can't use "%YAML 1.2" directive because brakes Github Actions
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)

Can't use "%YAML 1.2" directive because brakes Github Actions
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)

Can't use "%YAML 1.2" directive because brakes Github Actions
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)

Can't use "%YAML 1.2" directive because brakes Github Actions
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-py that referenced this issue Jun 9, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-csharp that referenced this issue Jun 10, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-go that referenced this issue Jun 10, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-go that referenced this issue Jun 10, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-java that referenced this issue Jun 11, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-js that referenced this issue Jun 11, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-ts that referenced this issue Jun 12, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
sir-gon pushed a commit to sir-gon/algorithm-exercises-ts that referenced this issue Jun 12, 2024
False positive in "on:" adrienverge/yamllint#430 (comment)
Can't use "%YAML 1.2" directive because brakes Github Actions

How to split long command as multiple lines (cross-SO way) https://stackoverflow.com/a/65808412/6366150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants