├── .gitignore ├── .idea ├── codeStyleSettings.xml ├── compiler.xml ├── dictionaries │ └── rudeshko.xml ├── encodings.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations │ ├── All_Tests.xml │ └── Run_plugin.xml ├── scopes │ └── scope_settings.xml └── vcs.xml ├── CSSReorder.iml ├── LICENSE ├── META-INF └── plugin.xml ├── README.md ├── change-notes.html ├── src └── com │ └── rudeshko │ └── css │ └── rearrange │ ├── CssArrangementParseInfo.java │ ├── CssArrangementVisitor.java │ ├── CssElementArrangementEntry.java │ ├── CssOrder.java │ └── CssRearranger.java ├── testData ├── comment │ ├── in.css │ └── out.css ├── imports │ ├── in.css │ └── out.css ├── media │ ├── in.css │ └── out.css ├── selection │ ├── in.css │ └── out.css ├── several │ ├── in.css │ └── out.css └── simple │ ├── in.css │ └── out.css └── tests └── com └── rudeshko └── css └── rearrange └── RearrangeTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | .idea/workspace.xml 3 | CSSReorder.jar 4 | -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/dictionaries/rudeshko.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | intelli 5 | webhelp 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 65 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations/All_Tests.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Run_plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CSSReorder.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.rudeshko.csscomb 3 | CSSReorder (beta) 4 | 0.5.1 5 | Anton Rudeshko 6 | 7 | Very early version, use on your own risk. Stay tuned for updates. 9 |

