Skip to content

Commit 69bc101

Browse files
vpavicphilwebb
authored andcommitted
Add SpringImportOrderCheck with package support
Add a `SpringImportOrderCheck` to allow spring import ordering with the option of configuring the project root package. See gh-62
1 parent e513125 commit 69bc101

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2017-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.javaformat.checkstyle.check;
18+
19+
import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
20+
21+
/**
22+
* Checks that the order of imports follow Spring conventions.
23+
*
24+
* @author Vedran Pavic
25+
*/
26+
public class SpringImportOrderCheck extends ImportOrderCheck {
27+
28+
private static final String DEFAULT_PROJECT_ROOT_PACKAGE = "org.springframework";
29+
30+
public SpringImportOrderCheck() {
31+
setProjectRootPackage(DEFAULT_PROJECT_ROOT_PACKAGE);
32+
setOrdered(true);
33+
setSeparated(true);
34+
setOption("bottom");
35+
setSortStaticImportsAlphabetically(true);
36+
}
37+
38+
public void setProjectRootPackage(String projectRootPackage) {
39+
setGroups("java", "/^javax?\\./", "*", projectRootPackage);
40+
}
41+
42+
}

spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@
8181
<module name="com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck">
8282
<property name="processJavadoc" value="true" />
8383
</module>
84-
<module name="com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck">
85-
<property name="groups" value="java,/^javax?\./,*,org.springframework" />
86-
<property name="ordered" value="true" />
87-
<property name="separated" value="true" />
88-
<property name="option" value="bottom" />
89-
<property name="sortStaticImportsAlphabetically" value="true" />
90-
</module>
84+
<module name="io.spring.javaformat.checkstyle.check.SpringImportOrderCheck"/>
9185

9286
<!-- Javadoc Comments -->
9387
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck">

0 commit comments

Comments
 (0)