aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.45k stars 592 forks source link

Provide linting on the value part of key-value pair #2563

Open yogesh-ti opened 1 year ago

yogesh-ti commented 1 year ago

Is this feature request related to a new rule or cfn-lint capabilities?

New capability

Describe the feature you'd like to request

I am writing a custom rule in python. My requirement includes to lint the warning on value part of key-value pair. Let's take the following snippet to understand.

{
    "AWSTemplateFormatVersion":"2010-09-09",
    "Resources":{
        "S3Bucket":{
            "Type": "AWS::S3::Bucket",
            "Properties":{
                "Name":"temp-s3-bucket"
            }
        }
    }
}

My usecase includes getting the exact position of "value" in a key-value pair. Considering the above case, let's assume that I have written some custom rule which will check the bucket name should only start with letter - "a". Now in cfn-lint custom ruleset, when I give the path value in return to match function Link, I give value as path=[S3Bucket,Properties,Name] which when run, will give the output warning as to change on (start: Line 7, col: 17 to end: Line 7, col 23), but my usecase is a little different. I want to get the warning as start: Line 7, col 24 to end: Line 7, col 40. Which means in Key-Value as "Name":"temp-s3-bucket", i want the recommednation to be shown on "temp-s3-bucket" instead of "Name".

Describe the solution you'd like

Add an optional argument, lintOnKey defaults to true, if false then this lints the value for this key

kddejong commented 1 year ago

@benbridts and @PatMyron what do you think of this idea? I think the idea is we would highlight the values and not the keys.

PatMyron commented 1 year ago

Always more advanced possibilities for power users, but I tend to err on the side of simple interfaces / abstractions. Findings are generally understood by users regardless if the key or value is highlighted