-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
[feature] manipulate captured variable in fix mode #436
Comments
I will only support string slicing in my first implementation. |
Is this |
@suyanhanx
|
The regex and replace parts may be difficult to distinguish. |
@suyanhanx Any suggestion to make them clear? |
It's actually difficult to decide which character to choose as the separator. Can we provide an additional configuration option to allow users to choose their own separator? Of course, we could also default to a common separator, such as # or %. |
I remember Vim has it and it is probably too nerdy to most modern devs. |
Alternatively, we could change the format by making it like a function call or dividing it into different configuration options. |
Old Proposal, withdrawn.
String Manipulation SyntaxReplace
DeletionSimilar to replace but leave
Concat
Transform$VAR.upperCase
$VAR.lowerCase.capitalize # multiple transformation can be chained SubstringNegative index is supported.
💻 Use Caseschange file extension from |
Added in 0.6.3 |
…e, substring and as a stand-alone transform
…e, substring and as a stand-alone transform
…ubstring and as a stand-alone transform
…ne chainable `convert` transform
…ne chainable `convert` transform
…ne chainable `convert` transform
…able `convert` transform
Suggestion
⭐ Suggestion
I think it is necessary to support string manipulation in fix mode. Reference #430
It is impossible to match some patterns in some languages. String manipulation is a must to support example like
get the inner content of a generator expression in Python
.📃 Motivating Example
Use ast-grep to change ESM
*.mjs
to CJSrequire("*")
.Proposal
New Field in YAML Rule
We will add a new field
transform
in YAML rule.The API will use YAML to encode string operations.
Pro:
Cons:
Substring
Replace
Convert
Similar to
https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#intrinsic-string-manipulation-types
You can specify separator by
separatedBy
option inconvert
.Deletion (IMPLEMENTED as replace)
Similar to replace but leave replace as empty.
Concat (NOT IMPLEMENTED)
The text was updated successfully, but these errors were encountered: