diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index a78ff3260c9..df222c17d73 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,7 +1,7 @@ --- name: Bug report 🐛 about: Existing feature does not behave as expected. -label: kind/bug +labels: kind/bug --- ## Bug report diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index d12a4be768d..cf0df9253c4 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,7 +1,7 @@ --- name: Feature request 🚀 about: I have a suggestion about a new feature (and may want to implement it)! -label: kind/feature request +labels: kind/feature request --- ## Feature request diff --git a/.github/ISSUE_TEMPLATE/rule_request.md b/.github/ISSUE_TEMPLATE/rule_request.md index 2f43fafe48d..26e2a078909 100644 --- a/.github/ISSUE_TEMPLATE/rule_request.md +++ b/.github/ISSUE_TEMPLATE/rule_request.md @@ -1,7 +1,7 @@ --- name: Rule request ✍️ about: I have a suggestion about a new rule (and may want to implement it)! -label: kind/feature request +labels: kind/feature request --- ## Rule request diff --git a/.github/ISSUE_TEMPLATE/support_question.md b/.github/ISSUE_TEMPLATE/support_question.md index 3ca94bfa033..debc85118f3 100644 --- a/.github/ISSUE_TEMPLATE/support_question.md +++ b/.github/ISSUE_TEMPLATE/support_question.md @@ -1,7 +1,7 @@ --- name: Support question ❓ about: You have a question about how the tool works or how to use it. -label: kind/question +labels: kind/question --- ## Support question diff --git a/README.rst b/README.rst index 72663fe63a4..10bf4824550 100644 --- a/README.rst +++ b/README.rst @@ -193,14 +193,14 @@ apply (the rule names must be separated by a comma): $ php php-cs-fixer.phar fix /path/to/dir --rules=line_ending,full_opening_tag,indentation_type -You can also blacklist the rules you don't want by placing a dash in front of the rule name, if this is more convenient, +You can also exclude the rules you don't want by placing a dash in front of the rule name, if this is more convenient, using ``-name_of_fixer``: .. code-block:: bash $ php php-cs-fixer.phar fix /path/to/dir --rules=-full_opening_tag,-indentation_type -When using combinations of exact and blacklist rules, applying exact rules along with above blacklisted results: +When using combinations of exact and exclude rules, applying exact rules along with above excluded results: .. code-block:: bash @@ -691,8 +691,8 @@ Choose from the list of available rules: Configuration options: - ``annotation-black-list`` (``array``): class level annotations tags that must be - omitted to fix the class, even if all of the white list ones are used - as well. (case insensitive); defaults to ``['@final', '@Entity', + omitted to fix the class, even if all of the excluded ones are used as + well. (case insensitive); defaults to ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity']`` - ``annotation-white-list`` (``array``): class level annotations tags that must be set in order to fix the class. (case insensitive); defaults to @@ -2061,7 +2061,7 @@ Both ``exclude`` and ``notPath`` methods accept only relative paths to the ones See `Symfony\\Finder `_ online documentation for other `Finder` methods. -You may also use a blacklist for the rules instead of the above shown whitelist approach. +You may also use an exclude list for the rules instead of the above shown include approach. The following example shows how to use all ``Symfony`` rules but the ``full_opening_tag`` rule. .. code-block:: php diff --git a/src/Console/Command/HelpCommand.php b/src/Console/Command/HelpCommand.php index 97f59fde659..ac0d836246e 100644 --- a/src/Console/Command/HelpCommand.php +++ b/src/Console/Command/HelpCommand.php @@ -94,12 +94,12 @@ public static function getHelpCopy() $ php %command.full_name% /path/to/dir --rules=line_ending,full_opening_tag,indentation_type -You can also blacklist the rules you don't want by placing a dash in front of the rule name, if this is more convenient, +You can also exclude the rules you don't want by placing a dash in front of the rule name, if this is more convenient, using -name_of_fixer: $ php %command.full_name% /path/to/dir --rules=-full_opening_tag,-indentation_type -When using combinations of exact and blacklist rules, applying exact rules along with above blacklisted results: +When using combinations of exact and exclude rules, applying exact rules along with above excluded results: $ php %command.full_name% /path/to/project --rules=@Symfony,-@PSR1,-blank_line_before_statement,strict_comparison @@ -203,7 +203,7 @@ public static function getHelpCopy() See `Symfony\Finder` (https://symfony.com/doc/current/components/finder.html) online documentation for other `Finder` methods. -You may also use a blacklist for the rules instead of the above shown whitelist approach. +You may also use an exclude list for the rules instead of the above shown include approach. The following example shows how to use all ``Symfony`` rules but the ``full_opening_tag`` rule. getName(), sprintf('Annotation cannot be used in both the white- and black list, got duplicates: "%s".', implode('", "', array_keys($intersect)))); + throw new InvalidFixerConfigurationException($this->getName(), sprintf('Annotation cannot be used in both the include and exclude list, got duplicates: "%s".', implode('", "', array_keys($intersect)))); } } @@ -152,7 +152,7 @@ protected function createConfigurationDefinition() ->setDefault(['@internal']) ->setNormalizer($annotationsNormalizer) ->getOption(), - (new FixerOptionBuilder('annotation-black-list', 'Class level annotations tags that must be omitted to fix the class, even if all of the white list ones are used as well. (case insensitive)')) + (new FixerOptionBuilder('annotation-black-list', 'Class level annotations tags that must be omitted to fix the class, even if all of the excluded ones are used as well. (case insensitive)')) ->setAllowedTypes(['array']) ->setAllowedValues($annotationsAsserts) ->setDefault([ @@ -196,7 +196,7 @@ private function isClassCandidate(Tokens $tokens, $index) $tag = strtolower(substr(array_shift($matches), 1)); foreach ($this->configuration['annotation-black-list'] as $tagStart => $true) { if (0 === strpos($tag, $tagStart)) { - return false; // ignore class: class-level PHPDoc contains tag that has been black listed through configuration + return false; // ignore class: class-level PHPDoc contains tag that has been excluded through configuration } } @@ -205,7 +205,7 @@ private function isClassCandidate(Tokens $tokens, $index) foreach ($this->configuration['annotation-white-list'] as $tag => $true) { if (!isset($tags[$tag])) { - return false; // ignore class: class-level PHPDoc does not contain all tags that has been white listed through configuration + return false; // ignore class: class-level PHPDoc does not contain all tags that has been included through configuration } } diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index d009bb4eedc..98b598e3da0 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -43,6 +43,16 @@ public function isCandidate(Tokens $tokens) return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds()); } + /** + * {@inheritdoc} + * + * Must run before ClassAttributesSeparationFixer. + */ + public function getPriority() + { + return 56; + } + /** * {@inheritdoc} */ diff --git a/src/Fixer/Comment/NoEmptyCommentFixer.php b/src/Fixer/Comment/NoEmptyCommentFixer.php index 652daab5be6..c6873e72a86 100644 --- a/src/Fixer/Comment/NoEmptyCommentFixer.php +++ b/src/Fixer/Comment/NoEmptyCommentFixer.php @@ -89,6 +89,11 @@ private function getCommentBlock(Tokens $tokens, $index) { $commentType = $this->getCommentType($tokens[$index]->getContent()); $empty = $this->isEmptyComment($tokens[$index]->getContent()); + + if (self::TYPE_SLASH_ASTERISK === $commentType) { + return [$index, $index, $empty]; + } + $start = $index; $count = \count($tokens); ++$index; diff --git a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php index 3f3ccaaa5f0..b38d49657ba 100644 --- a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php @@ -131,9 +131,9 @@ private function findCurlyBraceOpen(Tokens $tokens) */ private function isOverComplete(Tokens $tokens, $index) { - static $whiteList = ['{', '}', [T_OPEN_TAG], ':', ';']; + static $include = ['{', '}', [T_OPEN_TAG], ':', ';']; - return $tokens[$tokens->getPrevMeaningfulToken($index)]->equalsAny($whiteList); + return $tokens[$tokens->getPrevMeaningfulToken($index)]->equalsAny($include); } private function clearIfIsOverCompleteNamespaceBlock(Tokens $tokens) diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php index 86c6dce7e42..5ff458de406 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php @@ -38,6 +38,10 @@ public function getDefinition() new CodeSample( " false, 'before_array_assignments_equals' => false] + ), ], 'There must not be any space around parentheses; commas must be preceded by no space and followed by one space; there must be no space around named arguments assignment operator; there must be one space around array assignment operator.' ); diff --git a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php index 5d8f7981d37..e118e066205 100644 --- a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php +++ b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php @@ -164,6 +164,7 @@ function baz($options) * {@inheritdoc} * * Must run before GlobalNamespaceImportFixer. + * Must run after StrictParamFixer. */ public function getPriority() { diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index dda3fa27d69..2c9665e0866 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -34,7 +34,7 @@ final class PhpdocToReturnTypeFixer extends AbstractFixer implements Configurati /** * @var array> */ - private $blacklistFuncNames = [ + private $excludeFuncNames = [ [T_STRING, '__construct'], [T_STRING, '__destruct'], [T_STRING, '__clone'], @@ -115,6 +115,16 @@ function my_foo() ', new VersionSpecification(70200) ), + new VersionSpecificCodeSample( + ' false] + ), ], null, 'This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2] `@return` annotation is mandatory for the fixer to make changes, signatures of methods without it (no docblock, inheritdocs) will not be fixed. [3] Manual actions are required if inherited signatures are not properly documented. [4] `@inheritdocs` support is under construction.' @@ -179,7 +189,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $funcName = $tokens->getNextMeaningfulToken($index); - if ($tokens[$funcName]->equalsAny($this->blacklistFuncNames, false)) { + if ($tokens[$funcName]->equalsAny($this->excludeFuncNames, false)) { continue; } diff --git a/src/Fixer/FunctionNotation/VoidReturnFixer.php b/src/Fixer/FunctionNotation/VoidReturnFixer.php index 9784d0f5728..7f6107e4a77 100644 --- a/src/Fixer/FunctionNotation/VoidReturnFixer.php +++ b/src/Fixer/FunctionNotation/VoidReturnFixer.php @@ -50,6 +50,7 @@ public function getDefinition() * {@inheritdoc} * * Must run before PhpdocNoEmptyReturnFixer, ReturnTypeDeclarationFixer. + * Must run after SimplifiedNullReturnFixer. */ public function getPriority() { @@ -78,7 +79,7 @@ public function isRisky() protected function applyFix(\SplFileInfo $file, Tokens $tokens) { // These cause syntax errors. - static $blacklistFuncNames = [ + static $excludeFuncNames = [ [T_STRING, '__construct'], [T_STRING, '__destruct'], [T_STRING, '__clone'], @@ -90,7 +91,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $funcName = $tokens->getNextMeaningfulToken($index); - if ($tokens[$funcName]->equalsAny($blacklistFuncNames, false)) { + if ($tokens[$funcName]->equalsAny($excludeFuncNames, false)) { continue; } diff --git a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php index bb0bf276b0a..b7018a9215d 100644 --- a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php @@ -38,7 +38,13 @@ public function getDefinition() { return new FixerDefinition( 'All PHPUnit test classes should be marked as internal.', - [new CodeSample(" ['final']] + ), + ] ); } diff --git a/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php b/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php index a017279e5a9..2b0ba34a4a6 100644 --- a/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php @@ -49,16 +49,21 @@ final class PhpUnitNamespacedFixer extends AbstractFixer implements Configuratio */ public function getDefinition() { - return new FixerDefinition( - 'PHPUnit classes MUST be used in namespaced version, e.g. `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.', - [ - new CodeSample( - ' PhpUnitTargetVersion::VERSION_4_8]), ], "PHPUnit v6 has finally fully switched to namespaces.\n" ."You could start preparing the upgrade by switching from non-namespaced TestCase to namespaced one.\n" diff --git a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php index b05ef27b573..133cab3e0eb 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php @@ -274,11 +274,7 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractFixer implemen */ public function getDefinition() { - return new FixerDefinition( - 'Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type, either `$this->`, `self::` or `static::`.', - [ - new CodeSample( - '`, `self::` or `static::`.', + [ + new CodeSample($codeSample), + new CodeSample($codeSample, ['call_type' => self::CALL_TYPE_THIS]), ], null, 'Risky when PHPUnit methods are overridden or not accessible, or when project has PHPUnit incompatibilities.' diff --git a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php index 979227cc878..4a52d975038 100644 --- a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php +++ b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php @@ -40,12 +40,24 @@ public function getDefinition() ' ['author']] ), + new CodeSample( + ' ['package', 'subpackage']] + ), ] ); } diff --git a/src/Fixer/Phpdoc/PhpdocScalarFixer.php b/src/Fixer/Phpdoc/PhpdocScalarFixer.php index 5ab9f99d578..99ccd7dbcda 100644 --- a/src/Fixer/Phpdoc/PhpdocScalarFixer.php +++ b/src/Fixer/Phpdoc/PhpdocScalarFixer.php @@ -46,7 +46,8 @@ public function getDefinition() { return new FixerDefinition( 'Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.', - [new CodeSample(' ['boolean']] + ), + ] ); } diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php index 19c1f53d980..19d39b5ab81 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php @@ -98,6 +98,16 @@ public function getDefinition() */ ' ), + new CodeSample( + ' ['simple', 'alias']] + ), ] ); } diff --git a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php index 486a9de4935..6b324ea5f1e 100644 --- a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php +++ b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php @@ -53,11 +53,11 @@ function xyz(): void { return null; } /** * {@inheritdoc} * - * Must run before NoUselessReturnFixer. + * Must run before NoUselessReturnFixer, VoidReturnFixer. */ public function getPriority() { - return -17; + return 16; } /** diff --git a/src/Fixer/Strict/StrictParamFixer.php b/src/Fixer/Strict/StrictParamFixer.php index b8c5c17b9fd..fb982a3cf8f 100644 --- a/src/Fixer/Strict/StrictParamFixer.php +++ b/src/Fixer/Strict/StrictParamFixer.php @@ -53,6 +53,16 @@ public function isRisky() return true; } + /** + * {@inheritdoc} + * + * Must run before NativeFunctionInvocationFixer. + */ + public function getPriority() + { + return 11; + } + /** * {@inheritdoc} */ diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 4162b9d0d55..4d837589fec 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -237,6 +237,8 @@ public function provideFixersPriorityCases() [$fixers['protected_to_private'], $fixers['ordered_class_elements']], [$fixers['return_assignment'], $fixers['blank_line_before_statement']], [$fixers['simplified_null_return'], $fixers['no_useless_return']], + [$fixers['simplified_null_return'], $fixers['void_return']], + [$fixers['single_class_element_per_statement'], $fixers['class_attributes_separation']], [$fixers['single_import_per_statement'], $fixers['multiline_whitespace_before_semicolons']], [$fixers['single_import_per_statement'], $fixers['no_leading_import_slash']], [$fixers['single_import_per_statement'], $fixers['no_singleline_whitespace_before_semicolons']], @@ -248,6 +250,7 @@ public function provideFixersPriorityCases() [$fixers['standardize_increment'], $fixers['increment_style']], [$fixers['standardize_not_equals'], $fixers['binary_operator_spaces']], [$fixers['strict_comparison'], $fixers['binary_operator_spaces']], + [$fixers['strict_param'], $fixers['native_function_invocation']], [$fixers['unary_operator_spaces'], $fixers['not_operator_with_space']], [$fixers['unary_operator_spaces'], $fixers['not_operator_with_successor_space']], [$fixers['void_return'], $fixers['phpdoc_no_empty_return']], diff --git a/tests/AutoReview/FixerTest.php b/tests/AutoReview/FixerTest.php index 6b9daea9d04..3f1ce04d93b 100644 --- a/tests/AutoReview/FixerTest.php +++ b/tests/AutoReview/FixerTest.php @@ -133,20 +133,13 @@ public function testFixerDefinitions(AbstractFixer $fixer) static::assertArrayHasKey($fixerName, $this->allowedRequiredOptions, sprintf('[%s] Has no sample for default configuration.', $fixerName)); } - $fixerNamesWithKnownMissingSamplesWithConfig = [ + // It may only shrink, never add anything to it. + $fixerNamesWithKnownMissingSamplesWithConfig = [ // @TODO 3.0 - remove this 'comment_to_phpdoc', 'constant_case', - 'doctrine_annotation_spaces', - 'general_phpdoc_annotation_remove', - 'is_null', - 'php_unit_dedicate_assert_internal_type', - 'php_unit_internal_class', - 'php_unit_namespaced', - 'php_unit_test_case_static_method_calls', - 'phpdoc_scalar', 'phpdoc_to_param_type', - 'phpdoc_to_return_type', - 'phpdoc_types', + 'is_null', // has only one option which is deprecated + 'php_unit_dedicate_assert_internal_type', ]; if (\count($configSamplesProvided) < 2) { diff --git a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php index 38c08ee4542..d87a1970286 100644 --- a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php @@ -289,7 +289,7 @@ public function testConfigureSameAnnotationInBothLists() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp( - sprintf('#^%s$#', preg_quote('[final_internal_class] Annotation cannot be used in both the white- and black list, got duplicates: "internal123".', '#')) + sprintf('#^%s$#', preg_quote('[final_internal_class] Annotation cannot be used in both the include and exclude list, got duplicates: "internal123".', '#')) ); $this->fixer->configure([ diff --git a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php index 9cd2eb97510..87d39cb64b6 100644 --- a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php +++ b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php @@ -232,6 +232,22 @@ public function provideFixCases() ********/ ', ], + [ + ' [ ' [ + 'excluded class methods' => [ '