-
Notifications
You must be signed in to change notification settings - Fork 160
AC-672: Create phpcs static check for LicenseTest #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-devops-reposync-svc
merged 8 commits into
magento:develop
from
eliseacornejo:AC-672
Oct 14, 2021
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7fdd6b4
AC-672: Create phpcs static check for LicenseTest
eliseacornejo 001076c
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo e3cdba0
AC-672: Create phpcs static check for LicenseTest
eliseacornejo c22fd18
AC-672: Create phpcs static check for LicenseTest
eliseacornejo 0d1ae00
AC-672: Create phpcs static check for LicenseTest
eliseacornejo d5c7119
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo 6691ae8
AC-672: Create phpcs static check for LicenseTest
eliseacornejo ef49c1b
AC-672: Create phpcs static check for LicenseTest
eliseacornejo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento2\Sniffs\Legacy; | ||
|
||
use Magento2\Sniffs\Less\TokenizerSymbolsInterface; | ||
use PHP_CodeSniffer\Files\File; | ||
use PHP_CodeSniffer\Sniffs\Sniff; | ||
|
||
class LicenseSniff implements Sniff | ||
{ | ||
/** | ||
* A list of tokenizers this sniff supports. | ||
* | ||
* @var array | ||
*/ | ||
public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP']; | ||
|
||
private const WARNING_CODE = 'FoundLegacyTextInCopyright'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function register() | ||
{ | ||
return [ | ||
T_DOC_COMMENT_STRING, | ||
T_INLINE_HTML | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function process(File $phpcsFile, $stackPtr) | ||
{ | ||
$tokens = $phpcsFile->getTokens(); | ||
$content = null; | ||
|
||
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_STRING) { | ||
$content = $tokens[$stackPtr]['content']; | ||
} | ||
if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) { | ||
$content = $phpcsFile->getTokensAsString($stackPtr, 1); | ||
} | ||
if ($content != null) { | ||
$this->checkLicense($content, $stackPtr, $phpcsFile); | ||
} | ||
} | ||
|
||
/** | ||
* Check that the copyright license does not contain legacy text | ||
* | ||
* @param string $content | ||
* @param int $stackPtr | ||
* @param File $phpcsFile | ||
*/ | ||
private function checkLicense(string $content, int $stackPtr, File $phpcsFile): void | ||
{ | ||
$commentContent = $content; | ||
if (stripos($commentContent, 'copyright') === false) { | ||
return; | ||
} | ||
foreach (['Irubin Consulting Inc', 'DBA Varien', 'Magento Inc'] as $legacyText) { | ||
if (stripos($commentContent, $legacyText) !== false) { | ||
$phpcsFile->addWarning( | ||
sprintf("The copyright license contains legacy text: %s.", $legacyText), | ||
$stackPtr, | ||
self::WARNING_CODE | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright My testing text | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<tag> | ||
|
||
</tag> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* @copyright DBA Varien | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<tag> | ||
|
||
</tag> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* @copyright Copyright Irubin Consulting Inc | ||
* See COPYING.txt for license details. | ||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento2\Tests\Legacy; | ||
|
||
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; | ||
|
||
class LicenseUnitTest extends AbstractSniffUnitTest | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getErrorList(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getWarningList($testFile = ''): array | ||
{ | ||
if ($testFile === 'LicenseUnitTest.1.inc' || $testFile === 'LicenseUnitTest.3.xml') { | ||
return []; | ||
} | ||
|
||
if ($testFile === 'LicenseUnitTest.2.inc') { | ||
return [ | ||
3 => 1, | ||
]; | ||
} | ||
|
||
if ($testFile === 'LicenseUnitTest.4.xml') { | ||
return [ | ||
4 => 1, | ||
]; | ||
} | ||
|
||
if ($testFile === 'LicenseUnitTest.5.less') { | ||
return [ | ||
2 => 1, | ||
]; | ||
} | ||
|
||
return []; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,10 @@ | |
<type>warning</type> | ||
<exclude-pattern>*\.xml$</exclude-pattern> | ||
</rule> | ||
<rule ref="Magento2.Legacy.License"> | ||
<severity>9</severity> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move it to Magento specific (warning 8) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
<type>warning</type> | ||
</rule> | ||
|
||
<!-- Severity 8 warnings: Magento specific code issues and design violations. --> | ||
<rule ref="Magento2.Classes.AbstractApi"> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move the array to a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!