-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(groovy) strings are not allowed inside ternary clauses #2565
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.