Problem/Motivation
As mentioned in the parent issue #3238306: [META] Where possible, refactor existing jQuery uses to vanillaJS to reduce jQuery footprint, we are working towards reducing our jQuery footprint. One of the ways to accomplish this is to reduce the number of jQuery features used in Drupal core. We have added eslint rules that identify specific features and fail tests when those features are in use.
There are (or will be) individual issues for each jQuery-use eslint rule. This one is specific to jquery/no-clone, which targets the jQuery clone function.
Steps to reproduce
Proposed resolution
Remaining tasks
- In
core/.eslintrc.jquery.jsonChange"jquery/no-clone": 0,to"jquery/no-clone": 2,to enable eslint checks for uses of jQuery.clone(). With this change, you'll be able to see uses of the undesirable jQuery feature by runningyarn lint:core-js-passingfrom thecoredirectory - Add the following lines to
core/scripts/dev/commit-code-check.shso the DrupalCI testing script can catch this jQuery usage on all files, not just those which have changed
# @todo Remove the next chunk of lines before committing. This script only lints # JavaScript files that have changed, so we add this to check all files for # jQuery-specific lint errors. cd "$TOP_LEVEL/core" node ./node_modules/eslint/bin/eslint.js --quiet --config=.eslintrc.passing.json . CORRECTJQS=$? if [ "$CORRECTJQS" -ne "0" ]; then # No need to write any output the node command will do this for us. printf "${red}FAILURE ${reset}: unsupported jQuery usage. See errors above." STATUS=1 FINAL_STATUS=1 fi cd $TOP_LEVEL # @todo end lines to removeAdd the block about 10 lines before the end of the file, just before
if [[ "$FINAL_STATUS" == "1" ]] && [[ "$DRUPALCI" == "1" ]]; then, then remove it once all the jQuery uses have been refactored. - If it's determined to be feasible, refactor those uses of jQuery
.clone()to use Vanilla (native) JavaScript instead.
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3239490-8.patch | 1.39 KB | sakthi_dev |
Issue fork drupal-3239490
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 #7
Sam Phillemon commentedComment #8
sakthi_dev commentedUpdated the patch with 11.x. Please review.
Comment #9
Sam Phillemon commentedComment #10
Sam Phillemon commentedComment #11
Sam Phillemon commentedI am currently working on this issue.
Comment #12
Sam Phillemon commentedI have looked into this issue and didn't find any js related linting issues.
Comment #13
smustgrave commentedShould be MR and not include changes to core scripts.
Comment #15
Sam Phillemon commentedComment #16
smustgrave commentedNeed to remove change to the script. Can see other related issues for guidance
Comment #17
Sam Phillemon commentedRemoved the DrupalCI testing script. can you please let me know what other issues you are seeing?
Comment #18
guptahemant commentedComment #19
smustgrave commentedThat was it.
Comment #20
alexpottCommitted and pushed 9cdd64881d to 11.x and 5f2e43b35a to 10.3.x. Thanks!
Comment #23
alexpottCreated #3425580: Run linting jobs when config for the linter changes to ensure the linting pipeline runs when eslint config changes.