Skip to content

Commit a9c0ffd

Browse files
New: option withNodeModules to unignore node_modules folders.
1 parent 68271f8 commit a9c0ffd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ For the list of every available exclusion rule set, please see the [readme of es
121121
}]
122122
```
123123

124+
- `withNodeModules`: Prettier ignores files located in `node_modules` directories. To opt-out from this behavior set `true`, (default: `false`). May be useful if you are using multiple `node_modules` directories, example to avoid many `../..` sequences.
125+
126+
```json
127+
"prettier/prettier": ["error", {}, {
128+
"withNodeModules": true
129+
}]
130+
```
131+
124132
- The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
125133

126134
---

eslint-plugin-prettier.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ module.exports = {
131131
{
132132
type: 'object',
133133
properties: {
134-
usePrettierrc: { type: 'boolean' }
134+
usePrettierrc: { type: 'boolean' },
135+
withNodeModules: { type: 'boolean' }
135136
},
136137
additionalProperties: true
137138
}
@@ -140,6 +141,8 @@ module.exports = {
140141
create(context) {
141142
const usePrettierrc =
142143
!context.options[1] || context.options[1].usePrettierrc !== false;
144+
const withNodeModules =
145+
context.options[1] && context.options[1].withNodeModules !== false;
143146
const sourceCode = context.getSourceCode();
144147
const filepath = context.getFilename();
145148
const source = sourceCode.text;
@@ -164,7 +167,8 @@ module.exports = {
164167
: null;
165168

166169
const prettierFileInfo = prettier.getFileInfo.sync(filepath, {
167-
ignorePath: '.prettierignore'
170+
ignorePath: '.prettierignore',
171+
withNodeModules
168172
});
169173

170174
// Skip if file is ignored using a .prettierignore file

0 commit comments

Comments
 (0)