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 9222bc7

Browse filesBrowse files
Fixed issue in line length sniff for phrase and __ keyword
1 parent fde7fc5 commit 9222bc7
Copy full SHA for 9222bc7

File tree

Expand file treeCollapse file tree

3 files changed

+23
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-3
lines changed

‎Magento2/Sniffs/Files/LineLengthSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Files/LineLengthSniff.php
+21-3Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ class LineLengthSniff extends FilesLineLengthSniff
2727
*/
2828
protected $lastLineRegExp = '~__\(.+\)|\bPhrase\(.+\)~';
2929

30+
/**
31+
* Regular expression for finding a __ keyword added in the translation string.
32+
*
33+
* @var string
34+
*/
35+
protected $underscoreKeywordRegExp = '~\'[^\']+\'(*SKIP)(*F)| __~';
36+
37+
/**
38+
* Regular expression for finding a Phrase keyword added in the translation string.
39+
*
40+
* @var string
41+
*/
42+
protected $phaseKeywordRegExp = '~\'[^\']+\'(*SKIP)(*F)| \bPhrase~';
43+
3044
/**
3145
* Having the next-to-last line content allows to ignore long lines in case of translations.
3246
*
@@ -77,10 +91,14 @@ protected function checkLineLength($phpcsFile, $tokens, $stackPtr)
7791
*/
7892
protected function doesPreviousLineContainTranslationString()
7993
{
80-
$lastLineMatch = preg_match($this->lastLineRegExp, $this->lastLineContent) !== 0;
81-
$nextToLastLineMatch = preg_match($this->nextToLastLineRegexp, $this->nextToLastLineContent) !== 0;
94+
if (preg_match($this->phaseKeywordRegExp, $this->lastLineContent) == 0
95+
|| preg_match($this->underscoreKeywordRegExp, $this->lastLineContent) == 0
96+
) {
97+
$lastLineMatch = preg_match($this->lastLineRegExp, $this->lastLineContent) !== 0;
98+
$nextToLastLineMatch = preg_match($this->nextToLastLineRegexp, $this->nextToLastLineContent) !== 0;
99+
return $lastLineMatch || $nextToLastLineMatch;
100+
}
82101

83-
return $lastLineMatch || $nextToLastLineMatch;
84102
}
85103

86104
/**

‎Magento2/Tests/Files/LineLengthUnitTest.inc

Copy file name to clipboardExpand all lines: Magento2/Tests/Files/LineLengthUnitTest.inc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ $phraseObjects = [
2929
$test = '012344567890123445678901234456789012344567890123445678901234456789';
3030
$test1 = '01234456789012344567890123445678901234456789012344567890123445678901234456789';
3131
$test2 = '012344567890123445678901234456789012344567890123445678901234456789012344567890123445678901234456789';
32+
$test3 = "If a string exceeds 120 characters and a part of the string is Phrase('xy'), this would not be caught by the regular expression because it matches any line containing Phrase('xy') or __('xy').";

‎Magento2/Tests/Files/LineLengthUnitTest.php

Copy file name to clipboardExpand all lines: Magento2/Tests/Files/LineLengthUnitTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function getErrorList()
2020
return [
2121
9 => 1,
2222
19 => 1,
23+
32 => 1,
2324
];
2425
}
2526

0 commit comments

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