Comments (9)
I was able to get the automatic cwd stuff working by having a config in the root of the monorepo and a config for each package as described in the readme.
However, the config in the root actually needs rules in it, otherwise lint-staged
exits silently with exit code 1.
In other words, it appears you need something like this if you plan to use lint-staged in a monorepo but don't want any base rules for the monorepo root itself:
./lint-staged.config.cjs
module.exports = {
'*': 'true'
}
./packages/thing-1/lint-staged.config.cjs
module.exports = {
'*.{cjs,mjs,js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
}
from lint-staged.
Updated. Because I’m using shared eslint config which resolves tsconfig relative to process.cwd()
(details here).
However, I'm still looking for a way to specify the working dir per .lintstagedrc.js
in each package.
Feel free to close this thread if it does not make sense, thanks.
from lint-staged.
By default monorepo tasks run with the specific config file directory as the root. The npx lint-staged --cwd <some-directory>
can be used to override this for all tasks. Would that work for you?
For example, to run all tasks from the monorepo root, probably:
npx lint-staged --cwd $PWD
from lint-staged.
Yup, that works but if using lint-staged
with husky
, will I have to supply multiple lint-staged commands, so any process.cwd()
used inside each package will result in the correct value?
// pre-commit
npx lint-staged --cwd packages/frontend
npx lint-staged --cwd packages/backend
from lint-staged.
If you have multiple configs, in packages/frontend
and packages/backend
for example, the commands in those should already use those directories as CWD for the tasks. Is this not the case?
from lint-staged.
You are correct.
I previously added an empty config at root, follow the monorepo setup document "you can either add an "empty" lint-staged configuration to the root of the repo". When running lint-staged
at root, I found process.cwd()
resulting the root dir, though there are lint-staged config in each package.
Then update the root config from empty to @imhoffd suggestion and now it works correctly.
from lint-staged.
Is there something you think could be fixed, or at least the README updated?
from lint-staged.
Hi @iiroj, thanks for your work on lint-staged. I don't think there are any active bugs in this issue. Here are a few takeaways, if it helps:
- With an empty root config (e.g.
module.exports = {}
),lint-staged
exits silently with exit code 1. This could probably be improved with an error message if the intention is to require at least one rule. - If the intention is to require at least one rule, I would question that. If a root config is necessary, then an empty root config should indicate to lint-staged that no linters need to run. Right now, I have the rule
'*': 'true'
in my root config because I don't need to run any linters on the monorepo root (yet), so it literally runs thetrue
built-in bash command for all files--I don't see a better way to do this currently. - If a root config is necessary, I would further question that. lint-staged appears to correctly identify the root of the monorepo as well as the closest config file. Therefore, a missing root config should indicate to lint-staged that no linters need to run.
Basically, I expected to be able to install lint-staged in the root of my monorepo and add a single lint-staged config file in a package's subdirectory, but that ended up not working without doing some investigation. I was surprised that the root config file was necessary at all.
Thanks again!
from lint-staged.
Thanks! The root config itself is not strictly necessary, but in order to activate the "monorepo features", you need at least two valid configuration files. This is because of backwards-compatibility reasons, as lint-staged has supported the (single) configuration file being in a subdirectory of a git repo for a longer time.
Thus, having an "empty config" in the root is a workaround for enabling monorepo features with a single configuration file in one of monorepo's subdirectories.
from lint-staged.
Related Issues (20)
- Unable to run `lint-staged` programmatically due to lack of types. HOT 2
- Warning when running ESLint with lint-staged: File ignored by default (for eslint cofniguration file) HOT 1
- Use another exit code for internal error.
- Running lint-stage inexplicably changes code HOT 1
- Unsupported engine warning in node 18.2.0 HOT 1
- exit with exit code 1 without printing anything HOT 5
- How to restore stash files into workspace when lint-staged error HOT 2
- Failed to resolve git repo on mapped network drive HOT 12
- Commits from Github Desktop occur errors HOT 4
- Not all lintstagedrc.json files are found in the rush.js monorepo HOT 4
- Type '(filenames: string[]) => Commands | Promise<Commands>' is not assignable to type 'string' HOT 2
- There is a bug with bracketed folders HOT 5
- Importing a reusable json file to ESM JS config fails HOT 1
- Path for baseConfig HOT 2
- Many errors in standard output when using git sparse-checkout HOT 4
- `--all` flag HOT 3
- lint-staged repeat many time ,when commit in windows powershell,cmd HOT 2
- [feat] override the current pattern HOT 1
- Make lint-staged more compatible with git sparse checkout feature HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lint-staged.