Skip to content

Commit

Permalink
lint update
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Jul 12, 2019
1 parent c1c43a7 commit b3be801
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 46 deletions.
1 change: 1 addition & 0 deletions arch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
api project(':arch-annotation')
compileOnly project(':qmui')
testImplementation 'junit:junit:4.12'
lintChecks project(':qmuilintrule')
}

// deploy
Expand Down
1 change: 1 addition & 0 deletions qmui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
api "com.android.support:appcompat-v7:$supportVersion"
api "com.android.support:design:$supportVersion"
api "com.android.support:support-vector-drawable:$supportVersion" // need Gradle Plugin v1.5.0 or above
lintChecks project(':qmuilintrule')
//test
testImplementation 'junit:junit:4.12'
}
Expand Down
2 changes: 1 addition & 1 deletion qmuidemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation project(':lib')
implementation project(':qmuilint')
api project(':qmuilint')
implementation project(':qmui')
implementation project(':arch')
annotationProcessor project(':compiler')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.widget.ProgressBar;
import android.widget.ZoomButtonsController;

import com.qmuiteam.qmui.arch.annotation.MaybeFirstIn;
import com.qmuiteam.qmui.util.QMUILangHelper;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
Expand All @@ -40,6 +41,7 @@
import com.qmuiteam.qmui.widget.webview.QMUIWebView;
import com.qmuiteam.qmui.widget.webview.QMUIWebViewClient;
import com.qmuiteam.qmui.widget.webview.QMUIWebViewContainer;
import com.qmuiteam.qmuidemo.QDMainActivity;
import com.qmuiteam.qmuidemo.R;
import com.qmuiteam.qmuidemo.base.BaseFragment;
import com.qmuiteam.qmuidemo.view.QDWebView;
Expand All @@ -55,6 +57,7 @@
* Created by cgspine on 2017/12/4.
*/

@MaybeFirstIn(container = {QDMainActivity.class})
public class QDWebExplorerFragment extends BaseFragment {
public static final String EXTRA_URL = "EXTRA_URL";
public static final String EXTRA_TITLE = "EXTRA_TITLE";
Expand Down
9 changes: 1 addition & 8 deletions qmuilint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ android {
}
}


dependencies {
lintChecks project(':qmuilintrule')
lintPublish project(':qmuilintrule')
}

// deploy
//File deployConfig = rootProject.file('gradle/deploy.properties')
//if (deployConfig.exists()) {
// apply from: rootProject.file('gradle/deploy.gradle')
//}
5 changes: 3 additions & 2 deletions qmuilintrule/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
apply plugin: 'java-library'

dependencies {
compileOnly "com.android.tools.lint:lint-api:26.4.2"
compileOnly "com.android.tools.lint:lint-checks:26.4.2"
def lintVersion = '26.4.2'
compileOnly "com.android.tools.lint:lint-api:$lintVersion"
compileOnly "com.android.tools.lint:lint-checks:$lintVersion"
}

sourceCompatibility = "1.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,85 @@
package com.qmuiteam.qmui.lint;


import com.android.tools.lint.client.api.JavaEvaluator;
import com.android.tools.lint.client.api.UElementHandler;
import com.android.tools.lint.detector.api.Category;
import com.android.tools.lint.detector.api.Detector;
import com.android.tools.lint.detector.api.Implementation;
import com.android.tools.lint.detector.api.Issue;
import com.android.tools.lint.detector.api.JavaContext;
import com.android.tools.lint.detector.api.Scope;
import com.android.tools.lint.detector.api.Severity;
import com.intellij.psi.JavaElementVisitor;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiExpressionList;
import com.google.common.collect.Lists;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiMethodCallExpression;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.uast.UCallExpression;
import org.jetbrains.uast.UElement;
import org.jetbrains.uast.UExpression;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;

/**
* 检测 QMUILog 中是否使用了 F Word。
* Created by Kayo on 2017/9/19.
*/
public class QMUIFWordDetector extends Detector
implements Detector.UastScanner, Detector.ClassScanner {
public class QMUIFWordDetector extends Detector implements Detector.UastScanner {
public static final Issue ISSUE_F_WORD =
Issue.create("QMUIDontUseTheFWordInLog",
"Please, don't use the f word, type something more nicely.",
"Do I need to explain this? \uD83D\uDD95",
Category.MESSAGES, 2, Severity.WARNING,
new Implementation(QMUIFWordDetector.class, Scope.JAVA_FILE_SCOPE));

// @Override
// public List<String> getApplicableMethodNames() {
// return Arrays.asList("e", "w", "i", "d");
// }
Category.CORRECTNESS, 5, Severity.WARNING,
new Implementation(QMUIFWordDetector.class, EnumSet.of(Scope.JAVA_FILE)));

@Nullable
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
return Lists.<Class<? extends UElement>>newArrayList(
UCallExpression.class);
}

@Nullable
@Override
public void visitMethod(@NotNull JavaContext context,
@Nullable JavaElementVisitor visitor,
@NotNull PsiMethodCallExpression call,
@NotNull PsiMethod method) {
super.visitMethod(context, visitor, call, method);
String fullyQualifiedMethodName = call.getMethodExpression().getQualifiedName();
context.report(
ISSUE_F_WORD, method,
context.getLocation(method), fullyQualifiedMethodName);
if (fullyQualifiedMethodName.startsWith("android.util.Log") ||
fullyQualifiedMethodName.startsWith("com.qmuiteam.qmui.QMUILog")) {
PsiExpressionList args = call.getArgumentList();
if (args.isEmpty()) {
return;
}
for (PsiExpression expression : args.getExpressions()) {
String input = expression.toString();
if (input != null && input.contains("fuck")) {
context.report(
ISSUE_F_WORD, expression,
context.getLocation(expression), "\uD83D\uDD95");
public UElementHandler createUastHandler(@NotNull JavaContext context) {
return new FWordHandler(context);
}

static class FWordHandler extends UElementHandler {
private static final List<String> checkMedthods = Arrays.asList("e", "w", "i", "d");
private static final List<String> fWords = Arrays.asList("fuck", "bitch", "bullshit");

private JavaContext mJavaContext;

FWordHandler(@NotNull JavaContext context) {
mJavaContext = context;
}

@Override
public void visitCallExpression(@NotNull UCallExpression node) {
JavaEvaluator evaluator = mJavaContext.getEvaluator();
PsiMethod method = node.resolve();
if (evaluator.isMemberInClass(method, "android.util.Log") ||
evaluator.isMemberInClass(method, "com.qmuiteam.qmui.QMUILog")) {
String methodName = node.getMethodName();
if (checkMedthods.contains(methodName)) {
List<UExpression> expressions = node.getValueArguments();
for (UExpression expression : expressions) {
String text = expression.asRenderString();
for(String fword: fWords){
int index = text.indexOf(fword);
if(index >= 0){
mJavaContext.report(
ISSUE_F_WORD, expression,
mJavaContext.getRangeLocation(expression, index, fword.length()), "\uD83D\uDD95");
}
}

}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void visitMethod(@NotNull JavaContext context,
@NotNull PsiMethod method) {
super.visitMethod(context, visitor, call, method);
PsiExpressionList args = call.getArgumentList();
if (args.isEmpty()) {
if (args.getExpressions().length == 0) {
return;
}

Expand Down

0 comments on commit b3be801

Please sign in to comment.