Skip to content

Commit

Permalink
New Checkstyle rules (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Sep 5, 2016
1 parent 55ad0ae commit 46dcd01
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 33 deletions.
Expand Up @@ -22,12 +22,12 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class MainActivity extends AppCompatActivity {
private ChatAdapter chatAdapter;
private EmojiPopup emojiPopup;
private ChatAdapter chatAdapter;
private EmojiPopup emojiPopup;

private EmojiEditText editText;
private ViewGroup rootView;
private ImageView emojiButton;
private ViewGroup rootView;
private ImageView emojiButton;

@Override
protected void onCreate(final Bundle savedInstanceState) {
Expand Down
59 changes: 51 additions & 8 deletions code_quality_tools/checkstyle.xml
Expand Up @@ -103,12 +103,23 @@

<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="EmptyLineSeparatorCheck">
<property name="allowMultipleEmptyLines" value="false"/>
<property name="tokens" value="PACKAGE_DEF, IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, CTOR_DEF"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="EmptyForIteratorPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<property name="tokens" value="LITERAL_ASSERT,LITERAL_CATCH,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,DO_WHILE" />
</module>
<module name="EmptyForInitializerPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="NoLineWrap"/>

<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
Expand All @@ -131,7 +142,9 @@
<module name="EqualsHashCode"/>
<module name="CovariantEquals"/>
<module name="EqualsAvoidNull"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="VariableDeclarationUsageDistance">
<property name="allowedDistance" value="1"/>
</module>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber">
Expand Down Expand Up @@ -168,6 +181,7 @@
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="OuterTypeFilename"/>
<module name="TodoComment"/>
<module name="UpperEll"/>

Expand All @@ -182,30 +196,36 @@
</module>

<module name="RegexpSinglelineJava">
<property name="format" value="(final)?\s*[\w]+\s+a[A-Z]{1}[\w]+"/>
<property name="format" value="(final)?\s*[\w]+ a[A-Z]{1}[\w]+"/>
<property name="message" value="aVariable notation is deprecated and should be variable instead"/>
</module>

<module name="RegexpSinglelineJava">
<property name="format" value="(final)?\s*[\w]+\s+an[A-Z]{1}[\w]+"/>
<property name="format" value="(final)?\s*[\w]+ an[A-Z]{1}[\w]+"/>
<property name="message" value="anAwfulVariable notation is deprecated and should be variable instead"/>
</module>

<module name="RegexpSinglelineJava">
<property name="format" value="(final)?\s*[\w]+\s+p[A-Z]{1}[\w]+"/>
<property name="format" value="(final)?\s*[\w]+ p[A-Z]{1}[\w]+"/>
<property name="message" value="pVariable notation is deprecated"/>
</module>

<module name="RegexpSinglelineJava">
<property name="format" value="(final)?\s*[\w]+\s+m[A-Z]{1}[\w]+"/>
<property name="message" value="Say no to mVariable"/>
<property name="format" value="this\.m[A-Z]"/>
<property name="message" value="this.mNotation notation should not be used"/>
</module>

<module name="RegexpSinglelineJava">
<property name="format" value="this\.m[A-Z]"/>
<property name="message" value="this.mNotation notation should not be used"/>
<property name="format" value="^(?!\s+\* $).*?\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<!--<module name="RegexpSinglelineJava">
<property name="format" value="(B|b)oolean\s+(?=\S)(?!can|should|are|did|contains|is|must|has|will|needs|does|was)(?!.+\(.*\))"/>
<property name="message" value="boolean names should start with can, should, are, did, contains, is, must, has, needs, will, does or was."/>
<property name="ignoreComments" value="true"/>
</module>-->

<module name="RegexpSinglelineJava">
<property name="format" value='[\w]+.equals\(""\)'/>
<property name="message" value='To reduce the chance of a NPE use "".equals(var)'/>
Expand All @@ -218,4 +238,27 @@

</module>

<module name="RegexpMultiline">
<property name="message" value="Blank line at start of block should be removed" />
<property name="format" value="(?&lt;=(?&lt;!^beans )\{\s{0,99}$)^$" />
<property name="fileExtensions" value="groovy,java" />
</module>

<module name="RegexpMultiline">
<property name="message" value="Blank line at end of block should be removed" />
<property name="format" value="(?&lt;!\{\s{0,99}$)^$(?=^\s{0,99}\})" />
<property name="fileExtensions" value="groovy,java" />
</module>

<module name="RegexpMultiline">
<property name="message" value="Blank line before start of block should be removed" />
<property name="format" value="(?&lt;=[!-:&lt;-~] {0,48}?\r\n {0,48}?)\r\n *(\{|else)" />
<property name="fileExtensions" value="groovy,java" />
</module>

<module name="RegexpMultiline">
<property name="message" value="Extra blank line(s) should be removed" />
<property name="format" value="^(?:(?:\r\n){2,}|\r\n$)" />
<property name="fileExtensions" value="groovy,html,htm,java,jj,jjt,vm,xml,xsl" />
</module>
</module>
Expand Up @@ -1052,7 +1052,6 @@ public static void addEmojis(final Context context, final Spannable text, final
} else if (followUnicode == 0xfe0f) {
int followSkip = Character.charCount(followUnicode);
if (i + skip + followSkip < textLength) {

final int nextFollowUnicode = Character.codePointAt(text, i + skip + followSkip);
if (nextFollowUnicode == 0x20e3) {
int nextFollowSkip = Character.charCount(nextFollowUnicode);
Expand Down
1 change: 0 additions & 1 deletion library/src/main/java/com/vanniktech/emoji/EmojiPopup.java
Expand Up @@ -191,7 +191,6 @@ int getUsableScreenHeight() {
windowManager.getDefaultDisplay().getMetrics(metrics);

return metrics.heightPixels;

} else {
return rootView.getRootView().getHeight();
}
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/com/vanniktech/emoji/EmojiSpan.java
Expand Up @@ -7,10 +7,10 @@

final class EmojiSpan extends DynamicDrawableSpan {
private final Context context;
private final int resourceId;
private final int size;
private final int resourceId;
private final int size;

private Drawable drawable;
private Drawable drawable;

EmojiSpan(final Context context, final int resourceId, final int size) {
this.context = context;
Expand Down
Expand Up @@ -7,24 +7,23 @@
import android.view.View;

public final class RepeatListener implements View.OnTouchListener {

final long normalInterval;
private final long initialInterval;
final long normalInterval;
private final long initialInterval;

final View.OnClickListener clickListener;
final Handler handler = new Handler();
View downView;
final Handler handler = new Handler();
View downView;

private final Runnable handlerRunnable = new Runnable() {
@Override
public void run() {
if (downView != null) {
handler.removeCallbacksAndMessages(downView);
handler.postAtTime(this, downView, SystemClock.uptimeMillis() + normalInterval);
clickListener.onClick(downView);
}
}
};
private final Runnable handlerRunnable = new Runnable() {
@Override
public void run() {
if (downView != null) {
handler.removeCallbacksAndMessages(downView);
handler.postAtTime(this, downView, SystemClock.uptimeMillis() + normalInterval);
clickListener.onClick(downView);
}
}
};

public RepeatListener(final long initialInterval, final long normalInterval, final View.OnClickListener clickListener) {
if (clickListener == null) {
Expand Down
1 change: 0 additions & 1 deletion library/src/test/java/com/vanniktech/emoji/UtilsTest.java
@@ -1,6 +1,5 @@
package com.vanniktech.emoji;


import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker;

import org.junit.Rule;
Expand Down

0 comments on commit 46dcd01

Please sign in to comment.