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

[SPARK-3873] [build] Add style checker to enforce import ordering. #6502

Closed
wants to merge 4 commits into from

Conversation

vanzin
Copy link
Contributor

@vanzin vanzin commented May 29, 2015

The checker tries to follow as closely as possible the guidelines of
the code style document, and makes some decisions where the guide is
not clear. In particular:

  • wildcard imports come first when there are other imports in the
    same package
  • multi-import blocks come before single imports
  • lower-case names inside multi-import blocks come before others

In some projects, such as graphx, there seems to be a convention to
separate o.a.s imports from the project's own; to simplify the
checker, I chose not to allow that, which is a strict interpretation
of the code style guide, even though I think it makes sense.

Since the checks are based on syntax only, some edge cases may
generate spurious warnings; for example, when class names start
with a lower case letter (and are thus treated as a package name
by the checker).

The checker is currently only generating warnings, and since there
are many of those, the build output does get a little noisy. The
idea is to fix the code (and the checker, as needed) little by little
instead of having a huge change that touches everywhere.

@vanzin
Copy link
Contributor Author

vanzin commented May 29, 2015

This is the same code I sent out a long time ago, updated to also hook up to the maven build. I tried both sbt and maven. There is a huge number of warnings, so I won't even try to fix them (in this change or a separate one), but since there seems to be a push to add more style checks, thought I might send this out again.

@SparkQA
Copy link

SparkQA commented May 29, 2015

Test build #33752 has finished for PR 6502 at commit b3b87b1.

  • This patch fails MiMa tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class ImportOrderChecker extends ScalariformChecker

@andrewor14
Copy link
Contributor

Will this even pass tests in its current state? I imagine we violate the import ordering in a lot of places currently.

@rxin
Copy link
Contributor

rxin commented May 29, 2015

@andrewor14 he's doing warning level checks right now -- so there will be lots of warnings but still pass. Let's see how many warnings there are ...

@andrewor14
Copy link
Contributor

I see... retest this please?

@SparkQA
Copy link

SparkQA commented May 29, 2015

Test build #33764 has finished for PR 6502 at commit b3b87b1.

  • This patch fails MiMa tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented May 29, 2015

Test build #33771 has finished for PR 6502 at commit b4dca33.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class ImportOrderChecker extends ScalariformChecker

@vanzin
Copy link
Contributor Author

vanzin commented May 29, 2015

The PR builder script redirects the scalastyle output to a file and deletes it... so you don't see the warnings in the output and can't find them on the jenkins machines either.

But you'll see them if you try this change locally.

@rxin
Copy link
Contributor

rxin commented May 29, 2015

What happens to errors? Are they also redacted?

@vanzin
Copy link
Contributor Author

vanzin commented May 29, 2015

See dev/scalastyle. The script greps for errors and prints them out, everything else is lost. It's trivial to change the script to keep the generated file with all errors and warnings.

@rxin
Copy link
Contributor

rxin commented May 30, 2015

@vanzin - thanks, this looks great.

Can you do 3 things?

  1. Make the import ordering configurable.
  2. The style rule is pretty complicated. Add some unit tests for it.
  3. Submit a pull request against scalastyle proper.

The reason is we should avoid one-offs that make it harder to upgrade in the future (e.g. scalastyle sometimes change their internals, and then we'd need to learn how to upgrade this rule when we upgrade scalastyle). We can merge this as soon as there is a pull request against scalastyle and way to move forward. And once that is merged into scalastyle and scalastyle releases a new version, we can remove our one-off rule.

This is what we have done for all the one-off rules in the past.

@JoshRosen
Copy link
Contributor

By the way, if you make this configurable then I'd model the configuration language / format after IntelliJ's import ordering configuration dialog.

@vanzin
Copy link
Contributor Author

vanzin commented Jun 2, 2015

I filed a scalastyle PR (see link above) which contains tests, so I'll avoid adding those tests to this PR.

@SparkQA
Copy link

SparkQA commented Jun 2, 2015

Test build #33932 has finished for PR 6502 at commit acff79c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class ImportOrderChecker extends ScalariformChecker

@SparkQA
Copy link

SparkQA commented Jun 25, 2015

Test build #35797 has finished for PR 6502 at commit 6f0bc17.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class ImportOrderChecker extends ScalariformChecker

@andrewor14
Copy link
Contributor

LFTM. @rxin?

@JoshRosen
Copy link
Contributor

@vanzin, it looks like the Scalastyle PR was merged: scalastyle/scalastyle#147

Given this, can you update this PR to configure Scalastyle to use this new rule?

@vanzin
Copy link
Contributor Author

vanzin commented Sep 16, 2015

It was merged but I don't see a new scalastyle release. I was waiting for that before updating this pr.

@JoshRosen
Copy link
Contributor

Can you comment on scalastyle/scalastyle#157 to voice your support for a new Scalastyle release? The delays in getting new Scalastyle and Scalastyle-SBT versions published are causing a lot of pain for folks running Scala 2.10.5+, since the current master also contains bugfixes for a Scalariform parser issue.

@JoshRosen
Copy link
Contributor

Err, sorry, the link above should have been scalastyle/scalastyle#157

@JoshRosen
Copy link
Contributor

Still no Scalastyle release :(

I tried bumping that ticket again.

@JoshRosen
Copy link
Contributor

Now that Scalastyle 0.8.0 has been released, I think we can revive this PR. I've opened #10112 to bump the SBT and Scalastyle versions.

@vanzin
Copy link
Contributor Author

vanzin commented Dec 3, 2015

I'm looking into it.

Currently generates only warnings, since there are many violations.
dev/scalastyle was modified to not get rid of the output file, since
that contains the list of warnigs which could help with cleaning
things up.
@vanzin
Copy link
Contributor Author

vanzin commented Dec 3, 2015

I don't expect the tests to pass; there were style errors (unrelated to import ordering) when I tried things locally.

@SparkQA
Copy link

SparkQA commented Dec 3, 2015

Test build #47108 has finished for PR 6502 at commit aded027.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):\n * class CrossValidator @Since(\"1.2.0\") (@Since(\"1.4.0\") override val uid: String)\n * class ParamGridBuilder @Since(\"1.2.0\")\n * class TrainValidationSplit @Since(\"1.5.0\") (@Since(\"1.5.0\") override val uid: String)\n

@SparkQA
Copy link

SparkQA commented Dec 3, 2015

Test build #47149 has finished for PR 6502 at commit c1e5556.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 3, 2015

Test build #47150 has finished for PR 6502 at commit 28e8287.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 7, 2015

Test build #47274 has finished for PR 6502 at commit ce52797.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor Author

vanzin commented Dec 8, 2015

not that it should matter, but retest this please

@SparkQA
Copy link

SparkQA commented Dec 8, 2015

Test build #47355 has finished for PR 6502 at commit ce52797.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor Author

vanzin commented Dec 8, 2015

I'm gonna merge this so we can start cleaning things up before enabling errors.

@asfgit asfgit closed this in 2ff17bc Dec 8, 2015
@vanzin vanzin deleted the SPARK-3873 branch December 30, 2015 23:29
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

Successfully merging this pull request may close these issues.

5 participants