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

(groovy) strings are not allowed inside ternary clauses #2217

Closed
paladox opened this issue Oct 20, 2019 · 8 comments · Fixed by #2565
Closed

(groovy) strings are not allowed inside ternary clauses #2217

paladox opened this issue Oct 20, 2019 · 8 comments · Fixed by #2565
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Milestone

Comments

@paladox
Copy link
Member

paladox commented Oct 20, 2019

If you do for example:

def createCodeStyleMsgBody(build, label) {
    def codeStyleFiles = findCodestyleFilesInLog(build)
    def formattingMsg = label < 0 ? ('The following files need formatting:\n    ' +
        codeStyleFiles.join('\n    ')) : 'All files are correctly formatted'
    def url = build.url + "consoleText"

    return "${Globals.resTicks[build.result]} $formattingMsg\n    (${url})"
}

'The following files need formatting:\n ' is not highlighted correctly as a string, secondly everything after ' + is coloured in blue (so if you create another def after, it colours all that in blue).

@joshgoebel
Copy link
Member

Sounds like some issue with expectations around new lines... anyway you could make a jsfiddle of this so we can easily track it over time and confirm it? Or if you want to make an attempt at fixing it that'd be amazing. :-)

You can fork my template:
https://jsfiddle.net/ajoshguy/a1kntyg4/

@paladox
Copy link
Member Author

paladox commented Oct 20, 2019

Hi, here's the jsfiddle https://jsfiddle.net/j4gq5at6/

@joshgoebel
Copy link
Member

Thanks, yeah something strange is in the neighborhood there.

@paladox
Copy link
Member Author

paladox commented Oct 20, 2019

@yyyc514 i guess it's because of https://github.com/highlightjs/highlight.js/blob/master/src/highlight.js#L938 (as that piece of text actually includes \n)

@paladox
Copy link
Member Author

paladox commented Oct 20, 2019

Oh, just tested, nope.

@joshgoebel
Copy link
Member

No that's not it because the string is terminated, it doesn't bridge multiple lines.

@joshgoebel
Copy link
Member

It doesn't like the ternary, but not sure why.

@joshgoebel
Copy link
Member

joshgoebel commented Oct 20, 2019

    {
                // catch middle element of the ternary operator
                // to avoid highlight it as a label, named parameter, or map key
                begin: /\?/, end: /\:/
            },

Guessing this is it. It needs to be updated to know that strings are allowed to existing inside ternary's so that string grabs the ":" inside strings, not the ternary rule.

@joshgoebel joshgoebel added good first issue Should be easier for first time contributors help welcome Could use help from community labels Oct 20, 2019
@joshgoebel joshgoebel changed the title Groovy syntax broken (groovy) strings are not allowed inside ternary clauses Oct 20, 2019
@joshgoebel joshgoebel added this to the 10.1 milestone Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants