From 3151de32e729dba9c4f70bcd19973419b8bb8c92 Mon Sep 17 00:00:00 2001 From: Jan Galek Date: Thu, 19 Jul 2018 18:01:18 +0200 Subject: [PATCH] Update Fix yaml format --- .gitignore | 1 + .travis.yml | 4 +- README.md | 23 +- coding-standard-php56.neon | 232 ------------------ coding-standard-php56.yml | 227 +++++++++++++++++ coding-standard-php70.neon | 10 - coding-standard-php70.yml | 10 + coding-standard-php71.neon | 10 - coding-standard-php71.yml | 10 + composer.json | 17 +- ecs | 20 +- src/Finder/SourceProvider.php | 2 + src/Fixer/Basic/BracesFixer.php | 2 +- .../WhiteSpace/FunctionSpacingSniff.php | 12 +- 14 files changed, 289 insertions(+), 291 deletions(-) delete mode 100644 coding-standard-php56.neon create mode 100644 coding-standard-php56.yml delete mode 100644 coding-standard-php70.neon create mode 100644 coding-standard-php70.yml delete mode 100644 coding-standard-php71.neon create mode 100644 coding-standard-php71.yml diff --git a/.gitignore b/.gitignore index 8b7ef35..43dc798 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor composer.lock +.idea/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 509da97..f694e76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,11 @@ matrix: install: - composer install - - if [[ $COMPOSER_PROJECT != "" ]]; then composer create-project nette/coding-standard:dev-master temp/nette-coding-standard; fi + - if [[ $COMPOSER_PROJECT != "" ]]; then composer create-project galek/coding-standard:dev-master temp/coding-standard; fi script: - composer test - - if [[ $COMPOSER_PROJECT != "" ]]; then temp/nette-coding-standard/ecs check src examples --config temp/nette-coding-standard/coding-standard-php71.neon; fi + - if [[ $COMPOSER_PROJECT != "" ]]; then temp/coding-standard/ecs check src examples --config temp/coding-standard/coding-standard-php71.yml; fi notifications: email: false diff --git a/README.md b/README.md index 17acc8b..b04d3b5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ +# Forked +I forked from [nette/coding-standard](https://github.com/nette/coding-standard) + # Check & Fix Your Code with Nette Coding Standard -[![Downloads this Month](https://img.shields.io/packagist/dm/nette/coding-standard.svg)](https://packagist.org/packages/nette/coding-standard) -[![Build Status](https://travis-ci.org/nette/coding-standard.svg?branch=master)](https://travis-ci.org/nette/coding-standard) -[![Latest Stable Version](https://img.shields.io/packagist/v/nette/coding-standard.svg)](https://github.com/nette/coding-standard/releases) +[![Downloads this Month](https://img.shields.io/packagist/dm/galek/coding-standard.svg)](https://packagist.org/packages/galek/coding-standard) +[![Build Status](https://travis-ci.org/JanGalek/coding-standard.svg?branch=master)](https://travis-ci.org/JanGalek/coding-standard) +[![Latest Stable Version](https://img.shields.io/packagist/v/JanGalek/coding-standard.svg)](https://github.com/JanGalek/coding-standard/releases) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](/LICENSE) @@ -15,7 +18,7 @@ This package covers **part of [official rules](https://nette.org/en/coding-stand When you open [`/examples`](/examples) directory, all files you'll see are checked by this coding standard. The code might look invalid compared to Nette code you know, but it's only because this tool doesn't check it (yet). -All **general rules** you can find in [`coding-standard-php56.neon`](/coding-standard-php56.neon) file. +All **general rules** you can find in [`coding-standard-php56.yml`](/coding-standard-php56.yml) file. ## Install and Use @@ -23,22 +26,22 @@ All **general rules** you can find in [`coding-standard-php56.neon`](/coding-sta ### Local Setup -Installation into global folder named `nette-coding-standard`: +Installation into global folder named `coding-standard`: ``` -composer create-project nette/coding-standard nette-coding-standard +composer create-project galek/coding-standard ``` Check coding standard: ```bash -nette-coding-standard/ecs check src tests --config nette-coding-standard/coding-standard-php56.neon +coding-standard/ecs check src tests --config coding-standard/coding-standard-php56.yml ``` And fix it: ```bash -nette-coding-standard/ecs check src tests --config nette-coding-standard/coding-standard-php56.neon --fix +coding-standard/ecs check src tests --config coding-standard/coding-standard-php56.yml --fix ``` ### Travis Setup @@ -46,8 +49,8 @@ nette-coding-standard/ecs check src tests --config nette-coding-standard/coding- ```yaml # .travis.yml install: - - composer create-project nette/coding-standard temp/nette-coding-standard + - composer create-project galek/coding-standard temp/coding-standard script: - - temp/nette-coding-standard/ecs check src tests --config temp/nette-coding-standard/coding-standard-php56.neon + - temp/coding-standard/ecs check src tests --config temp/coding-standard/coding-standard-php56.yml ``` diff --git a/coding-standard-php56.neon b/coding-standard-php56.neon deleted file mode 100644 index 9111edc..0000000 --- a/coding-standard-php56.neon +++ /dev/null @@ -1,232 +0,0 @@ -parameters: - indentation: tab - -services: - Nette\CodingStandard\Finder\SourceProvider: ~ - -checkers: - # Checkers bellow aim on 1:1 copy of https://nette.org/en/coding-standard - - # General rules - https://nette.org/en/coding-standard#toc-general-rules - - # use tabs over spaces - - PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowSpaceIndentSniff - # PHP code must use only UTF-8 without BOM - - PhpCsFixer\Fixer\Basic\EncodingFixer - # tag must be omitted from files containing only PHP. - - PhpCsFixer\Fixer\PhpTag\NoClosingTagFixer - # There must not be trailing whitespace at the end of lines. - - PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer - # ...and at the end of blank lines. - - PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer - # All files must end with a single blank line. - - PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer - # File name should match class name if possible. - - PhpCsFixer\Fixer\Basic\Psr4Fixer - # Enforces using shorthand scalar typehint variants in phpDocs: `int` instead of `integer` and `bool` instead of `boolean` - - SlevomatCodingStandard\Sniffs\TypeHints\LongTypeHintsSniff - - # File Header - https://nette.org/en/coding-standard#toc-file-header - - # empty line before namespace - - PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer - # 1 Use statement per line - - PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer - # Use statements are alphabetically ordered - - PhpCsFixer\Fixer\Import\OrderedImportsFixer - # disallow group use declarations use FooLibrary\Bar\Baz\{ ClassA, ClassB, ClassC, ClassD as Fizbo } - - SlevomatCodingStandard\Sniffs\Namespaces\DisallowGroupUseSniff - # Disallows leading backslash in use statement: use \Foo\Bar; - - SlevomatCodingStandard\Sniffs\Namespaces\UseDoesNotStartWithBackslashSniff - # Looks for unused imports from other namespaces. - SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff: - searchAnnotations: yes - ignoredAnnotationNames: [@testCase] - ignoredAnnotations: [@internal] - - # Language Construct (should be placed before some other fixers) - - # Functions should be used with `$strict` param set to `true` - - PhpCsFixer\Fixer\Strict\StrictParamFixer - # replaces is_null(parameter) expression with `null === parameter`. - PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer: - use_yoda_style: no - # Calling `unset` on multiple items should be done in one call. - - PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer - # Replace all `<>` with `!=`. - - PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer - # Include/Require and file path should be divided with a single space. File path should not be placed under brackets. - - PhpCsFixer\Fixer\ControlStructure\IncludeFixer - # Requires short ternary operator ?: when possible - - SlevomatCodingStandard\Sniffs\ControlStructures\RequireShortTernaryOperatorSniff - - # Arrays - https://nette.org/en/coding-standard#toc-arrays - - # use short array fixes - PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer: - syntax: short - # use trailing command in last array element - - PhpCsFixer\Fixer\ArrayNotation\TrailingCommaInMultilineArrayFixer - # PHP single-line arrays should not have trailing comma. - - PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer - # In array declaration, there MUST NOT be a whitespace before each comma. - - PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer - # Arrays should be formatted like function/method arguments, without leading or trailing single line space. - - PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer - # In array declaration, there MUST be a whitespace after each comma. - - PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer - - # Strings - - # Convert `heredoc` to `nowdoc` where possible. - - PhpCsFixer\Fixer\StringNotation\HeredocToNowdocFixer - # Convert double quotes to single quotes for simple strings. - - PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer - - # Keywords and True/False/Null - https://nette.org/en/coding-standard#toc-keywords-and-true-false-null - - # PHP keywords must be in lower case - - PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer - # The PHP constants `true`, `false`, and `null` MUST be in lower case - - PhpCsFixer\Fixer\Casing\LowercaseConstantsFixer - - # Method and Functions Calls - https://nette.org/en/coding-standard#toc-method-and-function-calls - - # Function defined by PHP should be called using the correct casing - - PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer - # In the argument list, there must be one space after each comma, and there must no be a space before each comma - - PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer - # This sniff checks that there are two blank lines between functions declarations and single between signatures. - - Nette\CodingStandard\Sniffs\WhiteSpace\FunctionSpacingSniff - - # Classes - https://nette.org/en/coding-standard#toc-classes - - # Inside a classy element "self" should be preferred to the class name itself. - - PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer - # class element order: constants, properties, from public to private - PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer: - order: - - use_trait - - constant - - constant_public - - constant_protected - - constant_private - - property_public - - property_protected - - property_private - - # Constants - https://nette.org/en/coding-standard#toc-constants - - # constant names are CAPITALIZED (manuall fixing only :() - - PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff - - # Class Properties - https://nette.org/en/coding-standard#toc-class-properties - - # There MUST NOT be more than one property declared per statement. - PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer: - elements: ['property'] - - # Methods - https://nette.org/en/coding-standard#toc-methods - - # They must be declared in camelCase. - - PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff - # Checks that there's a single space between a typehint and a parameter name and no whitespace between a nullability symbol and a typehint - - SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSpacingSniff - # Spaces should be properly placed in a function declaration. - - PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer - # In function arguments there must not be arguments with default values before non-default ones. - - PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer - - # Constans, Class Properties, Methods - - # All Class and Trait elements should have visibility required - Nette\CodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer: - elements: [property, method] - - # Constants and Properties should be separated by 1 blank line -# PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: -# elements: [const, property] - - # Last property and 1st method should be separated by 2 spaces - Symplify\CodingStandard\Fixer\ClassNotation\LastPropertyAndFirstMethodSeparationFixer: - space_count: 2 - - # Control Statements - https://nette.org/en/coding-standard#toc-control-statements - - # The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words. - - PhpCsFixer\Fixer\ControlStructure\ElseifFixer - # Remove useless semicolon statements. - - PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer - # Remove trailing commas in list() calls. - - PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer - # Removes unneeded parentheses around control statements. - - PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer - # A case should be followed by a colon and not a semicolon. - - PhpCsFixer\Fixer\ControlStructure\SwitchCaseSemicolonToColonFixer - # The structure body must be indented once. - # The closing brace must be on the next line after the body. - # There should not be more than one statement per line. - Nette\CodingStandard\Fixer\Basic\BracesFixer: - allow_single_line_closure: yes - # changes if (1 === $cond) to if ($cond === 1) - - SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff - # finds unreachable catch blocks: - - SlevomatCodingStandard\Sniffs\Exceptions\DeadCatchSniff - - # Casting - - # A single space or none should be between cast and variable (int) $val - - PhpCsFixer\Fixer\CastNotation\CastSpacesFixer - # Cast should be written in lower case. - - PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer - # Replaces `intval`, `floatval`, `doubleval`, `strval` and `boolval` function calls with according type casting operator - - PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer - # Short cast `bool` using double exclamation mark should not be used - - PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer - # Cast `(boolean)` and `(integer)` should be written as `(bool)` and `(int)`, `(double)` and `(real)` as `(float)` - - PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer - - # Language Whitespace - - # Binary operators should be surrounded by at least one space. - - PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer - # Unary operators should be placed adjacent to their operands. - - PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer - # No space after the opening parenthesis and before the closing parenthesis - - PhpCsFixer\Fixer\Whitespace\NoSpacesInsideParenthesisFixer - # There MUST NOT be spaces around offset braces $a[0] - - PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer - # There should not be space before or after object `T_OBJECT_OPERATOR` `->`. - - PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer - # Standardize spaces around ternary operator. - - PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer - # Concatenation $a . $b should be spaced according configuration - PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: - spacing: one - # Removes extra spaces between colon and case value. - - PhpCsFixer\Fixer\ControlStructure\SwitchCaseSpaceFixer - - # Comments - - # Docblocks should have the same indentation as the documented subject. - - PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer - # There should not be any empty comments. - - PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer - # There should not be empty PHPDoc blocks. - - PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer - # Phpdocs should start and end with content, excluding the very first and last line of the docblocks. - - PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer - # Single-line comments comments with only one line of actual content should use the `//` syntax. - PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer: - comment_types: [hash] - - - # Properties MUST not be explicitly initialized with `null`. - - PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer - - PhpCsFixer\Fixer\ControlStructure\NoBreakCommentFixer: - comment_text: 'break omitted' diff --git a/coding-standard-php56.yml b/coding-standard-php56.yml new file mode 100644 index 0000000..68531f9 --- /dev/null +++ b/coding-standard-php56.yml @@ -0,0 +1,227 @@ +parameters: + indentation: tab #tab + +services: + Nette\CodingStandard\Finder\SourceProvider: ~ + # Looks for unused imports from other namespaces. + SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff: + searchAnnotations: yes + # replaces is_null(parameter) expression with `null === parameter`. + PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer: + use_yoda_style: false + # use short array fixes + PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer: + syntax: short + # class element order: constants, properties, from public to private + PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer: + order: + - use_trait + - constant + - constant_public + - constant_protected + - constant_private + - property_public + - property_protected + - property_private + + # There MUST NOT be more than one property declared per statement. + PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer: + elements: ['property'] + + # All Class and Trait elements should have visibility required + Nette\CodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer: + elements: [property, method] + + # Constants and Properties should be separated by 1 blank line + #PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: + #elements: [const, property] + + # The structure body must be indented once. + # The closing brace must be on the next line after the body. + # There should not be more than one statement per line. + Nette\CodingStandard\Fixer\Basic\BracesFixer: + allow_single_line_closure: true + # Concatenation $a . $b should be spaced according configuration + PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: + spacing: one + # Single-line comments comments with only one line of actual content should use the `//` syntax. + PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer: + comment_types: [hash] + + PhpCsFixer\Fixer\ControlStructure\NoBreakCommentFixer: + comment_text: 'break omitted' + +#checkers: + # Checkers bellow aim on 1:1 copy of https://nette.org/en/coding-standard + + # General rules - https://nette.org/en/coding-standard#toc-general-rules + + # use tabs over spaces + PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowSpaceIndentSniff: ~ + # PHP code must use only UTF-8 without BOM + PhpCsFixer\Fixer\Basic\EncodingFixer: ~ + # tag must be omitted from files containing only PHP. + PhpCsFixer\Fixer\PhpTag\NoClosingTagFixer: ~ + # There must not be trailing whitespace at the end of lines. + PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer: ~ + # ...and at the end of blank lines. + PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer: ~ + # All files must end with a single blank line. + PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer: ~ + # File name should match class name if possible. + PhpCsFixer\Fixer\Basic\Psr4Fixer: ~ + # Enforces using shorthand scalar typehint variants in phpDocs: `int` instead of `integer` and `bool` instead of `boolean` + SlevomatCodingStandard\Sniffs\TypeHints\LongTypeHintsSniff: ~ + + # File Header - https://nette.org/en/coding-standard#toc-file-header + + # empty line before namespace + PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer: ~ + # 1 Use statement per line + PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer: ~ + # Use statements are alphabetically ordered + PhpCsFixer\Fixer\Import\OrderedImportsFixer: ~ + # disallow group use declarations use FooLibrary\Bar\Baz\{ ClassA, ClassB, ClassC, ClassD as Fizbo } + SlevomatCodingStandard\Sniffs\Namespaces\DisallowGroupUseSniff: ~ + # Disallows leading backslash in use statement: use \Foo\Bar; + SlevomatCodingStandard\Sniffs\Namespaces\UseDoesNotStartWithBackslashSniff: ~ + + # Language Construct (should be placed before some other fixers) + + # Functions should be used with `$strict` param set to `true` + PhpCsFixer\Fixer\Strict\StrictParamFixer: ~ + # Calling `unset` on multiple items should be done in one call. + PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer: ~ + # Replace all `<>` with `!=`. + PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer: ~ + # Include/Require and file path should be divided with a single space. File path should not be placed under brackets. + PhpCsFixer\Fixer\ControlStructure\IncludeFixer: ~ + # Requires short ternary operator ?: when possible + SlevomatCodingStandard\Sniffs\ControlStructures\RequireShortTernaryOperatorSniff: ~ + + # Arrays - https://nette.org/en/coding-standard#toc-arrays + + # use trailing command in last array element + PhpCsFixer\Fixer\ArrayNotation\TrailingCommaInMultilineArrayFixer: ~ + # PHP single-line arrays should not have trailing comma. + PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer: ~ + # In array declaration, there MUST NOT be a whitespace before each comma. + PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer: ~ + # Arrays should be formatted like function/method arguments, without leading or trailing single line space. + PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer: ~ + # In array declaration, there MUST be a whitespace after each comma. + PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer: ~ + + # Strings + + # Convert `heredoc` to `nowdoc` where possible. + PhpCsFixer\Fixer\StringNotation\HeredocToNowdocFixer: ~ + # Convert double quotes to single quotes for simple strings. + PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer: ~ + + # Keywords and True/False/Null - https://nette.org/en/coding-standard#toc-keywords-and-true-false-null + + # PHP keywords must be in lower case + PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer: ~ + # The PHP constants `true`, `false`, and `null` MUST be in lower case + PhpCsFixer\Fixer\Casing\LowercaseConstantsFixer: ~ + + # Method and Functions Calls - https://nette.org/en/coding-standard#toc-method-and-function-calls + + # Function defined by PHP should be called using the correct casing + PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer: ~ + # In the argument list, there must be one space after each comma, and there must no be a space before each comma + PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer: ~ + # This sniff checks that there are two blank lines between functions declarations and single between signatures. + Nette\CodingStandard\Sniffs\WhiteSpace\FunctionSpacingSniff: ~ + + # Classes - https://nette.org/en/coding-standard#toc-classes + + # Inside a classy element "self" should be preferred to the class name itself. + PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer: ~ + + # Constants - https://nette.org/en/coding-standard#toc-constants + + # constant names are CAPITALIZED (manuall fixing only :() + PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff: ~ + + # Class Properties - https://nette.org/en/coding-standard#toc-class-properties + + # Methods - https://nette.org/en/coding-standard#toc-methods + + # They must be declared in camelCase. + PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff: ~ + # Checks that there's a single space between a typehint and a parameter name and no whitespace between a nullability symbol and a typehint + SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSpacingSniff: ~ + # Spaces should be properly placed in a function declaration. + PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer: ~ + # In function arguments there must not be arguments with default values before non-default ones. + PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer: ~ + + # Constans, Class Properties, Methods + + # Control Statements - https://nette.org/en/coding-standard#toc-control-statements + + # The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words. + PhpCsFixer\Fixer\ControlStructure\ElseifFixer: ~ + # Remove useless semicolon statements. + PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer: ~ + # Remove trailing commas in list() calls. + PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer: ~ + # Removes unneeded parentheses around control statements. + PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer: ~ + # A case should be followed by a colon and not a semicolon. + PhpCsFixer\Fixer\ControlStructure\SwitchCaseSemicolonToColonFixer: ~ + # changes if (1 === $cond) to if ($cond === 1) + SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff: ~ + # finds unreachable catch blocks: + SlevomatCodingStandard\Sniffs\Exceptions\DeadCatchSniff: ~ + + # Casting + + # A single space or none should be between cast and variable (int) $val + PhpCsFixer\Fixer\CastNotation\CastSpacesFixer: ~ + # Cast should be written in lower case. + PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer: ~ + # Replaces `intval`, `floatval`, `doubleval`, `strval` and `boolval` function calls with according type casting operator + PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer: ~ + # Short cast `bool` using double exclamation mark should not be used + PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer: ~ + # Cast `(boolean)` and `(integer)` should be written as `(bool)` and `(int)`, `(double)` and `(real)` as `(float)` + PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer: ~ + + # Language Whitespace + + # Binary operators should be surrounded by at least one space. + PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer: ~ + # Unary operators should be placed adjacent to their operands. + PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~ + # No space after the opening parenthesis and before the closing parenthesis + PhpCsFixer\Fixer\Whitespace\NoSpacesInsideParenthesisFixer: ~ + # There MUST NOT be spaces around offset braces $a[0] + PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer: ~ + # There should not be space before or after object `T_OBJECT_OPERATOR` `->`. + PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer: ~ + # Standardize spaces around ternary operator. + PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer: ~ + # Removes extra spaces between colon and case value. + PhpCsFixer\Fixer\ControlStructure\SwitchCaseSpaceFixer: ~ + + # Comments + + # Docblocks should have the same indentation as the documented subject. + PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer: ~ + # There should not be any empty comments. + PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer: ~ + # There should not be empty PHPDoc blocks. + PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer: ~ + # Phpdocs should start and end with content, excluding the very first and last line of the docblocks. + PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer: ~ + + + # Properties MUST not be explicitly initialized with `null`. + PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer: ~ diff --git a/coding-standard-php70.neon b/coding-standard-php70.neon deleted file mode 100644 index 95e95af..0000000 --- a/coding-standard-php70.neon +++ /dev/null @@ -1,10 +0,0 @@ -includes: - - coding-standard-php56.neon - -checkers: - # declare(strict_types=1); - - PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer - # Enforces consistent formatting of return typehints: function foo(): ?int - - SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff - # Use `null` coalescing operator `??` where possible. - - PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer diff --git a/coding-standard-php70.yml b/coding-standard-php70.yml new file mode 100644 index 0000000..4c1b8f1 --- /dev/null +++ b/coding-standard-php70.yml @@ -0,0 +1,10 @@ +imports: + - {resource: coding-standard-php56.yml } + +services: + # declare(strict_types=1); + PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer: ~ + # Enforces consistent formatting of return typehints: function foo(): ?int + SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff: ~ + # Use `null` coalescing operator `??` where possible. + PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer: ~ diff --git a/coding-standard-php71.neon b/coding-standard-php71.neon deleted file mode 100644 index 0dc5713..0000000 --- a/coding-standard-php71.neon +++ /dev/null @@ -1,10 +0,0 @@ -includes: - - coding-standard-php70.neon - -checkers: - Nette\CodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer: - elements: [const, property, method] - - # short list() syntax [] - PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer: - syntax: short diff --git a/coding-standard-php71.yml b/coding-standard-php71.yml new file mode 100644 index 0000000..8f4115e --- /dev/null +++ b/coding-standard-php71.yml @@ -0,0 +1,10 @@ +imports: + - {resource: coding-standard-php70.yml } + +services: + Nette\CodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer: + elements: [const, property, method] + + # short list() syntax [] + PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer: + syntax: short diff --git a/composer.json b/composer.json index e657a85..212a2bf 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { - "name": "nette/coding-standard", + "name": "galek/coding-standard", "license": "MIT", "require": { "php": "^7.1", - "symplify/easy-coding-standard": "3.2.28", - "symplify/coding-standard": "3.2.28", - "slevomat/coding-standard": "4.6" + "symplify/easy-coding-standard": "^4.5", + "symplify/coding-standard": "^4.5", + "slevomat/coding-standard": "^4.6" }, "require-dev": { "tracy/tracy": "^2.4" @@ -17,9 +17,10 @@ }, "scripts": { "test": [ - "ecs check examples --config coding-standard-php56.neon", - "ecs check examples --config coding-standard-php70.neon", - "ecs check examples --config coding-standard-php71.neon" + "ecs check examples --config coding-standard-php56.yml", + "ecs check examples --config coding-standard-php70.yml", + "ecs check examples --config coding-standard-php71.yml" ] - } + }, + "minimum-stability": "stable" } diff --git a/ecs b/ecs index 5c9eae9..6f3b89c 100755 --- a/ecs +++ b/ecs @@ -1,30 +1,26 @@ #!/usr/bin/env php get(Application::class); - /** @var InputInterface $input */ - $input = $container->get(InputInterface::class); - - /** @var OutputInterface $output */ - $output = $container->get(OutputInterface::class); - exit($application->run($input, $output)); + exit($application->run()); } catch (Throwable $throwable) { - $symfonyStyle = SymfonyStyleFactory::create(); - $symfonyStyle->error($throwable->getMessage()); + (new \Symplify\PackageBuilder\Console\ThrowableRenderer())->render($throwable); + /*$symfonyStyle = SymfonyStyleFactory::create(); + $symfonyStyle->error($throwable->getMessage());*/ exit(1); } diff --git a/src/Finder/SourceProvider.php b/src/Finder/SourceProvider.php index 819304a..2de84b7 100644 --- a/src/Finder/SourceProvider.php +++ b/src/Finder/SourceProvider.php @@ -11,8 +11,10 @@ final class SourceProvider implements CustomSourceProviderInterface { + /** * @param string[] $source + * @return IteratorAggregate */ public function find(array $source): IteratorAggregate { diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 3130a97..657d95b 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -127,7 +127,7 @@ public function bar($baz) /** * {@inheritdoc} */ - public function getPriority() + public function getPriority(): int { // should be run after the ElseIfFixer, NoEmptyStatementFixer and NoUselessElseFixer return -25; diff --git a/src/Sniffs/WhiteSpace/FunctionSpacingSniff.php b/src/Sniffs/WhiteSpace/FunctionSpacingSniff.php index 7d6375c..283e7a9 100644 --- a/src/Sniffs/WhiteSpace/FunctionSpacingSniff.php +++ b/src/Sniffs/WhiteSpace/FunctionSpacingSniff.php @@ -43,7 +43,7 @@ public function register() * * @return void */ - public function process(File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr): void { $tokens = $phpcsFile->getTokens(); @@ -153,7 +153,7 @@ public function process(File $phpcsFile, $stackPtr) && $tokens[$prevContent]['line'] === ($currentLine - 1) ) { // Account for function comments. - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$prevContent]['comment_opener'] - 1), null, true); + $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $tokens[$prevContent]['comment_opener'] - 1, null, true); } if ($tokens[$prevContent]['code'] === T_OPEN_CURLY_BRACKET) { @@ -188,7 +188,7 @@ public function process(File $phpcsFile, $stackPtr) break; } - if ($tokens[($i - 1)]['line'] < $currentLine && $tokens[($i + 1)]['line'] > $currentLine) { + if ($tokens[$i - 1]['line'] < $currentLine && $tokens[$i + 1]['line'] > $currentLine) { // This token is on a line by itself. If it is whitespace, the line is empty. if ($tokens[$i]['code'] === T_WHITESPACE) { $foundLines++; @@ -216,17 +216,17 @@ public function process(File $phpcsFile, $stackPtr) if ($prevContent === 0) { $nextSpace = 0; } else { - $nextSpace = $phpcsFile->findNext(T_WHITESPACE, ($prevContent + 1), $stackPtr); + $nextSpace = $phpcsFile->findNext(T_WHITESPACE, $prevContent + 1, $stackPtr); if ($nextSpace === false) { $nextSpace = ($stackPtr - 1); } } if ($foundLines < $this->spacing) { - $padding = str_repeat($phpcsFile->eolChar, ($this->spacing - $foundLines)); + $padding = str_repeat($phpcsFile->eolChar, $this->spacing - $foundLines); $phpcsFile->fixer->addContent($nextSpace, $padding); } else { - $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true); + $nextContent = $phpcsFile->findNext(T_WHITESPACE, $nextSpace + 1, null, true); $phpcsFile->fixer->beginChangeset(); for ($i = $nextSpace; $i < ($nextContent - 1); $i++) { if (strpos($tokens[$i]['content'], "\n") !== false) {