Reputation: 1998
Given this JS code or CSS code in the WebStorm IDE:
const foo = {
z: 'zip',
a: 'zot'
}
or
.foo {
z-index: 1;
align-content: center;
}
Is there a way to select the code and reorder the property names alphabetically? To make:
const foo = {
a: 'zot',
z: 'zip'
}
or
.foo {
align-content: center;
z-index: 1;
}
Upvotes: 3
Views: 2878
Reputation: 59
To sort properties in CSS, SCSS, Less, Sass, JavaScript, or TypeScript in WebStorm, follow these steps:
- For Style Sheets (CSS, SCSS, Less, Sass):
- For TypeScript and JavaScript:
I selected 'order by name' for all my rules and this is my final result:
You can customize these rules and create your own if needed. For example, you can set specific ordering for Angular component methods like ngOnInit and ngOnDestroy by adding custom rules.
If you have any further questions, feel free to ask
Upvotes: 0
Reputation: 93828
For CSS, you can enable Sort CSS properties in Settings | Editor | Code Style | Style Sheets | CSS | Arrangement and then use Code > Rearrange Code
For JS, no options are there out of the box. But you can use a third-party String manipulation plugin that supports lines sorting
Upvotes: 4
Reputation: 1
CSS = Styling
JS = Animations / Logic, which is really CHANGING the behavior.
Therefore: Use JS for that. Sort array by firstname (alphabetically) in Javascript
happy to help
Upvotes: -2