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

yml/plain-scalar should ignore 'yes'/'no'/'true'/'false'/etc. by default #174

Closed
neildaniels opened this issue Jul 27, 2022 · 2 comments · Fixed by #175
Closed

yml/plain-scalar should ignore 'yes'/'no'/'true'/'false'/etc. by default #174

neildaniels opened this issue Jul 27, 2022 · 2 comments · Fixed by #175
Labels
enhancement New feature or request

Comments

@neildaniels
Copy link

neildaniels commented Jul 27, 2022

Ran into an issue where an existing YAML file had 'yes' and 'no' specified.

The yml/plain-scalar rule was a little egregious and changed those to yes and no scalar boolean values. Because these are treated as true/false in YAML, the code consuming these errored about them being the wrong type. https://yaml.org/type/bool.html

Adding them to the ignorePatterns array was sufficient to address this, but this should be handled automatically. Any time one of the reserved words appears in quotes, they should remain in quotes.

Workaround:

{
    "extends": [
        "plugin:yml/standard"
    ],
    "rules": {
        "yml/plain-scalar": ["error", "always", {
            "ignorePatterns": [
                "[\\v\\f\\u0085\\u00a0\\u1680\\u180e\\u2000-\\u200b\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]",
                "y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF"
            ]
        }]
    }
}

Example YAML file:

    test:
      - ['y', 'Y', 'yes', 'Yes', 'YES', 'n', 'N', 'no', 'No', 'NO', 'true', 'True', 'TRUE', 'false', 'False', 'FALSE', 'on', 'On', 'ON', 'off', 'Off', 'OFF']
@ota-meshi
Copy link
Owner

Thank you for posting issue.

It is a YAML 1.1 specification that yes is treated as a bool. Currently this plugin only supports YAML>=1.2. Perhaps the most sensible solution is that this plugin supports YAML 1.1.

@ota-meshi
Copy link
Owner

ota-meshi commented Jul 28, 2022

I have released a new version of the parser and plugin.
Use the latest version and use the %YAML 1.1 directive, or specify "1.1" in parserOptions.defaultYAMLVersion.

https://github.com/ota-meshi/eslint-plugin-yml#parser-options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants