Skip to content

Commit

Permalink
Implement 'meaningful' checks to .js (#112)
Browse files Browse the repository at this point in the history
Implement 'meaningful' checks to `.js`

Part of #110 

## Ignore Override Warning
```
| IGNR  | Override (phtml/js/html) | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/ignore.js                                      | app/design/frontend/Ampersand/theme/Magento_Checkout/web/js/ignore.js                                                              |
```

In this case `vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/ignore.js` was updated with some whitespace/comment/etc so its not really changed, so don't bother reporting on it. The `IGNR` entries are suppressed without `--show-ignore`

## Redundant override
```
| WARN  | Redundant Override       | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/redundant.js                                   | app/design/frontend/Ampersand/theme/Magento_Checkout/web/js/redundant.js                                                           |
```

In this case `vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/redundant.js` has been updated and is now equivalent (excluding some whitespace/comments) to `app/design/frontend/Ampersand/theme/Magento_Checkout/web/js/redundant.js`

The `app/design` override is now redundant and not necessary


## Additional test case changes

The additional test cases needed updated as this file is being ignored, due to the fact its only a comment / whitespace from magento/magento2@1697149

Previously a human would have had to look at the change and work it out themselves, now its not reported.

```diff
diff -ur -N vendor_orig/magento/module-vault/view/frontend/web/js/view/payment/vault.js vendor/magento/module-vault/view/frontend/web/js/view/payment/vault.js
--- vendor_orig/magento/module-vault/view/frontend/web/js/view/payment/vault.js	2020-04-13 17:35:44.000000000 +0000
+++ vendor/magento/module-vault/view/frontend/web/js/view/payment/vault.js	2023-06-07 19:25:10.000000000 +0000
@@ -3,7 +3,7 @@
  * See COPYING.txt for license details.
  */
 /*browser:true*/
-/*global define*/
+
 /* @api */
 define([
     'underscore',
```

And these files are being flagged as redundant, because `vendor/paypal/module-braintree-core/view/base/web/js/form-builder.js` has been edited/changed and is now the same as `vendor/paypal/module-braintree-core/view/frontend/web/js/form-builder.js`

```
e676f80e153b2a8e55da763f237cabf4  vendor/paypal/module-braintree-core/view/base/web/js/form-builder.js
e676f80e153b2a8e55da763f237cabf4  vendor/paypal/module-braintree-core/view/frontend/web/js/form-builder.js
```
  • Loading branch information
convenient authored Nov 2, 2023
1 parent fe63dc1 commit 7c6bb63
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 22 deletions.
2 changes: 2 additions & 0 deletions dev/Docker/setup-magento-with-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ echo "<!-- --><p>some change</p>" >> vendor/magento/module-ui/view/base/web/tem
# Redundant override
echo " " >> vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Ui/web/templates/redundant.html
echo " " >> vendor/ampersand/upgrade-patch-helper-test-module/src/module/view/frontend/email/redundant.html
echo " " >> vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/redundant.js

# Ignored change
echo "<!-- -->" >> vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Ui/web/templates/ignore.html
echo "<!-- -->" >> vendor/ampersand/upgrade-patch-helper-test-module/src/module/view/frontend/email/ignore.html
echo "/* some comment */" >> vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/ignore.js

echo "#" >> vendor/magento/module-customer/view/frontend/web/js/model/authentication-popup.js

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Some copyright header.
* Goes here
*
*
* foobar
*/
define([
'abc123'
], function (resolver) {
'use strict';

/**
* Some function comment.
*
* @param {Object} config - Optional configuration
*/
function the_function_names_are_different(config) {
// this has been overridden and the function is different now
var foo = 1;
}

/**
* Some other function comment
*
* @param {Object} config - Optional configuration
*/
function init(config) {
resolver(the_function_names_are_different.bind(config));
}

return init;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Some copyright header.
* Goes here
*/
define([
'abc123'
], function (resolver) {
'use strict';

/**
* Some function comment.
*
* @param {Object} config - Optional configuration
*/
function foobar(config) {
var foo = 1;
}


/**
* what comments // do we have here
* /*
*
* oh what comments are here
* /
*/


/**
* Some other function comment
*
* @param {Object} config - Optional configuration
*/
function init(config) {
resolver(foobar.bind(config));
}
// more comments

return init;
});
29 changes: 29 additions & 0 deletions dev/TestVendorModule/src/theme/Magento_Checkout/web/js/ignore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Some copyright header.
* Goes here
*/
define([
'abc123'
], function (resolver) {
'use strict';

/**
* Some function comment.
*
* @param {Object} config - Optional configuration
*/
function this_is_the_base_function_name(config) {
var foo = 1;
}

/**
* Some other function comment
*
* @param {Object} config - Optional configuration
*/
function init(config) {
resolver(this_is_the_base_function_name.bind(config));
}

return init;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Some copyright header.
* Goes here
*/
define([
'abc123'
], function (resolver) {
'use strict';


// more comments
/*
like this
*/
/**
* Some function comment.
*
* @param {Object} config - Optional configuration
*/
function foobar(config) {
var foo = 1;
}

// more comments

/**
* Some other function comment
*
* @param {Object} config - Optional configuration
*/
function init(config) {
resolver(foobar.bind(config));
}

return init;
});
5 changes: 3 additions & 2 deletions dev/phpunit/functional/expected_output/magentom23.out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete |
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/module/view/frontend/email/redundant.html | app/design/frontend/Ampersand/theme/Ampersand_TestVendor/email/redundant.html |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/redundant.js | app/design/frontend/Ampersand/theme/Magento_Checkout/web/js/redundant.js |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Ui/web/templates/redundant.html | app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/redundant.html |
+-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
WARN count: 64
WARN count: 65
INFO count: 309 (to view re-run this tool with --show-info)
IGNORE count: 2 (to view re-run this tool with --show-ignore)
IGNORE count: 3 (to view re-run this tool with --show-ignore)
For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete |
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/module/view/frontend/email/redundant.html | app/design/frontend/Ampersand/theme/Ampersand_TestVendor/email/redundant.html |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/redundant.js | app/design/frontend/Ampersand/theme/Magento_Checkout/web/js/redundant.js |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Ui/web/templates/redundant.html | app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/redundant.html |
+-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
WARN count: 65
WARN count: 66
INFO count: 314 (to view re-run this tool with --show-info)
IGNORE count: 2 (to view re-run this tool with --show-ignore)
IGNORE count: 3 (to view re-run this tool with --show-ignore)
For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
| WARN | Override (phtml/js/html) | vendor/magento/module-sales/view/frontend/layout/sales_order_print.xml | app/design/frontend/Ampersand/theme/Magento_Sales/layout/sales_order_print.xml |
| WARN | Override (phtml/js/html) | vendor/magento/module-ui/view/base/web/templates/block-loader.html | app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/block-loader.html |
| WARN | Override (phtml/js/html) | vendor/magento/module-ui/view/base/web/templates/grid/masonry.html | app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/masonry.html |
| WARN | Override (phtml/js/html) | vendor/magento/module-vault/view/frontend/web/js/view/payment/method-renderer/vault.js | app/design/frontend/Ampersand/theme/Magento_Vault/web/js/view/payment/method-renderer/vault.js |
| WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-blank/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml |
| WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-blank/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml |
| WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/Magento_Sales/email/order_new.html | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Sales/email/order_new.html |
| WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml |
| WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml |
| WARN | Override (phtml/js/html) | vendor/paypal/module-braintree-core/view/base/web/js/form-builder.js | vendor/paypal/module-braintree-core/view/frontend/web/js/form-builder.js |
| WARN | Plugin | vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php | Ampersand\Test\Plugin\PhpCookieManager::beforeSetPublicCookie |
| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt |
| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt |
Expand All @@ -60,9 +58,11 @@
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete |
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/module/view/frontend/email/redundant.html | app/design/frontend/Ampersand/theme/Ampersand_TestVendor/email/redundant.html |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Checkout/web/js/redundant.js | app/design/frontend/Ampersand/theme/Magento_Checkout/web/js/redundant.js |
| WARN | Redundant Override | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/Magento_Ui/web/templates/redundant.html | app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/redundant.html |
| WARN | Redundant Override | vendor/paypal/module-braintree-core/view/base/web/js/form-builder.js | vendor/paypal/module-braintree-core/view/frontend/web/js/form-builder.js |
+-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
WARN count: 60
INFO count: 395 (to view re-run this tool with --show-info)
IGNORE count: 2 (to view re-run this tool with --show-ignore)
IGNORE count: 4 (to view re-run this tool with --show-ignore)
For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md
Loading

0 comments on commit 7c6bb63

Please sign in to comment.