1

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;
}
dbj44
  • 1,919
  • 2
  • 24
  • 45
  • You have a slight error in your CSS. Declarations are separated by semicolons `;`, not by commas `,`. – bcafuk Jun 23 '21 at 09:21

2 Answers2

5

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

lena
  • 90,154
  • 11
  • 145
  • 150
  • 3
    BTW: the IDE also has the `Edit | Sort Lines` action for a while now: https://youtrack.jetbrains.com/issue/IDEA-218836. But yes, String Manipulation plugin is better and has many more other useful actions available (reverse order; case-insensitivity etc). – LazyOne Jun 23 '21 at 10:39
  • This sort all lines. I want to sort by property – user1034912 May 25 '22 at 23:28
-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