Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Custom Lint not covering files inside assets folder #7

Open
pravinkmrr opened this issue Apr 9, 2017 · 1 comment
Open

Comments

@pravinkmrr
Copy link

pravinkmrr commented Apr 9, 2017

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
  • prod
    • assets
      • properties
        • x.properties
@Luziie
Copy link

Luziie commented Sep 3, 2023

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
  • prod

    • assets

      • properties

        • x.properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants