Problem/Motivation

JSLint is an awesome tool to help detect potential JavaScript problems but the current core js files do not indent inside the initial enclosing "scope creating" function cause JSLint to issue many messages.

The current method of indention in core is "pretty." It eliminates "indentation noise" inside the source file but is still nonstandard and compromises our ability to use standard tools like JSLint.

Proposed resolution

Use standard indentation. Indent lines inside even the initial enclosing function 2 spaces.

Remaining tasks

Change all the JavaScript files to use standard identation.

User interface changes

None.

API changes

None.

Comments

mitron’s picture

Status: Active » Needs review
StatusFileSize
new23.18 KB

This is an example patch for toolbar.js. Making this fix is very simple since some IDEs will correct indentation automatically. If this patch is approved by the community, we can proceed to correct all the files. Please provide advice on how to proceed: Create multiple patched and issues? Do all the files in a single patch? Etc.

scresante’s picture

Compatability with JSLint is not my concern. What is is that there are discrepancies amongst the .js files in terms of indentation on the main body of code. This patch addresses the fact that indentation in these files does not strictly match the Drupal JS Coding standards.

This patch changes indentation in all .js files in core/modules which were not indented properly.

scresante’s picture

And this addresses the same issues in the core/misc directory.
I did not and will not fix these problems in misc/ckeditor or misc/ui/ui since in those javascripts, the indentation problem is going to recur from the vendor.

jeffschuler’s picture

Issue tags: +SprintWeekend2013
enhdless’s picture

Issue summary: View changes
Status: Needs review » Needs work

Patches failed to apply

ivanstegic’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: drupal-standard_javascript_indentation_misc-1913510-3.patch, failed testing.

nod_’s picture

Title: Core Javascript Files Not Using Standard Indentation Triggering JSLint Noise » Core Javascript Files Not Using Standard Indentation
Issue tags: +JavaScript
erich_s’s picture

Status: Needs work » Needs review
StatusFileSize
new26.19 KB

modified formatting in core/misc/drupal.js

erich_s’s picture

modified core/misc/drupal.js to fix indenting according to drupal standards (2 spaces). Followed the instructions on setting up phpstorm per this url: https://drupal.org/node/1962108 Also needed to modify phpstorm's javascript settings to 2 spaces.

Then I used PHPStorm's Reformat Code, but it modified a couple lines. I undid those changes and the latest patch returns nothing with git diff -w.

erich_s’s picture

trying again to cleanly change the indentation on drupal.js.

nod_’s picture

That last patch is perfect for drupal.js, now on to the misc/ then modules/ folder :)

Thanks!

The last submitted patch, 9: drupal-fix_formatting_drupal.js-1913510-8.patch, failed testing.

The last submitted patch, 10: drupal-fix_formatting_drupal.js-1913510-9.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: drupal-fix_formatting_drupal.js-1913510-10.patch, failed testing.

nod_’s picture

Status: Needs work » Needs review

Cancelled patch test, it's only changing JS files.

erich_s’s picture

modified the rest of the javascript files in the core/misc folder.

nod_’s picture

Status: Needs review » Needs work

The last patch doesn't seem to include changes from the previous patch, can you make a single patch with all the changes at the end?

ajax.js:138–145 comment not indented properly (same issue that was in drupal.js)
tableheader.js:18,26,46,58 comment not indented properly
tableresponsive.js:136 comment not indented properly

And you missed the core/misc/dropbutton/dropbutton.js file :)

erich_s’s picture

modified all js files under core/modules to use standard indentation

yesct’s picture

Status: Needs work » Needs review

triggering testbot by setting to needs review.
erich_s is also going to merge the two patches, so I'm going to also cancel the testbot requests to keep them out of the test queue.

Status: Needs review » Needs work

The last submitted patch, 19: drupal-fix_formatting_drupal.js-1913510-13.patch, failed testing.

The last submitted patch, 17: drupal-fix_formatting_drupal.js-1913510-12.patch, failed testing.

The last submitted patch, 19: drupal-fix_formatting_drupal.js-1913510-13.patch, failed testing.

The last submitted patch, 17: drupal-fix_formatting_drupal.js-1913510-12.patch, failed testing.

erich_s’s picture

combined earlier patches numbered 10, 12 and 13. This contains all js files in core/misc and core/modules.

erich_s’s picture

Sorry for the delay on this - had internet troubles. I believe patch 26 addresses all the issues. It contains all the javascript files in core/misc and core/modules. Single-line comments should all be fixed.

erich_s’s picture

Status: Needs work » Needs review
nod_’s picture

oh just one last issue.

Could you remove the changes made to the core/modules/tour/js/jquery.joyride-2.0.3.js file please? this is an external file and we shouldn't change it. Beside that, it's RTBC!

nod_’s picture

Status: Needs review » Needs work
jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new19.72 KB
new1.34 MB

Here we go.

jibran’s picture

StatusFileSize
new19.72 KB

Correct interdiff ignore the last one.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

And that's a wrap!

Thank you very much for the patch. Really happy to get that RTBC :D

Review all the files, all comments are indented properly. git diff -w is empty. It's all good.

nod_’s picture

Status: Reviewed & tested by the community » Needs work

Ah sorry, still a couple comments not indented

collapse.js:110
drupal.js:99
states.js:558,563,568
tabbingmanager.js:284,285

The last submitted patch, 25: drupal-fix_formatting_drupal.js-1913510-21.patch, failed testing.

The last submitted patch, 26: drupal-fix_formatting_drupal.js-1913510-26.patch, failed testing.

The last submitted patch, 30: drupal-fix_formatting_drupal.js-1913510-30.patch, failed testing.

erich_s’s picture

nod,
Sorry for the oversight. I need to deal with something else this morning, but I'll take care of this today. Should I start with the interdiff, apply that to the latest 8.x, make my changes then create the patch?

nod_’s picture

you can apply #30 on a clean 8.x codebase, make the changes in #33 and post the patch :)

erich_s’s picture

Sounds good. Working on it now. Will have it to you in a jiffy.

erich_s’s picture

Status: Needs work » Needs review
StatusFileSize
new1.34 MB

40th time's a charm! Got my fingers crossed. This should be the whole kit & kaboodle.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

No more comment problems, all good now!

git diff -w still empty. Only indent changes in this patch :)

droplet’s picture

Status: Reviewed & tested by the community » Needs work

EDIT:

the summary said that it uses JSLINT to check errors. But the CORE is using JSHINT.
Please add "indent" option to .jshintrc :)

$ jshint core
core\modules\edit\js\editors\formEditor.js: line 74, col 43, Expected '}' to have an indentation at 9 instead at 43.
core\modules\views_ui\js\views-admin.js: line 160, col 6, Expected '}' to have an indentation at 3 instead at 6.
core\modules\views_ui\js\views-admin.js: line 758, col 6, Expected '}' to have an indentation at 3 instead at 6.

3 errors
erich_s’s picture

Status: Needs work » Needs review
StatusFileSize
new1.34 MB

Here's the same patch as 40, but with indent: 2 added to .jshintrc

erich_s’s picture

I'm trying to make the changes in #42, but the first one sounds like I should change it like this, however that'll result in git diff -w producing a result (although not sure why since it's only a line break I added):

--- a/core/modules/edit/js/editors/formEditor.js
+++ b/core/modules/edit/js/editors/formEditor.js
@@ -71,7 +71,8 @@ Drupal.edit.editors.form = Drupal.edit.EditorView.extend({
// Render form container.
var $formContainer = this.$formContainer = $(Drupal.theme('editFormContainer', {
id: id,
- loadingMsg: Drupal.t('Loading…')}
+ loadingMsg: Drupal.t('Loading…')
+ }
));
$formContainer
.find('.edit-form')

droplet’s picture

@erich_s,

Yeah, it would produces visible difference. "-w" option only skips the spaces checking.

erich_s’s picture

Here's another patch that addresses Droplets comments. Also, it contains NO changes to the .jshintrc file - I misunderstood Droplet's comment on that.

erich_s’s picture

Let's try this again. This version has all the js files, think the issues pointed out by Droplet and nod have been addressed. .jshintrc has been modified to include indent:2

nod_’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.47 KB

All right, jshint core/ returns no errors.

Attached the output of git diff -w

The last submitted patch, 40: drupal-fix_formatting_drupal.js-1913510-40.patch, failed testing.

The last submitted patch, 43: drupal-fix_formatting_drupal.js-1913510-43.patch, failed testing.

The last submitted patch, 46: drupal-fix_formatting_drupal.js-1913510-46.patch, failed testing.

droplet’s picture

x2 RTBC. :)

alexpott’s picture

Title: Core Javascript Files Not Using Standard Indentation » Change notice: Core Javascript Files Not Using Standard Indentation
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed 2d476a5 and pushed to 8.x. Thanks!

nod_’s picture

Title: Change notice: Core Javascript Files Not Using Standard Indentation » Core Javascript Files Not Using Standard Indentation
Priority: Major » Normal
Status: Active » Fixed
Issue tags: -Needs change record
nod_’s picture

Should someone have a problem with rerolling an existing patch because of this change, feel free to ping me and I'll help reroll it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.