Skip to content

[4.2] javascript cs warning#38613

Merged
wilsonge merged 1 commit intojoomla:4.2-devfrom
heelc29:issue-javascript-cs
Sep 2, 2022
Merged

[4.2] javascript cs warning#38613
wilsonge merged 1 commit intojoomla:4.2-devfrom
heelc29:issue-javascript-cs

Conversation

@heelc29
Copy link
Copy Markdown
Contributor

@heelc29 heelc29 commented Aug 27, 2022

Summary of Changes

Convert unnamed function to arrow function

Testing Instructions

follow #38154

Actual result BEFORE applying this Pull Request

warning at npm run lint:js
image

Expected result AFTER applying this Pull Request

no warning at npm run lint:js
image

@joomla-cms-bot joomla-cms-bot added NPM Resource Changed This Pull Request can't be tested by Patchtester PR-4.2-dev labels Aug 27, 2022
@brianteeman
Copy link
Copy Markdown
Contributor

obvioously there is an issue with drone as this should have been picked up

@heelc29
Copy link
Copy Markdown
Contributor Author

heelc29 commented Aug 27, 2022

obvioously there is an issue with drone as this should have been picked up

That it's just a warning, I guess it's ok for drone ...
image

Copy link
Copy Markdown
Member

@richard67 richard67 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fits to the syntax we have elsewhere.

@richard67 richard67 added the Maintainers Checked Used if the PR is conceptional useful label Aug 27, 2022
@richard67
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on dd0e85e

Warning from eslint is fixed.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38613.

@viocassel
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on dd0e85e


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38613.

@richard67
Copy link
Copy Markdown
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38613.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Aug 27, 2022
@dgrammatiko
Copy link
Copy Markdown
Contributor

dgrammatiko commented Aug 28, 2022

Although this PR cleans up the warning there are more problems in this file, eg the addEventListener('DOMContentLoaded', ...) is an ANTIPATTERN and should be removed (the file is either loaded with attribute defer or type=module which render the waiting for the DOM to be ready useless). I had fixed it correctly with #38225: https://github.com/joomla/joomla-cms/pull/38225/files#diff-4afb4f910136391957e62b8afcb5f0d6b240ee226cd69b4960777bc15ddfe668

The code should be:

/**
 * @copyright  (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
[].slice.call(document.querySelectorAll('.article-status')).forEach((element) => {
  element.addEventListener('click', (event) => {
    event.stopPropagation();
  });
});

or even more compact:

/**
 * @copyright  (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
[].slice.call(document.querySelectorAll('.article-status')).forEach((element) => element.addEventListener('click', (event) => event.stopPropagation()));

@obuisard this might be a good project for 4.3: clean all the addEventListener('DOMContentLoaded', ...) from the javascript files!
The anti pattern is explained here: https://www.youtube.com/watch?v=_iq1fPjeqMQ

@obuisard
Copy link
Copy Markdown
Contributor

I agree @dgrammatiko, this should be cleaned up. Do you mind writing a PR for this issue and if you can't work on it I will try and rally the troops so you get help :-)

@dgrammatiko
Copy link
Copy Markdown
Contributor

@obuisard you could use #35725 as a guide.
In short the scripts need to:

  • be converted to type=module + add the -es5 in the dependencies
  • remove the iife, if exists (type= module scripts are scoped by default)
  • remove strict mode (type= module is strict by default)
  • remove the addEventListener('DOMContentLoaded', ...) as it's pure overhead

@wilsonge wilsonge merged commit 1b01462 into joomla:4.2-dev Sep 2, 2022
@wilsonge wilsonge added this to the Joomla! 4.2.2 milestone Sep 2, 2022
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Sep 2, 2022
@heelc29 heelc29 deleted the issue-javascript-cs branch September 2, 2022 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Maintainers Checked Used if the PR is conceptional useful NPM Resource Changed This Pull Request can't be tested by Patchtester

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants