-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
feat: skip processing code blocks on specific languages like stylelint-prettier
#415
Conversation
@BPScott Friendly ping. |
Heya @JounQin, sorry for the long delay. This change and #413 both touch the same portion of code. Is the expectation that only one of them should be merged? If so which PR is preferable? I'm guessing this one as it was creating slightly later? I was originally a bit confused by the title of this PR as we already have logic in place to skip processing code blocks when encountering languages that are not JS. But I think I understand what is happening - you're adding a new case that says we should bail out of doing any processing when both I think I'd have found this change a bit easier to understand if instead of adding an extra nested condition to existing code, the following block was added above line 209 (leaving the existing code unchanged): const nonVirtualProcessorParserBlockList = ['babel', 'babylon' 'flow', 'typescript', 'vue', 'markdown', 'mdx' 'html'];
if (
filepath !== onDiskFilepath &&
nonVirtualProcessorParserBlockList .indexOf(prettierFileInfo.inferredParser) !== -1) {
return;
} Could you explain why the that list of parsers was chosen for when you're not dealing with a file created by a processor that specifies a virtual filename? I would have expected the list to be the same as when you're using virtual filenames? I've been thinking for a while it might soon be time to drop older node / eslint / prettier versions. It seems like eslint/eslint#14616 is close to being merged. Perhaps I should wait till a version of eslint is released with that change present, and that can be eslint-plugin-prettier v4. That'd massively simplify a lot of the "filename on disk" logic. |
@BPScott Thanks for reply finally first.
They are both valid, while #413 only add support for
I just want to keep compatibility and borrowed the list from The original list is used for some legacy ESLint plugins as I commented: // The following list means the plugin process source into js content
// but with same filename, so we need to change the parser to `babel`
// by default.
// Related ESLint plugins are:
// 1. `eslint-plugin-graphql` (replacement: `@graphql-eslint/eslint-plugin`)
// 2. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`)
// 3. `eslint-plugin-html` |
That would just help to remove |
OK, that makes sense - I see that
I don't think legacy is the right word here. It is totally valid for eslint plugins to choose not to use virtual filenames. I'd absolutely prefer that they did use virtual filenames, but I don't think there's anything that suggests not specifying a filename going to be unsupported by eslint in the future.
I think it will need to be updated. THe list in stylelint-prettier is designed to removed non-css file types but for eslint-plugin-prettier we'd want to remove non-js file types - for instance currently this code does an early return when the parser is
There are a few other simplifications too. e.g. supporting only prettier v2 means the |
Oh, sorry, but I mean:
That's not true, they are just skipped when The original js/ts file will still be processed because
Right, I was saying your mentioned ESLint PR only adds |
I don't think processors needed to do anything for These processors are only ever going to create filenames like I agree with the sentiment in #413 (comment) and prettier/stylelint-prettier#22 that eslint-plugin-prettier shouldn't bother running prettier over these fragments of a file: If you're this interested in prettier then you probably want to run prettier over the rest your |
// test.js
const test = gql`
# content
` See also: https://github.com/dotansimha/graphql-eslint#configuration And also |
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.
just noticed a typo so bringing it up 😅
Yep sure but what's the result of |
For For |
@BPScott Any news? It's already two months after our last conversation... |
Heya @JounQin. Thank you for your patience. As you've saw I've found it hard to find time for this project thanks to personal stuff. I wanted to spend some time understanding how processors interact with tests and if getFilename stuff made any of that easier, I managed a bit but didn't find any easy answers. I see you've pushed for a bunch of improvements in eslint/eslint#14616 and eslint/eslint#14800. Thank you for doing all of that, hopefully eslint adds eslint/rfcs#31 at some point to make the e2e testing of all this a lot easier. I've merged #413 and have released it as v3.4.1. Would you be able to rebase this PR atop latest master. When you originally opened this PR i wasn't sure how to reconcile the the conflicting changes in #413 and this PR. I'll try and drop the old versions of eslint in a major version at some point, which should let us leverage getPhysicalFilename() and simplify some of this. |
Thanks @BPScott No worry, I've already had a rebased branch locally, I'll push it when I'm free today. Before eslint/rfcs#31, we can still use our own |
@BPScott Already rebased! |
@BPScott I just added Maybe snapshot based test cases would be better. |
@BPScott Any news again? |
@BPScott any news? 🙏 |
Rebased.
|
Just released # yarn
yarn add -D eslint-plugin-prettier@npm:@rxts/eslint-plugin-prettier@^4.1.0
# pnpm
pnpm add -D eslint-plugin-prettier@npm:@rxts/eslint-plugin-prettier@^4.1.0
# npm
npm i -D eslint-plugin-prettier@npm:@rxts/eslint-plugin-prettier@^4.1.0 Then it will just work the same as before with this feature enabled. |
@BPScott please merge this PR |
https://github.com/prettier/eslint-plugin-prettier/releases/tag/v4.1.0
|
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) | devDependencies | minor | [`4.0.0` -> `4.1.0`](https://renovatebot.com/diffs/npm/eslint-plugin-prettier/4.0.0/4.1.0) | --- ### Release Notes <details> <summary>prettier/eslint-plugin-prettier</summary> ### [`v4.1.0`](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#v410-2022-06-27) [Compare Source](prettier/eslint-plugin-prettier@v4.0.0...v4.1.0) - feat: skip processing code blocks on specific languages like `stylelint-prettier` ([#​415](prettier/eslint-plugin-prettier#415)) ([52eec48](prettier/eslint-plugin-prettier@52eec48)) - build(deps): Bump minimist from 1.2.5 to 1.2.6 ([#​464](prettier/eslint-plugin-prettier#464)) ([42bfe88](prettier/eslint-plugin-prettier@42bfe88)) - build(deps-dev): Bump graphql from 15.5.1 to 15.7.2 ([#​442](prettier/eslint-plugin-prettier#442)) ([0158640](prettier/eslint-plugin-prettier@0158640)) - build(deps-dev): Bump [@​graphql-eslint/eslint-plugin](https://github.com/graphql-eslint/eslint-plugin) from 2.3.0 to 2.4.0 ([#​444](prettier/eslint-plugin-prettier#444)) ([4bcaca2](prettier/eslint-plugin-prettier@4bcaca2)) - chore(CI): add tests for ESLint 8 ([#​428](prettier/eslint-plugin-prettier#428)) ([f3713be](prettier/eslint-plugin-prettier@f3713be)) - README.md: HTTP => HTTPS ([#​443](prettier/eslint-plugin-prettier#443)) ([44e1478](prettier/eslint-plugin-prettier@44e1478)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [x] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1435 Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
close #412, #414
Just like prettier/stylelint-prettier#22
The e2e test is a bit difficult to be added because we're supporting very long time ago versions of ESLint/Node, and such e2e test cases requires a lot of ESLint plugins to be installed which are very likely incompatible with old versions of ESLint/Node.
If you have a good idea to add e2e tests, I'll follow your advices.