10 | A tool for sorting CSS properties in specific order (for now using default order as defined on http://csscomb.ru/online/). 11 |

12 | Feel free to contribute: 13 | https://github.com/anton-rudeshko/CSSReorder 14 | ]]>
15 | 16 | v0.5.1 (24.07.2014) 18 | 21 | 22 | v0.5.0 (06.11.2013) 23 | 28 | 29 | v0.4.0 (02.07.2013) 30 | 48 | 49 | v0.3.1 (29.06.2013) 50 | 56 | 57 | v0.3 (27.06.2013) 58 | 68 | 69 | v0.2 (30.01.2013) 70 | 77 | 78 | v0.1 (19.01.2013) 79 | 82 | ]]> 83 | 84 | 85 | 86 | 87 | com.intellij.modules.lang 88 | com.intellij.css 89 | 90 | 91 | 92 | 93 |
94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSSReorder 2 | ## About 3 | **Very early version, use on your own risk. Stay tuned for updates.** 4 | 5 | Sorting CSS properties in predefined order. 6 | Consider also using node.js/npm version: csscomb.js 7 | 8 | ## Disclaimer 9 | Requires IntelliJ platform version ≥ 13. 10 | 11 | Formerly known as CSSComb but was renamed to avoid people confusion. 12 | This plugin is NOT supported by [CSSComb organization](https://github.com/csscomb) and have no shared codebase. 13 | CSSComb author is not responsible for any bugs. 14 | This is only my initiative to implement original CSSComb features as native to IDEA platform. 15 | 16 | Based on [platform provided rearrangement](http://blogs.jetbrains.com/idea/2012/10/arrange-your-code-automatically-with-intellij-idea-12/). 17 | 18 | ## Installation 19 | Install from IntelliJ IDEA plugin repositories or download manually [here](http://plugins.jetbrains.com/plugin?pr=&pluginId=7164). 20 | 21 | ## Usage 22 | Should be invoked using *Code → Rearrange* action on CSS files. 23 | This action also can be invoked on code reformatting action by checking corresponding option (Rearrange entries) in 24 | [Reformat code dialog](https://www.jetbrains.com/help/idea/2016.1/reformat-file-dialog.html). 25 | 26 | ## Contribution 27 | Feel free to report bugs, request features and contribute. 28 | 29 | ### How to Run Tests 30 | 1. Install desired product (PHPStorm, WebStorm, IntelliJ IDEA, etc). 31 | 1. Download sources from [IntelliJ Community](https://github.com/jetbrains/intellij-community). 32 | 1. Checkout required tag. 33 | 1. Create new SDK and point it into installed instance. 34 | 1. Attach sources from Community. 35 | 1. Plugin should fully compile by now. 36 | 1. Fix hardcoded path. 37 | 1. ... something else 38 | 1. If getting error about `TestCase class is not found` try using IDEA SDK 39 | 40 | Useful links: 41 | * [IDEA Logs and settings](https://intellij-support.jetbrains.com/entries/23358108-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs) 42 | -------------------------------------------------------------------------------- /change-notes.html: -------------------------------------------------------------------------------- 1 | v0.4.0 (02.07.2013) 2 | 20 | 21 | v0.3.1 (29.06.2013) 22 | 28 | 29 | v0.3 (27.06.2013) 30 | 40 | 41 | v0.2 (30.01.2013) 42 | 49 | 50 | v0.1 (19.01.2013) 51 | 54 | -------------------------------------------------------------------------------- /src/com/rudeshko/css/rearrange/CssArrangementParseInfo.java: -------------------------------------------------------------------------------- 1 | package com.rudeshko.css.rearrange; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class CssArrangementParseInfo { 9 | @NotNull 10 | private final List myEntries = new ArrayList(); 11 | 12 | @NotNull 13 | public List getEntries() { 14 | return myEntries; 15 | } 16 | 17 | public void addEntry(@NotNull CssElementArrangementEntry entry) { 18 | myEntries.add(entry); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/rudeshko/css/rearrange/CssArrangementVisitor.java: -------------------------------------------------------------------------------- 1 | package com.rudeshko.css.rearrange; 2 | 3 | import com.intellij.openapi.util.TextRange; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiFile; 6 | import com.intellij.psi.css.*; 7 | import com.intellij.util.containers.Stack; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.util.Collection; 12 | 13 | public class CssArrangementVisitor extends CssElementVisitor { 14 | private final CssArrangementParseInfo myInfo; 15 | private final Collection myRanges; 16 | 17 | @NotNull 18 | private final Stack myStack = new Stack(); 19 | 20 | public CssArrangementVisitor(@NotNull CssArrangementParseInfo parseInfo, @NotNull Collection ranges) { 21 | this.myInfo = parseInfo; 22 | this.myRanges = ranges; 23 | } 24 | 25 | @Override 26 | public void visitFile(PsiFile file) { 27 | if (file instanceof CssFile) { 28 | visitCssFile((CssFile) file); 29 | } 30 | } 31 | 32 | @Override 33 | public void visitCssFile(CssFile file) { 34 | visitCssStylesheet(file.getStylesheet()); 35 | } 36 | 37 | @Override 38 | public void visitCssStylesheet(CssStylesheet stylesheet) { 39 | for (CssRuleset ruleset : stylesheet.getRulesets(true)) { 40 | visitCssRuleset(ruleset); 41 | } 42 | } 43 | 44 | public void visitCssMedia(CssMedia media) { 45 | for (CssRuleset ruleset : media.getRulesets()) { 46 | visitCssRuleset(ruleset); 47 | } 48 | } 49 | 50 | @Override 51 | public void visitAtRule(CssAtRule atRule) { 52 | if (atRule instanceof CssMedia) { 53 | visitCssMedia((CssMedia) atRule); 54 | } 55 | } 56 | 57 | @Override 58 | public void visitCssRuleset(CssRuleset ruleset) { 59 | visitCssBlock(ruleset.getBlock()); 60 | } 61 | 62 | @Override 63 | public void visitCssBlock(CssBlock block) { 64 | processEntry(createNewEntry(block.getTextRange(), null), block); 65 | } 66 | 67 | @Override 68 | public void visitCssDeclaration(CssDeclaration declaration) { 69 | createNewEntry(declaration.getTextRange(), declaration.getPropertyName()); 70 | } 71 | 72 | private 73 | @Nullable 74 | CssElementArrangementEntry createNewEntry(@NotNull TextRange range, @Nullable String propertyName) { 75 | if (!isWithinBounds(range)) { 76 | return null; 77 | } 78 | 79 | CssElementArrangementEntry current = getCurrent(); 80 | CssElementArrangementEntry entry = new CssElementArrangementEntry(current, range, propertyName); 81 | if (current == null) { 82 | myInfo.addEntry(entry); 83 | } else { 84 | current.addChild(entry); 85 | } 86 | return entry; 87 | } 88 | 89 | private void processEntry(@Nullable CssElementArrangementEntry entry, @Nullable PsiElement nextPsiRoot) { 90 | if (entry == null || nextPsiRoot == null) { 91 | return; 92 | } 93 | myStack.push(entry); 94 | try { 95 | nextPsiRoot.acceptChildren(this); 96 | } finally { 97 | myStack.pop(); 98 | } 99 | } 100 | 101 | @Nullable 102 | private CssElementArrangementEntry getCurrent() { 103 | return myStack.isEmpty() ? null : myStack.peek(); 104 | } 105 | 106 | private boolean isWithinBounds(@NotNull TextRange range) { 107 | for (TextRange textRange : myRanges) { 108 | if (textRange.intersects(range)) { 109 | return true; 110 | } 111 | } 112 | return false; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/com/rudeshko/css/rearrange/CssElementArrangementEntry.java: -------------------------------------------------------------------------------- 1 | package com.rudeshko.css.rearrange; 2 | 3 | import com.intellij.openapi.util.TextRange; 4 | import com.intellij.psi.codeStyle.arrangement.DefaultArrangementEntry; 5 | import com.intellij.psi.codeStyle.arrangement.NameAwareArrangementEntry; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | public class CssElementArrangementEntry extends DefaultArrangementEntry implements NameAwareArrangementEntry { 10 | @Nullable 11 | private String name; 12 | 13 | public CssElementArrangementEntry(@Nullable CssElementArrangementEntry parent, @NotNull TextRange range, @Nullable String name) { 14 | super(parent, range.getStartOffset(), range.getEndOffset(), true); 15 | this.name = name; 16 | } 17 | 18 | @Nullable 19 | @Override 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "CssElementArrangementEntry{" + 27 | "name='" + name + '\'' + 28 | ", children.size='" + getChildren().size() + '\'' + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/rudeshko/css/rearrange/CssOrder.java: -------------------------------------------------------------------------------- 1 | package com.rudeshko.css.rearrange; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import java.util.List; 6 | 7 | import static java.util.Arrays.asList; 8 | 9 | public class CssOrder { 10 | 11 | @NotNull 12 | public static final List DEFAULT_ORDER = asList( 13 | "position", 14 | "top", 15 | "right", 16 | "bottom", 17 | "left", 18 | "z-index", 19 | "display", 20 | "visibility", 21 | "-webkit-flex-direction", 22 | "-moz-flex-direction", 23 | "-ms-flex-direction", 24 | "-o-flex-direction", 25 | "flex-direction", 26 | "-webkit-flex-order", 27 | "-moz-flex-order", 28 | "-ms-flex-order", 29 | "-o-flex-order", 30 | "flex-order", 31 | "-webkit-flex-pack", 32 | "-moz-flex-pack", 33 | "-ms-flex-pack", 34 | "-o-flex-pack", 35 | "flex-pack", 36 | "float", 37 | "clear", 38 | "-webkit-flex-align", 39 | "-moz-flex-align", 40 | "-ms-flex-align", 41 | "-o-flex-align", 42 | "flex-align", 43 | "overflow", 44 | "-ms-overflow-x", 45 | "-ms-overflow-y", 46 | "overflow-x", 47 | "overflow-y", 48 | "clip", 49 | "-webkit-box-sizing", 50 | "-moz-box-sizing", 51 | "box-sizing", 52 | "margin", 53 | "margin-top", 54 | "margin-right", 55 | "margin-bottom", 56 | "margin-left", 57 | "padding", 58 | "padding-top", 59 | "padding-right", 60 | "padding-bottom", 61 | "padding-left", 62 | "min-width", 63 | "min-height", 64 | "max-width", 65 | "max-height", 66 | "width", 67 | "height", 68 | "outline", 69 | "outline-width", 70 | "outline-style", 71 | "outline-color", 72 | "outline-offset", 73 | "border", 74 | "border-spacing", 75 | "border-collapse", 76 | "border-width", 77 | "border-style", 78 | "border-color", 79 | "border-top", 80 | "border-top-width", 81 | "border-top-style", 82 | "border-top-color", 83 | "border-right", 84 | "border-right-width", 85 | "border-right-style", 86 | "border-right-color", 87 | "border-bottom", 88 | "border-bottom-width", 89 | "border-bottom-style", 90 | "border-bottom-color", 91 | "border-left", 92 | "border-left-width", 93 | "border-left-style", 94 | "border-left-color", 95 | "-webkit-border-radius", 96 | "-moz-border-radius", 97 | "border-radius", 98 | "-webkit-border-top-left-radius", 99 | "-moz-border-radius-topleft", 100 | "border-top-left-radius", 101 | "-webkit-border-top-right-radius", 102 | "-moz-border-radius-topright", 103 | "border-top-right-radius", 104 | "-webkit-border-bottom-right-radius", 105 | "-moz-border-radius-bottomright", 106 | "border-bottom-right-radius", 107 | "-webkit-border-bottom-left-radius", 108 | "-moz-border-radius-bottomleft", 109 | "border-bottom-left-radius", 110 | "-webkit-border-image", 111 | "-moz-border-image", 112 | "-o-border-image", 113 | "border-image", 114 | "-webkit-border-image-source", 115 | "-moz-border-image-source", 116 | "-o-border-image-source", 117 | "border-image-source", 118 | "-webkit-border-image-slice", 119 | "-moz-border-image-slice", 120 | "-o-border-image-slice", 121 | "border-image-slice", 122 | "-webkit-border-image-width", 123 | "-moz-border-image-width", 124 | "-o-border-image-width", 125 | "border-image-width", 126 | "-webkit-border-image-outset", 127 | "-moz-border-image-outset", 128 | "-o-border-image-outset", 129 | "border-image-outset", 130 | "-webkit-border-image-repeat", 131 | "-moz-border-image-repeat", 132 | "-o-border-image-repeat", 133 | "border-image-repeat", 134 | "-webkit-border-top-image", 135 | "-moz-border-top-image", 136 | "-o-border-top-image", 137 | "border-top-image", 138 | "-webkit-border-right-image", 139 | "-moz-border-right-image", 140 | "-o-border-right-image", 141 | "border-right-image", 142 | "-webkit-border-bottom-image", 143 | "-moz-border-bottom-image", 144 | "-o-border-bottom-image", 145 | "border-bottom-image", 146 | "-webkit-border-left-image", 147 | "-moz-border-left-image", 148 | "-o-border-left-image", 149 | "border-left-image", 150 | "-webkit-border-corner-image", 151 | "-moz-border-corner-image", 152 | "-o-border-corner-image", 153 | "border-corner-image", 154 | "-webkit-border-top-left-image", 155 | "-moz-border-top-left-image", 156 | "-o-border-top-left-image", 157 | "border-top-left-image", 158 | "-webkit-border-top-right-image", 159 | "-moz-border-top-right-image", 160 | "-o-border-top-right-image", 161 | "border-top-right-image", 162 | "-webkit-border-bottom-right-image", 163 | "-moz-border-bottom-right-image", 164 | "-o-border-bottom-right-image", 165 | "border-bottom-right-image", 166 | "-webkit-border-bottom-left-image", 167 | "-moz-border-bottom-left-image", 168 | "-o-border-bottom-left-image", 169 | "border-bottom-left-image", 170 | "background", 171 | "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader", 172 | "background-color", 173 | "background-image", 174 | "background-attachment", 175 | "background-position", 176 | "-ms-background-position-x", 177 | "-ms-background-position-y", 178 | "background-position-x", 179 | "background-position-y", 180 | "background-clip", 181 | "background-origin", 182 | "background-size", 183 | "background-repeat", 184 | "box-decoration-break", 185 | "-webkit-box-shadow", 186 | "-moz-box-shadow", 187 | "box-shadow", 188 | "color", 189 | "table-layout", 190 | "caption-side", 191 | "empty-cells", 192 | "list-style", 193 | "list-style-position", 194 | "list-style-type", 195 | "list-style-image", 196 | "quotes", 197 | "content", 198 | "counter-increment", 199 | "counter-reset", 200 | "-ms-writing-mode", 201 | "vertical-align", 202 | "text-align", 203 | "-webkit-text-align-last", 204 | "-moz-text-align-last", 205 | "-ms-text-align-last", 206 | "text-align-last", 207 | "text-decoration", 208 | "text-emphasis", 209 | "text-emphasis-position", 210 | "text-emphasis-style", 211 | "text-emphasis-color", 212 | "text-indent", 213 | "-ms-text-justify", 214 | "text-justify", 215 | "text-outline", 216 | "text-transform", 217 | "text-wrap", 218 | "-ms-text-overflow", 219 | "text-overflow", 220 | "text-overflow-ellipsis", 221 | "text-overflow-mode", 222 | "text-shadow", 223 | "white-space", 224 | "word-spacing", 225 | "-ms-word-wrap", 226 | "word-wrap", 227 | "-ms-word-break", 228 | "word-break", 229 | "-moz-tab-size", 230 | "-o-tab-size", 231 | "tab-size", 232 | "-webkit-hyphens", 233 | "-moz-hyphens", 234 | "hyphens", 235 | "letter-spacing", 236 | "font", 237 | "font-weight", 238 | "font-style", 239 | "font-variant", 240 | "font-size-adjust", 241 | "font-stretch", 242 | "font-size", 243 | "font-family", 244 | "src", 245 | "line-height", 246 | "opacity", 247 | "-ms-filter:'progid:DXImageTransform.Microsoft.Alpha", 248 | "filter:progid:DXImageTransform.Microsoft.Alpha(Opacity", 249 | "-ms-interpolation-mode", 250 | "-webkit-filter", 251 | "-ms-filter", 252 | "filter", 253 | "resize", 254 | "cursor", 255 | "nav-index", 256 | "nav-up", 257 | "nav-right", 258 | "nav-down", 259 | "nav-left", 260 | "-webkit-transition", 261 | "-moz-transition", 262 | "-ms-transition", 263 | "-o-transition", 264 | "transition", 265 | "-webkit-transition-delay", 266 | "-moz-transition-delay", 267 | "-ms-transition-delay", 268 | "-o-transition-delay", 269 | "transition-delay", 270 | "-webkit-transition-timing-function", 271 | "-moz-transition-timing-function", 272 | "-ms-transition-timing-function", 273 | "-o-transition-timing-function", 274 | "transition-timing-function", 275 | "-webkit-transition-duration", 276 | "-moz-transition-duration", 277 | "-ms-transition-duration", 278 | "-o-transition-duration", 279 | "transition-duration", 280 | "-webkit-transition-property", 281 | "-moz-transition-property", 282 | "-ms-transition-property", 283 | "-o-transition-property", 284 | "transition-property", 285 | "-webkit-transform", 286 | "-moz-transform", 287 | "-ms-transform", 288 | "-o-transform", 289 | "transform", 290 | "-webkit-transform-origin", 291 | "-moz-transform-origin", 292 | "-ms-transform-origin", 293 | "-o-transform-origin", 294 | "transform-origin", 295 | "-webkit-animation", 296 | "-moz-animation", 297 | "-ms-animation", 298 | "-o-animation", 299 | "animation", 300 | "-webkit-animation-name", 301 | "-moz-animation-name", 302 | "-ms-animation-name", 303 | "-o-animation-name", 304 | "animation-name", 305 | "-webkit-animation-duration", 306 | "-moz-animation-duration", 307 | "-ms-animation-duration", 308 | "-o-animation-duration", 309 | "animation-duration", 310 | "-webkit-animation-play-state", 311 | "-moz-animation-play-state", 312 | "-ms-animation-play-state", 313 | "-o-animation-play-state", 314 | "animation-play-state", 315 | "-webkit-animation-timing-function", 316 | "-moz-animation-timing-function", 317 | "-ms-animation-timing-function", 318 | "-o-animation-timing-function", 319 | "animation-timing-function", 320 | "-webkit-animation-delay", 321 | "-moz-animation-delay", 322 | "-ms-animation-delay", 323 | "-o-animation-delay", 324 | "animation-delay", 325 | "-webkit-animation-iteration-count", 326 | "-moz-animation-iteration-count", 327 | "-ms-animation-iteration-count", 328 | "-o-animation-iteration-count", 329 | "animation-iteration-count", 330 | "-webkit-animation-direction", 331 | "-moz-animation-direction", 332 | "-ms-animation-direction", 333 | "-o-animation-direction", 334 | "animation-direction", 335 | "pointer-events", 336 | "unicode-bidi", 337 | "direction", 338 | "-webkit-columns", 339 | "-moz-columns", 340 | "columns", 341 | "-webkit-column-span", 342 | "-moz-column-span", 343 | "column-span", 344 | "-webkit-column-width", 345 | "-moz-column-width", 346 | "column-width", 347 | "-webkit-column-count", 348 | "-moz-column-count", 349 | "column-count", 350 | "-webkit-column-fill", 351 | "-moz-column-fill", 352 | "column-fill", 353 | "-webkit-column-gap", 354 | "-moz-column-gap", 355 | "column-gap", 356 | "-webkit-column-rule", 357 | "-moz-column-rule", 358 | "column-rule", 359 | "-webkit-column-rule-width", 360 | "-moz-column-rule-width", 361 | "column-rule-width", 362 | "-webkit-column-rule-style", 363 | "-moz-column-rule-style", 364 | "column-rule-style", 365 | "-webkit-column-rule-color", 366 | "-moz-column-rule-color", 367 | "column-rule-color", 368 | "break-before", 369 | "break-inside", 370 | "break-after", 371 | "page-break-before", 372 | "page-break-inside", 373 | "page-break-after", 374 | "orphans", 375 | "widows", 376 | "-ms-zoom", 377 | "zoom", 378 | "max-zoom", 379 | "min-zoom", 380 | "user-zoom", 381 | "orientation" 382 | ); 383 | } 384 | -------------------------------------------------------------------------------- /src/com/rudeshko/css/rearrange/CssRearranger.java: -------------------------------------------------------------------------------- 1 | package com.rudeshko.css.rearrange; 2 | 3 | import com.intellij.openapi.editor.Document; 4 | import com.intellij.openapi.util.Pair; 5 | import com.intellij.openapi.util.TextRange; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.psi.codeStyle.CodeStyleSettings; 8 | import com.intellij.psi.codeStyle.arrangement.ArrangementSettings; 9 | import com.intellij.psi.codeStyle.arrangement.ArrangementSettingsSerializer; 10 | import com.intellij.psi.codeStyle.arrangement.DefaultArrangementSettingsSerializer; 11 | import com.intellij.psi.codeStyle.arrangement.Rearranger; 12 | import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher; 13 | import com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule; 14 | import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher; 15 | import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule; 16 | import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition; 17 | import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition; 18 | import com.intellij.psi.codeStyle.arrangement.std.*; 19 | import com.intellij.util.containers.ContainerUtilRt; 20 | import org.jetbrains.annotations.NotNull; 21 | import org.jetbrains.annotations.Nullable; 22 | 23 | import java.util.*; 24 | 25 | public class CssRearranger implements Rearranger, ArrangementStandardSettingsAware { 26 | /** 27 | * Describing and filling out default order rules. 28 | * It will be used in default settings and then settings used to rearrange properties. 29 | */ 30 | private static final List DEFAULT_MATCH_RULES = new ArrayList(); 31 | 32 | static { 33 | for (String propertyName : CssOrder.DEFAULT_ORDER) { 34 | addRule(propertyName); 35 | } 36 | } 37 | 38 | private static void addRule(String propertyName) { 39 | ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, propertyName); 40 | StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition); 41 | StdArrangementMatchRule matchRule = new StdArrangementMatchRule(matcher, StdArrangementTokens.Order.BY_NAME); 42 | DEFAULT_MATCH_RULES.add(ArrangementSectionRule.create(matchRule)); 43 | } 44 | 45 | private static final StdArrangementSettings DEFAULT_SETTINGS = new StdArrangementSettings(DEFAULT_MATCH_RULES); 46 | private static final DefaultArrangementSettingsSerializer SETTINGS_SERIALIZER = new DefaultArrangementSettingsSerializer(DEFAULT_SETTINGS); 47 | private static final Set SUPPORTED_TYPES = ContainerUtilRt.newLinkedHashSet(StdArrangementTokens.EntryType.PROPERTY); 48 | 49 | @Nullable 50 | @Override 51 | public Pair> parseWithNew(@NotNull PsiElement root, 52 | @Nullable Document document, 53 | @NotNull Collection ranges, 54 | @NotNull PsiElement element, 55 | @Nullable ArrangementSettings settings) { 56 | return null; // TODO: implement 57 | } 58 | 59 | @NotNull 60 | @Override 61 | public List parse(@NotNull PsiElement root, @Nullable Document document, @NotNull Collection ranges, @Nullable ArrangementSettings settings) { 62 | CssArrangementParseInfo parseInfo = new CssArrangementParseInfo(); 63 | root.accept(new CssArrangementVisitor(parseInfo, ranges)); 64 | return parseInfo.getEntries(); 65 | } 66 | 67 | @Override 68 | public int getBlankLines(@NotNull CodeStyleSettings settings, @Nullable CssElementArrangementEntry parent, @Nullable CssElementArrangementEntry previous, @NotNull CssElementArrangementEntry target) { 69 | return -1; 70 | } 71 | 72 | @NotNull 73 | @Override 74 | public ArrangementSettingsSerializer getSerializer() { 75 | return SETTINGS_SERIALIZER; 76 | } 77 | 78 | @Nullable 79 | @Override 80 | public StdArrangementSettings getDefaultSettings() { 81 | return DEFAULT_SETTINGS; 82 | } 83 | 84 | @Nullable 85 | @Override 86 | public List getSupportedGroupingTokens() { 87 | return null; 88 | } 89 | 90 | @Nullable 91 | @Override 92 | public List getSupportedMatchingTokens() { 93 | return null; 94 | } 95 | 96 | @Override 97 | public boolean isEnabled(@NotNull ArrangementSettingsToken token, @Nullable ArrangementMatchCondition current) { 98 | return SUPPORTED_TYPES.contains(token); 99 | } 100 | 101 | @NotNull 102 | @Override 103 | public Collection> getMutexes() { 104 | return Collections.singleton(SUPPORTED_TYPES); 105 | } 106 | 107 | @NotNull 108 | @Override 109 | public ArrangementEntryMatcher buildMatcher(@NotNull ArrangementMatchCondition condition) throws IllegalArgumentException { 110 | throw new IllegalArgumentException("Can't build a matcher for condition " + condition); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /testData/comment/in.css: -------------------------------------------------------------------------------- 1 | .a { 2 | color: #fff000; 3 | width: auto; /* my comment */ 4 | } -------------------------------------------------------------------------------- /testData/comment/out.css: -------------------------------------------------------------------------------- 1 | .a { 2 | width: auto; /* my comment */ 3 | color: #fff000; 4 | } -------------------------------------------------------------------------------- /testData/imports/in.css: -------------------------------------------------------------------------------- 1 | /* YAML Framework CSS file */ 2 | @import url(common/yaml.css); 3 | /* YAML Builder settings */ 4 | @import url(quickstart/basemod.css); 5 | /* import vendor files */ 6 | @import url(../vendor/jquery-ui/css/smoothness/jquery-ui-1.10.1.custom.css); 7 | @import url(../vendor/slimbox/css/slimbox2.css); 8 | 9 | .a { 10 | display: none; 11 | } -------------------------------------------------------------------------------- /testData/imports/out.css: -------------------------------------------------------------------------------- 1 | /* YAML Framework CSS file */ 2 | @import url(common/yaml.css); 3 | /* YAML Builder settings */ 4 | @import url(quickstart/basemod.css); 5 | /* import vendor files */ 6 | @import url(../vendor/jquery-ui/css/smoothness/jquery-ui-1.10.1.custom.css); 7 | @import url(../vendor/slimbox/css/slimbox2.css); 8 | 9 | .a { 10 | display: none; 11 | } -------------------------------------------------------------------------------- /testData/media/in.css: -------------------------------------------------------------------------------- 1 | @media all { 2 | .a { 3 | top: 0; 4 | position: absolute; 5 | } 6 | } -------------------------------------------------------------------------------- /testData/media/out.css: -------------------------------------------------------------------------------- 1 | @media all { 2 | .a { 3 | position: absolute; 4 | top: 0; 5 | } 6 | } -------------------------------------------------------------------------------- /testData/selection/in.css: -------------------------------------------------------------------------------- 1 | .a { 2 | top: 0; 3 | position: absolute; 4 | } 5 | 6 | .a2 { 7 | top: 0; 8 | position: absolute; 9 | } 10 | 11 | .a3 { 12 | top: 0; 13 | position: absolute; 14 | } -------------------------------------------------------------------------------- /testData/selection/out.css: -------------------------------------------------------------------------------- 1 | .a { 2 | top: 0; 3 | position: absolute; 4 | } 5 | 6 | .a2 { 7 | position: absolute; 8 | top: 0; 9 | } 10 | 11 | .a3 { 12 | top: 0; 13 | position: absolute; 14 | } -------------------------------------------------------------------------------- /testData/several/in.css: -------------------------------------------------------------------------------- 1 | .a { 2 | right: 10px; 3 | top: 0; 4 | position: absolute; 5 | display: none; 6 | } -------------------------------------------------------------------------------- /testData/several/out.css: -------------------------------------------------------------------------------- 1 | .a { 2 | position: absolute; 3 | top: 0; 4 | right: 10px; 5 | display: none; 6 | } -------------------------------------------------------------------------------- /testData/simple/in.css: -------------------------------------------------------------------------------- 1 | .a { 2 | top: 0; 3 | position: absolute; 4 | } -------------------------------------------------------------------------------- /testData/simple/out.css: -------------------------------------------------------------------------------- 1 | .a { 2 | position: absolute; 3 | top: 0; 4 | } -------------------------------------------------------------------------------- /tests/com/rudeshko/css/rearrange/RearrangeTest.java: -------------------------------------------------------------------------------- 1 | package com.rudeshko.css.rearrange; 2 | 3 | import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; 4 | 5 | /** 6 | * @link http://confluence.jetbrains.com/display/IDEADEV/Testing+IntelliJ+IDEA+Plugins 7 | * @link http://confluence.jetbrains.com/display/IntelliJIDEA/Tests+Prerequisites 8 | */ 9 | public class RearrangeTest extends LightPlatformCodeInsightFixtureTestCase { 10 | @Override 11 | protected String getTestDataPath() { 12 | // TODO: Dunno how to do it platform independent for now 13 | return "/Users/rudeshko/dev/idea/CSSReorder/testData"; 14 | } 15 | 16 | public void testSimple() throws Exception { 17 | runCase("simple"); 18 | } 19 | 20 | public void testSeveral() throws Exception { 21 | runCase("several"); 22 | } 23 | 24 | public void _testComment() throws Exception { 25 | runCase("comment"); // Failing. TODO: implement 26 | } 27 | 28 | public void testMedia() throws Exception { 29 | runCase("media"); 30 | } 31 | 32 | public void testSelection() throws Exception { 33 | runCase("selection"); 34 | } 35 | 36 | public void testImports() throws Exception { 37 | runCase("imports"); 38 | } 39 | 40 | public void runCase(String testDir) { 41 | myFixture.configureByFiles(testDir + "/in.css"); 42 | myFixture.performEditorAction("RearrangeCode"); 43 | myFixture.checkResultByFile(testDir + "/out.css"); 44 | } 45 | 46 | } 47 | --------------------------------------------------------------------------------