Control of empty lines
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
Hi,
I have just made a recast script and it is working well but I have a final request that I did not manage to solve. I wonder if it possible.
My script reorders `requirejs` define's calls according to a giving priority.
```
define([
'views/1',
'models/2',
'views/3',
], function (
v1,
m2,
v3
) {
// BODY
});
```
with priority `[ 'views', 'models' ]` is transformed into
```
define([
'views/1',
'views/3',
'models/2'
], function (
v1,
v3,
m2
) {
// BODY
})
```
The only problem here is that recast is smart enough to reuse the whitespace so it puts an empty line between `views/1` and `views/3` but I want to put this empty line between `views/3` and `models/2`. I was thinking of tricking `recast` by modifying the `node.original` object but skimming through the source code of `lines.js`, I saw that lines are supposed to be immutable.
Is there a proper way to do that ? I have tried with `reuseWhitespace` set to `false` but to no avail..
Thanks for recast, it is awesome :+1:
My complete script is here : https://gist.github.com/ptbrowne/2b5e9682698cdd5316f1
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the complete script from the linked gist and reading lines.js, especially the whitespace reuse behavior and the effect of reuseWhitespace. Done means the requested ordering preserves or relocates the empty line as intended through a supported recast API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100