Skip to content

Commit 7ba9541

Browse files
committed
more google style configs
1 parent 83d710c commit 7ba9541

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

code-assert/src/main/java/guru/nidi/codeassert/checkstyle/StyleChecks.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ protected Google() {
5959
"parameterName", "^[a-z][a-z0-9][a-zA-Z0-9]*$",
6060
"catchParameterName", "^[a-z][a-z0-9][a-zA-Z0-9]*$",
6161
"localVariableName", "^[a-z][a-z0-9][a-zA-Z0-9]*$",
62+
"memberName", "^[a-z][a-z0-9][a-zA-Z0-9]*$",
63+
"methodName", "^[a-z][a-z0-9][a-zA-Z0-9_]*$",
6264
"emptyLine-tokens", asList(PACKAGE_DEF, IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
6365
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF));
6466
}
@@ -99,6 +101,14 @@ public Google localVarName(String pattern) {
99101
return withParam("localVariableName", pattern);
100102
}
101103

104+
public Google memberName(String pattern) {
105+
return withParam("memberName", pattern);
106+
}
107+
108+
public Google methodName(String pattern) {
109+
return withParam("methodName", pattern);
110+
}
111+
102112
public Google emptyLineSeparatorTokens(int... tokens) {
103113
final List<Integer> ts = new ArrayList<>();
104114
for (final int token : tokens) {

code-assert/src/main/java/guru/nidi/codeassert/junit/PredefConfig.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import static guru.nidi.codeassert.pmd.PmdRulesets.*;
2626

2727
public final class PredefConfig {
28+
private static final String VARIABLE_PATTERN = "^[a-z][a-zA-Z0-9]*$";
29+
2830
private PredefConfig() {
2931
}
3032

@@ -94,17 +96,19 @@ public static CollectorTemplate<Ignore> minimalCheckstyleIgnore() {
9496
"design.forExtension", "hidden.field", "inline.conditional.avoid", "magic.number"));
9597
}
9698

97-
public static StyleChecks adjustedGoogleStyleChecks() {
99+
public static StyleChecks.Google adjustedGoogleStyleChecks() {
98100
return StyleChecks.google()
99101
.maxLineLen(120).indentBasic(4).indentCase(4)
100-
.paramName("^[a-z][a-zA-Z0-9]*$")
101-
.catchParamName("^[a-z][a-zA-Z0-9]*$")
102-
.localVarName("^[a-z][a-zA-Z0-9]*$")
102+
.paramName(VARIABLE_PATTERN)
103+
.catchParamName(VARIABLE_PATTERN)
104+
.localVarName(VARIABLE_PATTERN)
105+
.memberName(VARIABLE_PATTERN)
106+
.methodName(VARIABLE_PATTERN)
103107
.emptyLineSeparatorTokens(IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
104108
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF);
105109
}
106110

107-
public static StyleChecks adjustedSunStyleChecks() {
111+
public static StyleChecks.Sun adjustedSunStyleChecks() {
108112
return StyleChecks.sun().maxLineLen(120).allowDefaultAccessMembers(true);
109113
}
110114
}

code-assert/src/main/resources/guru/nidi/codeassert/checkstyle/google_checks.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
value="Type name ''{0}'' must match pattern ''{1}''."/>
9999
</module>
100100
<module name="MemberName">
101-
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
101+
<property name="format" value="${memberName}"/>
102102
<message key="name.invalidPattern"
103103
value="Member name ''{0}'' must match pattern ''{1}''."/>
104104
</module>
@@ -196,7 +196,7 @@
196196
<property name="allowThrowsTagsForSubclasses" value="true"/>
197197
</module>
198198
<module name="MethodName">
199-
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
199+
<property name="format" value="${methodName}"/>
200200
<message key="name.invalidPattern"
201201
value="Method name ''{0}'' must match pattern ''{1}''."/>
202202
</module>

0 commit comments

Comments
 (0)