Closed big-dream closed 1 month ago
我建议放弃 StyleCi ,转为使用开源工具 php-cs-fixer。 并使用现代化的社区规范:PER-CS1.0
我暂时设置了 只有pr的时候才会检测 这样基本不影响正式提交或合并 PER-CS1.0好像已经过时了吧 现在2.0了
https://cs.symfony.com/doc/ruleSets/index.html
PER-CS 1.0 暂时还没标记为过时,但有更新的 PER-CS 2.0
改变为:
--- Original
+++ New
<?php
$foo = [
- 'bar' => [
- 'baz' => true,
- ],
+ 'bar' => [
+ 'baz' => true,
+ ],
];
--- Original
+++ New
<?php
-$bar = ( string ) $a;
-$foo = (int)$b;
+$bar = (string) $a;
+$foo = (int) $b;
--- Original
+++ New
<?php
-$foo = 'bar' . 3 . 'baz'.'qux';
+$foo = 'bar'. 3 .'baz'.'qux';
--- Original
+++ New
<?php
class Foo
{
- public static function bar ( $baz , $foo )
+ public static function bar($baz , $foo)
{
return false;
}
}
-function foo ($bar, $baz)
+function foo($bar, $baz)
{
return false;
}
<?php
-$f = function () {};
+$f = function() {};
<?php
-$f = fn () => null;
+$f = fn() => null;
--- Original
+++ New
<?php
-function sample($a=10,$b=20,$c=30) {}
-sample(1, 2);
+function sample($a=10, $b=20, $c=30) {}
+sample(1, 2);
<?php
-function sample($a=10,
- $b=20,$c=30) {}
-sample(1,
- 2);
+function sample(
+ $a=10,
+ $b=20,
+ $c=30
+) {}
+sample(
+ 1,
+ 2
+);
<?php
sample(
<<<EOD
foo
- EOD
- ,
+ EOD,
'bar'
);
--- Original
+++ New
<?php function foo(
int $x
-)
-{
-}
+) {}
--- Original
+++ New
<?php
array(
1,
- 2
+ 2,
);
用 StyleCi 的一个好处就是,对于不符合规则的代码,会给出调整示例,且跟 github 比较搭配。
用 StyleCi 的一个好处就是,对于不符合规则的代码,会给出调整示例,且跟 github 比较搭配。
能使用更统一的标准就是好的一步(这样无论用哪个工具都能正确适配)。
提php-cs-fixer
主要是本地可用,ide
也有支持,不依赖云端服务。
ps: php-cs-fixer
可用使用phar
打包版本:php-cs-fixer/shim
,不污染项目依赖
现代化编辑器都有类似插件或功能的 php-cs-fixer phpfmt 不知道StyleCi 现在搞什么幺蛾子
因现在仓库每次的提交的 StyleCi 检查都不通过,且 StyleCi 的默认规则又不符合我们的需求,因此花了些时间整理出了 StyleCi 默认配置的影响。
一、配置文件
目前计划增加该配置文件
二、问题配置项概览
以下为 styleci 推荐配置产生的影响范围概览,列举了推荐配置中,每项配置影响的文件数和行数。禁用列为
Y
的,表示个人认为影响范围较大,可不使用该配置。禁用列为?
的,个人拿不定主意,不确定要不要使用。二、问题详情
align_double_arrow
更改:5 个文件,增加 32 行,删除 32 行
alpha_ordered_imports
更改:3 个文件,增加 3 行,删除 3 行
binary_operator_exactly_one_space
更改:79 个文件,增加 864 行,删除 864 行
blank_line_after_opening_tag
更改:148 个文件,增加 148 行,删除 0 行
blank_line_before_return
更改:44 个文件,增加 128 行,删除 0 行
blank_line_before_throw
更改:8 个文件,增加 8 行,删除 0 行
blank_line_before_try
更改:1 个文件,增加 1 行,删除 0 行
concat_without_spaces
更改:76 个文件,增加 351 行,删除 351 行
declare_equal_normalize
更改:28 个文件,增加 28 行,删除 28 行
heredoc_to_nowdoc
更改:2 个文件,增加 2 行,删除 2 行
method_separation
更改:27 个文件,增加 2 行,删除 28 行
new_with_parentheses
更改:8 个文件,增加 13 行,删除 13 行
no_blank_lines_after_class_opening
更改:26 个文件,增加 0 行,删除 26 行
no_unneeded_control_parentheses
更改:1 个文件,增加 1 行,删除 1 行
no_unused_lambda_imports
更改:1 个文件,增加 1 行,删除 1 行
no_useless_return
更改:2 个文件,增加 2 行,删除 2 行
no_whitespace_in_blank_line
更改:2 个文件,增加 2 行,删除 2 行
phpdoc_align
更改:100 个文件,增加 1510 行,删除 1510 行
phpdoc_no_access
更改:87 个文件,增加 0 行,删除 756 行
phpdoc_no_package
更改:36 个文件,增加 0 行,删除 36 行
phpdoc_no_useless_inheritdoc
更改:2 个文件,增加 3 行,删除 3 行
phpdoc_order
更改:18 个文件,增加 32 行,删除 32 行
phpdoc_scalar
更改:16 个文件,增加 28 行,删除 28 行
phpdoc_separation
更改:112 个文件,增加 2824 行,删除 1 行
phpdoc_single_line_var_spacing
更改:3 个文件,增加 9 行,删除 9 行
phpdoc_summary
更改:122 个文件,增加 1157 行,删除 1157 行
phpdoc_trim
更改:1 个文件,增加 0 行,删除 1 行
phpdoc_types
更改:4 个文件,增加 5 行,删除 5 行
post_increment
更改:4 个文件,增加 5 行,删除 5 行
return_type_declaration
更改:1 个文件,增加 2 行,删除 2 行
single_blank_line_before_namespace
更改:13 个文件,增加 13 行,删除 0 行
single_quote
更改:31 个文件,增加 86 行,删除 86 行
symfony_braces
更改:65 个文件,增加 28 行,删除 96 行
unalign_equals
更改:73 个文件,增加 344 行,删除 344 行
union_type_without_spaces
更改:3 个文件,增加 6 行,删除 6 行