Я добавил конфигурацию PHPCS, чтобы получить некоторые стандарты в унаследованный проект.
Я использую расслабленную версию PSR-2 в качестве промежуточного шага. Теперь то, что я хочу сделать, медленно удаляет исключения, один за другим, совершая изменения в Git на каждом шагу.
Как мне запустить PHPCBF для данной конфигурации?
В моем наборе правил у меня есть:
<arg name="tab-width" value="4"/>
<rule ref="PSR2">
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="Generic.Formatting.DisallowMultipleStatements.SameLine"/>
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma"/>
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma"/>
<!--<exclude name="Generic.PHP.LowerCaseConstant.Found"/>-->
<!--<exclude name="Generic.PHP.LowerCaseKeyword.Found"/>-->
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
<exclude name="Generic.WhiteSpace.ScopeIndent"/>
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
<exclude name="PSR2.Classes.ClassDeclaration.SpaceBeforeBrace"/>
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNotAlone"/>
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakIndent"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakNotNewLine"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT"/>
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments"/>
<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine"/>
<exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket"/>
<exclude name="PSR2.Methods.FunctionCallSignature.Indent"/>
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket"/>
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBrace"/>
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterBracket"/>
<exclude name="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace"/>
<exclude name="Squiz.ControlStructures.ForLoopDeclaration.NoSpaceAfterFirst"/>
<exclude name="Squiz.ControlStructures.ForLoopDeclaration.NoSpaceAfterSecond"/>
<exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen"/>
<exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose"/>
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals"/>
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterDefault"/>
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpenHint"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterBracket"/>
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen"/>
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose"/>
<exclude name="Squiz.Scope.MethodScope.Missing"/>
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.Indent"/>
<exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine"/>
<exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed"/>
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpaceBeforeCloseBrace"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment"/>
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses"/>
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
<exclude name="PSR2.Files.EndFileNewline.NoneFound"/>
<exclude name="PSR2.Files.EndFileNewline.TooMany"/>
</rule>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
Итак, я спрашиваю, как я запускаю PHPCBF для, например, "Generic.PHP.LowerCaseConstant.Found".
До сих пор я пробовал следующее:
./www/vendor/bin/phpcbf www/application --sniffs=Generic.PHP.LowerCaseConstant.Found
./www/vendor/bin/phpcbf www/application --sniffs=Generic.Sniffs.PHP.LowerCaseConstant.Found
./www/vendor/bin/phpcbf www/application --sniffs=Generic.Sniffs.PHP.LowerCaseConstantSniff
./www/vendor/bin/phpcbf www/application --standard=Generic --sniffs=Generic.Sniffs.PHP.LowerCaseConstantSniff
./www/vendor/bin/phpcbf -w www/application --standard=Generic --sniffs=Generic.Sniffs.PHP.LowerCaseConstantSniff
./www/vendor/bin/phpcbf -w www/application --standard=generic --sniffs=Generic.Sniffs.PHP.LowerCaseConstantSniff
Ни одно из них не является правильным. Они просто создают текст справки PHPCBF.
Я смог запустить phbcbf на конкретном сообщении об ошибке в определенном файле ньюс, используя правила исключения, как вы указали в приведенном выше примере кода. Вы можете использовать xml файл непосредственно в команде phbcbf
phpcbf --standard=path_to_your_ruleset_file.xml
Пытаться запустить phpcbf, выбрав определенные нюансы в командной строке, не позволяло мне это делать.
Это было единственное правило, которое я имел в файле настраиваемых правил
<rule ref="Drupal.Commenting.FunctionComment">
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingFile"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/>
<exclude name="Drupal.Commenting.FunctionComment.WrongStyle"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentNewLine"/>
<exclude name="Drupal.Commenting.FunctionComment.IncorrectParamVarName"/>
<exclude name="Drupal.Commenting.FunctionComment.SpacingAfter"/>
<exclude name="Drupal.Commenting.FunctionComment.SpacingAfterParamType"/>
</rule>
Обратите внимание, что я явно не исключал все возможные ошибки, но вместо этого исключил только те ошибки, которые присутствовали в кодовой базе, для которой я запускал это. Единственная ошибка, которую я хотел исправить, - это тот, который я не включил в список исключений.
Вы можете исправить ошибки всего за один раз, а не конкретное сообщение об ошибке. Таким образом, вам придется запускать:
./www/vendor/bin/phpcbf www/application --standard=Generic --sniffs=Generic.PHP.LowerCaseConstant
Чтобы исправить все ошибки, о которых сообщалось в Generic.PHP.LowerCaseConstant
с Generic.PHP.LowerCaseConstant