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

Feature suggestion: Fail compile on file contents #46

Closed
HaasJona opened this issue Oct 31, 2016 · 5 comments
Closed

Feature suggestion: Fail compile on file contents #46

HaasJona opened this issue Oct 31, 2016 · 5 comments

Comments

@HaasJona
Copy link

HaasJona commented Oct 31, 2016

It's very nice that we can automatically reformat code and replace things with spotless, but we also have sometimes problems that aren't easily fixed by replacements (for example missing license headers (no, just adding them automatically doesn't work because we want to list contributors and so on), usage of prohibited/deprecated classes, swear words in comments and so on.

It would be great if we could do something like

spotless {
		java {
			customFailure 'test', {
                            // it = file contents
                            if(it.contains("java.util.Scanner") {
                                fail('please use BufferedReader instead')
                            }
			}
		}

of course that's a very rough example. The currect "custom" block unfortunately eats all exceptions more or less silently ("Unable to apply step "), else that would be a workaround by just replacing nothing and throwing an exception.

@nedtwigg
Copy link
Member

Great idea! The exceptions are actually swallowed not by the custom block but by a higher part of Spotless. Some of the complex formatters (especially eclipse) can barf on some inputs, and we didn't want a finnicky formatter library to block a user's build.

How about if we let Error and its subclasses through, but continue to swallow Exception? That would allow the use of testing and assertion libraries like JUnit in your custom rules, and it means that Spotless would need almost no modifications.

@HaasJona
Copy link
Author

I think your suggestion sounds very simple and great.

@nedtwigg
Copy link
Member

Now available in 2.4.0-SNAPSHOT. There's an integration test that shows what it looks like in practice here.

Any comments before we ship?

@HaasJona
Copy link
Author

Looks good to me. Thanks for implementing my suggestion.

nedtwigg added a commit that referenced this issue Oct 31, 2016
@nedtwigg
Copy link
Member

nedtwigg commented Nov 1, 2016

Shipped in 2.4.0.

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