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-21259] More rules for scalastyle #18471

Closed
wants to merge 8 commits into from

Conversation

gengliangwang
Copy link
Member

What changes were proposed in this pull request?

Add more rules for scalastyle

During code review, we spent so much time on code style issues.
It would be great if we add rules:

  1. disallow space before colon
  2. disallow space before right parentheses
  3. disallow space after left parentheses

How was this patch tested?

unit tests, integration tests

Please review http://spark.apache.org/contributing.html before opening a pull request.

@gengliangwang
Copy link
Member Author

Most changes are done by my ruby script:

lines = `./dev/lint-scala 2>&1 | grep "before\\|after"`.split("\n")
lines.each do |line|
  file, line_num=line.split(/[ ,:]/)[1,2]
  if line =~ /Space before token :/
    `sed -i '' '#{line_num}s/ :/:/g' #{file}`
  elsif line =~ /Space before token \)/
    `sed -i '' '#{line_num}s/ )/)/g' #{file}`
  elsif line =~ /Space after token \(/
    `sed -i '' '#{line_num}s/( /(/g' #{file}`
  end
end

@@ -68,7 +68,9 @@ class Accumulable[R, T] private (
}

private[spark] def this(initialValue: R, param: AccumulableParam[R, T], name: Option[String]) = {
// scalastyle:off
this(initialValue, param, name, false /* countFailedValues */)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: countFailedValues = false is better, this style is only useful for java

@@ -46,7 +46,7 @@ This file is divided into 3 sections:

<check level="error" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>

<check level="error" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
<check level="error" class="org.scalastyle.file.HeaderMatchesChecker" enabled="false">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. Should we disable this rule to enable the new rule?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I made a mistake.

</parameters>
</check>

<check level="error" class="org.scalastyle.scalariform.DisallowSpaceAfterTokenChecker" enabled="true">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question. Could we add customId and disable this only when scalastyle:off and scalastyle:on is required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have updated the xml file.

@SparkQA
Copy link

SparkQA commented Jun 30, 2017

Test build #78937 has finished for PR 18471 at commit f68e600.

  • This patch fails Spark unit tests.
  • This patch does not merge cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 30, 2017

Test build #78940 has finished for PR 18471 at commit d1b4bbe.

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

@SparkQA
Copy link

SparkQA commented Jun 30, 2017

Test build #78948 has finished for PR 18471 at commit 05084a9.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 30, 2017

Test build #78951 has finished for PR 18471 at commit fd5bde5.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen
Copy link
Member

srowen commented Jun 30, 2017

I tend to agree with the style change, but, am concerned about what a huge diff this creates for little gain. I personally am not sure I'd bother with the colon change; some instances of space before colon are conventional like [K : ClassTag], although many you fixed should indeed not have had a space. I also am not sure we want to enforce the naming convention you suggest here.

The space inside parens change seems OK, maybe smaller.

@@ -52,8 +52,8 @@ private[spark] class BroadcastManager(

private val nextBroadcastId = new AtomicLong(0)

def newBroadcast[T: ClassTag](value_ : T, isLocal: Boolean): Broadcast[T] = {
broadcastFactory.newBroadcast[T](value_, isLocal, nextBroadcastId.getAndIncrement())
def newBroadcast[T: ClassTag](_value: T, isLocal: Boolean): Broadcast[T] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure of this naming change. I mean the change does not look particulaily better to me. I believe we have a open PR - databricks/scala-style-guide#52 which appearntly stays against some cases here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not about adding _ to the name of private val, but kind of avoiding name conflict if 2 variables have similar meaning. At least this is fine to me, I also do this a lot...

Copy link
Member

@HyukjinKwon HyukjinKwon Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine if we prefer a specific way. My only worry is we happen to fix it back again in the future but no one stays against because they don't know which way is preferred...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, this can be an example other contributors like me can refer in the future BTW.

this(initialValue, param, name, false /* countFailedValues */)
// scalastyle:on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we could enable and disable via scalastyle:on customid rather than switching off whole style rules here IIRC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nvm. I just read your commit log ...

@cloud-fan
Copy link
Contributor

My only concern is [K : ClassTag]. This is conventional in scala but the new style check rule rejects it. If it's hard to make a corrected rule for this case, we can drop it.

@jiangxb1987
Copy link
Contributor

Do we still want this?

@gengliangwang
Copy link
Member Author

Close this for now.

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.

6 participants