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

prettier-plugin-hermes-parser: incorrectly suggesting removal of () brackets #1047

Closed
1 task
mrtnzlml opened this issue Jul 6, 2023 · 1 comment
Closed
1 task
Labels
bug Something isn't working

Comments

@mrtnzlml
Copy link

mrtnzlml commented Jul 6, 2023

Bug Description

I am trying to use prettier-plugin-hermes-parser in my project (because of breaking changes in Prettier 3) and everything seems to be working well except one thing:

const _ = (path.join(__dirname, 'jest-setup.js') /*: string */)

Prettier together with prettier-plugin-hermes-parser suggest the following change:

const _ = path.join(__dirname, 'jest-setup.js') /*: string */;

This is however not correct when running Flow:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/sx-design/jest.config.js:5:49

Unexpected token :, expected the token ;

     2│
     3│ const path = require('path');
     4│
     5│ const _ = path.join(__dirname, 'jest-setup.js') /*: string */;
     6│
     7│ module.exports = {
     8│   rootDir: __dirname,

Found 1 error
  • I have run gradle clean and confirmed this bug does not occur with JSC

Hermes version: 0.14.0 (prettier-plugin-hermes-parser)
React Native version (if any):
OS version (if any):
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64):

Steps To Reproduce

  1. Try to format const _ = (path.join(__dirname, 'jest-setup.js') /*: string */) with Prettier using prettier-plugin-hermes-parser (for example: npx prettier --config=./prettier.config.js src/sx-design/jest.config.js)
  2. 💥

Here is the config I am currently trying to use:

// @flow strict

module.exports = {
  bracketSpacing: true,
  printWidth: 100,
  singleQuote: true,
  tabWidth: 2,
  trailingComma: 'all',
  quoteProps: 'consistent',
  plugins: ['prettier-plugin-hermes-parser'],
  overrides: [
    {
      files: ['*.js', '*.jsx', '*.flow'],
      options: {
        parser: 'hermes',
      },
    },
  ],
};

The Expected Behavior

Prettier won't suggest the removal of "()" brackets in const _ = (path.join(__dirname, 'jest-setup.js') /*: string */) (no change should be suggested)

@pieterv
Copy link
Member

pieterv commented Jul 18, 2023

This isn't really something we can support without heavy modifications to the prettier printer (the reason they also removed it), so it's not realistic for us to support this without forking prettier which we are not interested in doing.

However having done the prettier upgrade within Meta i have found this case pretty easy to work around by shifting the annotation location to the left hand side of the var, e.g.

const _ /*: string */ = path.join(__dirname, 'jest-setup.js');

@avp avp closed this as completed Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants