Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Style error information
https://eslint.org/docs/rules/camelcase
Remark
- Code refactoring. Review it carefully :)
How to Review
## 1. Apply Patch
## 2. Review Code Changes
## 3. Confirm no Code Standard Errors
yarn & yarn lint:core-js-passing
## 4.1 If `NO` errors, mark the issue as `Reviewed & tested by the community` (Don't be shy, we're all friendly)
## 4.2 If `HAS` errors, fix it and upload a new patch (Just do it and you can!!!)
Background
- #2912962: Step 1 JS codestyle: [meta] Fix JS coding standards in core
- We adapted the airbnb coding standard (#2815077: Adopt airbnb javascript style guide v14.1 as new baseline javascript coding standards for Drupal 8 core and contrib), but we are not fully compliant to it yet.
More Information
- Using ES6 in Core
https://www.drupal.org/node/2815083
- To find JS code standard errors stats
cd core/ && yarn & yarn lint:core-js-stats
Comment | File | Size | Author |
---|---|---|---|
#57 | 2915784-57.patch | 26.2 KB | mikejw |
#51 | 2915784-51.patch | 26.34 KB | mikejw |
#45 | interdiff-2915784-36-45.txt | 254 bytes | GrandmaGlassesRopeMan |
#45 | 2915784-45.patch | 25.9 KB | GrandmaGlassesRopeMan |
#36 | interdiff-2915784-28-36.txt | 47.69 KB | GrandmaGlassesRopeMan |
Comments
Comment #2
GrandmaGlassesRopeManComment #3
dawehner❓ I'm quite sure this is a BC break. Ajax commandos, modules overriding other parts of
Drupal.Ajax
etc. might all access this information, don't you think so?Mh, so this is a public method, renaming that might be tricky as well. Here is an idea: a) still provide
shift_color()
which calls toshiftColor
. This single line could then be ignored🔧 If we change
drupalSettings
we need to change the PHP for that as well ... On top of that this might be a BC break. What about providing both ajax_path and ajaxPath and call it a day?Comment #4
lauriiiBased on #3, this should be NW
Comment #5
justafishUpdated patch for @dawehner's comments.
Generated from https://github.com/drupal/drupal/compare/8.5.x...justafish:2915784.patch
Interdiff:
https://github.com/justafish/drupal/commit/e2f8fb29d4670b52f3de4352857f5...
https://github.com/justafish/drupal/commit/e2f8fb29d4670b52f3de4352857f5...
Comment #6
dawehner@justafish
You forgot to run babel:
yarn run build:js
Comment #7
dawehnerComment #8
justafishPatch:
https://github.com/justafish/drupal/compare/8.5.x...justafish:2915784
https://github.com/justafish/drupal/compare/8.5.x...justafish:2915784.patch
Interdiff:
https://github.com/justafish/drupal/commit/e31ec2c6690d7bac9d16d24cb0216...
https://github.com/justafish/drupal/commit/e31ec2c6690d7bac9d16d24cb0216...
Comment #9
tedbow#8 looks good to me.
Ran
yarn lint:core-js-passing
and the only error wasThis was expected because of problem in #3.3
I see that @justafish added
let ajaxPath = drupalSettings.views.ajax_path; // eslint-ignore-line camelcase
To ignore this problem I tried to do the same for
shift_color
but is not working for me.UPDATE. @drpal point out don't need the
// eslint-ignore-line camelcase
because a key on specific object is not linted.Added
function shift_color(given, ref1, ref2) { // eslint-disable-line camelcase
to ignore this. Also updated the docs on
shift_color
Comment #10
dawehner👍
Comment #11
xjmThis sounds like a job for
git diff --color-words="."
. Winning.Here are all the renamed names from the current patch (from a manual inspection):
I haven't checked the BC of all the things yet, but definitely glad to see us providing BC and a deprecation for
element_settings
. One thing that @drpal mentioned to me once before is that @deprecated isn't really a thing in JS. He recommended something else at the time and I've forgotten what it was. This is probably a good time to establish a couple best practices on how we do BC for JS, so setting NR to discuss whether there's something other than @deprecated we should be using here. Thanks!Comment #12
GrandmaGlassesRopeMan@xjm - I think it is
@deprecated
. Sorry if I misrepresented that previously. http://usejsdoc.org/tags-deprecated.htmlComment #13
dawehnerI had a quick look of what react is doing and they totally use throw/console.warn, see https://github.com/facebook/react/blob/15-stable/src/shared/utils/deprec... and https://github.com/facebook/react/blob/15-stable/src/shared/utils/lowPri...
Comment #14
xjmOkay so I was confused. It was actually a past conversation about
@internal
not being a thing in JS.Also I am totally excited by #13! That is great.
So while I still think we should add this to our BC policy, what's in the patch is probably okay. :) Setting back to RTBC and looking a bit more closely at the current patch.
Comment #15
xjmCan we adopt the same message format for the
@deprecated
that we use for PHP? Like:Edit: added the @see
Edit: Because that's four pieces of information the person needs, and so far this patch only includes one of them. :)
Comment #16
xjmThis issue would be adding our two very first deprecations in our JS code. :) So, I posted #2918868: [policy, no patch] Use a deprecation process for JavaScript similar to what we use for PHP code.
Comment #17
xjm(
tmp
is a file containing the list in #11.)Lines 1-3 are the things we're providing BC for, but should the Views AJAX
this.element_settings
also have the same rename-and-deprecation that we are using elsewhere?Also, for
drupalSettings.views.ajax_path
, should we rename and deprecate that too, or would that have (e.g.) notable performance cost?Comment #18
xjmAh, I see that dawehner said:
Can we file a followup for that (and anything else like that)? And also explicitly deprecate the old thing if possible.
Edit: also:
O.o
Comment #19
dawehner❓ I am wondering to which degree we could test this change? Could we have some code overriding the Ajax framework in a test and then check whether it is still working as expected?
On top of that I am wondering whether we could actually as of now remove entries from the
.eslintrc.json
and move it into ignore comments of the files which fail. This way other files could not introduce regressions and new code would have to comply with it already.Comment #20
GrandmaGlassesRopeMan@dawehner So, Needs Tests?
Comment #21
dawehner@drpal
Well, I'm wondering whether we could add more confidence into the patch by adding test. This would make the life of the committers much easier ...
Comment #22
dawehnerHere is a patch which "proves" that both 'element_settings' and 'elementSettings' both work.
Comment #25
dawehnerI'm stupid.
Comment #26
webchickIn general:
- The "after" of this patch looks SO much better on the eyes. Ahhh...
- Wow, +1 to the BC layers! That's a very nice touch. :)
- The AJAX test coverage is also great! But, is there any way that could be split out from this patch so we could look at that on its own and keep this patch to straight renames only? The tests look like useful additions on their own, regardless.
Found a few what look like missed spots in the review:
core/modules/views/js/ajax_view.es6.js, line 72:
top line still shows "element_settings". Same with lines 100, 117, 165.
In core/modules/system/tests/modules/js_ajax_test/js/js_ajax_test.ajax[.es6].js:
1) BZZZT on the
debugger
line, per Matt. ;)2) We're assigning 'catbro' to element_settings still. This seems strange, since later on we have a test specifically for BC. I worry that in Drupal 9 when we blow away the @deprecated element_settings, we're going to create a test failure here.
On the test specifically:
s/ajax/AJAX/g here and various other places (docblocks, etc.)
Rather than an empty string, let's give it an actual description that explains what's being tested.
I can't tell if this is a bug or by design that this function body is missing. If it's by design, let's leave a comment here to explain.
One thing I didn't do as part of my review: do a "global" grep in core's JS files for the old names for various variables (element_settings, form_values, source_id, etc.) to ensure there aren't any other stragglers. That probably would've caught the ajax_view problem above.
I just committed #2925064: [1/2] JS codestyle: no-restricted-syntax , so this one will need a messy re-roll. :\ Sorry about that!
Comment #27
GrandmaGlassesRopeMan- reroll
- About
element_settings
, since this is an object's key and not a variable identifier, the same camelcase rules don't apply. Sorry, I should have caught that when we did the live review.- @dawehner I didn't fiddle with the test, so I'll assign that part to you.
Comment #28
dawehnerDropped it, well, it proves at least that I did some manual testing.
Well, the point is: element_settings still works. We want to prove that old code continues to work.
I used Ajax, where possible now. Thank you!
I added
// Nothing to do.
now.Comment #29
xjmCan we update the deprecations and add a change record as per #15? Thanks!
Comment #30
xjmOh, a more specific comment about why there's
// Nothing to do.
might be helpful also.Comment #31
dawehnerI don't think its worth documenting an empty submit method in a test at all.
"Implement an empty submit method because the form interface requires us to do" ....
Comment #32
xjmWell, just that
Nothing to do
isn't really much better than an empty method. :) How aboutNo submit handling for this form
?Oh and I agree with including the test coverage in the commit that adds the deprecations (inlcuding the old versions!) as @dawehner suggests. Massive +1 for having that since it makes it clear the patch is safe.
I also agree with Angie's point though. My default would (again) be to suggest separate issues, a first 1-2 which renames and deprecates the things where we would need to think about BC at least, with their tests, and then a big followup that renames everything else that is local variables and clearly doesn't need BC. That got pushback on the other issues so I'm reluctant to suggest it, but it's what I would suggest for a PHP patch as well. :)
Oh, as for Angie's question about introducing a test failure when we remove the deprecated code in D9, I think that's a good thing since it also reminds us that we can remove that part of the test. :) We haven't yet really started separating out legacy/deprecation tests for PHP so I don't think we need to try to do so here. It could be a followup or something.
Comment #33
dawehnerUnassigned for now.
I guess its fine to have 2 issues which are pure internal refactorings and then a third issue to actually reach the goal of fixing our eslintrc.
Here is a list of form submit methods which do the same:
Comment #34
dawehnerLooking at the patch there are two API changes:
So just these two changes + the test for ajax_settings should be in one issue?
Then another issue to rename all the uses of ajax_settings to ajaxSettings
And then another issue to rename all the other local variables to camelCase? At least for me this process is a bit sad, because along the process in 1 and 2 you never know whether you caught all instances. You just see that once in step 3 you are actually able to change the eslintrc file, but maybe its fine to accept that the current patch is fine as it is, it just needs to be split up
Comment #35
GrandmaGlassesRopeManComment #36
GrandmaGlassesRopeMan- Removed everything related to color and ajax changes. I'll open subsequent issues + patches for those.
Comment #37
GrandmaGlassesRopeManI've created,
- #2927228: 2/3 JS codestyle: camelcase
- #2927230: 3/3 JS codestyle: camelcase
Comment #38
dawehnerWorks for me. Ideally we wouldn't remove the eslintrc line yet, but this is sadly the problem of splitting it up into these small packages.
Comment #40
GrandmaGlassesRopeManComment #42
webchick"Unable to allocate memory for pool" seems a bit spurious...
Comment #43
dawehnerLet's remove the eslint line for now :(
Comment #44
xjmYeah for phpcs rules when a rule's fixes are too big/varied to be a single scope, we do one of two things:
So I think we can do the same here.
Comment #45
GrandmaGlassesRopeMan- returns
.eslintrc.passing.json
to it's original state.Comment #46
dawehnerThank you @matt!
Comment #47
webchickOk great, this is all nice and straight-forward.
I did raise an eyebrow at:
...there's no corresponding "
- let dependent_columns;
" line to the "+ let dependentColumns;
" line. @drpal explained that this was an optimization because the old code was re-instantiating the variable on every loop that he caught while doing the camel case conversions. That's a nice improvement, but in general it'd be great to split these types of things out into a separate "optimize JS code" issues (I'm not going to ask for it here, because it's just this one instance, and this poor issue has already been "could you please split this out into ..." to deathed. :P Just in general, here is some guidance on patch scoping: http://webchick.net/please-stop-eating-baby-kittens)Everything else, however, is just straight-forward s/foo_bar/fooBar/g; changes.
Ran the patch on simplytest.me, manually checking:
- Machine names + vertical tabs on content type admin
- Dragging/dropping table rows in the block admin page and menu admin page.
- CKEditor (both end-user and config interface)
- States system used in Content Translation admin page
- Color module preview
No problems detected.
Committed and pushed to 8.5.x. w00t! Onward! :)
Comment #50
xjmI had to revert this because a revert was requested on #2925064: [1/2] JS codestyle: no-restricted-syntax and it conflicted. :( @webchick and I have both reviewed this closely already so if we can just reroll this it can probably go back in. I've postponed the other on this since this one is easier to review.
Comment #51
mikejw CreditAttribution: mikejw at University of Adelaide commentedFirst time attempt at a reroll - not a straight reroll as a couple of things in the content_translation.admin were different.
Comment #52
mikejw CreditAttribution: mikejw at University of Adelaide commentedComment #53
dawehnerThank you for the revert @xjm. Reverts are cheap :)
Thank you @mikejw for the quick reroll!
Comment #54
webchickI'm guessing that was meant to be this. :)
Comment #55
webchickCan't seem to commit this because https://github.com/alexpott/d8githooks is giving me:
Any ideas?
Comment #56
mikejw CreditAttribution: mikejw at University of Adelaide commentedI don't get any issues - did you run a `git pull` on 8.5.x before you tried? I will now double check on fresh checkout of 8.5.x.
Comment #57
mikejw CreditAttribution: mikejw at University of Adelaide commentedOk, I found something :) yeah, needed to run build.
Comment #58
mikejw CreditAttribution: mikejw at University of Adelaide commentedComment #59
dawehnerThank you @mikejw
Comment #61
webchickOkay, take two! :)
Committed and pushed to 8.5.x. Thanks!