facebookincubator / fastmod

A fast partial replacement for the codemod tool
Apache License 2.0
1.68k stars 42 forks source link

Exit code 0, but arbitrary error messages with no matches #44

Open konsalex opened 1 year ago

konsalex commented 1 year ago

Hey folks,

The DX is a bit confusing when there are no matches, as the exit code is indeed 0 which is great, but the output for an example command: fastmod -- '--palette-(dark)-([\w-]+)' '--theme-${1}-palette-${2}' -g '!base.css' -g '*.{tsx,ts,js,jsx,css,pcss}' ./src

would be:

Warning: -g: No such file or directory (os error 2)
Warning: !base.css: No such file or directory (os error 2)
Warning: -g: No such file or directory (os error 2)
Warning: *.{tsx,ts,js,jsx,css,pcss}: No such file or directory (os error 2)

which took me quite some time to figure out that indeed it run smoothly, the selectors just did not match anything.

Am I doing something wrong myself maybe?

Edit:

I get this only on times that I need to prepend with -- to avoid throwing with --palette for example

swolchok commented 1 year ago

It looks like you used --, so everything after that is taken literally, not as a flag, including your -g.

On Sep 18, 2023, at 6:48 AM, Costa Alexoglou @.***> wrote:

 Hey folks, The DX is a bit confusing when there are no matches, as the exit code is indeed 0 which is great, but the output for an example command: fastmod -- '--palette-(dark)-([\w-]+)' '--theme-${1}-palette-${2}' -g '!base. css' -g '*. {tsx,ts,js,jsx,css,pcss}' ZjQcmQRYFpfptBannerStart This Message Is From an External Sender

ZjQcmQRYFpfptBannerEnd

Hey folks,

The DX is a bit confusing when there are no matches, as the exit code is indeed 0 which is great, but the output for an example command: fastmod -- '--palette-(dark)-([\w-]+)' '--theme-${1}-palette-${2}' -g '!base.css' -g '*.{tsx,ts,js,jsx,css,pcss}' ./src

would be:

Warning: -g: No such file or directory (os error 2) Warning: !base.css: No such file or directory (os error 2) Warning: -g: No such file or directory (os error 2) Warning: *.{tsx,ts,js,jsx,css,pcss}: No such file or directory (os error 2)

which took me quite some time to figure out that indeed it run smoothly, the selectors just did not match anything.

Am I doing something wrong myself maybe?

— Reply to this email directly, view it on GitHubhttps://github.com/facebookincubator/fastmod/issues/44, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAAIK6B5A4XXKR6Q4YYNLVTX3BGKLANCNFSM6AAAAAA44YHDFQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

konsalex commented 1 year ago

@swolchok without the double hyphen I get to an issue:

error: Found argument '--palette-(dark)-([\w-]+)' which wasn't expected, or isn't valid in this context

Then to solve this I try to escape the hyphens:

fastmod '\-\-palette-(dark)-([\w-]+)' '\-\-theme-${1}-palette-${2}' -g '!base.css' -g '*.{tsx,ts,js,jsx,css,pcss}' ./src

and this one leads to weird replacement

-                 color: "var(--palette-dark-neutral-bg)",
+                 color: "var(\-\-theme-dark-palette-neutral-bg)",

Do you have any clue how this one can be resolved?

swolchok commented 1 year ago

I think moving the flags before the double hyphen should do it: fastmod -g '!base.css' -g '*.{tsx,ts,js,jsx,css,pcss}' -- '--palette-(dark)-([\w-]+)' '--theme-${1}-palette-${2}' ./src