Problem/Motivation
While I was updating the 2.x branch to use Drupal.org's GitLab CI for automated linting and testing, the new eslint lints started identifying a bunch of issues with the JavaScript and/or YAML in the project. At time-of-writing, the most recent set of lints were in job 462178.
I tried automatically fixing the issues identified, but there were some that were non-trivial to fix, and my JS isn't good enough to the best way to fix these, so I have left the file as-is (i.e.: without committing the automatic fixes). Here are the lints left over after the automatic fixes:
web/modules/contrib/multiselect/js/multiselect.js
5:2 warning Unexpected unnamed function func-names
34:37 warning Unexpected unnamed function func-names
40:9 warning Unexpected unnamed function func-names
46:25 warning Unexpected unnamed function func-names
54:44 warning Unexpected unnamed function func-names
62:43 warning Unexpected unnamed function func-names
70:35 warning Unexpected unnamed function func-names
79:38 warning Unexpected unnamed function func-names
103:23 warning Unexpected unnamed function func-names
104:13 warning Unexpected unnamed function func-names
116:32 warning Unexpected unnamed function func-names
117:16 error Use the rest parameters instead of 'arguments' prefer-rest-params
118:13 warning Unexpected unnamed function func-names
129:29 warning Unexpected unnamed function func-names
130:16 error Use the rest parameters instead of 'arguments' prefer-rest-params
131:13 warning Unexpected unnamed function func-names
137:9 warning Unary operator '--' used no-plusplus
147:23 warning Unexpected unnamed function func-names
148:18 error Use the rest parameters instead of 'arguments' prefer-rest-params
149:13 warning Unexpected unnamed function func-names
164:26 warning Unexpected unnamed function func-names
165:22 error Use the rest parameters instead of 'arguments' prefer-rest-params
166:13 warning Unexpected unnamed function func-names
169:24 error Expected '===' and instead saw '==' eqeqeq
✖ 24 problems (5 errors, 19 warnings)
Steps to reproduce
To reproduce this locally...
- Download and install Drupal 10.1.
- Make sure that JS packages are installed (one of which is eslint):
cd web/coreyarn installcd ../..
- Install the multiselect module and dependencies, and get it ready for development:
composer require --prefer-install=source "drupal/multiselect"cd web/modules/contrib/multiselectgit fetch --all -t -pgit checkout 2.xgit pull- (follow the git instructions for this issue)
- Set up eslint config files like the GitLab CI job does. Note this ignores the files so they won't accidentally get committed. We probably don't want to commit them so that Drupal core's JS standards can evolve upstream:
cp ../../../core/.prettierrc.json . && echo ".prettierrc.json" | tee -a .git/info/excludeecho '*.yml' > .prettierignore && echo ".prettierignore" | tee -a .git/info/exclude
- Run eslint - this will show all 94 problems, including ones that can be automatically fixed:
../../../core/node_modules/.bin/eslint --no-error-on-unmatched-pattern --ignore-pattern="*.es6.js" --resolve-plugins-relative-to=../../../core --ext=.js,.yml .: this should match what you currently see in GitLab CI, i.e.: in job 462178 - Ask eslint to fix the problems it can fix safely:
../../../core/node_modules/.bin/eslint --no-error-on-unmatched-pattern --ignore-pattern="*.es6.js" --resolve-plugins-relative-to=../../../core --ext=.js,.yml . --fix: this will do what it can and write out the problems it can't fix, which will probably match what I pasted in the Problem/Motivation section above. - (fix the errors)
- Make sure to run eslint one more time before committing:
../../../core/node_modules/.bin/eslint --no-error-on-unmatched-pattern --ignore-pattern="*.es6.js" --resolve-plugins-relative-to=../../../core --ext=.js,.yml .
Proposed resolution
Fix the errors.
Remaining tasks
- Write a patch or merge request.
- Review and feedback
- RTBC and feedback
- Commit
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork multiselect-3407697
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mparker17Whoops I made a small typo in the issue summary.
Comment #3
bobi-mel commentedComment #5
bobi-mel commentedI've fixed the issue. Please check it.
Comment #7
mparker17Code review looks good; manual testing works; automated tests work. Looks good to me! Thanks very much @bobi-mel!
Comment #8
bobi-mel commentedThanks for the really fast review.
Comment #9
rgpublicUm, this commit changed jQuery.fn.selectAll to an arrow function. Due to this change, the selectAll function doesn't seem to work anymore it seems - causing JS errors. I guess the reason is that the semantics of "this" has been changed inadvertently. Using the arrow function, "this" is now pointing to a window and not to the JQuery object anymore.
Comment #10
mparker17@rgpublic, thanks for noticing this issue, and reporting it here! (JavaScript scope resolution is hard!)
I will move this ticket back to "Needs work" so that we fix it before the next release.
Comment #11
bobi-mel commentedI'll review and correct these remarks and correct as soon as possible
Comment #13
bobi-mel commentedHI @mparker17 @rgpublic
I have reviewed your remarks and agree with them. I haven't checked whether the data is saved after the form is saved. I fixed it and tested everything works as expected.
@mparker17
No CTA only IFU
I found that the jQuery.fn.removeOption() function is never called, so it probably needs to be removed, I suggest creating a separate issue for this for a deeper investigation.
Comment #15
mparker17The follow-up has been merged; thanks @rgpublic and @bobi-mel!