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

spotless-groovy with spock where throws error #357

Closed
AnEmortalKid opened this issue Feb 13, 2019 · 13 comments
Closed

spotless-groovy with spock where throws error #357

AnEmortalKid opened this issue Feb 13, 2019 · 13 comments
Labels

Comments

@AnEmortalKid
Copy link

Summary

An unexpected token | is found when formatting a spec

unexpected token: | @ line 24

If I comment out the where section or the test, everything works fine.

Versions

Gradle + OS

------------------------------------------------------------
Gradle 4.8.1
------------------------------------------------------------

Build time:   2018-06-21 07:53:06 UTC
Revision:     0abdea078047b12df42e7750ccba34d69b516a22

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_162 (Oracle Corporation 25.162-b12)
OS:           Mac OS X 10.13.6 x86_64

Spotless config + Version:

plugins { id "com.diffplug.gradle.spotless" version "3.18.0" }
apply plugin: 'groovy'

sourceCompatibility = 1.8
targetCompatibility = 1.8

spotless {
  groovy {
    greclipse()
    paddedCell() // avoid cyclic ambiguities
    indentWithSpaces(2)
  }
  groovyGradle {
    greclipse()
    indentWithSpaces(2)
  }
}

dependencies {
  testCompile group: 'org.spockframework', name: 'spock-core', version: '1.2-groovy-2.4'
}

Stacktrace

gw spotlessApply --stacktrace
Using gradle at '/Users/jm034719/workspaces/build-guild/spotless-check/gradlew' to run buildfile '/Users/jm034719/workspaces/build-guild/spotless-check/build.gradle':


> Task :spotlessGroovy FAILED
Step 'groovy eclipse formatter' found problem in 'src/test/groovy/TestSpec.groovy':
Multiple problems detected during step execution:
Snippet.groovy: 24: unexpected token: | @ line 24, column 1.
   | true
   ^
Snippet.groovy: 24: expecting EOF, found '|' @ line 24, column 1.
   | true
   ^
java.lang.IllegalArgumentException: Multiple problems detected during step execution:
Snippet.groovy: 24: unexpected token: | @ line 24, column 1.
   | true
   ^
Snippet.groovy: 24: expecting EOF, found '|' @ line 24, column 1.
   | true
   ^
        at com.diffplug.spotless.extra.eclipse.groovy.GrEclipseFormatterStepImpl.format(GrEclipseFormatterStepImpl.java:83)
        at com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep.lambda$apply$0(GrEclipseFormatterStep.java:71)
        at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:31)
        at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
        at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
        at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
        at com.diffplug.spotless.PaddedCellBulk.applyAnyChanged(PaddedCellBulk.java:208)
        at com.diffplug.gradle.spotless.SpotlessTask.applyAnyChanged(SpotlessTask.java:255)
        at com.diffplug.gradle.spotless.SpotlessTask.performAction(SpotlessTask.java:226)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:246)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:136)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:201)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.executeWithTask(DefaultTaskPlanExecutor.java:192)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':spotlessGroovy'.
> Multiple problems detected during step execution:
  Snippet.groovy: 24: unexpected token: | @ line 24, column 1.
     | true
     ^
  Snippet.groovy: 24: expecting EOF, found '|' @ line 24, column 1.
     | true
     ^

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':spotlessGroovy'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:246)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:136)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:201)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.executeWithTask(DefaultTaskPlanExecutor.java:192)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.IllegalArgumentException: Multiple problems detected during step execution:
Snippet.groovy: 24: unexpected token: | @ line 24, column 1.
   | true
   ^
Snippet.groovy: 24: expecting EOF, found '|' @ line 24, column 1.
   | true
   ^
        at com.diffplug.spotless.extra.eclipse.groovy.GrEclipseFormatterStepImpl.format(GrEclipseFormatterStepImpl.java:83)
        at com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep.lambda$apply$0(GrEclipseFormatterStep.java:71)
        at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:31)
        at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
        at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
        at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
        at com.diffplug.spotless.PaddedCellBulk.applyAnyChanged(PaddedCellBulk.java:208)
        at com.diffplug.gradle.spotless.SpotlessTask.applyAnyChanged(SpotlessTask.java:255)
        at com.diffplug.gradle.spotless.SpotlessTask.performAction(SpotlessTask.java:226)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
        ... 30 more


* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed

Repo: https://github.com/AnEmortalKid/spotless-check

@fvgh
Copy link
Member

fvgh commented Feb 13, 2019

Parser errors lead per default to an abortion of the Spotless task.
But you can change this behaviour:
ignoreFormatterProblems=true

Have a look at the description...

It seems that the latest groovy-eclipse release fixed the parser problem. The Spotless formatter still uses version 3.0.0. But I am afraid that the formatted code does not look that nice 😞 .

Let's keep the issue open as a reminder to upgrade the Spotless formatter for groovy-eclipse. But I am afraid, it may take a while...

@AnEmortalKid
Copy link
Author

Ah:

Groovy-Eclipse formatting errors/warnings lead per default to a build failure. This behavior can be changed by adding the property/key value ignoreFormatterProblems=true to a configuration file. In this scenario, files causing problems, will not be modified by this formatter step.

I noticed that the groovy_eclipse_formatter defines the version: https://github.com/diffplug/spotless/blob/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/groovy_eclipse_formatter/v4.8.1.lockfile#L2

I wasn't entirely sure if:

  // optional: you can specify a specific version or config file(s)

Would let me define a groovy_eclipse_formatter file that would use the 3.2.0 formatter versions.

@fvgh
Copy link
Member

fvgh commented Feb 13, 2019

For Eclipse JDT this is nearly as simple, since their JARs are available via M2.
Groovy-Eclipse it is not as simple, since we include their classes from P2 in our JAR. Here's the code....

@nedtwigg nedtwigg added the bug label Feb 13, 2019
@AnEmortalKid
Copy link
Author

I did a little more digging on this.

After spotlessApply runs, the formatted chunks in the where: section end up not compiling

So given:

where:
 object | expected
[[ something ]] | true

the formatter will end up with:

where:
object | expected
[ 
  [something ]] 
| true

So even after making it not fail during the spotless check, it will still fail to compile.

@fvgh
Copy link
Member

fvgh commented Feb 19, 2019

@AnEmortalKid I am afraid that even with the latest Groovy-Eclipse version the formatted code may not compile. At least the formatted code looked dodgy. I only checked (using Eclipse IDE with latest Groovy-Eclipse release) whether the formatter throws an exception. It did not, but as mentioned before, the formatter code looked not very nice / dodgy. I am afraid I can only provide the glue between Groovy-Eclipse formatter and Spotless. Issues within the Groovy-Eclipse should be discussed directly with the Groovy-Eclipse team.

@AnEmortalKid
Copy link
Author

I've created an issue in that repository. Maybe once that's resolved this will be resolved too (or be able to be resolved with dependency updating).

@AnEmortalKid
Copy link
Author

Also, @fvgh question on the ignoreFormatterProblems=true.

I found that just specifying it in a file and configuring spotless:

greclipse().configFile('formatter.properties')

Wouldn't pickup the ignore formatter problems. However, specifying more properties in the file would end up picking up ignoreFormatterProblems. Was there something I am missing?

@fvgh
Copy link
Member

fvgh commented Mar 11, 2019

@AnEmortalKid Sorry, I was occupied with other things. About your last comment, so you say that if you have only one property in the properties file does not work?

@AnEmortalKid
Copy link
Author

No worries @fvgh , I understand life gets busy.

Yeah, it didn't seem to be picking a single property, so I had to have more than one or maybe my property was wrong. I can double check but this is what i had iirc

# Disable formatting errors
ignoreFormatterProblems=true

https://github.com/AnEmortalKid/spotless-check/blob/master/formatter.properties

Can't seem to get it to reproduce at the moment.... maybe it was user error.

@fvgh
Copy link
Member

fvgh commented Mar 11, 2019

This part of the code is common for all Eclipse based formatters. So I cannot imagine a bug there. Anyhow, I'll check whether this dedicated scenario is part of the unit-test and add one if missing.

Relating groovy/groovy-eclipse#822:
It's some time ago I worked with groovy and wrote the initial groovy-eclipse Spotless extension. As far as I understood the outcome of your discussion with @eric-milles, groovy-eclipse works as you expect it.

I will provide an update to groovy-eclipse 3.2.0 for Eclipse 4.10. The groovy-2.6.0-indy as it is provided with groovy-eclipse should do, shouldn't it?

@AnEmortalKid
Copy link
Author

It seemed to work for eric-milles, but I believe there's compilation errors in what it formatted: https://issues.apache.org/jira/browse/GROOVY-9004

@fvgh
Copy link
Member

fvgh commented Mar 26, 2019

@AnEmortalKid
I provided the new spotless-eclipse-groovy version as stated above with #382. As you already said, it will not fix your original problem, but since that problem is not within Spotless, I can't help it. Please let me know as soon as there is a new Groovy-Eclipse version out, fixing your problem.
The formatter properties anomaly with one parameter I cannot reproduce. But you said already that it might have been a user error.
So I close this issue for now.

@fvgh fvgh closed this as completed Mar 26, 2019
@AnEmortalKid
Copy link
Author

@fvgh thank you! I’ll upgrade at least :)

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

No branches or pull requests

3 participants