Skip to content

Commit 56450cc

Browse files
committed
Adding Prettier specific rulesets for existing rulesets.
1 parent 876746d commit 56450cc

File tree

5 files changed

+168
-4
lines changed

5 files changed

+168
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ The following example returns a configuration with the [default](https://github.
2828
<?php
2929

3030
use PhpCsFixer\Finder;
31+
use function Weerd\PhpStyle\configure;
3132

3233
$finder = Finder::create()
3334
->in([
3435
__DIR__.'/src',
3536
__DIR__.'/tests',
3637
]);
3738

38-
return Weerd\PhpStyle\configure($finder);
39+
return configure($finder);
3940
```
4041

4142
### Example using default ruleset and additional rules
@@ -46,6 +47,7 @@ The following example returns a configuration with the [default](https://github.
4647
<?php
4748

4849
use PhpCsFixer\Finder;
50+
use function Weerd\PhpStyle\configure;
4951

5052
$finder = Finder::create()
5153
->in([
@@ -60,7 +62,7 @@ $options = [
6062
],
6163
];
6264

63-
return Weerd\PhpStyle\configure($finder, $options);
65+
return configure($finder, $options);
6466
```
6567

6668
### Example using laravel ruleset
@@ -71,6 +73,7 @@ The following example returns a configuration with the [laravel](https://github.
7173
<?php
7274

7375
use PhpCsFixer\Finder;
76+
use function Weerd\PhpStyle\configure;
7477

7578
$finder = Finder::create()
7679
->in([
@@ -82,7 +85,7 @@ $finder = Finder::create()
8285
])
8386
->notName('*.blade.php');
8487

85-
return Weerd\PhpStyle\configure($finder, ['base' => 'laravel']);
88+
return configure($finder, ['base' => 'laravel']);
8689
```
8790

8891
Once you have the `.php_cs.dist` file setup, you can run the PHP CS Fixer tool by running:

src/rules/default-prettier.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* Default ruleset for PHP projects also using Prettier PHP plugin.
5+
*/
6+
return [
7+
'@PSR2' => true,
8+
'array_syntax' => ['syntax' => 'short'],
9+
'binary_operator_spaces' => true,
10+
'blank_line_before_statement' => [
11+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
12+
],
13+
'method_argument_space' => [
14+
'on_multiline' => 'ensure_fully_multiline',
15+
'keep_multiple_spaces_after_comma' => true,
16+
],
17+
'no_unused_imports' => true,
18+
'not_operator_with_successor_space' => false,
19+
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
20+
'phpdoc_scalar' => true,
21+
'phpdoc_single_line_var_spacing' => true,
22+
'phpdoc_var_without_name' => true,
23+
'trailing_comma_in_multiline_array' => true,
24+
'unary_operator_spaces' => true,
25+
];

src/rules/default.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
/**
4+
* Default ruleset for PHP projects.
5+
*/
36
return [
47
'@PSR2' => true,
58
'array_syntax' => ['syntax' => 'short'],

src/rules/laravel-prettier.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/**
4+
* Ruleset for Laravel projects also using Prettier PHP plugin.
5+
*
6+
* @see https://git.io/JJASj
7+
*/
8+
return [
9+
'@PSR2' => true,
10+
'array_syntax' => ['syntax' => 'short'],
11+
'binary_operator_spaces' => [
12+
'default' => 'single_space',
13+
'operators' => ['=>' => null],
14+
],
15+
'blank_line_after_namespace' => true,
16+
'blank_line_after_opening_tag' => true,
17+
'blank_line_before_statement' => [
18+
'statements' => ['return'],
19+
],
20+
'braces' => true,
21+
'cast_spaces' => true,
22+
'class_attributes_separation' => [
23+
'elements' => ['method'],
24+
],
25+
'class_definition' => true,
26+
'concat_space' => [
27+
'spacing' => 'one',
28+
],
29+
'declare_equal_normalize' => true,
30+
'elseif' => true,
31+
'encoding' => true,
32+
'full_opening_tag' => true,
33+
'fully_qualified_strict_types' => true,
34+
'function_declaration' => true,
35+
'function_typehint_space' => true,
36+
'heredoc_to_nowdoc' => true,
37+
'include' => true,
38+
'increment_style' => ['style' => 'post'],
39+
'indentation_type' => true,
40+
'linebreak_after_opening_tag' => true,
41+
'line_ending' => true,
42+
'lowercase_cast' => true,
43+
'lowercase_constants' => true,
44+
'lowercase_keywords' => true,
45+
'lowercase_static_reference' => true,
46+
'magic_method_casing' => true,
47+
'magic_constant_casing' => true,
48+
'method_argument_space' => true,
49+
'native_function_casing' => true,
50+
'no_alias_functions' => true,
51+
'no_extra_blank_lines' => [
52+
'tokens' => [
53+
'extra',
54+
'throw',
55+
'use',
56+
'use_trait',
57+
],
58+
],
59+
'no_blank_lines_after_class_opening' => true,
60+
'no_blank_lines_after_phpdoc' => true,
61+
'no_closing_tag' => true,
62+
'no_empty_phpdoc' => true,
63+
'no_empty_statement' => true,
64+
'no_leading_import_slash' => true,
65+
'no_leading_namespace_whitespace' => true,
66+
'no_mixed_echo_print' => [
67+
'use' => 'echo',
68+
],
69+
'no_multiline_whitespace_around_double_arrow' => false,
70+
'multiline_whitespace_before_semicolons' => [
71+
'strategy' => 'no_multi_line',
72+
],
73+
'no_short_bool_cast' => true,
74+
'no_singleline_whitespace_before_semicolons' => true,
75+
'no_spaces_after_function_name' => true,
76+
'no_spaces_around_offset' => true,
77+
'no_spaces_inside_parenthesis' => true,
78+
'no_trailing_comma_in_list_call' => true,
79+
'no_trailing_comma_in_singleline_array' => true,
80+
'no_trailing_whitespace' => true,
81+
'no_trailing_whitespace_in_comment' => true,
82+
'no_unneeded_control_parentheses' => true,
83+
'no_unreachable_default_argument_value' => true,
84+
'no_useless_return' => true,
85+
'no_whitespace_before_comma_in_array' => true,
86+
'no_whitespace_in_blank_line' => true,
87+
'normalize_index_brace' => true,
88+
'not_operator_with_successor_space' => false,
89+
'object_operator_without_whitespace' => true,
90+
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
91+
'phpdoc_indent' => true,
92+
'phpdoc_inline_tag' => true,
93+
'phpdoc_no_access' => true,
94+
'phpdoc_no_package' => true,
95+
'phpdoc_no_useless_inheritdoc' => true,
96+
'phpdoc_scalar' => true,
97+
'phpdoc_single_line_var_spacing' => true,
98+
'phpdoc_summary' => true,
99+
'phpdoc_to_comment' => true,
100+
'phpdoc_trim' => true,
101+
'phpdoc_types' => true,
102+
'phpdoc_var_without_name' => true,
103+
'psr4' => true,
104+
'self_accessor' => true,
105+
'short_scalar_cast' => true,
106+
'simplified_null_return' => false,
107+
'single_blank_line_at_eof' => true,
108+
'single_blank_line_before_namespace' => true,
109+
'single_class_element_per_statement' => true,
110+
'single_import_per_statement' => true,
111+
'single_line_after_imports' => true,
112+
'single_line_comment_style' => [
113+
'comment_types' => ['hash'],
114+
],
115+
'single_quote' => true,
116+
'space_after_semicolon' => true,
117+
'standardize_not_equals' => true,
118+
'switch_case_semicolon_to_colon' => true,
119+
'switch_case_space' => true,
120+
'ternary_operator_spaces' => true,
121+
'trailing_comma_in_multiline_array' => true,
122+
'trim_array_spaces' => true,
123+
'unary_operator_spaces' => true,
124+
'visibility_required' => [
125+
'elements' => ['method', 'property'],
126+
],
127+
'whitespace_after_comma_in_array' => true,
128+
];

src/rules/laravel.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
/**
4+
* Ruleset for Laravel projects.
5+
*
6+
* @see https://git.io/JJASj
7+
*/
38
return [
49
'@PSR2' => true,
510
'array_syntax' => ['syntax' => 'short'],
@@ -98,7 +103,7 @@
98103
'psr4' => true,
99104
'self_accessor' => true,
100105
'short_scalar_cast' => true,
101-
'simplified_null_return' => false, // disabled by Shift
106+
'simplified_null_return' => false,
102107
'single_blank_line_at_eof' => true,
103108
'single_blank_line_before_namespace' => true,
104109
'single_class_element_per_statement' => true,

0 commit comments

Comments
 (0)