adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.79k stars 265 forks source link

Disable rules by key #672

Open Pandapip1 opened 2 months ago

Pandapip1 commented 2 months ago

I have the following config:

...
jobs:
  markdownlint:
    name: 🖋️ Markdownlint
    runs-on: ubuntu-latest
    steps:
      - name: 📦 Checkout Repository
        uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b  # v4.1.5
        with:
          fetch-depth: 2
...

Due to other tooling I have, those lines with uses are always going to be too long. I'd like to disable the line-length rule, but only for those lines, and without spamming yamllint disable-line everywhere.

andrewimeson commented 2 months ago

This isn't currently possible, but I have two suggestions:

  1. Move the comment to be above the line

    jobs:
     markdownlint:
       name: 🖋️ Markdownlint
       runs-on: ubuntu-latest
       steps:
         - name: 📦 Checkout Repository
           # v4.1.5
           uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
           with:
             fetch-depth: 2
  2. Disable the line-length rule for part of the file, and optionally re-enable it for the rest of the file

    jobs:
     markdownlint:
       name: 🖋️ Markdownlint
       runs-on: ubuntu-latest
       steps:
         # yamllint disable rule:line-length
         - name: 📦 Checkout Repository
           uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b  # v4.1.5
           with:
             fetch-depth: 2
    
         - name: 🐍 Setup Python
           uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d  # v5.1.0
    
         # yamllint enable rule:line-length
         - name: 🐚 Do stuff that you still want line-length linted on
           run: |
             for _ in {1..100}; do
                echo hi
             done
Pandapip1 commented 2 months ago

Move the comment to be above the line

Unfortunately, this isn't possible due to the automatic dependency update system (Renovate) being used.

Disable the line-length rule for part of the file, and optionally re-enable it for the rest of the file

I've just disabled that particular rule globally for now.

The ideal situation would be to be able to do something like

# yamllint disable-for-item *.uses rule:line-length
steps: