3

我正在尝试在 phpcs 中添加 Drupal 编码标准。
我可以运行 Drupal 标准 phpcs --standard=Drupal

现在我想用 Sonar 执行相同的标准。

在 Sonar 中,我可以在rules.xml扩展中添加所有规则集的键,但是如何获取这些规则的所有键?

我可以使用文件和文件夹结构识别一些键,*sniff.php但我不确定我是否得到了所有这些键。

谁能建议一种自动化的方法来获取特定标准中的所有可用规则?

4

2 回答 2

2

您必须识别 Drupal 标准引用的所有嗅探,并在 Sonar(通过 Web UI)中创建一个引用它们的配置文件。然后您激活此配置文件作为默认配置文件,您就可以进行分析了。

于 2012-05-31T12:15:39.290 回答
0

从帮助消息中可能不清楚,但命令行工具对此有一个标志:

-e    Explain a standard by showing the sniffs it includes

因此,要显示 Drupal 编码标准中的所有嗅探,可以运行:

phpcs -e --standard=Drupal

输出将是这样的:

The vendor/drupal/coder/coder_sniffer/Drupal/ standard contains 111 sniffs

Drupal (68 sniffs)
------------------
  Drupal.Array.Array
  Drupal.Array.DisallowLongArraySyntax
  Drupal.CSS.ClassDefinitionNameSpacing
  Drupal.CSS.ColourDefinition
  Drupal.Classes.ClassCreateInstance
  Drupal.Classes.ClassDeclaration
  Drupal.Classes.FullyQualifiedNamespace
  Drupal.Classes.InterfaceName
  Drupal.Classes.PropertyDeclaration
  Drupal.Classes.UnusedUseStatement
  Drupal.Classes.UseLeadingBackslash
  Drupal.Commenting.ClassComment
  Drupal.Commenting.DataTypeNamespace
  Drupal.Commenting.DocCommentAlignment
  Drupal.Commenting.DocComment
  Drupal.Commenting.DocCommentStar
  Drupal.Commenting.FileComment
  Drupal.Commenting.FunctionComment
  Drupal.Commenting.HookComment
  Drupal.Commenting.InlineComment
  Drupal.Commenting.PostStatementComment
  Drupal.Commenting.VariableComment
  Drupal.ControlStructures.ControlSignature
  Drupal.ControlStructures.ElseIf
  Drupal.ControlStructures.InlineControlStructure
  Drupal.Files.EndFileNewline
  Drupal.Files.FileEncoding
  Drupal.Files.LineLength
  Drupal.Files.TxtFileLineLength
  Drupal.Formatting.MultiLineAssignment
  Drupal.Formatting.MultipleStatementAlignment
  Drupal.Formatting.SpaceInlineIf
  Drupal.Formatting.SpaceUnaryOperator
  Drupal.Functions.DiscouragedFunctions
  Drupal.Functions.FunctionDeclaration
  Drupal.InfoFiles.AutoAddedKeys
  Drupal.InfoFiles.ClassFiles
  Drupal.InfoFiles.DuplicateEntry
  Drupal.InfoFiles.Required
  Drupal.Methods.MethodDeclaration
  Drupal.NamingConventions.ValidClassName
  Drupal.NamingConventions.ValidFunctionName
  Drupal.NamingConventions.ValidGlobal
  Drupal.NamingConventions.ValidVariableName
  Drupal.Scope.MethodScope
  Drupal.Semantics.ConstantName
  Drupal.Semantics.EmptyInstall
  Drupal.Semantics.FunctionAlias
  Drupal.Semantics.FunctionT
  Drupal.Semantics.FunctionWatchdog
  Drupal.Semantics.InstallHooks
  Drupal.Semantics.LStringTranslatable
  Drupal.Semantics.PregSecurity
  Drupal.Semantics.RemoteAddress
  Drupal.Semantics.TInHookMenu
  Drupal.Semantics.TInHookSchema
  Drupal.Strings.UnnecessaryStringConcat
  Drupal.WhiteSpace.CloseBracketSpacing
  Drupal.WhiteSpace.Comma
  Drupal.WhiteSpace.EmptyLines
  Drupal.WhiteSpace.Namespace
  Drupal.WhiteSpace.ObjectOperatorIndent
  Drupal.WhiteSpace.ObjectOperatorSpacing
  Drupal.WhiteSpace.OpenBracketSpacing
  Drupal.WhiteSpace.OpenTagNewline
  Drupal.WhiteSpace.OperatorSpacing
  Drupal.WhiteSpace.ScopeClosingBrace
  Drupal.WhiteSpace.ScopeIndent

Generic (13 sniffs)
-------------------
  Generic.CodeAnalysis.UselessOverridingMethod
  Generic.Files.ByteOrderMark
  Generic.Files.LineEndings
  Generic.Formatting.SpaceAfterCast
  Generic.Functions.FunctionCallArgumentSpacing
  Generic.Functions.OpeningFunctionBraceKernighanRitchie
  Generic.NamingConventions.ConstructorName
  Generic.NamingConventions.UpperCaseConstantName
  Generic.PHP.DeprecatedFunctions
  Generic.PHP.DisallowShortOpenTag
  Generic.PHP.LowerCaseKeyword
  Generic.PHP.UpperCaseConstant
  Generic.WhiteSpace.DisallowTabIndent

MySource (1 sniffs)
-------------------
  MySource.Debug.DebugCode

PEAR (3 sniffs)
---------------
  PEAR.Files.IncludingFile
  PEAR.Functions.FunctionCallSignature
  PEAR.Functions.ValidDefaultValue

PSR2 (2 sniffs)
---------------
  PSR2.Namespaces.NamespaceDeclaration
  PSR2.Namespaces.UseDeclaration

Squiz (23 sniffs)
-----------------
  Squiz.Arrays.ArrayBracketSpacing
  Squiz.Arrays.ArrayDeclaration
  Squiz.CSS.ClassDefinitionClosingBraceSpace
  Squiz.CSS.ClassDefinitionOpeningBraceSpace
  Squiz.CSS.ColonSpacing
  Squiz.CSS.DisallowMultipleStyleDefinitions
  Squiz.CSS.EmptyClassDefinition
  Squiz.CSS.EmptyStyleDefinition
  Squiz.CSS.Indentation
  Squiz.CSS.MissingColon
  Squiz.CSS.SemicolonSpacing
  Squiz.ControlStructures.ForEachLoopDeclaration
  Squiz.ControlStructures.ForLoopDeclaration
  Squiz.ControlStructures.SwitchDeclaration
  Squiz.Functions.FunctionDeclarationArgumentSpacing
  Squiz.Functions.MultiLineFunctionDeclaration
  Squiz.PHP.LowercasePHPFunctions
  Squiz.PHP.NonExecutableCode
  Squiz.Strings.ConcatenationSpacing
  Squiz.WhiteSpace.FunctionSpacing
  Squiz.WhiteSpace.LanguageConstructSpacing
  Squiz.WhiteSpace.SemicolonSpacing
  Squiz.WhiteSpace.SuperfluousWhitespace

Zend (1 sniffs)
---------------
  Zend.Files.ClosingTag
于 2012-09-20T14:22:19.910 回答