-
-
Notifications
You must be signed in to change notification settings - Fork 206
New: option withNodeModules to unignore node_modules folders.
#118
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,7 +131,8 @@ module.exports = { | |
| { | ||
| type: 'object', | ||
| properties: { | ||
| usePrettierrc: { type: 'boolean' } | ||
| usePrettierrc: { type: 'boolean' }, | ||
| withNodeModules: { type: 'boolean' } | ||
| }, | ||
| additionalProperties: true | ||
| } | ||
|
|
@@ -140,6 +141,8 @@ module.exports = { | |
| create(context) { | ||
| const usePrettierrc = | ||
| !context.options[1] || context.options[1].usePrettierrc !== false; | ||
| const withNodeModules = | ||
| context.options[1] && context.options[1].withNodeModules !== false; | ||
| const sourceCode = context.getSourceCode(); | ||
| const filepath = context.getFilename(); | ||
| const source = sourceCode.text; | ||
|
|
@@ -164,7 +167,8 @@ module.exports = { | |
| : null; | ||
|
|
||
| const prettierFileInfo = prettier.getFileInfo.sync(filepath, { | ||
| ignorePath: '.prettierignore' | ||
| ignorePath: '.prettierignore', | ||
| withNodeModules | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than pass in a single value within the options here, I think it would be more future-compatible to pass in an object that is merged with some defaults. That means that if prettier decides to add additional options to getFileInfo() then we won't need to make additional changes to accommodate them. Something like this (written but not tested): const fileInfoOptions = Object.assign(
{},
{ ignorePath: '.prettierignore' }
eslintFileInfoOptions
)
const prettierFileInfo = prettier.getFileInfo.sync(filepath, fileInfoOptions);Where const eslintFileInfoOptions = context.options[1] && context.options[1].fileInfoOptions || {} |
||
| }); | ||
|
|
||
| // Skip if file is ignored using a .prettierignore file | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| CODE: | ||
| a();;;; | ||
|
|
||
| OUTPUT: | ||
| a(); | ||
|
|
||
| OPTIONS: | ||
| [{}, { withNodeModules: true }] | ||
|
|
||
| ERRORS: | ||
| [ | ||
| { | ||
| message: 'Delete `;;;`', | ||
| line: 1, column: 5, endLine: 1, endColumn: 8, | ||
| }, | ||
| ] | ||
|
|
||
| FILENAME: | ||
| node_modules/dummy.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,17 @@ ruleTester.run('prettier', rule, { | |
| { | ||
| code: `('');\n`, | ||
| filename: getPrettierRcJsFilename('single-quote', 'dummy.md') | ||
| }, | ||
| // Should ignore files from node_modules | ||
| { | ||
| code: 'a();;;;;;\n', | ||
| filename: 'node_modules/dummy.js' | ||
| }, | ||
| // Should check files from node_modules too | ||
| { | ||
| code: 'a();\n', | ||
| filename: 'node_modules/dummy.js', | ||
| options: [{}, { withNodeModules: true }] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated usage would be |
||
| } | ||
| ], | ||
| invalid: [ | ||
|
|
@@ -81,7 +92,8 @@ ruleTester.run('prettier', rule, { | |
| '14', | ||
| '15', | ||
| '16', | ||
| '17' | ||
| '17', | ||
| '18' | ||
| ].map(loadInvalidFixture) | ||
| }); | ||
|
|
||
|
|
@@ -127,6 +139,9 @@ function loadInvalidFixture(name) { | |
| options: eval(sections[3]), // eslint-disable-line no-eval | ||
| errors: eval(sections[4]) // eslint-disable-line no-eval | ||
| }; | ||
| if (sections.length >= 6) { | ||
| item.filename = sections[5]; | ||
| } | ||
| return item; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this an object named
fileInfoOptions