Skip to content

Commit 17f55d9

Browse files
authored
Merge pull request #76 from magento-commerce/imported-magento-magento-coding-standard-287
[Imported] Version 11 master update
2 parents 6e5f03a + e59094a commit 17f55d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4159
-5
lines changed

.github/workflows/php.yml

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies
2626

2727
steps:
28+
- name: Setup node
29+
uses: actions/setup-node@v2
30+
with:
31+
node-version: '16'
32+
2833
- uses: actions/checkout@v2
2934

3035
- name: Setup PHP
@@ -34,6 +39,11 @@ jobs:
3439
env:
3540
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3641

42+
- name: Install dependencies
43+
run: npm install
44+
- name: Run ESLint
45+
run: npm run eslint -- eslint/rules
46+
3747
- name: Validate composer
3848
run: composer validate
3949

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/vendor/*
22
/bin/*
3+
/node_modules
34

45
# IDE files
56
.idea/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento2\Sniffs\Html;
10+
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
use PHP_CodeSniffer\Files\File;
13+
14+
/**
15+
* Sniff for self-closing tags
16+
*/
17+
class HtmlSelfClosingTagsSniff implements Sniff
18+
{
19+
/**
20+
* List of void elements
21+
*
22+
* https://www.w3.org/TR/html51/syntax.html#writing-html-documents-elements
23+
*
24+
* @var string[]
25+
*/
26+
private $voidElements = [
27+
'area',
28+
'base',
29+
'br',
30+
'col',
31+
'embed',
32+
'hr',
33+
'img',
34+
'input',
35+
'keygen',
36+
'link',
37+
'menuitem',
38+
'meta',
39+
'param',
40+
'source',
41+
'track',
42+
'wbr',
43+
];
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
public function register()
49+
{
50+
return [T_INLINE_HTML];
51+
}
52+
53+
/**
54+
* Detect use of self-closing tag with non-void html element
55+
*
56+
* @param File $phpcsFile
57+
* @param int $stackPtr
58+
* @return int|void
59+
*/
60+
public function process(File $phpcsFile, $stackPtr)
61+
{
62+
if ($stackPtr !== 0) {
63+
return;
64+
}
65+
$html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
66+
67+
if (empty($html)) {
68+
return;
69+
}
70+
71+
if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) {
72+
foreach ($matches as $match) {
73+
if (!in_array($match[1], $this->voidElements)) {
74+
$phpcsFile->addError(
75+
'Avoid using self-closing tag with non-void html element'
76+
. ' - "' . $match[0] . PHP_EOL,
77+
null,
78+
'HtmlSelfClosingNonVoidTag'
79+
);
80+
}
81+
}
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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\Legacy;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
use SplFileInfo;
13+
14+
class InstallUpgradeSniff implements Sniff
15+
{
16+
private const ERROR_CODE = 'obsoleteScript';
17+
18+
/**
19+
* @var string[]
20+
*/
21+
private $wrongPrefixes = [
22+
'install-' => 'Install scripts are obsolete. '
23+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
24+
'InstallSchema' => 'InstallSchema scripts are obsolete. '
25+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
26+
'InstallData' => 'InstallData scripts are obsolete. '
27+
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
28+
'data-install-' => 'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder',
29+
'upgrade-' => 'Upgrade scripts are obsolete. '
30+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
31+
'UpgradeSchema' => 'UpgradeSchema scripts are obsolete. '
32+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
33+
'UpgradeData' => 'UpgradeSchema scripts are obsolete. '
34+
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
35+
'data-upgrade-' => 'Upgrade scripts are obsolete. '
36+
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
37+
'recurring' => 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder',
38+
];
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
public function register(): array
44+
{
45+
return [
46+
T_OPEN_TAG
47+
];
48+
}
49+
50+
/**
51+
* @inheritDoc
52+
*/
53+
public function process(File $phpcsFile, $stackPtr)
54+
{
55+
if ($stackPtr > 0) {
56+
return;
57+
}
58+
59+
$fileInfo = new SplFileInfo($phpcsFile->getFilename());
60+
61+
foreach ($this->wrongPrefixes as $prefix => $errorMessage) {
62+
if (strpos($fileInfo->getFilename(), $prefix) === 0) {
63+
$phpcsFile->addError($errorMessage, 0, self::ERROR_CODE);
64+
}
65+
}
66+
67+
if (preg_match('/(sql|data)/', $fileInfo->getPath()) === 1) {
68+
$phpcsFile->addError(
69+
$fileInfo->getFilename()." is in an invalid directory ".$fileInfo->getPath().":\n"
70+
. "- Create a data patch within module's Setup/Patch/Data folder for data upgrades.\n"
71+
. "- Use declarative schema approach in module's etc/db_schema.xml file for schema changes.",
72+
0,
73+
self::ERROR_CODE
74+
);
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)