question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run linter in a subdirectory

See original GitHub issue

Our monorepo has two relatively separate projects in it, with their own Prettier config in project-A and project-B. I’m looking for a way to do something like this:

"lint-staged": {
    "project-A/**/*.js": [
      "cd project-A && prettier --check"
    ],
    "project-B/**/*.js": [
      "cd project-B && prettier --check"
    ],
}

(Prettier needs to have a working directory set to either project-A or project-B to pick up the right ignore & config files.)

This doesn’t work as it resolves to something like this:

  lint-staged:task bin: /usr/bin/cd +8ms
  lint-staged:task args: [ 'project-A',
  lint-staged:task   '&&',
  lint-staged:task   'yarn',
  lint-staged:task   'prettier',
  lint-staged:task   '--check',
  lint-staged:task   '/Users/borekb/example/project-A/index.js' ] +0ms

A workaround is to create npm scripts like this:

"scripts": {
  "prettier-A": "cd project-A && prettier --check",
  "prettier-B": "cd project-B && prettier --check"
},
"lint-staged": {
    "project-A/**/*.js": [ "yarn prettier-A" ],
    "project-B/**/*.js": [ "yarn prettier-B" ]
}

Is there a built-in way to run lint-staged in a subdirectory / subfolder?

(We’re using lint-staged@8.1.15.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
motincommented, Nov 12, 2021

Another way of working around this is to use yarn workspaces. Then you can basically run:

"lint-staged": {
    "project-A/**/*.js": [ "yarn workspace @myorg/project-A prettier" ],
    "project-B/**/*.js": [ "yarn workspace @myorg/project-B prettier" ]
}

(Replying here since this thread pops up on web searches)

1reaction
iirojcommented, Jun 6, 2019

Feel free to re-open this issue if that’s not good enough!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lint Staged does not access subfolders
It seems like your file pattern string in .lintstagedrc.json is wrong. Try remove dot before bracket and put it before each file extension ......
Read more >
Using Husky Git Hooks and Lint-Staged With Nested Folders
Lint -staged allows you to run code against your staged git files to automate the tedious part of your workflows, such as formatting...
Read more >
Running golangci-lint run for various different files
Hey when i run golangci-lint run app/main.go utils/db/db.go i get an error stating `named files must all be in one directory golang` why...
Read more >
ESLint | AppCode Documentation
Configure linting scope · Open the Preferences dialog ( ⌃ ⌥ S ), go to Languages & Frameworks | JavaScript | Code Quality...
Read more >
Ignoring Code - ESLint - Pluggable JavaScript Linter
When ESLint is run, it looks in the current working directory to find a .eslintignore file before determining which files to lint. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found