Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca25070

Browse filesBrowse files
authored
Merge pull request #116 from magento-commerce/develop
Develop to Master Version 15
2 parents daf56b8 + 6bba04d commit ca25070
Copy full SHA for ca25070
Expand file treeCollapse file tree

20 files changed

+866
-5798
lines changed

‎.github/workflows/php.yml

Copy file name to clipboardExpand all lines: .github/workflows/php.yml
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,3 @@ jobs:
7575

7676
- name: Run ESLint
7777
run: npm run eslint -- eslint/rules
78-
79-
- name: Run JSCS
80-
run: npm run jscs eslint/rules Magento2
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Sniffs\PHP;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
/**
14+
* Sniff to validate array autovivification.
15+
*/
16+
class ArrayAutovivificationSniff implements Sniff
17+
{
18+
/**
19+
* String representation of error.
20+
*
21+
* @var string
22+
*/
23+
private $warningMessage = 'Deprecated: Automatic conversion of false to array is deprecated.';
24+
25+
/**
26+
* Warning violation code.
27+
*
28+
* @var string
29+
*/
30+
private $warningCode = 'Autovivification';
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function register(): array
36+
{
37+
return [
38+
T_VARIABLE
39+
];
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function process(File $phpcsFile, $stackPtr): void
46+
{
47+
$positionSquareBracket = $phpcsFile->findNext(T_OPEN_SQUARE_BRACKET, $stackPtr, $stackPtr + 2);
48+
49+
if ($positionSquareBracket) {
50+
$tokens = $phpcsFile->getTokens();
51+
$positionFunction = $phpcsFile->findPrevious(T_FUNCTION, $positionSquareBracket) ?: 0;
52+
$sliceLength = $stackPtr - $positionFunction;
53+
$sliceToken = array_slice(array_column($tokens, 'content'), $positionFunction, $sliceLength, true);
54+
$propertyTokenKey = array_keys($sliceToken, $tokens[$stackPtr]['content']);
55+
56+
arsort($propertyTokenKey);
57+
58+
foreach ($propertyTokenKey as $tokenKey) {
59+
if ($tokens[$tokenKey + 2]['content'] === '=') {
60+
if ($tokens[$tokenKey + 4]['content'] != 'false') {
61+
return;
62+
}
63+
64+
$phpcsFile->addWarning($this->warningMessage, $positionSquareBracket, $this->warningCode);
65+
}
66+
}
67+
}
68+
}
69+
}
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\PHP;
9+
10+
/**
11+
* Class to test array avtovivification.
12+
*/
13+
class Avtovivification
14+
{
15+
/**
16+
* @return array
17+
*/
18+
public function testNullAvtovivification()
19+
{
20+
$productIds = null;
21+
22+
$productIds[] = 'test_array_value';
23+
24+
return $productIds;
25+
}
26+
27+
/**
28+
* @return array
29+
*/
30+
public function testArrayAvtovivification()
31+
{
32+
$productIds = [];
33+
34+
$productIds[] = 'test_array_value';
35+
36+
return $productIds;
37+
}
38+
39+
/**
40+
* @return array
41+
*/
42+
public function testFalseAvtovivification()
43+
{
44+
$productIds = false;
45+
46+
$productIds[] = 'test_array_value';
47+
48+
return $productIds;
49+
}
50+
51+
/**
52+
* @return array
53+
*/
54+
public function testUndefineAvtovivification()
55+
{
56+
$productIds[] = 'test_array_value';
57+
58+
return $productIds;
59+
}
60+
}
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\PHP;
9+
10+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
11+
12+
class ArrayAutovivificationUnitTest extends AbstractSniffUnitTest
13+
{
14+
/**
15+
* @inheritdoc
16+
*/
17+
public function getErrorList(): array
18+
{
19+
return [];
20+
}
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
public function getWarningList($testFile = ''): array
26+
{
27+
if ($testFile === 'ArrayAutovivificationUnitTest.inc') {
28+
return [
29+
46 => 1
30+
];
31+
}
32+
33+
return [];
34+
}
35+
}

‎Magento2/ruleset.xml

Copy file name to clipboardExpand all lines: Magento2/ruleset.xml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@
400400
<type>warning</type>
401401
<exclude-pattern>*\.xml$</exclude-pattern>
402402
</rule>
403+
<rule ref="Magento2.PHP.ArrayAutovivification">
404+
<severity>7</severity>
405+
<type>warning</type>
406+
<exclude-pattern>*\.xml$</exclude-pattern>
407+
</rule>
403408
<rule ref="Magento2.Performance.ForeachArrayMerge">
404409
<severity>7</severity>
405410
<type>warning</type>
@@ -497,6 +502,7 @@
497502
</properties>
498503
<severity>6</severity>
499504
<type>warning</type>
505+
<exclude-pattern>*\.js$</exclude-pattern>
500506
</rule>
501507
<rule ref="Magento2.GraphQL.ValidArgumentName">
502508
<severity>6</severity>
@@ -572,6 +578,7 @@
572578
<rule ref="PSR2.Methods.FunctionCallSignature">
573579
<severity>6</severity>
574580
<type>warning</type>
581+
<exclude-pattern>*\.js$</exclude-pattern>
575582
</rule>
576583
<rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket">
577584
<severity>0</severity>

‎README.md

Copy file name to clipboardExpand all lines: README.md
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,19 @@ Also, verify that the sniffer code itself is written according to the Magento Co
9999
vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php
100100
```
101101

102-
### ESLint and JSCS
102+
### ESLint
103103
Prerequisites: [Node.js](https://nodejs.org/) (`^12.22.0`, `^14.17.0`, or `>=16.0.0`).
104104

105105
You need to run the following command to install all the necessary packages described in the `package.json` file:
106106
```bash
107107
npm install
108108
```
109109

110-
You can just execute ESLint as follows:
110+
You can execute ESLint as follows:
111111
```bash
112112
npm run eslint -- path/to/analyze
113113
```
114114

115-
Run the following command to execute JSCS:
116-
```bash
117-
npm run jscs path/to/analyze
118-
```
119115
## License
120116

121117
Each Magento source file included in this distribution is licensed under the OSL-3.0 license.

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"AFL-3.0"
77
],
88
"type": "phpcodesniffer-standard",
9-
"version": "14",
9+
"version": "15",
1010
"require": {
1111
"php": ">=7.3",
1212
"squizlabs/php_codesniffer": "^3.6",

‎composer.lock

Copy file name to clipboardExpand all lines: composer.lock
+7-7Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎eslint/.eslintrc

Copy file name to clipboardExpand all lines: eslint/.eslintrc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"./.eslintrc-reset",
44
"./.eslintrc-magento",
55
"./.eslintrc-jquery",
6-
"./.eslintrc-misc"
6+
"./.eslintrc-misc",
7+
"./.eslintrc-jscs"
78
]
89
}

‎eslint/.eslintrc-jscs

Copy file name to clipboard
+64Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"rules": {
3+
"no-with": 2,
4+
"space-before-function-paren": [
5+
2,
6+
{
7+
"anonymous": "always",
8+
"named": "never",
9+
"asyncArrow": "always"
10+
}
11+
],
12+
"curly": [
13+
2,
14+
"all"
15+
],
16+
"keyword-spacing": [
17+
2,
18+
{}
19+
],
20+
"no-empty": [
21+
2,
22+
{
23+
"allowEmptyCatch": true
24+
}
25+
],
26+
"no-mixed-spaces-and-tabs": 2,
27+
"no-multiple-empty-lines": 2,
28+
"no-multi-str": 2,
29+
"space-unary-ops": [
30+
2,
31+
{
32+
"words": false,
33+
"nonwords": false
34+
}
35+
],
36+
"space-in-parens": [
37+
2,
38+
"never"
39+
],
40+
"comma-dangle": [
41+
2,
42+
"never"
43+
],
44+
"no-trailing-spaces": 2,
45+
"comma-style": [
46+
2,
47+
"last"
48+
],
49+
"eol-last": 2,
50+
"one-var": [
51+
2,
52+
"always"
53+
],
54+
"space-infix-ops": 2,
55+
"space-before-blocks": [
56+
2,
57+
"always"
58+
],
59+
"quotes": [
60+
2,
61+
"single"
62+
]
63+
}
64+
}

‎eslint/rules/jquery-no-andSelf.js

Copy file name to clipboardExpand all lines: eslint/rules/jquery-no-andSelf.js
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ module.exports = {
3131
* @param {Object} node - The node to check.
3232
*/
3333
CallExpression: function (node) {
34-
// jscs:disable requireCurlyBraces
35-
if (node.callee.type !== 'MemberExpression') return;
34+
if (node.callee.type !== 'MemberExpression') {return;}
3635

37-
if (node.callee.property.name !== 'andSelf') return;
38-
// jscs:enable requireCurlyBraces
36+
if (node.callee.property.name !== 'andSelf') {return;}
3937

4038
if (utils.isjQuery(node)) {
4139
context.report({

‎eslint/rules/jquery-no-bind-unbind.js

Copy file name to clipboardExpand all lines: eslint/rules/jquery-no-bind-unbind.js
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ module.exports = {
3131
* @param {Object} node - The node to check.
3232
*/
3333
CallExpression: function (node) {
34-
// jscs:disable requireCurlyBraces
35-
if (node.callee.type !== 'MemberExpression') return;
34+
if (node.callee.type !== 'MemberExpression') {return;}
3635

37-
if (!['bind', 'unbind'].includes(node.callee.property.name)) return;
38-
// jscs:enable requireCurlyBraces
36+
if (!['bind', 'unbind'].includes(node.callee.property.name)) {return;}
3937

4038
if (utils.isjQuery(node)) {
4139
context.report({

‎eslint/rules/jquery-no-click-event-shorthand.js

Copy file name to clipboardExpand all lines: eslint/rules/jquery-no-click-event-shorthand.js
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ module.exports = {
3434
'mouseup', 'mousemove','mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'change', 'select',
3535
'submit', 'keydown', 'keypress', 'keyup', 'contextmenu', 'click'];
3636

37-
// jscs:disable requireCurlyBraces
38-
if (node.callee.type !== 'MemberExpression') return;
37+
if (node.callee.type !== 'MemberExpression') {return;}
3938

40-
if (!names.includes(node.callee.property.name)) return;
41-
// jscs:enable requireCurlyBraces
39+
if (!names.includes(node.callee.property.name)) {return;}
4240

4341
if (utils.isjQuery(node)) {
4442
name = node.callee.property.name;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.