-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
add a glob example for how to ignore node_modules #1358
Comments
What about |
That works to ignore when find . -name "*.js" | grep -v node_modules | xargs prettier --write --single-quote --trailing-comma es5 is what I found now |
I find |
Maybe some way that prettier would ignore node_modules by default |
That seems like it could cause some unexpected behavior, plus it doesn't really align with the unix philosophy. |
For For reference, our setup has node_modules in git versioning...which is why I needed this. Abnormal use case. facepalm |
I'm trying to lint all files ending in There has to be a way that's both performant and not limiting. In the meantime, I ended up writing a script that generates a glob based on the directories in my project folder, including and excluding the files I want: // Generates a glob string for prettier
const fs = require('fs');
const path = require('path');
// EXCLUDE and INCLUDE must be directories, and not contain trailing slashes
// This script does not create globs that ignore individual files
const EXCLUDE = ['node_modules', 'dist'];
const INCLUDE = ['storybook/.storybook'];
let dirs = fs
.readdirSync(path.join(__dirname, '../../'))
.filter(path => fs.statSync(path).isDirectory())
.filter(dir => dir.indexOf('.') !== 0)
.filter(dir => EXCLUDE.indexOf(dir) === -1);
dirs = dirs.concat(INCLUDE).map(dir => `${dir}/**/`);
const glob = `{,${dirs.join(',')}}*.js`;
process.stdout.write(`${glob}`); and my package.json: {
// ...
"scripts": {
// ...
"prettier": "prettier $(node genPrettierGlob.js) --write"
}
} |
Sort of related, but I wish there was a way to configure Prettier to ignore specific directories. I've previously used XO, but like Prettier more but I use it with a Yeoman generator and each directory has a template subdirectory that is templated with EJS and Prettier hangs itself up on these files each time. Being able to configure which directories to ignore would be nice, otherwise I end up doing |
Building on @Haroenv's answer, I found the following useful to exclude all find . -name \"*.js\" | grep -v -f .gitignore | xargs prettier [opts] |
Given the complexity of those globs and the fact that in 99% of situations you will never want to go though node_modules, could we ignore them by default? Like proposed by @jlongster here: #1048 (comment) |
@SEAPUNK, does this help?
|
I tried some globs, but none work, so adding this as an example somewhere will make my day!
http://globtester.com was useful, but not enough 😄
Thanks a lot!
The text was updated successfully, but these errors were encountered: