Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

reklatsmasters
Copy link

This PR add option withNodeModules (default: false) to unignore node_modules folders. May be useful if you are using multiple node_modules directories, example to avoid many ../.. sequences.

@BPScott
Copy link
Member

BPScott commented Oct 10, 2018

Hi @reklatsmasters, can you please add a test for this

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for being patient :)

For the sake of future compatibility I think we should pass in a whole object that represents all of the options in getFileInfo. That way if prettier were to add an extra option to getFileInfo() then we wouldn't need to add extra code to allow users to modify it.

@@ -164,7 +167,8 @@ module.exports = {
: null;

const prettierFileInfo = prettier.getFileInfo.sync(filepath, {
ignorePath: '.prettierignore'
ignorePath: '.prettierignore',
withNodeModules
Copy link
Member

Choose a reason for hiding this comment

The 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 eslintFileInfoOptions is defined above as something like this: (written but not tested)

const eslintFileInfoOptions = context.options[1] && context.options[1].fileInfoOptions || {}

@@ -131,7 +131,8 @@ module.exports = {
{
type: 'object',
properties: {
usePrettierrc: { type: 'boolean' }
usePrettierrc: { type: 'boolean' },
withNodeModules: { type: 'boolean' }
Copy link
Member

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

{
code: 'a();\n',
filename: 'node_modules/dummy.js',
options: [{}, { withNodeModules: true }]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated usage would be

options: [{}, { fileInfoOptions: { withNodeModules: true }}]

@BPScott
Copy link
Member

BPScott commented May 11, 2019

Replaced by #187

@BPScott BPScott closed this May 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants