Comments (2)
Hey, I use this plugin in my everyday work and I want to contribute with some refactorings at some point. To get to know how the plugin works I started working on this particular refactoring here. I have it working, however I have some failing test cases because I cannot control or do not understand how the formatting works.
Consider the example of your proposed solution:
if (!isValid) {
return;
}
Rather than putting the if
and the return
in one line my implementation will change the code to
if (!isValid)
return;
Which, of course, is also a valid solution. So my questions are
- Should we care about the output formatting or force a particular formatting style?
- If yes, how should we go about achieving this? Since in the refactoring we're manipulating an Abstract Syntax Tree which afaik only deals with the structure of a piece of code I currently don't see a way to influence the formatting at all. Perhaps I'm overlooking something.
Any pointers would be welcome.
from abracadabra.
Hi @automatensalat 👋
First of all, thank you for your help, it's very much appreciated!
Should we care about the output formatting or force a particular formatting style?
It would be fine to have the feature working first, and then we optimize from the feedback we received. Thus, if you have a valid solution that generates this output, you can already open a PR.
If people use some tooling to prettify their code, it may not even matter for them.
If yes, how should we go about achieving this?
As a user of the extension, I would expect the result to be on a single line if it has no braces. So I'll try to find a solution to this.
As you said, you can't achieve this with the AST. I don't think we could configure it so it produces a one-liner.
What we could do is transform the generated code string, after the AST transformation and before we write it back to the editor. We could detect this pattern (if + new line return) and replace the new line with a single space. The tricky part would be to change only the transformed if
.
I did something a bit similar here:
abracadabra/src/refactorings/flip-if-else/flip-if-else.ts
Lines 19 to 23 in 5cc121f
from abracadabra.
Related Issues (20)
- Automatically "Convert to Template String" if we write ${} in a string HOT 2
- Abracadabra does not play nice with cursorless HOT 29
- Inlining JSX removes curly braces HOT 1
- Extract refactoring runs on JSX attribute HOT 3
- Inline async arrow function misses braces HOT 1
- Abracadabra replaces system key binding HOT 3
- Extract Variable insert position doesn't right HOT 2
- change activationEvent to onLanguage
- Idea: Migrate to TypeScript plugin HOT 4
- "Change Signature" doesn't work on a nested function HOT 3
- "Add explicit type" refactoring HOT 1
- Inline variable if ternary misses parens HOT 5
- split declaration & init when working inside class
- JS and TS code without `;` is broken after refactoring HOT 3
- Abracadabra extension causes performance issues with other extensions (prettier formatting, etc.) HOT 7
- More inline variable missing parentheses edge-cases HOT 1
- Can't move class to an existing file HOT 2
- Move to new file: configure case of the new filename HOT 3
- Upgrade babel/traverse ti eliminate vulnerability. HOT 1
- Convert to Arrow Function: Does not work with a `export default function` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abracadabra.