Question

I am trying to add the Drupal Coding standards in phpcs.
I can run the Drupal Standards with phpcs --standard=Drupal

Now I want to execute the same standards with Sonar.

In Sonar I can add the keys of all the rulesets in the rules.xml extension, but how can I get all the keys for these rules?

I can identify some of the keys using the *sniff.php files and the folder structure but I'm not sure I am getting all of them.

Can anyone suggest an automated way to get all the rules available in a particular standard?

Was it helpful?

Solution

You have to identify all the sniffs referenced by the Drupal standard and create a profile in Sonar (through the Web UI) that references them all. Then you activate this profile as the default one, and you're ready for an analysis.

OTHER TIPS

It may not be clear from the help message but the command-line tools has a flag for this:

-e    Explain a standard by showing the sniffs it includes

So to show all of the sniffs in the Drupal coding standard one would run:

phpcs -e --standard=Drupal

The output would be something like this:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top