brackets-archive / bracketsIssues

Archive of issues in brackets.
0 stars 0 forks source link

jQuery indentation #12641

Open core-ai-bot opened 3 years ago

core-ai-bot commented 3 years ago

Issue by FezVrasta Monday Apr 28, 2014 at 06:56 GMT Originally opened as https://github.com/adobe/brackets/issues/7672


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

core-ai-bot commented 3 years ago

Comment by architectcodes Wednesday Apr 30, 2014 at 17:48 GMT


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

$someModule.
    doStuff().
    doMoreStuff();
core-ai-bot commented 3 years ago

Comment by FezVrasta Sunday May 04, 2014 at 07:00 GMT


Would be still better then the current behavior.

core-ai-bot commented 3 years ago

Comment by MarcelGerber Sunday May 04, 2014 at 11:57 GMT


This has to be implemented in CodeMirror.

core-ai-bot commented 3 years ago

Comment by njx Monday May 05, 2014 at 18:58 GMT


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.

core-ai-bot commented 3 years ago

Comment by FezVrasta Tuesday May 06, 2014 at 07:21 GMT


. 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();
core-ai-bot commented 3 years ago

Comment by MarcelGerber Tuesday May 06, 2014 at 16:38 GMT


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

core-ai-bot commented 3 years ago

Comment by architectcodes Wednesday May 14, 2014 at 17:50 GMT


@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 :)

core-ai-bot commented 3 years ago

Comment by njx Wednesday May 14, 2014 at 17:58 GMT


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

core-ai-bot commented 3 years ago

Comment by peterflynn Wednesday May 14, 2014 at 23:44 GMT


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
core-ai-bot commented 3 years ago

Comment by MarcelGerber Friday May 16, 2014 at 15:11 GMT


@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.