Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
IreneStr committed Feb 6, 2020
2 parents 2f445be + c586fef commit 42e4150
Show file tree
Hide file tree
Showing 24 changed files with 262 additions and 217 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/phpcs.xml.dist export-ignore
/phpunit.xml export-ignore
/phpunit.xml.dist export-ignore
/.github export-ignore
/Yoast/Tests export-ignore

#
Expand All @@ -27,3 +28,4 @@
#
*.md text
*.php text
*.inc text
28 changes: 28 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

<description>The Coding standard for the YoastCS Coding Standard itself.</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

<!-- Scan all files. -->
<file>.</file>

Expand All @@ -14,6 +21,19 @@
<!-- Show progress, show the error codes for each message (source). -->
<arg value="sp"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>


<!--
#############################################################################
USE THE YoastCS RULESET
#############################################################################
-->

<!-- YoastCS supports PHP 5.4 or higher. -->
<config name="testVersion" value="5.4-"/>

Expand All @@ -32,11 +52,19 @@
<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration"/>


<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->

<rule ref="Yoast.NamingConventions.NamespaceName">
<properties>
<property name="prefixes" type="array">
<element value="YoastCS\Yoast"/>
</property>
<property name="src_directory" value="Yoast"/>
</properties>
</rule>

Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ php:
- 7.1
- 7.2
- 7.3
- "7.4snapshot"
- 7.4

env:
# Test against the highest/lowest supported PHPCS and WPCS versions.
Expand Down Expand Up @@ -67,9 +67,9 @@ matrix:
# This is a much quicker test which only runs the unit tests and linting against low/high
# supported PHP/PHPCS/WPCS combinations.
- stage: quicktest
php: 7.3
php: 7.4
env: PHPCS_BRANCH="dev-master" WPCS="dev-develop" PHPLINT=1
- php: 7.3
- php: 7.4
env: PHPCS_BRANCH="3.5.0" WPCS="2.2.0"
- php: 5.4
env: PHPCS_BRANCH="dev-master" WPCS="2.2.0" PHPLINT=1
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).

### [2.0.1] - 2020-02-06

#### Changed
* Composer: Supported version of the [DealerDirect Composer PHPCS plugin] has been changed from `^0.5.0` to `^0.5 || ^0.6`.
Note: this requirement is flexible to prevent conflicts with included standards which may include the plugin as well.
* Various housekeeping.

#### Fixed
* `Yoast.NamingConventions.NamespaceName`: fixed a potential "undefined index" notice.


### [2.0.0] - 2019-12-17

#### Added
Expand Down Expand Up @@ -358,6 +369,7 @@ Initial public release as a stand-alone package.
[DealerDirect Composer PHPCS plugin]: https://github.com/Dealerdirect/phpcodesniffer-composer-installer/releases
[Parallel-Lint]: https://packagist.org/packages/jakub-onderka/php-parallel-lint

[2.0.1]: https://github.com/Yoast/yoastcs/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/Yoast/yoastcs/compare/1.3.0...2.0.0
[1.3.0]: https://github.com/Yoast/yoastcs/compare/1.2.2...1.3.0
[1.2.2]: https://github.com/Yoast/yoastcs/compare/1.2.1...1.2.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Composer will automatically install dependencies, register standards paths, and
To include standards as part of a project require them as development dependencies:

```bash
composer require --dev yoast/yoastcs:^1.0
composer require --dev yoast/yoastcs:^2.0
```

Composer will automatically install dependencies and register the YoastCS and other external standards with PHP_CodeSniffer.
Expand Down
14 changes: 7 additions & 7 deletions Yoast/Sniffs/Commenting/CodeCoverageIgnoreDeprecatedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class CodeCoverageIgnoreDeprecatedSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return (int|string)[]
*/
public function register() {
return [
T_FUNCTION,
\T_FUNCTION,
];
}

Expand All @@ -41,14 +41,14 @@ public function process( File $phpcsFile, $stackPtr ) {

$tokens = $phpcsFile->getTokens();
$find = Tokens::$methodPrefixes;
$find[] = T_WHITESPACE;
$find[] = \T_WHITESPACE;

$commentEnd = $stackPtr;
do {
$commentEnd = $phpcsFile->findPrevious( $find, ( $commentEnd - 1 ), null, true );
} while ( $tokens[ $commentEnd ]['line'] === $tokens[ $stackPtr ]['line'] );

if ( $tokens[ $commentEnd ]['code'] !== T_DOC_COMMENT_CLOSE_TAG
if ( $tokens[ $commentEnd ]['code'] !== \T_DOC_COMMENT_CLOSE_TAG
|| $tokens[ $commentEnd ]['line'] !== ( $tokens[ $stackPtr ]['line'] - 1 )
) {
// Function without (proper) docblock. Not our concern.
Expand Down Expand Up @@ -83,10 +83,10 @@ public function process( File $phpcsFile, $stackPtr ) {
return;
}

$hasTagAsString = $phpcsFile->findNext( T_DOC_COMMENT_STRING, ( $commentStart + 1 ), $commentEnd, false, 'codeCoverageIgnore' );
$hasTagAsString = $phpcsFile->findNext( \T_DOC_COMMENT_STRING, ( $commentStart + 1 ), $commentEnd, false, 'codeCoverageIgnore' );
if ( $hasTagAsString !== false ) {
$prev = $phpcsFile->findPrevious( T_DOC_COMMENT_WHITESPACE, ( $hasTagAsString - 1 ), $commentStart, true );
if ( $prev !== false && $tokens[ $prev ]['code'] === T_DOC_COMMENT_STAR ) {
$prev = $phpcsFile->findPrevious( \T_DOC_COMMENT_WHITESPACE, ( $hasTagAsString - 1 ), $commentStart, true );
if ( $prev !== false && $tokens[ $prev ]['code'] === \T_DOC_COMMENT_STAR ) {
$fix = $phpcsFile->addFixableError(
'The `codeCoverageIgnore` annotation in the function docblock needs to be prefixed with an `@`.',
$hasTagAsString,
Expand Down
52 changes: 25 additions & 27 deletions Yoast/Sniffs/Commenting/CoversTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class CoversTagSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return (int|string)[]
*/
public function register() {
return [
T_DOC_COMMENT_OPEN_TAG,
\T_DOC_COMMENT_OPEN_TAG,
];
}

Expand Down Expand Up @@ -80,8 +80,8 @@ public function process( File $phpcsFile, $stackPtr ) {
}

// Found a @covers tag.
$next = $phpcsFile->findNext( T_DOC_COMMENT_WHITESPACE, ( $tag + 1 ), null, true );
if ( $tokens[ $next ]['code'] !== T_DOC_COMMENT_STRING
$next = $phpcsFile->findNext( \T_DOC_COMMENT_WHITESPACE, ( $tag + 1 ), null, true );
if ( $tokens[ $next ]['code'] !== \T_DOC_COMMENT_STRING
|| $tokens[ $next ]['line'] !== $tokens[ $tag ]['line']
) {
$phpcsFile->addError(
Expand All @@ -96,7 +96,7 @@ public function process( File $phpcsFile, $stackPtr ) {
$annotation = $tokens[ $next ]['content'];
$coversTags[ "$tag-$next" ] = $annotation;

if ( preg_match( '`^' . self::VALID_CONTENT_REGEX . '$`', $annotation ) === 1 ) {
if ( \preg_match( '`^' . self::VALID_CONTENT_REGEX . '$`', $annotation ) === 1 ) {
continue;
}

Expand All @@ -107,15 +107,15 @@ public function process( File $phpcsFile, $stackPtr ) {
$errorThrown = false;

// Check for Union/Intersect types.
if ( strpos( $annotation, '&' ) !== false ) {
if ( \strpos( $annotation, '&' ) !== false ) {
if ( $this->fixAnnotationToSplit( $phpcsFile, $next, 'IntersectFound', '&' ) === true ) {
continue;
}

$errorThrown = true;
}

if ( strpos( $annotation, '|' ) !== false ) {
if ( \strpos( $annotation, '|' ) !== false ) {
if ( $this->fixAnnotationToSplit( $phpcsFile, $next, 'UnionFound', '|' ) === true ) {
continue;
}
Expand All @@ -124,16 +124,15 @@ public function process( File $phpcsFile, $stackPtr ) {
}

// Parentheses/Braces at the end of the annotation.
$expected = rtrim( $annotation, '(){} ' );
$expected = \rtrim( $annotation, '(){} ' );
if ( $this->fixSimpleError( $phpcsFile, $next, $expected, 'InvalidBraces' ) === true ) {
$errorThrown = true;

}

// Incorrect `<public|protected|private>` annotation.
if ( preg_match( '`::[{(\[]?(!)?(public|protected|private)[})\]]?`', $annotation, $matches ) === 1 ) {
if ( \preg_match( '`::[{(\[]?(!)?(public|protected|private)[})\]]?`', $annotation, $matches ) === 1 ) {
$replacement = '::<' . $matches[1] . $matches[2] . '>';
$expected = str_replace( $matches[0], $replacement, $annotation );
$expected = \str_replace( $matches[0], $replacement, $annotation );

if ( $this->fixSimpleError( $phpcsFile, $next, $expected, 'InvalidFunctionGroup' ) === true ) {
$errorThrown = true;
Expand All @@ -152,7 +151,7 @@ public function process( File $phpcsFile, $stackPtr ) {
$phpcsFile->addError( $error, $next, 'Invalid', $data );
}

$coversNothingCount = count( $coversNothingTags );
$coversNothingCount = \count( $coversNothingTags );
if ( $firstCoversTag !== false && $coversNothingCount > 0 ) {
$error = 'A test can\'t both cover something as well as cover nothing. First @coversNothing tag encountered on line %d; first @covers tag encountered on line %d';
$data = [
Expand All @@ -166,19 +165,18 @@ public function process( File $phpcsFile, $stackPtr ) {
if ( $coversNothingCount > 1 ) {
$error = 'Only one @coversNothing tag allowed per test';
$code = 'DuplicateCoversNothing';
$fixable = true;
$removeTags = [];
foreach ( $coversNothingTags as $position => $ptr ) {
foreach ( $coversNothingTags as $ptr ) {
$next = ( $ptr + 1 );
if ( $tokens[ $next ]['code'] === T_DOC_COMMENT_WHITESPACE
if ( $tokens[ $next ]['code'] === \T_DOC_COMMENT_WHITESPACE
&& $tokens[ $next ]['content'] === $phpcsFile->eolChar
) {
// No comment, ok to remove.
$removeTags[] = $ptr;
}
}

$removalCount = count( $removeTags );
$removalCount = \count( $removeTags );
if ( ( $coversNothingCount - $removalCount ) > 1 ) {
// More than one tag had a comment.
$phpcsFile->addError( $error, $tokens[ $stackPtr ]['comment_closer'], $code );
Expand Down Expand Up @@ -212,11 +210,11 @@ public function process( File $phpcsFile, $stackPtr ) {
}
}

$coversCount = count( $coversTags );
$coversCount = \count( $coversTags );
if ( $coversCount > 1 ) {
$unique = array_unique( $coversTags );
if ( count( $unique ) !== $coversCount ) {
$value_count = array_count_values( $coversTags );
$unique = \array_unique( $coversTags );
if ( \count( $unique ) !== $coversCount ) {
$value_count = \array_count_values( $coversTags );
$error = 'Duplicate @covers tag found. First tag with the same annotation encountered on line %d';
$code = 'DuplicateCovers';
foreach ( $value_count as $annotation => $count ) {
Expand All @@ -231,12 +229,12 @@ public function process( File $phpcsFile, $stackPtr ) {
}

if ( ! isset( $first ) ) {
$first = explode( '-', $ptrs );
$first = \explode( '-', $ptrs );
$data = [ $tokens[ $first[0] ]['line'] ];
continue;
}

$ptrs = explode( '-', $ptrs );
$ptrs = \explode( '-', $ptrs );

$fix = $phpcsFile->addFixableError( $error, $ptrs[0], $code, $data );
if ( $fix === true ) {
Expand All @@ -246,7 +244,7 @@ public function process( File $phpcsFile, $stackPtr ) {
// Remove the whole line.
for ( $i = ( $ptrs[1] ); $i >= 0; $i-- ) {
if ( $tokens[ $i ]['line'] !== $tokens[ $ptrs[1] ]['line'] ) {
if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_WHITESPACE
if ( $tokens[ $i ]['code'] === \T_DOC_COMMENT_WHITESPACE
&& $tokens[ $i ]['content'] === $phpcsFile->eolChar
) {
$phpcsFile->fixer->replaceToken( $i, '' );
Expand Down Expand Up @@ -282,7 +280,7 @@ protected function fixSimpleError( File $phpcsFile, $stackPtr, $expected, $error
$annotation = $tokens[ $stackPtr ]['content'];

if ( $expected === $annotation
|| preg_match( '`^' . self::VALID_CONTENT_REGEX . '$`', $expected ) !== 1
|| \preg_match( '`^' . self::VALID_CONTENT_REGEX . '$`', $expected ) !== 1
) {
return false;
}
Expand Down Expand Up @@ -323,9 +321,9 @@ protected function fixAnnotationToSplit( File $phpcsFile, $stackPtr, $errorCode,
if ( $fix === true ) {
$tokens = $phpcsFile->getTokens();
$annotation = $tokens[ $stackPtr ]['content'];
$annotations = explode( $separator, $annotation );
$annotations = array_map( 'trim', $annotations );
$annotations = array_filter( $annotations ); // Remove empties.
$annotations = \explode( $separator, $annotation );
$annotations = \array_map( 'trim', $annotations );
$annotations = \array_filter( $annotations ); // Remove empties.

$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken( $stackPtr, '' );
Expand Down
12 changes: 6 additions & 6 deletions Yoast/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FileCommentSniff extends Squiz_FileCommentSniff {
*/
public function process( File $phpcsFile, $stackPtr ) {

$namespace_token = $phpcsFile->findNext( T_NAMESPACE, $stackPtr );
$namespace_token = $phpcsFile->findNext( \T_NAMESPACE, $stackPtr );
if ( $namespace_token === false ) {
// No namespace found, fall through to parent sniff.
return parent::process( $phpcsFile, $stackPtr );
Expand All @@ -50,18 +50,18 @@ public function process( File $phpcsFile, $stackPtr ) {

$next_non_empty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $namespace_token + 1 ), null, true );
if ( $next_non_empty === false
|| $tokens[ $next_non_empty ]['code'] === T_SEMICOLON
|| $tokens[ $next_non_empty ]['code'] === T_OPEN_CURLY_BRACKET
|| $tokens[ $next_non_empty ]['code'] === T_NS_SEPARATOR
|| $tokens[ $next_non_empty ]['code'] === \T_SEMICOLON
|| $tokens[ $next_non_empty ]['code'] === \T_OPEN_CURLY_BRACKET
|| $tokens[ $next_non_empty ]['code'] === \T_NS_SEPARATOR
) {
// Either live coding, global namespace (i.e. not really namespaced) or namespace operator.
// Fall through to parent sniff.
return parent::process( $phpcsFile, $stackPtr );
}

$comment_start = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), $namespace_token, true );
$comment_start = $phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), $namespace_token, true );

if ( $tokens[ $comment_start ]['code'] === T_DOC_COMMENT_OPEN_TAG ) {
if ( $tokens[ $comment_start ]['code'] === \T_DOC_COMMENT_OPEN_TAG ) {
$phpcsFile->addWarning(
'A file containing a (named) namespace declaration does not need a file docblock',
$comment_start,
Expand Down
Loading

0 comments on commit 42e4150

Please sign in to comment.