eslint-plugin-prettier icon indicating copy to clipboard operation
eslint-plugin-prettier copied to clipboard

Incorrect differences being generated with eslintv9

Open Stono opened this issue 1 year ago • 10 comments

Hello I originally raised this issue over on eslint : https://github.com/eslint/eslint/issues/19258 so there's quite a bit of context there, however I've been debugging and the issue appears to be in the generateDifferences function of the eslint-plugin-prettier package.

It's a bit crude this debugging but on eslint-plugin-prettier.js, lines 243, I added:

            if (source !== prettierSource) {
              const differences = generateDifferences(source, prettierSource);
              if(onDiskFilepath === '/Users/karl.stoney/git/autotrader/node-at-webserver/examples/basic-app/types/client/sdk.gen.ts') {
                console.log(source)
                console.log('--------------->')
                console.log(prettierSource)
                console.log('--------------->')
                console.log(differences)
              }
              for (const difference of differences) {
                reportDifference(context, difference);
              }
            }

If you notice the output in my terminal both source and prettierSource are correct, but the differences generated by generateDifferences includes

{ offset: 622, operation: 'delete', deleteText: '}' }

Which is incorrect.

Screenshot 2024-12-20 at 07 32 42

Stono avatar Dec 20 '24 07:12 Stono

hmmm actually no this may be fine because you're inserting { on the difference above it.... gah So it's back to being an eslint issue I think.

Stono avatar Dec 20 '24 07:12 Stono

Decided to reopen this because I'm not sure if the issue is with prettier, or eslint, but it only manifests since eslint v9. https://github.com/Stono/eslint-19258 contains a reproduction

Stono avatar Dec 20 '24 08:12 Stono

Should report to https://github.com/prettier/prettier-linter-helpers instead.

cc @BPScott

Image

See the last two reports, they can not be applied one by one.

JounQin avatar Jan 15 '25 05:01 JounQin

I haven't looked deep, but I highly doubt this is not related to prettier-linter-helpers, should be another conflicting rule.

fisker avatar Mar 06 '25 15:03 fisker

I haven't looked deep, but I highly doubt this is not related to prettier-linter-helpers, should be another conflicting rule.

Nope. :(

JounQin avatar Mar 06 '25 15:03 JounQin

Right, https://github.com/prettier/prettier-linter-helpers/issues/111#issuecomment-2704289627

fisker avatar Mar 06 '25 16:03 fisker

No, not related to prettier-linter-helpers, the diff is correct. It's conflicting with no-trailing-spaces. But in a strange way.

fisker avatar Mar 06 '25 16:03 fisker

But in a strange way.

Yep.

JounQin avatar Mar 06 '25 16:03 JounQin

I'll report to ESLint.

fisker avatar Mar 06 '25 16:03 fisker

https://github.com/eslint/eslint/issues/19258#issuecomment-2704385061

fisker avatar Mar 06 '25 16:03 fisker