Skip to content
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

Respect .prettierignore config #104

Closed
wants to merge 1 commit into from

Conversation

kapowaz
Copy link

@kapowaz kapowaz commented Jul 17, 2018

This PR fixes an issue with eslint-plugin-prettier not respecting file ignore patterns specified in .prettierignore (#88).

Currently this is failing due to #98 (since I need to upgrade to prettier 1.13.x to make use of prettier.getFileInfo()) and so many of the erroneous examples fail with this message:

Error: No parser could be inferred for file: <input>

@kapowaz kapowaz force-pushed the fix-respect-prettierignore branch 5 times, most recently from 4d12158 to d0e37fc Compare July 17, 2018 13:43
}

prettier.getFileInfo(sourceFileName, {
ignorePath: '.prettierignore'
Copy link
Author

Choose a reason for hiding this comment

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

I’m not sure if there’s some generic mechanism for exposing default config so that people can specify eslint-plugin-prettier to use a different file than .prettierignore, but given that this was broken until now I’m not sure just how much it matters… maybe one to be addressed in a later PR? 🤷‍♂️

@kapowaz kapowaz force-pushed the fix-respect-prettierignore branch from d0e37fc to 5237166 Compare July 17, 2018 14:50
Copy link
Member

@not-an-aardvark not-an-aardvark 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 the PR! I left a few comments.

CHANGELOG.md Outdated
## v2.6.3 (2018-07-17)

* Fix: respect .prettierignore settings ([#88](/~https://github.com/prettier/eslint-plugin-prettier/issues/88))

Copy link
Member

Choose a reason for hiding this comment

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

It's not necessary to update the changelog -- it will be automatically updated during the release.

Copy link
Author

Choose a reason for hiding this comment

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

Great! I did wonder if that might be automated… 🙈


prettier.getFileInfo(sourceFileName, {
ignorePath: '.prettierignore'
}).then((sourceFileInfo) => {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will work -- ESLint rules are required to be synchronous. Does prettier provide a synchronous API for this?

Copy link
Author

Choose a reason for hiding this comment

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

Yes! I tried both ways so I can update this to use the .sync version 👍

@kapowaz kapowaz force-pushed the fix-respect-prettierignore branch from 5237166 to e7d46c7 Compare July 20, 2018 09:13
@kapowaz
Copy link
Author

kapowaz commented Jul 20, 2018

Thanks for the comments — I’ve pushed a revised PR, hopefully this should address the issues. The tests still fail due to the issues mentioned in #98, but assuming that can be fixed I think this should be good.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-prettier",
"version": "2.6.2",
"version": "2.6.3",
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I should have mentioned this before, but it's also not necessary to update the version in package.json (it will also be automatically updated on release).

const prettierSource = prettier.format(source, prettierOptions);
if (source !== prettierSource) {
const sourceFileInfo = prettier.getFileInfo.sync(sourceFileName, {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for this behavior?

Copy link
Member

Choose a reason for hiding this comment

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

Can you check for the existence of prettier.getFileInfo.sync before calling it? The plugin needs to continue being able to work for users on old versions of prettier.

Copy link
Author

Choose a reason for hiding this comment

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

I’ll look into adding a test for this.

As regards checking for the existence of prettier.getFileInfo.sync I could do this, but this functionality is required in order to test for whether a file is being ignored, and so I’ve bumped the dependency to prettier ^1.13.0 for that reason. Is there a reason even future releases of eslint-plugin-prettier needs to always support old versions of prettier?

Maybe this be a minor release instead of a patch release, perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

Since the user installs prettier independently of eslint-plugin-prettier, it would be a breaking change to drop support for old versions of prettier, because we don't have any control over what version the user has installed.

Copy link
Author

Choose a reason for hiding this comment

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

I assume that’s an intentional thing, rather than explicitly having this depend on a given version of prettier? I’m not sure it would be possible to add a test to cover checking for a file being correctly ignored if we can’t guarantee a minimum version of prettier is installed though. Would welcome ideas if you think that is possible!

Copy link
Member

@not-an-aardvark not-an-aardvark Jul 23, 2018

Choose a reason for hiding this comment

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

Yes, the reasoning is that the user might want to choose a specific version of prettier to lint their code with (also see: #1). Admittedly, this was probably more important at the time that pull request was created than it is now, because prettier wasn't yet stable and was making breaking changes more frequently, and people wanted to use the plugin with several different versions.

As far as testing is concerned, I'd be fine with just adding an existence check without directly testing it for now. At some point it might be nice to test on multiple versions of prettier in CI, but that doesn't need to be part of this PR.

Copy link
Author

Choose a reason for hiding this comment

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

Cool. Like I say this can’t be merged until #98 is fixed anyway, so I guess I can revisit when that is handled (or maybe dive in and have a go at fixing that myself! 😁)

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that would be great.

@kapowaz kapowaz force-pushed the fix-respect-prettierignore branch from e7d46c7 to e62f05c Compare July 23, 2018 09:42
@kapowaz
Copy link
Author

kapowaz commented Jul 23, 2018

I’ve updated the PR again with some existence-guarding checks against prettier.getFileInfo. As I commented above, I’m not sure how we can reliably test for this functionality if there is no specific version of prettier guaranteed to be installed (and getFileInfo was only added in v1.13.0). Feedback on how to solve that welcomed!

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

This looks good to me once the tests pass.

@not-an-aardvark
Copy link
Member

Closing this PR because the functionality was included in #111. Thanks again for contributing!

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