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

Unused wild card imports are not removed #240

Closed
scottresnik opened this issue Apr 28, 2018 · 6 comments
Closed

Unused wild card imports are not removed #240

scottresnik opened this issue Apr 28, 2018 · 6 comments

Comments

@scottresnik
Copy link

Wild card imports seem to be ignored if they are unused. Is it possible to correct this? At the very least would it be possible to add a setting to fail if wild card imports are encountered?

  • Gradle 4.7
  • Spotless 3.10.0
  • Windows 10 Pro
scottresnik pushed a commit to scottresnik/spotless-wildcard that referenced this issue Apr 28, 2018
@scottresnik
Copy link
Author

Example on github.

@nedtwigg
Copy link
Member

Consider this situation:

import pkgA.*;
import pkgB.*;

public class Clazz {
    WhatPackageDidIComeFrom field;
}

Without slurping in the classpath, and then looking at the classfiles in those jars, we cannot know which package it came from. Basically requires a full compile. With #239 it might be vaguely possible to do, but it will certainly be a lot of work.

@nedtwigg nedtwigg changed the title Wild card imports are ignored Unused wild card imports are not removed Apr 28, 2018
@scottresnik
Copy link
Author

I kind of figured that would be the case.

What do you think about a setting to fail on cases of wild card imports?

@nedtwigg
Copy link
Member

You can use a custom rule, something like:

custom 'noWildcardImports', {
  if (it.contains('*;\n')) {
    throw new Error('No wildcard imports allowed')
  }
}
bumpThisNumberIfACustomStepChanges(1)

@scottresnik
Copy link
Author

Thanks @nedtwigg . While that would work, I think the a cleaner solution would be to use one of the static code analysis tools out there.

@nedtwigg
Copy link
Member

Sounds good. Spotless is optimized for code formatting of the form String -> String. If you want to disallow wildcards, you can fudge it with Spotless, or use another tool. I don't think it makes sense to integrate static code analysis with Spotless unless it produces the String -> String output required for spotlessApply to work.

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

No branches or pull requests

2 participants