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

PPX attribute vanishes when the propValue variable has the exact name of the prop #2822

Open
pedrobslisboa opened this issue Jan 6, 2025 · 2 comments

Comments

@pedrobslisboa
Copy link

pedrobslisboa commented Jan 6, 2025

Description

I was trying to use ppx attributes on prop variables with the exact name of the prop itself, but the refmt converts it to a shorthand value

<button onFocus={onFocus} onClick={[@foo] onClick} /> becomes <button onFocus onClick/>

The same happens to long records

// This is the initial code
let foo = {a: [@hey] a};
let foo = {a:a, b:b, c:c, d: [@hey] d};

// Turns into the below after refmt
let foo = {d: [@hey] d};
let foo = {
  a,
  b,
  c,
  d,
};

We can see that it happens only on reason:

Solution

On those cases, I think we can keep the prop without shorthand:

// This is the initial code
let bar = <button onFocus={onFocus} onClick={[@foo] onClick} />
let foo = {a:a, b:b, c:c, d: [@hey] d}

// Turns into the below after refmt
let bar = <button onFocus onClick={[@foo] onClick} />
let foo = {
  a,
  b,
  c,
  d: [@hey] d
};

Record

Gravacao.de.Tela.2025-01-06.as.11.46.17.mov
@EmileTrotignon
Copy link

ocamlformat would never do such a thing, it checks that you get the same AST before and after formatting (ignoring locations). Such a bug would be possible, but it would result in ocamlformat crashing. Maybe the same needs to be added to refmt ?

@anmonteiro
Copy link
Member

it makes sense to fix this issue and open a new one for the AST check.

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

No branches or pull requests

3 participants