10: Create TextInputValidationPlugin
This commit is contained in:
@@ -107,4 +107,10 @@ public class PluginModule {
|
||||
public Plugin dangerousPermissionPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) {
|
||||
return new DangerousPermissionPlugin(globMatcher, xmlHelper);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@IntoSet
|
||||
public Plugin textInputValidationPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) {
|
||||
return new TextInputValidationPlugin(globMatcher, xmlHelper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.bartek.esa.core.plugin;
|
||||
|
||||
import com.bartek.esa.core.archetype.ResourceLayoutPlugin;
|
||||
import com.bartek.esa.core.model.enumeration.Severity;
|
||||
import com.bartek.esa.core.xml.XmlHelper;
|
||||
import com.bartek.esa.file.matcher.GlobMatcher;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TextInputValidationPlugin extends ResourceLayoutPlugin {
|
||||
|
||||
@Inject
|
||||
public TextInputValidationPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) {
|
||||
super(globMatcher, xmlHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(Document xml) {
|
||||
NodeList editTextNodes = xml.getElementsByTagName("EditText");
|
||||
stream(editTextNodes)
|
||||
.filter(this::doesNotHaveInputType)
|
||||
.forEach(n -> addIssue(Severity.WARNING, null, tagString(n)));
|
||||
}
|
||||
|
||||
private boolean doesNotHaveInputType(Node editText) {
|
||||
Boolean doesHaveInputType = Optional.ofNullable(editText.getAttributes().getNamedItem("android:inputType"))
|
||||
.map(Node::getNodeValue)
|
||||
.map(v -> !v.isEmpty())
|
||||
.orElse(false);
|
||||
return !doesHaveInputType;
|
||||
}
|
||||
}
|
||||
@@ -112,3 +112,8 @@ com.bartek.esa.core.plugin.DangerousPermissionPlugin=Custom permission without d
|
||||
Custom permission with 'dangerous' protection level was found and it doesn't have any description.\n\
|
||||
As long as the permission requires user attention, he should have provided a meaningful description about\n\
|
||||
permission.
|
||||
|
||||
com.bartek.esa.core.plugin.TextInputValidationPlugin=Input type is no selected.\n\
|
||||
The EditText view doesn't have a input type selected.\n\
|
||||
Consider associating a input type with this view.\n\
|
||||
For example: <EditText android:inputType="number" ...
|
||||
|
||||
Reference in New Issue
Block a user