Skip to content
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

Upgrade Fixer and Sniffer #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
composer.lock
filelist.tmp
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "nette/coding-standard",
"license": "MIT",
"require": {
"php": "^7.2 || ^8.0",
"slevomat/coding-standard": "^8.6 <8.12",
"friendsofphp/php-cs-fixer": "^3.10 <3.16",
"php": "^7.4 || ^8.0",
"slevomat/coding-standard": "^8.6 <8.16",
"friendsofphp/php-cs-fixer": "^3.10 <3.59",
"squizlabs/php_codesniffer": "^3.6",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.5"
},
Expand Down
2 changes: 1 addition & 1 deletion fix.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


// try to find out the PHP version from the composer.json
$presetVersions = ['8.1', '8.0', '7.4', '7.3', '7.1'];
$presetVersions = ['8.3', '8.2', '8.1', '8.0', '7.4', '7.3', '7.1'];


$root = getcwd();
Expand Down
3 changes: 1 addition & 2 deletions preset-fixer/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
}, $files);

$config = new PhpCsFixer\Config;
$config->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect());
$config->registerCustomFixers([
new NetteCodingStandard\Fixer\Whitespace\StatementIndentationFixer,
new NetteCodingStandard\Fixer\Basic\CurlyBracesPositionFixer,
new NetteCodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer,
new NetteCodingStandard\Fixer\FunctionNotation\MethodArgumentSpaceFixer,
new NetteCodingStandard\Fixer\FunctionNotation\FunctionDeclarationFixer,
Expand Down
21 changes: 7 additions & 14 deletions preset-fixer/common/Nette.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
return [
'@PSR12' => true,
'@PSR12:risky' => true,
'new_with_braces' => false, // new stdClass
'new_with_parentheses' => false, // new stdClass
'single_line_after_imports' => false, // Nette uses two empty lines
'blank_line_after_namespace' => false,
'ordered_imports' => true, // Use statements are alphabetically ordered
'ordered_imports' => false, // Use statements are alphabetically ordered
'blank_line_between_import_groups' => false,

// braces split
'braces' => false,
// Ensures a single space after language constructs
'single_space_after_construct' => true,
'single_space_around_construct' => true,
// The body of each control structure MUST be enclosed within braces
'control_structure_braces' => true,
// Control structure continuation keyword must be on the configured line
Expand All @@ -23,15 +21,10 @@
'declare_parentheses' => true,
// There must not be more than one statement per line
'no_multiple_statements_per_line' => true,


// overriden rules

// Curly braces must be placed as configured
'Nette/curly_braces_position' => true,

'braces_position' => true,
// Each statement must be indented
'Nette/statement_indentation' => true,
'statement_indentation' => true,

// In the argument list, there must be one space after each comma, and there must no be a space before each comma
'method_argument_space' => false,
Expand Down Expand Up @@ -106,7 +99,7 @@
// Remove useless semicolon statements
'no_empty_statement' => true,

'no_unneeded_curly_braces' => true,
'no_unneeded_braces' => true,

// Remove trailing commas in list() calls.
'no_trailing_comma_in_singleline' => true,
Expand Down Expand Up @@ -164,7 +157,7 @@
// Convert double quotes to single quotes for simple strings.
'single_quote' => true,

'escape_implicit_backslashes' => true,
'string_implicit_backslashes' => true,

// Convert ${..} to {$..}
'simple_to_complex_string_variable' => true,
Expand Down
12 changes: 12 additions & 0 deletions preset-fixer/php83.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

$config = require __DIR__ . '/php82.php';

$rules = [
'@PHP83Migration' => true,
];

$config->setRules($rules + $config->getRules());
return $config;
5 changes: 5 additions & 0 deletions preset-sniffer/php71.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<ruleset name="PHP 7.1" namespace="Nette">
<rule ref="./Nette.xml"/>

<!-- Fixer and Sniffer do not have the same result of sorting uses. -->
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses">
<exclude-pattern>*\.phpt?</exclude-pattern>
</rule>

<!-- Enforces consistent formatting of return typehints: function foo(): ?int -->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>

Expand Down
6 changes: 6 additions & 0 deletions preset-sniffer/php83.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="PHP 8.3" namespace="Nette">
<rule ref="./php82.xml"/>

<config name="php_version" value="80300"/>
</ruleset>
Loading