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

Using functions as linters prints file list to console, static linters do not #674

Closed
strann opened this issue Jul 29, 2019 · 4 comments · Fixed by #706
Closed

Using functions as linters prints file list to console, static linters do not #674

strann opened this issue Jul 29, 2019 · 4 comments · Fixed by #706
Labels

Comments

@strann
Copy link

strann commented Jul 29, 2019

Description

Hello, I am looking at migrating our lint-staged config in package.json to a lint-staged.config.js file, moving from v8.1.5 to v9.2.1.

I've noticed something relatively minor in the console output that could be tweaked for a smoother experience.

When I just moved our JSON based config into the file everything worked as expected. However when I tried to pass functions for linters, this is when I noticed that the entire file list would be passed through to Listr and be output in the console when a function is detected as the linter. Here is an example of the output I am seeing:

git commit -m "Test lint-staged"
husky > pre-commit (node v10.13.0)
  ↓ Stashing changes... [skipped]
    → No partially staged files found...
  ❯ Running tasks...
    ❯ Running tasks for /project1{src,__mocks__}/**/*.{ts,tsx}
      ✔ lerna run lint:fix:prettier --scope project1 -- /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx
      ✖ lerna run lint:fix --scope project1 -- /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx
        git add /project1/src/some/file1.tsx /project1/src/some/file2.tsx /project1/src/some/file3.tsx
        lerna run test:related --scope project1 -- /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx
    ↓ Running tasks for /project1{src,__mocks__}/**/*.{json,css,md} [skipped]
      → No staged files match /project1{src,__mocks__}/**/*.{json,css,md}
    ↓ Running tasks for project2/**/*.{ts,tsx} [skipped]
      → No staged files match project2/**/*.{ts,tsx}
    ↓ Running tasks for project3/**/*.{ts,tsx} [skipped]
      → No staged files match project3/**/*.{ts,tsx}
    ↓ Running tasks for project4/**/*.{ts,tsx} [skipped]
      → No staged files match project4/**/*.{ts,tsx}
    ↓ Running tasks for project5/**/*.{ts,tsx} [skipped]
      → No staged files match project5/**/*.{ts,tsx}

The trouble with the above is, as I said relatively minor, however it gets a bit nastier when there are many files in the change list. We are working in a medium sized TypeScript monorepo that if you fall behind master for 3-4 days you will definitely have many files when pulling. I personally ran into problems during merge conflicts where I would be forced to run pre-commit against hundreds of changes from the master merge in potentially each project. In that case the console output while Listr is doing it's thing would be quite nasty:

  ❯ Running tasks...
    ❯ Running tasks for /project1{src,__mocks__}/**/*.{ts,tsx}
      ✖ lerna run lint:fix --scope project1 -- /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx
      /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx 
      project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx 
      /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx 
      /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx 
      project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx 
      /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx 
      /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx 
      project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx /
      project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx 
      /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx 
      project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx 
      /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx 
      /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx 
      project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx 
      /project1/src/some/file3.tsx /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx 
      /project1/src/some/file1.tsx project1/src/some/file2.tsx /project1/src/some/file3.tsx /project1/src/some/file1.tsx 
      project1/src/some/file2.tsx /project1/src/some/file3.tsx
    ↓ Running tasks for /project1{src,__mocks__}/**/*.{json,css,md} [skipped]
      → No staged files match /project1{src,__mocks__}/**/*.{json,css,md}
    ↓ Running tasks for project2/**/*.{ts,tsx} [skipped]
      → No staged files match project2/**/*.{ts,tsx}
    ↓ Running tasks for project3/**/*.{ts,tsx} [skipped]
      → No staged files match project3/**/*.{ts,tsx}
    ↓ Running tasks for project4/**/*.{ts,tsx} [skipped]
      → No staged files match project4/**/*.{ts,tsx}
    ↓ Running tasks for project5/**/*.{ts,tsx} [skipped]
      → No staged files match project5/**/*.{ts,tsx}

It would be nice to have consistent, clean output while Listr is printing the stages to the console. I believe when no linter function is used and just a glob + static command is found, no files are printed.

Steps to reproduce

Use a function as a linter in v9.2.1

Environment

  • OS: macOS Mojave 10.14.2
  • Node.js: v10.13.0
  • lint-staged: v9.2.1
@iiroj
Copy link
Member

iiroj commented Jul 30, 2019

Yes, the behaviour of generateTasks is to use the entire task as the name passed to Listr, so this is a side-effect.

Maybe we could generate the name separately by using ["[file]"] or something as the array of filenames, so the command would be shorter, but still display where the file would go.

@JounQin
Copy link

JounQin commented Sep 13, 2019

+1 For this, and the performance seems wrose.

@shanedg
Copy link

shanedg commented Sep 23, 2019

+1

Possible to introduce an option to omit or truncate the file list re: function linters? We have to resolve large merge commit conflicts pretty regularly, and moving to a functional linter was the only way we could ignore files from match.

I don't want to suppress all of lint-staged's output with the -q flag because I don't think it should be an entirely invisible thing.

okonet pushed a commit that referenced this issue Sep 26, 2019
* refactor: remove usage of `linter` and prefer `command`
* test: remove full snapshot since new git version changed the text
* improvement: create shorter titles for function tasks with many staged files

Closes #674
@okonet
Copy link
Collaborator

okonet commented Sep 26, 2019

🎉 This issue has been resolved in version 9.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

5 participants