Weird coffeescript code style in Intellij IDEA - intellij-idea

I have this line in my coffeescript file
if someVariable then no else yes
One of the most valuable feature in IDEA for me is code clean up. But it doesn't work as I expect here. After pressing Ctrl+Alt+L, IDEA reformats this line to ugly
if someVariable then {
no
} else yes
Which is not just bad style but error when compile from coffeescript to javascript.
Here is similar line which couldn't be formatted properly by IDEA.
return true if someVariable is 5
...becomes...
{
return true
} if someVariable is 5
Why is that?

It's a bug caused by the if() statement, Force braces: Always setting in JavaScript Wrapping and Braces.
Issue is submitted to YouTrack.

That looks like JavaScript code style. Try checking settings under File>Settings>Project Settings>Code Style.
If you can't manage to set the code style to a correct form, then you still have the option to customize it yourself..
Eventually take a look # http://www.jetbrains.com/webstorm/webhelp/coffeescript-support.html, you might find something interesting if you haven't gone over it all ready. Good luck!

Related

Codeception ->see("String") fails but ->seeInSource("String") succeeds

Something is wrong with the AcceptanceTester->see() method for me. It can't see things that are plainly there in the source, as shown by the AcceptanceTester->seeInSource() method.
Here's my test, which runs in PHPBrowser within the WP-Browser implementation of Codeception:
public function testAfricaIsVisible(AcceptanceTester $I) {
$I->amOnPage('/');
$I->seeResponseCodeIs(200);
$I->seeInSource('Africa');
$I->see('Africa');
}
Here's the result I get:
As you can see, ->SeeInSource("Africa") works, but ->see("Africa") fails.
I understand that ->SeeInSource() sometimes "sees" things that ->see() doesn't, but in this case, the word "Africa" is link text that should be clearly visible with or without strip_tags() applied.
In this case, when I open up the Html link the word "Africa" is clearly visible:
Anyone have any idea why Codeception doesn't ->see() this text?
I figured it out. For anyone with a similar problem, the underlying issue was malformed HTML that was glossed over by Chrome/Firefox but screwed up the site as seen by Phpbrowser. I bet if I was using the WebDriver module instead, it would work.
The solution: Use an HTML validation tool and fix the reported syntax errors.
In this case it was a title tag with a single-quote in it, e.g. title='doesn't'

Clang format for banner style

An open-source project I contribute to uses banner style (also called Ratliff style). It looks like that:
// In C
for (i = 0; i < 10; i++) {
if (i % 2 == 0) {
doSomething(i);
}
else {
doSomethingElse(i);
}
}
Some IDE's like QtCreator have their own configurations for formatting, but others, like Visual Studio Code, require a .clang-format file.
I looked online for existing configurations, and couldn't find any. Then I tried to make one from scratch using this clang-format generator, but I couldn't manage to indent the braces right.
So, is it possible to create a clang-format file for Ratliff/Banner style, or is there some missing configuration that will force us to use some other generator?
This answer is not going to be the "answer" that you were looking for, but it is what I've discovered over the last two days of digging through the code for clang-format. I, too, have been looking for a way to auto-format a variant of banner style with clang-format.
clang-format seems to be missing some capabilities that would enable it to auto-format banner style.
For instance, you need to indent ending (right) braces for code blocks. clang-format does not even appear to track ending braces, but it does track starting (left) braces within its internals.
I started out my studying streak thinking I could understand the way clang-format implements its formatter system, so I could add the features needed to do it. Sadly it was way too complicated for me.
Perhaps someday we will be able to auto-format banner style with clang-format, but not today.
If someone out there knows this answer is inaccurate, please don't hesitate to correct me.
edit: Instead of giving you just a verification of what can't be done with clang-format, perhaps you might find http://astyle.sourceforge.net useful.

Chained methods and continuation indent in Intellij

I've never figured out how to make Intellij handle continuation indent for chained methods properly, and apparently today is the day it's annoyed me enough to consult you lovely people.
What I want is this:
makeAThing(
"with",
"params"
)
.setProperty("with some more params")
.start();
What I get is this:
makeAThing(
"with",
"params"
)
.setProperty("with some more params")
.start();
I get this in Java, Groovy, JavaScript and a bunch of other places. How can I persuade Intellij not to add continuation indent after a chained method call?
I just switched to intellij and also have found this rather annoying.
Only found two solutions:
forcing the coding style to have 0 for "continuation indent" which I'm starting to like anyway albeit not very canonical Java.
Turing off the formatter for blocks of code and press shift tab
Works for Java not sure for JS:
// #formatter:off
...
// #formatter:on

Javascript code not recognised in Intellij IDEA 12 in scala template for Play 2

I just installed the recently released Intellij IDEA 12, which is GREAT for Play Framework 2.
However, I'm having the following issue: in an HTML Scala template, any JavaScript code enclosed in a <script> tag within the body of the template is not recognised as JavaScript by IDEA, thus not offering code completion and incorrectly showing errors where they aren't. I suspect it is interpreting the code as Scala code, ergo offering incorrect code completion and making it quite painful to write JS in a template.
This issue was not present in IDEA 11.
Any ideas?
Update
I have the JavaScript Support plugin enabled. Simple code completion works fine. However, if I type function (){} to code an anonymous function and hit Enter with the caret between the curly brackets, IDEA does the following:
If I manually fix the incorrectly added }, and write code for the anonymous function, it offers correct variable suggestion for the console.log although it is stil showing errors:
I can't confirm that, I can see that both, Scala and JavaScript completion works properly.
Go to Settings > Plugins and make sure that you have JavaScript Support enabled. After that close and reopen all your views to let the Idea analize syntax once again.
It appears that your function statement is invalid because you did not name your function. The details of what is going on here are answered in this post. I'm not sure of the details of your particular needs, but you might try this syntax instead:
<script>
(function() {
})();
</script>

JSLint, when using JS frameworks

I use the Dojo framework, which I load from an url.
How should I deal with the 'dojo' was used before it was defined errors, and the alike?
Yes, my feeling really get hurt, when running code through JSlint.
Perhaps you can put something like
/* globals dojo */
in the beggining of your file to tell JSLint that dojo exists?
I personaly use JSHint (a fork of JSLint that is less nitpicky) instead and one of the preconfigured options is support for Dojo.
Sounds like you need to put Dojo first in your JavaScript. The message suggests that you have an ordering problem.
Don't take it personally. You are not your code. Just make it better, learn something, and don't do it again.
If you scroll all the way down to the bottom there is a "predefined" textbox. Simply put in any of the variables you need into there (comma separated).