Skip to content

Rule: use-array-flatten #1855

@anderseknert

Description

@anderseknert

It's been a while since we had a new rule for recommending the use of a built-in function. But it struck me now that since my rationale for adding array.flatten to OPA was to be able to replace code like this..

flat := array.concat([a], array.concat(b, [c]))

with this..

flat := array.flatten([a, b, c])

..we should of course let our users know that they too can do this! Let's create a rule that recognizes nested array.concat calls and suggests using array.flatten instead — unless of course that built-in is not in the target OPA's capabilities.

Thinking about it, we can probably do this for a few more functions, like recommending object.union_n if we find nested calls to object.union. I also looked at suggesting to replace repeated replace calls -> strings.repeat_n... but AFAICS those aren't interchangeable.Oh well, that should be another issue/rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category/idiomaticruleIssues related to new or existing linter rules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions