Skip to content

Order fileMatches from more specific to more generic #293

@KuSh

Description

@KuSh

I have a .github/workflows/site.yml file that matches multiple entries from schemastore catalog:

    {
      "name": "Ansible Playbook",
      "description": "Ansible playbook files",
      "fileMatch": [
        "playbook.yml",
        "playbook.yaml",
        "site.yml",
        "site.yaml",
        "**/playbooks/*.yml",
        "**/playbooks/*.yaml"
      ],
      "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/playbook"
    }

and

    {
      "name": "GitHub Workflow",
      "description": "YAML GitHub Workflow",
      "fileMatch": [
        "**/.github/workflows/*.yml",
        "**/.github/workflows/*.yaml",
        "**/.gitea/workflows/*.yml",
        "**/.gitea/workflows/*.yaml",
        "**/.forgejo/workflows/*.yml",
        "**/.forgejo/workflows/*.yaml"
      ],
      "url": "https://www.schemastore.org/github-workflow.json"
    }

Unfortunately, actually, Ansible Playbook is selected, which generates lots of false warnings in the file.

Could it be possible to prioritize the selection of the schema according to the number of characters matched outside of wildcards?
This way the more specific fileMatch will be selected if more that one match.


For example in my case, .github/workflows/site.yml:

  • matches 8 characters for site.yml
  • matches 23 characters for **/.github/workflows/*.yml, excluding characters matched by wildcards

The second one is more specific characters and should be preferred


This should fix most of the cases relatively easily
Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions