joenye / coc-cfn-lint

Coc (coc.nvim) extension to lint CloudFormation via cfn-python-lint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get cfn-lint to work with coc

glnds opened this issue · comments

I can't get this plugin working. Other linting works fine. Cfn-lint on the cmd line also runs fine...
Not sure if there's a conflict with https://github.com/neoclide/coc-yaml
How can i tell to only lint certain files with coc-cfn-lint? like cfn-.yml and cnf-.yaml?

Two issues here:

  1. There is an issue with coc-yaml where it gives lint errors in YAML CloudFormation templates. I've tried a few workarounds and the only one that worked reliably for me is disabling linting in all YAML files:

    "yaml.validate": "false"

    Alternatively, you can keep linting enabled for all YAML files, and ignore most errors in CloudFormation templates by setting yaml.customTags. See here for an example of yaml.customTags.

  2. This plugin should lint alongside coc-yaml, even if linting is enabled in both. This plugin only lints a file if it detects the file as being valid CloudFormation. You can run :CocInfo inside vim to see the coc-cfn-lint logs and you'll see whether your file is being detected as CloudFormation. It currently doesn't do this check by looking at filename. Instead, it looks at file contents. By default, it will detect the file as CloudFormation if it contains both "AWSTemplateFormatVersion" and "Resources". In my case, I'm working with non-standard template files that don't always contain both these lines, so I have set the cfnlint.detectCfnRegExps as follows:

    "cfnlint.detectCfnRegExps": ["AWS::", "\\n?\"Resources\"?\\s*:"],

    These RegExps ensure the plugin will lint any file containing "AWS::" or "Resources:". If your file isn't being detected as valid CloudFormation, then consider adding your own RegExps here.

cfn-lint works fine now but i had to disable yaml linting.

"yaml.validate": "false"

Setting custom tags is not sufficient as a solution, the CloudFormation syntax still keeps giving false positives with those set.