Does anyone know how to configure EnsureSingleSpaceAfterTokenChecker?

88 views
Skip to first unread message

Eric Wehrmeister

unread,
Sep 11, 2014, 3:12:51 PM9/11/14
to scalasty...@googlegroups.com
I have been trying something like this:

<check enabled="true" class="org.scalastyle.scalariform.EnsureSingleSpaceAfterTokenChecker" level="warning">
     <parameters>
           <parameter name="token">"for"</parameter>
     </parameters>
 </check>

but to no avail. Can't find any documentation of examples anywhere.

Ben Symonds

unread,
Sep 11, 2014, 3:35:04 PM9/11/14
to scalasty...@googlegroups.com
Hi Eric,

I think you want to use `FOR` (no quotes) as the token. It uses the tokens from scalariform[1].

Bear in mind that `EnsureSingleSpaceAfterTokenChecker` has some default tokens[2], so if you want to keep those checks you'll have to add them to your list (I think).

Yeah the documentation could be improved here! Although the code (which I read through to discover all this when I went through it) is pretty clear, even for a Scala novice like me.

Hope it works,

Ben


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Scalastyle users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse scalastyle-use...@googlegroups.com.
Pour envoyer un message à ce groupe, envoyez un e-mail à l'adresse scalasty...@googlegroups.com.
Visitez ce groupe à l'adresse http://groups.google.com/group/scalastyle-users.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Eric Wehrmeister

unread,
Sep 11, 2014, 4:02:50 PM9/11/14
to scalasty...@googlegroups.com
Hi! Thanks for the help! I tried configuring it with <parameter name="token">FOR</parameter> but I'm still not getting a violation.

My code looks like this:

class s(xi: Int) {
  var x: Int = xi

  def getX = {
    for(5 <- Range ){
     
    }
  }
}


(it's just a dummy class to test the violations.)

And I'm not getting a violation. Is there anything else that might be wrong with the config?

Ben Symonds

unread,
Sep 12, 2014, 5:42:00 AM9/12/14
to scalasty...@googlegroups.com
Ok yeah it didn't work for me either, and now I see there is a bug in the checking code: it ends up skipping the check because of the preceding newline (which would make sense if you were looking for a space _before_, but not _after_). So if you have something before the `for`, it works. Bummer. I recently fixed another bug in this checker - I guess in general it's a bit flaky and needs some love. I'd happily look at it, but no promises on how long it would take!

Btw there _is_ an issue with your config though - the param name is `tokens` not `token`!

Eric Wehrmeister

unread,
Sep 12, 2014, 3:32:29 PM9/12/14
to scalasty...@googlegroups.com
Okay thanks! I'm using 'tokens' now, and I tried it with for on the previous line so it is:


def getX = {for(5 <- Range ){

    }

and it produced a violation. So I'm seeing the same issue as you now. Thanks for the help! Do you know if there's anything I can do in the meantime to enforce a space after a FOR coming after a newline?

Ben Symonds

unread,
Sep 12, 2014, 6:08:10 PM9/12/14
to scalasty...@googlegroups.com
Not really, sorry. Maybe you can use `RegexChecker`..? But might be hard to avoid false positives...

Eric Wehrmeister

unread,
Sep 15, 2014, 5:28:30 PM9/15/14
to scalasty...@googlegroups.com
I'm working on it again today and am using the RegexChecker. It's working for what I need so far, so thanks for the suggestion!

Ben Symonds

unread,
Sep 22, 2014, 7:18:29 AM9/22/14
to scalasty...@googlegroups.com
No worries! And I took a look at this on Friday and submitted a PR to fix properly: https://github.com/scalastyle/scalastyle/pull/119.

I'm not 100% convinced there aren't some broken edge cases, but I don't really have time right now to understand how scalariform tokenises newlines and whitespace and stuff. The PR definitely fixes your example and a few others I found though.

Dmitry Petrashko

unread,
Apr 9, 2015, 12:06:19 PM4/9/15
to scalasty...@googlegroups.com, b...@the-symonds.net
Hi Ben,

Running on 0.6 I'm having the same exact issue:
<check level="warning" class="org.scalastyle.scalariform.EnsureSingleSpaceAfterTokenChecker" enabled="true">
  <parameters>
     <parameter name="tokens">IF</parameter>
  </parameters>
</check>

 if(true) true else false
isn't matched.

I'm trying to replicate same functionality with RegEx:
<check level="warning" class="org.scalastyle.file.RegexChecker" enabled="false">
   <parameters>
      <parameter name="regexp"><![CDATA[if\\(]]></parameter>
   </parameters>
</check>

But this seems to hang scalastyle.

Cheers,
Dmitry

Matthew Farwell

unread,
Apr 9, 2015, 12:19:52 PM4/9/15
to scalasty...@googlegroups.com, b...@the-symonds.net
Can you provide a project which makes scalastyle hang please?

Thanks.

Matthew Farwell.

Dmitry Petrashko

unread,
Apr 9, 2015, 12:45:24 PM4/9/15
to scalasty...@googlegroups.com, b...@the-symonds.net
Hi Matthew,
I guess I know what the problem was: the parameter that I should have used was regex, not regexp.
Here is the link if you need it: https://github.com/dotty-staging/dotty/commit/ae04df448ed37038cd620138e7c273c292369528

Cheers,
Dmitry

Matthew Farwell

unread,
Apr 14, 2015, 7:42:37 AM4/14/15
to scalasty...@googlegroups.com, Ben Symonds
Thanks.

I can reproduce the problem, or at least a very similar one. For me, it gives me an out of memory error: GC overhead limit exceeded. I suspect that this is leading to the slowness.

For me, this is a bug, but a minor one because it goes away when you specify your regex properly.

Have fun,

Matthew Farwell.
Reply all
Reply to author
Forward
0 new messages