adobe / brackets

An open source code editor for the web, written in JavaScript, HTML and CSS.
http://brackets.io
MIT License
33.25k stars 7.63k forks source link

jQuery indentation #7672

Open FezVrasta opened 10 years ago

FezVrasta commented 10 years ago

When I write Javascript jQuery code I get this automatic indentation:

$("<a/>")
.append("<span/>")
.find("span")
.remove()
.end()
.remove();

Instead, following the jQuery line guides it should be:

$("<a/>")
    .append("<span/>")
    .find("span")
        .remove()
    .end()
    .remove();

There are chances this problem will be fixed? Thanks

tomek-he-him commented 10 years ago

AngularJS proposes a coding style which could possibly be easier to implement. How about that?

$someModule.
    doStuff().
    doMoreStuff();
FezVrasta commented 10 years ago

Would be still better then the current behavior.

marcelgerber commented 10 years ago

This has to be implemented in CodeMirror.

njx commented 10 years ago

Reviewed. One way we could do this is by making . an electric char when it's at the beginning of a line in JS. Not sure if we would also have to make changes in the CM mode though.

Marking low priority to me.

FezVrasta commented 10 years ago

. is a very "not specific" character and make it electric could interfere with other stuff...

Remember we have to handle even when someone uses alias for the $ char, example:

jQuery('#sth')
    .remove();

or

var sth = $;

sth('#something')
    .remove();
marcelgerber commented 10 years ago

I guess it would be ok to just check whether the previous line ends with a semicolon or not.

tomek-he-him commented 10 years ago

@SAPlayer, that's a perfectly simple idea in my opinion. Less is more.

Works also for the AngularJS coding style.

The only problem I see is that some developers still don't use semicolons at the end of the line. Perhaps the behaviour you propose could be toggled by using strict mode? That would also encourage some of those sloppier devs to switch to coding in strict mode :)

njx commented 10 years ago

@tomekwi I don't think strict mode requires semicolons, unfortunately.

peterflynn commented 10 years ago

Yeah, it seems like this would require two changes:

  1. Change the JS indenter logic to say that a line starting with "." (or following a line ending with ".") should be indented an extra level
  2. Make "." an "electric char" so that typing it triggers recalculating the indent level of the line
marcelgerber commented 10 years ago

@peterflynn I guess it's better implemented in CM (maybe with an option) 'cause it's valid JS coding style, which should also be supported by pure CM.