Open
Description
I have project, in that properties files are taken from assets folder. But when I wrote a custom lint to validate the values in properties files, it is not showing up with the following code.
public class PropertyFileValidator extends Detector implements Detector.OtherFileScanner {
/**
* Using HTTP instead of HTTPS for the wrapper
*/
public static final Issue ISSUE = Issue.create(LintConstants.KOUPON_PROPERTY_VALIDATOR, //$NON-NLS-1$
"Using HTTP instead of HTTPS", "The Gradle Wrapper is available both via HTTP and HTTPS. HTTPS is more " +
"secure since it protects against man-in-the-middle attacks etc. Older " +
"projects created in Android Studio used HTTP but we now default to HTTPS " +
"and recommend upgrading existing projects.", LintConstants.DEV_CHECKLIST, 6, Severity.WARNING, new Implementation(PropertyFileValidator.class, Scope.OTHER_SCOPE));
/**
* Constructs a new {@link PropertyFileDetector}
*/
public PropertyFileValidator() {
}
@Override
public boolean appliesTo(@NonNull Context context, @NonNull File file) {
return true;
}
@Override
public EnumSet<Scope> getApplicableFiles() {
return Scope.OTHER_SCOPE;
}
@Override
public void run(@NonNull Context context) {
if(context.file.getPath().contains(DOT_PROPERTIES)) {
try {
InputStream comp = new FileInputStream(context.file);
Properties properties = new Properties();
properties.load(comp);
for(Object line : properties.keySet()) {
context.report(ISSUE, Location.create(context.file), properties.getProperty(line.toString()));
}
} catch(IOException e) {
e.printStackTrace();
}
context.report(ISSUE, Location.create(context.file), "line");
}
}
}
Correct me if anything else need to be added to the code to include assets also into the scope.
More info:
I have two falvors - dev and prod.
assets folder is available in both dev and prod folder.
Folder Structure
- dev
- assets
- properties
- x.properties
- properties
- assets
- prod
- assets
- properties
- x.properties
- properties
- assets
Activity
Luziie commentedon Sep 3, 2023