Forked from geerlingguy/SonarDrupalKeyGenerator.php
Last active
June 28, 2019 11:06
-
-
Save Eli-TW/7499132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Generate rules for Drupal Coding Standards Sniffs. | |
* | |
* SonarQube requires manually-entered PHP CodeSniffer rules if you use anything | |
* outside of the standard set of rules. In this case, there are a bunch of | |
* Drupal-specific sniffs that we'd like to use. | |
* | |
* This file takes an array of sniff keys and generates the appropriate XML to | |
* pasted into the sonar.phpCodesniffer.customRules.definition setting inside | |
* Sonar's Configuration area. | |
* | |
* After pasting the generated XML, you need to restart the SonarQube server, | |
* then enable all the rules you want to use in a quality profile. | |
* | |
* @see http://docs.codehaus.org/display/SONAR/PHP+Custom+Coding+Rules | |
* @see http://docs.codehaus.org/display/SONAR/Quality+Profiles | |
*/ | |
// Create an XML document and open the rules tag. | |
print '<?xml version="1.0" encoding="UTF-8"?> | |
<rules> | |
'; | |
// Define the missing php_codesniffer keys. | |
$keys = array( | |
'Drupal.Commenting.FunctionComment.ParamCommentNewLine', | |
'Drupal.Commenting.FunctionComment.HookReturnDoc', | |
'Drupal.Commenting.FunctionComment.MissingReturnType', | |
'Drupal.Commenting.FunctionComment.HookParamDoc', | |
'Drupal.Commenting.FunctionComment.ParamNameNoMatch', | |
'Drupal.Commenting.FunctionComment.SpacingBeforeParamType', | |
'Drupal.Commenting.InlineComment.SpacingBefore', | |
'Drupal.Commenting.FileComment', | |
'Drupal.ControlStructures.InlineControlStructure.NotAllowed', | |
'Drupal.Commenting.FunctionComment', | |
'Drupal.Files.LineLength.TooLong', | |
'Drupal.Semantics.FunctionCall.LArg', | |
'Drupal.WhiteSpace.OperatorSpacing.SpacingAfter', | |
'Drupal.Formatting.DisallowCloseTag.FinalClose', | |
'Drupal.WhiteSpace.OpenBracketSpacing.OpeningWhitespace', | |
'Drupal.Commenting.FileComment.DescriptionMissing', | |
'Drupal.Commenting.InlineComment.NoSpaceBefore', | |
'Drupal.Strings.ConcatenationSpacing.Missing', | |
'Drupal.Commenting.InlineComment.WrongStyle', | |
'Drupal.Semantics.Br.XHTMLBr', | |
'Drupal.Strings.UnnecessaryStringConcat.Found', | |
'Drupal.Commenting.FunctionComment.Empty', | |
'Drupal.NamingConventions.ValidClassName.NoUnderscores', | |
'Drupal.Commenting.FileComment.SpacingAfter', | |
'Drupal.Commenting.FunctionComment.$InReturnType', | |
'Drupal.Array.Array.LongLineDeclaration', | |
'Drupal.Commenting.DocCommentAlignment.SpaceBeforeAsterisk', | |
'Drupal.Commenting.FunctionComment.ShortSingleLine', | |
'Drupal.Semantics.FunctionCall.NotLiteralString', | |
'Drupal.Commenting.FunctionComment.ShortFullStop', | |
'Drupal.Commenting.InlineComment.NotCapital', | |
'Drupal.Commenting.InlineComment.SpacingAfter', | |
'Drupal.Commenting.FileComment.WrongStyle', | |
'Drupal.Formatting.SpaceInlineIf.NoSpaceAfter', | |
'Drupal.Commenting.FunctionComment.ShortNotCapital', | |
'Drupal.Array.Array.ArrayIndentation', | |
'Drupal.Commenting.FunctionComment.MissingParamType', | |
'Drupal.ControlStructures.ElseIf', | |
'Drupal.Array.Array', | |
'Drupal.ControlStructures.TemplateControlStructure.CurlyBracket', | |
'Drupal.Array.Array.ArrayClosingIndentation', | |
'Drupal.WhiteSpace.ScopeIndent.IncorrectExact', | |
'Drupal.ControlStructures.ControlSignature', | |
'Drupal.Formatting.SpaceInlineIf.NoSpaceBefore', | |
'Drupal.Semantics.EmptyInstall.EmptyInstall', | |
'Drupal.Commenting.FunctionComment.ShortStartSpace', | |
'Drupal.WhiteSpace.OperatorSpacing.NoSpaceAfter', | |
'Drupal.ControlStructures.ElseCatchNewline.ElseNewline', | |
'Drupal.Commenting.InlineComment.InvalidEndChar', | |
'Drupal.WhiteSpace.CloseBracketSpacing.ClosingWhitespace', | |
'Drupal.Semantics.TInHookMenu.TFound', | |
'Drupal.Commenting.FunctionComment.Missing', | |
'Drupal.Semantics.FunctionCall.EmptyString', | |
'Drupal.Semantics.FunctionCall.ConstantStart', | |
'Drupal.Formatting.MultiLineAssignment', | |
'Drupal.Commenting.InlineComment.Empty', | |
'Drupal.NamingConventions.ValidVariableName', | |
'Drupal.Commenting.DocCommentAlignment.BlankLine', | |
'Drupal.WhiteSpace.OperatorSpacing.NoSpaceBefore', | |
'Drupal.WhiteSpace.EmptyLines.EmptyLines', | |
'Drupal.WhiteSpace.FileEnd.FileEnd', | |
'Drupal.WhiteSpace.ScopeIndent.Incorrect', | |
'Drupal.WhiteSpace.ScopeClosingBrace.BreakIdent', | |
'Drupal.WhiteSpace.ObjectOperatorSpacing.After', | |
'Drupal.NamingConventions.ValidClassName.StartWithCaptial', | |
'Drupal.WhiteSpace.ScopeClosingBrace.Indent', | |
'Squiz.WhiteSpace.SuperfluousWhitespace.EndLine', | |
'Drupal.Commenting.FileComment.Missing', | |
'Squiz.WhiteSpace.SuperfluousWhitespace.StartFile', | |
'Generic.Functions.OpeningFunctionBraceKernighanRitchie.SpaceAfterBracket', | |
'Drupal.WhiteSpace.ObjectOperatorSpacing.Before', | |
); | |
// Loop through the keys and print them as rules. | |
foreach ($keys as $key) { | |
$parts = explode('.', $key); | |
$rule = end($parts); | |
print ' <rule key="' . $key . '" priority="MAJOR"> | |
<name>' . $key . '</name> | |
<configKey>' . strtoupper($rule) . '</configKey> | |
<description>' . $key . '</description> | |
</rule> | |
'; | |
} | |
// Close the rules tag. | |
print '</rules>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment