-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(groovy) strings are not allowed inside ternary clauses (#2565)
* fix(groovy) strings are not allowed inside ternary clauses * whitespace can also include tabs
- Loading branch information
1 parent
02bdae3
commit c6f2995
Showing
6 changed files
with
206 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<span class="hljs-meta">#!/usr/bin/env groovy</span> | ||
<span class="hljs-keyword">package</span> model | ||
|
||
<span class="hljs-keyword">import</span> groovy.transform.CompileStatic | ||
<span class="hljs-keyword">import</span> java.util.List <span class="hljs-keyword">as</span> MyList | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">trait</span> <span class="hljs-title">Distributable</span> {</span> | ||
<span class="hljs-keyword">void</span> distribute(String version) {} | ||
} | ||
|
||
<span class="hljs-meta">@CompileStatic</span> | ||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Distribution</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Distributable</span> {</span> | ||
<span class="hljs-keyword">double</span> number = <span class="hljs-number">1234.234</span> / <span class="hljs-number">567</span> | ||
<span class="hljs-keyword">def</span> otherNumber = <span class="hljs-number">3</span> / <span class="hljs-number">4</span> | ||
<span class="hljs-keyword">boolean</span> archivable = condition ?: <span class="hljs-literal">true</span> | ||
<span class="hljs-keyword">def</span> ternary = a ? b : c | ||
String name = <span class="hljs-string">"Guillaume"</span> | ||
Closure description = <span class="hljs-literal">null</span> | ||
List<DownloadPackage> packages = [] | ||
String regex = <span class="hljs-regexp">~/.*foo.*/</span> | ||
String multi = <span class="hljs-string">''' | ||
multi line string | ||
'''</span> + <span class="hljs-string">""" | ||
now with double quotes and ${gstring} | ||
"""</span> + <span class="hljs-string">$/ | ||
even with dollar slashy strings | ||
/$</span> | ||
|
||
<span class="hljs-comment">/** | ||
* description method | ||
* @param cl the closure | ||
*/</span> | ||
<span class="hljs-keyword">void</span> description(Closure cl) { <span class="hljs-built_in">this</span>.description = cl } | ||
|
||
<span class="hljs-keyword">void</span> version(String name, Closure versionSpec) { | ||
<span class="hljs-keyword">def</span> closure = { println <span class="hljs-string">"hi"</span> } <span class="hljs-keyword">as</span> Runnable | ||
|
||
MyList ml = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, [<span class="hljs-attr">a:</span> <span class="hljs-number">1</span>, <span class="hljs-attr">b:</span><span class="hljs-number">2</span>,<span class="hljs-attr">c :</span><span class="hljs-number">3</span>]] | ||
<span class="hljs-keyword">for</span> (ch <span class="hljs-keyword">in</span> <span class="hljs-string">"name"</span>) {} | ||
|
||
<span class="hljs-comment">// single line comment</span> | ||
DownloadPackage pkg = <span class="hljs-keyword">new</span> DownloadPackage(<span class="hljs-attr">version:</span> name) | ||
|
||
check <span class="hljs-attr">that:</span> <span class="hljs-literal">true</span> | ||
|
||
<span class="hljs-symbol">label:</span> | ||
<span class="hljs-comment">// This is purposely tabbed</span> | ||
<span class="hljs-symbol">tabbed_label:</span> | ||
<span class="hljs-keyword">def</span> clone = versionSpec.rehydrate(pkg, pkg, pkg) | ||
<span class="hljs-comment">/* | ||
now clone() in a multiline comment | ||
*/</span> | ||
clone() | ||
packages.add(pkg) | ||
|
||
<span class="hljs-keyword">assert</span> <span class="hljs-number">4</span> / <span class="hljs-number">2</span> == <span class="hljs-number">2</span> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env groovy | ||
package model | ||
|
||
import groovy.transform.CompileStatic | ||
import java.util.List as MyList | ||
|
||
trait Distributable { | ||
void distribute(String version) {} | ||
} | ||
|
||
@CompileStatic | ||
class Distribution implements Distributable { | ||
double number = 1234.234 / 567 | ||
def otherNumber = 3 / 4 | ||
boolean archivable = condition ?: true | ||
def ternary = a ? b : c | ||
String name = "Guillaume" | ||
Closure description = null | ||
List<DownloadPackage> packages = [] | ||
String regex = ~/.*foo.*/ | ||
String multi = ''' | ||
multi line string | ||
''' + """ | ||
now with double quotes and ${gstring} | ||
""" + $/ | ||
even with dollar slashy strings | ||
/$ | ||
|
||
/** | ||
* description method | ||
* @param cl the closure | ||
*/ | ||
void description(Closure cl) { this.description = cl } | ||
|
||
void version(String name, Closure versionSpec) { | ||
def closure = { println "hi" } as Runnable | ||
|
||
MyList ml = [1, 2, [a: 1, b:2,c :3]] | ||
for (ch in "name") {} | ||
|
||
// single line comment | ||
DownloadPackage pkg = new DownloadPackage(version: name) | ||
|
||
check that: true | ||
|
||
label: | ||
// This is purposely tabbed | ||
tabbed_label: | ||
def clone = versionSpec.rehydrate(pkg, pkg, pkg) | ||
/* | ||
now clone() in a multiline comment | ||
*/ | ||
clone() | ||
packages.add(pkg) | ||
|
||
assert 4 / 2 == 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<span class="hljs-comment">// ternary can include quotes</span> | ||
<span class="hljs-keyword">def</span> formattingMsg = label < <span class="hljs-number">0</span> ? (<span class="hljs-string">'The following files need formatting:\n '</span> + | ||
codeStyleFiles.join(<span class="hljs-string">'\n '</span>)) : <span class="hljs-string">'All files are correctly formatted'</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// ternary can include quotes | ||
def formattingMsg = label < 0 ? ('The following files need formatting:\n ' + | ||
codeStyleFiles.join('\n ')) : 'All files are correctly formatted' |