diff --git a/src/RuleSet/Sets/Relax.php b/src/RuleSet/Sets/Relax.php index 39256e9..2ceef6d 100644 --- a/src/RuleSet/Sets/Relax.php +++ b/src/RuleSet/Sets/Relax.php @@ -9,80 +9,125 @@ final class Relax extends AbstractRuleSet { /** * Inherit the rules from Laravel - * - * @see \Realodix\Relax\RuleSet\Sets\Laravel */ public function rules(): array - { - return $this->mainRules(); - } - - /** - * Returns the main rules - * - * @internal - */ - public function mainRules(): array { return [ '@PER-CS2.0' => true, + 'braces_position' => ['anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end'], + 'concat_space' => ['spacing' => 'none'], + 'method_argument_space' => ['on_multiline' => 'ignore', 'after_heredoc' => true], + 'new_with_parentheses' => ['named_class' => false, 'anonymous_class' => false], + 'single_class_element_per_statement' => ['elements' => ['const', 'property']], + // TODO: Add 'match' & 'parameters' when PHP 8.0+ is required + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments']], + 'visibility_required' => ['elements' => ['method', 'property']], + // 'class_definition' => ['inline_constructor_arguments' => false, 'space_before_parenthesis' => true], + // 'function_declaration' => ['closure_fn_spacing' => 'none'], + // 'no_break_comment' => true, + // 'ordered_class_elements' => ['order' => ['use_trait']], + // 'single_import_per_statement' => ['group_to_single_imports' => false], + // 'unary_operator_spaces' => ['only_dec_inc' => true], 'align_multiline_comment' => true, + 'array_syntax' => ['syntax' => 'short'], 'attribute_empty_parentheses' => true, + 'blank_line_before_statement' => ['statements' => ['continue', 'return']], 'class_reference_name_casing' => true, 'combine_consecutive_unsets' => true, - 'no_break_comment' => true, + 'declare_parentheses' => true, + 'heredoc_to_nowdoc' => true, + 'increment_style' => ['style' => 'post'], + 'lambda_not_used_import' => true, + 'list_syntax' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'method_chaining_indentation' => true, + 'multiline_whitespace_before_semicolons' => true, + 'native_function_casing' => true, + 'native_type_declaration_casing' => true, + 'no_alias_functions' => true, + 'no_alias_language_construct_call' => true, + 'no_binary_string' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_mixed_echo_print' => ['use' => 'echo'], + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_around_offset' => ['positions' => ['inside', 'outside']], + 'no_trailing_comma_in_singleline' => true, + 'no_unneeded_braces' => true, + 'no_unneeded_control_parentheses' => true, 'no_unneeded_import_alias' => true, + 'no_unreachable_default_argument_value' => true, + 'no_unset_cast' => true, + 'no_unused_imports' => true, 'no_useless_concat_operator' => true, 'no_useless_else' => true, 'no_useless_nullsafe_operator' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'not_operator_with_successor_space' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'nullable_type_declaration' => true, + 'object_operator_without_whitespace' => true, 'operator_linebreak' => ['only_booleans' => true], - 'ordered_class_elements' => ['order' => ['use_trait']], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'ordered_interfaces' => true, + 'ordered_traits' => true, 'ordered_types' => ['sort_algorithm' => 'none'], + 'phpdoc_no_access' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => ['order' => ['param', 'return', 'throws']], 'phpdoc_param_order' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_tag_type' => ['tags' => ['inheritdoc' => 'inline']], 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types_order' => ['sort_algorithm' => 'none'], + 'phpdoc_types' => true, 'phpdoc_var_annotation_correct_order' => true, + 'self_static_accessor' => true, 'simple_to_complex_string_variable' => true, 'single_line_comment_spacing' => true, - - Fixer\MultilineCommentOpeningClosingAloneFixer::name() => true, - Fixer\MultilinePromotedPropertiesFixer::name() => ['minimum_number_of_parameters' => 2], - Fixer\NoImportFromGlobalNamespaceFixer::name() => true, - Fixer\NoUselessParenthesisFixer::name() => true, - // This makes Laravel `no_superfluous_phpdoc_tags['allow_unused_params']` not work - Fixer\PhpdocNoSuperfluousParamFixer::name() => true, - Fixer\PhpdocParamTypeFixer::name() => true, - Fixer\PhpdocSelfAccessorFixer::name() => true, - Fixer\PhpdocTypesCommaSpacesFixer::name() => true, - Fixer\PhpdocTypesTrimFixer::name() => true, - - /* - * Laravel rules adjustment - */ + 'single_line_comment_style' => ['comment_types' => ['hash']], + 'single_quote' => true, + 'single_space_around_construct' => true, + 'space_after_semicolon' => ['remove_in_empty_for_expressions' => true], + 'trim_array_spaces' => true, + 'type_declaration_spaces' => true, + 'types_spaces' => true, + 'whitespace_after_comma_in_array' => ['ensure_single_space' => true], 'binary_operator_spaces' => [ 'default' => 'single_space', 'operators' => ['=>' => 'at_least_single_space'], ], - 'class_definition' => ['inline_constructor_arguments' => false, 'space_before_parenthesis' => true], - 'braces_position' => ['anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end'], - 'function_declaration' => ['closure_fn_spacing' => 'none'], - 'method_argument_space' => ['on_multiline' => 'ignore', 'after_heredoc' => true], + 'class_attributes_separation' => [ + 'elements' => [ + 'const' => 'one', + 'method' => 'one', + 'property' => 'one', + 'trait_import' => 'none', + ], + ], 'no_extra_blank_lines' => [ 'tokens' => [ 'default', 'attribute', 'case', 'continue', 'extra', 'switch', 'throw', 'use', 'curly_brace_block', 'parenthesis_brace_block', 'square_brace_block', ], ], - 'single_import_per_statement' => ['group_to_single_imports' => false], - 'space_after_semicolon' => ['remove_in_empty_for_expressions' => true], - // TODO: Add 'match' & 'parameters' when PHP 8.0+ is required - 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments']], - 'unary_operator_spaces' => ['only_dec_inc' => true], - 'whitespace_after_comma_in_array' => ['ensure_single_space' => true], 'phpdoc_align' => [ 'tags' => ['method', 'param', 'property', 'property-read', 'property-write', 'throws', 'type', 'var'], ], + 'yoda_style' => [ + 'always_move_variable' => false, + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false, + ], 'phpdoc_separation' => [ 'groups' => [ ['param', 'param-out', 'return'], ['var', 'readonly'], @@ -107,6 +152,17 @@ public function mainRules(): array ], ], ], + + Fixer\MultilineCommentOpeningClosingAloneFixer::name() => true, + Fixer\MultilinePromotedPropertiesFixer::name() => ['minimum_number_of_parameters' => 2], + Fixer\NoImportFromGlobalNamespaceFixer::name() => true, + Fixer\NoUselessParenthesisFixer::name() => true, + // This makes Laravel `no_superfluous_phpdoc_tags['allow_unused_params']` not work + Fixer\PhpdocNoSuperfluousParamFixer::name() => true, + Fixer\PhpdocParamTypeFixer::name() => true, + Fixer\PhpdocSelfAccessorFixer::name() => true, + Fixer\PhpdocTypesCommaSpacesFixer::name() => true, + Fixer\PhpdocTypesTrimFixer::name() => true, ]; } } diff --git a/tests/Fixtures/Ruleset/relax-commonbox2_expected.php b/tests/Fixtures/Ruleset/relax-commonbox2_expected.php index 61e28d4..40551c1 100644 --- a/tests/Fixtures/Ruleset/relax-commonbox2_expected.php +++ b/tests/Fixtures/Ruleset/relax-commonbox2_expected.php @@ -11,20 +11,22 @@ namespace Realodix\Relax; // no_leading_namespace_whitespace +use function CCC\AA; +use function DDD; + use const OtherNamespace\AAAA; -use const OtherNamespace\BBB; use OtherNamespace\AAC; use OtherNamespace\Acme; use OtherNamespace\Bar; + +use const OtherNamespace\BBB; + use OtherNamespace\no_leading_import_slash; use SingleImportPerStatement\SIPSB; use SingleImportPerStatement\SIPSC; use SingleImportPerStatement\{SIPSA, SIPSAA}; -use function CCC\AA; -use function DDD; - /** * ordered_imports * blank_line_between_import_groups diff --git a/tests/Fixtures/Ruleset/relax_actual.php b/tests/Fixtures/Ruleset/relax_actual.php index 0a3d87d..23eb9c0 100644 --- a/tests/Fixtures/Ruleset/relax_actual.php +++ b/tests/Fixtures/Ruleset/relax_actual.php @@ -153,8 +153,7 @@ public function class_notation__ordered_types(string|int|null $foo):string|int|n public function comment__single_line_comment_spacing() { //comment 1 - #comment 2 - /*comment 3*/ + /*comment 2*/ } public function comment__single_line_comment_style() diff --git a/tests/Fixtures/Ruleset/relax_expected.php b/tests/Fixtures/Ruleset/relax_expected.php index 178f100..cbbac88 100644 --- a/tests/Fixtures/Ruleset/relax_expected.php +++ b/tests/Fixtures/Ruleset/relax_expected.php @@ -153,8 +153,7 @@ public function class_notation__ordered_types(null|string|int $foo): null|string public function comment__single_line_comment_spacing() { // comment 1 - // comment 2 - /* comment 3 */ + /* comment 2 */ } public function comment__single_line_comment_style() @@ -419,6 +418,7 @@ public function attribute_notation__attribute_empty_parentheses() {} /** * This is a DOC Comment * with a line not prefixed with asterisk + * */ public function phpdoc__align_multiline_comment() {}