Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tasks do not have meaningful name #828

Closed
jd20 opened this issue Apr 3, 2020 · 4 comments · Fixed by #865
Closed

Functional tasks do not have meaningful name #828

jd20 opened this issue Apr 3, 2020 · 4 comments · Fixed by #865

Comments

@jd20
Copy link

jd20 commented Apr 3, 2020

Description

For tasks defined as a function, the console output doesn't really show a meaningful name (because it emits only the first word of the command). Having a way to name tasks in the config (requested before in #410) would solve this issue, as well as for tasks that are not functional, but may have long or confusing commands. For example, npx --no-install eslint --quiet --fix could be shown in console output as simply eslint --quiet --fix if we could provide a custom name.

Steps to reproduce

Here's an example, for this config:

module.exports = {
    "*.{ts,tsx}": [
        "npx --no-install eslint --quiet --fix",
        (filenames) => (filenames.length > 0 ? 'npx --no-install tsc --noEmit' : '')
    ]
}

The console output I currently get:

husky > pre-commit (node v12.12.0)
  ✔ Preparing...
  ❯ Running tasks...
    ❯ Running tasks for *.{ts,tsx}
      ✔ npx --no-install eslint --quiet --fix
      ✔ [Function] npx ...

What I'd like:

husky > pre-commit (node v12.12.0)
  ✔ Preparing...
  ❯ Running tasks...
    ❯ Running tasks for *.{ts,tsx}
      ✔ eslint --quiet --fix
      ✔ [Function] tsc --noEmit ...

Maybe even the ability to get rid of [Function] if specifying a custom name.

@iiroj
Copy link
Member

iiroj commented Apr 3, 2020

Hey,

We did try to create a custom name using placeholders, but the problem was that the function was evaluated multiple times. This was problematic for when the task had side-effects.

Feel free to suggest a good way of generating the name. We have the full command string (including arguments) at that point, but it can be very long depending on how many staged files there are.

@iiroj
Copy link
Member

iiroj commented Apr 3, 2020

This is basically where we generate the name:
https://github.com/okonet/lint-staged/blob/master/lib/makeCmdTasks.js#L46

I guess we could try splitting from the first stage filename, since we know that, instead of the first space.

@jd20
Copy link
Author

jd20 commented Apr 5, 2020

Sure, let me try putting together a PR for that.

Would it also make sense to strip common package runner commands like yarn/npm/npx and their options from the beginning of the command when generating the name? That would fix the other issue I alluded to.

@iiroj iiroj linked a pull request May 28, 2020 that will close this issue
@iiroj
Copy link
Member

iiroj commented May 28, 2020

This has been fixed in 10.2.5 by using the full command string, and truncating it to fit on a single console line.

@iiroj iiroj closed this as completed May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants