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.
| Comment | File | Size | Author |
|---|---|---|---|
| #48 | whitespaceless-diff.txt | 1.47 KB | nod_ |
| #47 | drupal-fix_formatting_drupal.js-1913510-47.patch | 1.34 MB | erich_s |
| #1 | drupal-standard_javascript_indentation-1913510-1-do-not-test.patch | 23.18 KB | mitron |
Comments
Comment #1
mitron commentedThis 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.
Comment #2
scresante commentedCompatability 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.
Comment #3
scresante commentedAnd 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.
Comment #4
jeffschulerComment #5
enhdless commentedPatches failed to apply
Comment #6
ivanstegic commented3: drupal-standard_javascript_indentation_misc-1913510-3.patch queued for re-testing.
Comment #8
nod_Comment #9
erich_s commentedmodified formatting in core/misc/drupal.js
Comment #10
erich_s commentedmodified 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.
Comment #11
erich_s commentedtrying again to cleanly change the indentation on drupal.js.
Comment #12
nod_That last patch is perfect for drupal.js, now on to the misc/ then modules/ folder :)
Thanks!
Comment #16
nod_Cancelled patch test, it's only changing JS files.
Comment #17
erich_s commentedmodified the rest of the javascript files in the core/misc folder.
Comment #18
nod_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 :)
Comment #19
erich_s commentedmodified all js files under core/modules to use standard indentation
Comment #20
yesct commentedtriggering 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.
Comment #25
erich_s commentedcombined earlier patches numbered 10, 12 and 13. This contains all js files in core/misc and core/modules.
Comment #26
erich_s commentedSorry 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.
Comment #27
erich_s commentedComment #28
nod_oh just one last issue.
Could you remove the changes made to the
core/modules/tour/js/jquery.joyride-2.0.3.jsfile please? this is an external file and we shouldn't change it. Beside that, it's RTBC!Comment #29
nod_Comment #30
jibranHere we go.
Comment #31
jibranCorrect interdiff ignore the last one.
Comment #32
nod_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 -wis empty. It's all good.Comment #33
nod_Ah sorry, still a couple comments not indented
collapse.js:110
drupal.js:99
states.js:558,563,568
tabbingmanager.js:284,285
Comment #37
erich_s commentednod,
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?
Comment #38
nod_you can apply #30 on a clean 8.x codebase, make the changes in #33 and post the patch :)
Comment #39
erich_s commentedSounds good. Working on it now. Will have it to you in a jiffy.
Comment #40
erich_s commented40th time's a charm! Got my fingers crossed. This should be the whole kit & kaboodle.
Comment #41
nod_No more comment problems, all good now!
git diff -w still empty. Only indent changes in this patch :)
Comment #42
droplet commentedEDIT:
the summary said that it uses JSLINT to check errors. But the CORE is using JSHINT.
Please add "indent" option to .jshintrc :)
Comment #43
erich_s commentedHere's the same patch as 40, but with indent: 2 added to .jshintrc
Comment #44
erich_s commentedI'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')
Comment #45
droplet commented@erich_s,
Yeah, it would produces visible difference. "-w" option only skips the spaces checking.
Comment #46
erich_s commentedHere's another patch that addresses Droplets comments. Also, it contains NO changes to the .jshintrc file - I misunderstood Droplet's comment on that.
Comment #47
erich_s commentedLet'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
Comment #48
nod_All right,
jshint core/returns no errors.Attached the output of
git diff -wComment #52
droplet commentedx2 RTBC. :)
Comment #53
alexpottCommitted 2d476a5 and pushed to 8.x. Thanks!
Comment #54
nod_change notice at: https://drupal.org/node/2183065
Comment #55
nod_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.