【问题标题】:How to get all the keys for of a PHP Codesniffer Ruleset to use with Sonar?如何获取 PHP Codesniffer 规则集的所有密钥以与 Sonar 一起使用?
【发布时间】:2018-07-25 15:39:28
【问题描述】:

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

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

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

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

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

【问题讨论】:

标签: php sonarqube codesniffer


【解决方案1】:

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

【讨论】:

  • Fabrice,谢谢你的回复,你没看明白我想创建个人资料,我没有。声纳的 php 插件中没有可用的规则。
  • 嗯,这就是我所说的:你必须“在 Sonar 中创建配置文件”......当你说没有可用的规则时,你的意思是“没有规则在all”(在这种情况下您的安装有问题)或“没有 Drupal 相关规则”(在这种情况下您必须 add them like it is explained on the Wiki)?
  • 再次感谢您的回复,我知道我必须使用docs.codehaus.org/display/SONAR/Extend+PHP+coding+rules 添加该规则并且我已经做到了。对于一些已知的。但我想要的是规则的关键价值。我身边一个都没有。并且没有可用的列表。
  • 好的,我认为 Wiki 上缺少文档的某些部分:我更新了页面以解释如何找到要添加到 XML 文件中的特定规则的“键” .您必须手动完成(但也许 PHPCodeSniffer 在某处提供了 Drupal 标准嗅探的列表?)。
  • 这就是那里需要的东西,我确实也找到了这种方式,但我仍然认为这个过程必须有一些自动化。
【解决方案2】:

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

-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

【讨论】:

  • 我也在shell脚本上创建了相同的。
  • @DhvanitDave 如果你还有它,我很想看看那个脚本的代码。
猜你喜欢
  • 1970-01-01
  • 2017-02-06
  • 2017-06-08
  • 2011-07-06
  • 1970-01-01
  • 2011-08-02
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多