go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.01k stars 584 forks source link

Make `sources:` respect a new `.taskignore` file, similar to `.gitignore` #1753

Open nikaro opened 1 month ago

nikaro commented 1 month ago

I'm using this task to lint JSON files:

  json:
    desc: Lint JSON files
    sources:
      - ./**/*.json
      - exclude: .venv/**/*.json
    cmds:
      - for: sources
        cmd: jq empty {{.ITEM}}
      - for: sources
        cmd: prettier --check --parser json {{.ITEM}}

And it would be nice if sources could respect the .gitignore content instead of having to exclude all ignored patterns.

This is especially needed as i'm using this task from a Remote Taskfiles #1317 and cannot easily edit it.

andreynering commented 1 month ago

Respecting .gitignore is a nice suggestion. In theory it'd be a small breaking change, though, because some users may not expect it to be excluded.

Alternative, we could introduce a .taskignore, using the same format. Or, just have a global ignore: setting on the Taskfile that would be globally respected.

nikaro commented 1 month ago

we could introduce a .taskignore, using the same format

This would be fine as it could be a symlink to .gitignore to avoid duplicating file content in case you want to ignore the same things.

have a global ignore: setting on the Taskfile that would be globally respected

For this one i think its value should be gitignore-like file to parse, maybe .taskignore by default, then it could be overridden (ex. with .gitignore) for those who do not want to add another file/symlink.

For the record, in the meantime my workaround is using fd [...] | xargs [...] as fd exclude .gitignore content by default. Ex:


  json:
    desc: Lint JSON files
    sources:
      - ./**/*.json
    cmds:
      - fd --hidden --extension json | xargs --no-run-if-empty jq empty
      - fd --hidden --extension json | xargs --no-run-if-empty prettier --check --parser json
nikaro commented 1 month ago

I don't have much time right now to give this a try, but this lib could probably be used to help for gitignore parsing: https://pkg.go.dev/github.com/go-git/go-git/v5/plumbing/format/gitignore

vmaerten commented 1 month ago

Hey! I think .taskignore is a good idea! I am not in favor reading .gitignore