Skip to content

Drupal standard

The sniffs of Coder's own Drupal standard, by category. The sniffs taken from other standards are on Sniffs from other standards.

Arrays

Sniff Handled by
Drupal.Arrays.Array mago format, partly

Drupal.Arrays.Array

The drupal preset writes the trailing comma, the indentation and the line breaks of a long array.

Codes Handled by
ArrayClosingIndentation, ArrayIndentation mago format, partly
CommaLastItem, LongLineDeclaration mago format
  • ArrayClosingIndentation: An array that opens on a continuation line gets the indent of the statement's first line. Coder counts from the line the array opens on, and reports its items and closing bracket.
  • ArrayIndentation: When the value after => is a ?? chain that breaks over lines, the formatter writes the next lines at the key's indent. Coder wants them one level deeper. The formatter also writes the broken && or || condition of a ternary in an array element at the element's indent, and breaks an array at a block comment between its elements, and Coder reports both.

Attributes

Sniff Handled by
Drupal.Attributes.ValidHookName drupal/hook-attribute-name

Classes

Sniff Handled by
Drupal.Classes.ClassDeclaration mago format, drupal/post-statement-comment, Mago parse, partly
Drupal.Classes.FullyQualifiedNamespace drupal/fully-qualified-name
Drupal.Classes.PropertyDeclaration drupal/property-visibility
Drupal.Classes.UseGlobalClass drupal/redundant-use

Drupal.Classes.ClassDeclaration

Codes Handled by
BraceOnNewLine, CloseBraceAfterBody, ExtendsIndentation, ExtendsInterfaceSameLine, ExtendsLine, FirstExtendsInterfaceSameLine, FirstInterfaceSameLine, ImplementsLine, InterfaceSameLine, InterfaceWrongIndent, NewlineBeforeKeyword, NoSpaceBeforeName, SpaceAfterKeyword, SpaceAfterName, SpaceBeforeBrace, SpaceBeforeComma, SpaceBeforeExtends, SpaceBeforeImplements, SpaceBeforeKeyword, SpaceBeforeName mago format
CloseBraceSameLine drupal/post-statement-comment, mago format, partly
ContentAfterBrace mago format, drupal/post-statement-comment
MissingBrace Mago parse
  • CloseBraceSameLine: drupal/post-statement-comment reports a comment after the closing brace of a class, such as } // end class. The formatter moves code after the brace to a line of its own and removes trailing spaces. A ?> after the brace isn't reported when HTML follows it. At the end of a file, no-closing-tag reports the tag and the formatter removes it.
  • MissingBrace: A class without braces doesn't parse. Mago reports a parse error, and the formatter skips the file.

Commenting

Sniff Handled by
Drupal.Commenting.ClassComment drupal/missing-class-comment, drupal/class-comment
Drupal.Commenting.Deprecated drupal/deprecated-tag
Drupal.Commenting.DocComment drupal/doc-comment, Mago no-empty-comment, drupal/long-description-punctuation, drupal/doc-sentence, drupal/missing-summary, drupal/doc-tag-groups, partly
Drupal.Commenting.DocCommentAlignment drupal/doc-comment, mago format
Drupal.Commenting.DocCommentLongArraySyntax drupal/doc-comment-array-syntax
Drupal.Commenting.DocCommentStar mago format
Drupal.Commenting.FileComment drupal/file-comment, drupal/missing-file-comment, mago format, nothing, partly
Drupal.Commenting.FunctionComment drupal/doc-tag-types, drupal/doc-see-tag, mago analyze (invalid-param-tag), drupal/doc-tag-descriptions, drupal/doc-type-name, mago analyze (missing-return-statement), mago analyze (invalid-return-statement), mago analyze (invalid-generator-return-type), drupal/missing-function-comment, drupal/doc-sentence, drupal/doc-tag-layout, drupal/function-comment
Drupal.Commenting.GenderNeutralComment drupal/gender-neutral-comment
Drupal.Commenting.HookComment drupal/hook-comment
Drupal.Commenting.InlineComment drupal/inline-comment, Mago no-empty-comment, drupal/inline-comment-punctuation, drupal/inline-comment-blank-line, mago format, partly
Drupal.Commenting.InlineVariableComment drupal/inline-variable-comment
Drupal.Commenting.PostStatementComment drupal/post-statement-comment
Drupal.Commenting.TodoComment drupal/todo-comment
Drupal.Commenting.VariableComment drupal/variable-comment, drupal/doc-see-tag, drupal/doc-type-name, drupal/missing-property-comment, partly

Drupal.Commenting.ClassComment

Codes Handled by
Missing drupal/missing-class-comment
Short, SpacingAfter, WrongStyle drupal/class-comment

Drupal.Commenting.DocComment

Codes Handled by
ContentAfterOpen, InheritDocWithoutBraces, ShortStartSpace, SpacingAfter, SpacingBeforeShort, SpacingBetween, TagValueIndent, WrongEnd drupal/doc-comment
Empty Mago no-empty-comment
LongFullStop drupal/long-description-punctuation
LongNotCapital, ShortFullStop, ShortNotCapital, ShortSingleLine drupal/doc-sentence
MissingShort drupal/missing-summary, partly
ParamGroup, ParamNotFirst, SpacingAfterTagGroup, SpacingBeforeTags, TagGroupSpacing, TagsNotGrouped drupal/doc-tag-groups
  • MissingShort: A phpcs: line above the summary is skipped, and the line below it counts as the summary. Coder reports it. In Drupal core, only the KernelTests, Unit and FunctionalJavascript directories are checked, as in core's phpcs.xml.dist.

Drupal.Commenting.DocCommentAlignment

Codes Handled by
NoSpaceAfterStar, SpaceAfterStar drupal/doc-comment
SpaceBeforeStar mago format

Drupal.Commenting.DocCommentStar

The formatter puts the star back on a docblock line that doesn't have one.

Drupal.Commenting.FileComment

Codes Handled by
FileTag, NamespaceNoFileDoc drupal/file-comment
Missing drupal/missing-file-comment
SpacingAfterComment drupal/file-comment, mago format
TemplateSpacingAfterComment nothing
WrongStyle drupal/file-comment, partly
  • TemplateSpacingAfterComment: A blank line between the file docblock and the ?> that follows it, in a file of any extension. Not ported.
  • WrongStyle: A // @codingStandardsIgnoreFile comment at the start of a file isn't reported under this code. drupal/missing-file-comment reports the file instead. The fix converts a comment only when a blank line follows it.

Drupal.Commenting.FunctionComment

Codes Handled by
DuplicateReturn, InvalidThrows, MissingParamName, MissingParamType, MissingReturnType drupal/doc-tag-types
EmptySees, SeeAdditionalText, SeePunctuation drupal/doc-see-tag
ExtraParamComment mago analyze (invalid-param-tag), drupal/doc-tag-descriptions
IncorrectParamVarName, InvalidReturn drupal/doc-type-name
InvalidNoReturn mago analyze (missing-return-statement)
InvalidReturnNotVoid mago analyze (invalid-return-statement)
InvalidReturnVoid mago analyze (invalid-return-statement), mago analyze (invalid-generator-return-type)
Missing drupal/missing-function-comment
MissingParamComment, MissingReturnComment, ParamMissingDefinition drupal/doc-tag-descriptions
ParamCommentFullStop, ParamCommentNotCapital, ThrowsNoFullStop, ThrowsNotCapital drupal/doc-sentence
ParamCommentIndentation, ParamCommentNewLine, ParamNameDot, ParamTypeSpaces, ReturnCommentIndentation, ReturnTypeSpaces, ReturnVarName, SpacingAfterParamType, ThrowsComment, ThrowsCommentIndentation drupal/doc-tag-layout
ParamNameNoCaseMatch mago analyze (invalid-param-tag)
ParamNameNoMatch drupal/doc-tag-descriptions, mago analyze (invalid-param-tag)
SpacingAfter, WrongStyle drupal/function-comment
  • ExtraParamComment: mago analyze reports a @param whose name isn't a parameter, and drupal/doc-tag-descriptions one that repeats a name.
  • InvalidNoReturn: Reported on the function, not on the @return tag.
  • InvalidReturnVoid: Reported on the return statement, not on the @return void tag. A yield in such a function is reported as invalid-generator-return-type.
  • ParamNameNoMatch: drupal/doc-tag-descriptions reports a repeated @param, one that is out of order, and a & on a parameter that isn't taken by reference. mago analyze reports a name that isn't a parameter, and a ... on a parameter that isn't variadic.

Drupal.Commenting.InlineComment

Codes Handled by
DocBlock, NoSpaceBefore, NotCapital, SpacingBefore, TabBefore drupal/inline-comment
Empty Mago no-empty-comment
InvalidEndChar drupal/inline-comment-punctuation
SpacingAfter drupal/inline-comment-blank-line, mago format, partly
SpacingAfterAtFunctionEnd mago format
WrongStyle mago format, drupal/inline-comment
  • Empty: Mago's rule. It also reports an empty /* */, which Coder doesn't. Its fix leaves a blank line where phpcbf removes the line.
  • SpacingAfter: The rule leaves the blank line between a comment and a closing bracket to the formatter. Before the closing brace of a class, interface, trait or enum with members the formatter always writes one, and Coder reports it.

Drupal.Commenting.VariableComment

Codes Handled by
DuplicateVar, EmptyVar, InlineVariableName, MissingVar, VarOrder, WrongStyle drupal/variable-comment
EmptySees drupal/doc-see-tag
IncorrectVarType drupal/doc-type-name, partly
Missing drupal/missing-property-comment
  • IncorrectVarType: Coder runs the whole @var line, description included, through its type check, so it also reports a description with a ., ;, ! or = in it. The rule checks only the type.

ControlStructures

Sniff Handled by
Drupal.ControlStructures.ControlSignature mago format, partly

Drupal.ControlStructures.ControlSignature

Codes Handled by
NewlineAfterCloseBrace, SpaceAfterCloseBrace, SpaceAfterCloseParenthesis, SpaceAfterKeyword, SpaceBeforeSemicolon mago format
NewlineAfterOpenBrace mago format, partly
  • NewlineAfterOpenBrace: The formatter writes a match with one arm on one line, and Coder reports that line under this code and under OpenBracketSpacing.OpeningWhitespace, CloseBracketSpacing.ClosingWhitespace and ScopeClosingBrace.Line.

Files

Sniff Handled by
Drupal.Files.EndFileNewline mago format
Drupal.Files.FileEncoding drupal/file-encoding
Drupal.Files.LineLength drupal/comment-line-length
Drupal.Files.TxtFileLineLength phpcs

Drupal.Files.EndFileNewline

PHP files only. Coder also checks the last line of .txt, .md and .yml files. Mago doesn't read .txt and .md files, and the formatter skips .yml files.

Drupal.Files.FileEncoding

Coder also checks .txt and .md files, which aren't read by Mago, and the YAML files of a config directory, which drupal.mago.toml leaves out of the linter.

Drupal.Files.TxtFileLineLength

Checks .txt and .md files. Mago reads every file as PHP, and a <?php example in such a file gives parse errors, so they stay with phpcs.

Formatting

Sniff Handled by
Drupal.Formatting.MultiLineAssignment mago format
Drupal.Formatting.MultipleStatementAlignment mago format
Drupal.Formatting.SpaceInlineIf mago format
Drupal.Formatting.SpaceUnaryOperator mago format

Functions

Sniff Handled by
Drupal.Functions.DiscouragedFunctions drupal/discouraged-function, Mago no-eval
Drupal.Functions.MultiLineFunctionDeclaration mago format, drupal/parameter-blank-line

Drupal.Functions.MultiLineFunctionDeclaration

Codes Handled by
BraceOnNewLine, CloseBracketLine, ContentAfterBrace, FirstParamSpacing, Indent, MissingTrailingComma, NewlineBeforeOpenBrace, OneParamPerLine, SpaceAfterFunction, SpaceAfterUse, SpaceBeforeBrace, SpaceBeforeOpenBrace, SpaceBeforeOpenParen, SpaceBeforeSemicolon, SpaceBeforeUse, UseCloseBracketLine mago format
EmptyLine drupal/parameter-blank-line

InfoFiles

Sniff Handled by
Drupal.InfoFiles.AutoAddedKeys drupal/info-auto-added-keys
Drupal.InfoFiles.ClassFiles phpcs
Drupal.InfoFiles.DependenciesArray drupal/info-dependencies-array
Drupal.InfoFiles.DuplicateEntry phpcs
Drupal.InfoFiles.Required phpcs

Drupal.InfoFiles.AutoAddedKeys

The rule doesn't report the keys below the comment of the drupal.org packaging script. Coder reports them, so it reports every module installed by Composer. The rule reads .info.yml files only, and the same keys in a Drupal 7 .info file need phpcs. Both tools skip the version key of a file under a core directory. Coder looks for /core/ in the absolute path, and the rule in the path from the workspace.

Drupal.InfoFiles.ClassFiles

Checks the files[] lines of a Drupal 7 .info file, which phpcs reads only when its extensions include info. It doesn't read .info.yml files.

Drupal.InfoFiles.DuplicateEntry

Checks a Drupal 7 .info file, which phpcs reads only when its extensions include info. It doesn't read .info.yml files.

Drupal.InfoFiles.Required

Checks a Drupal 7 .info file, which phpcs reads only when its extensions include info. It doesn't read .info.yml files.

NamingConventions

Sniff Handled by
Drupal.NamingConventions.ValidClassName Mago class-name, Mago interface-name, Mago trait-name, Mago enum-name, drupal/class-name-acronym
Drupal.NamingConventions.ValidEnumCase drupal/enum-case-name
Drupal.NamingConventions.ValidFunctionName drupal/function-name, drupal/function-prefix, drupal/method-name-underscore, drupal/method-name
Drupal.NamingConventions.ValidGlobal drupal/global-variable
Drupal.NamingConventions.ValidVariableName drupal/property-name, drupal/variable-name

Drupal.NamingConventions.ValidClassName

Codes Handled by
NoUnderscores, StartWithCapital Mago class-name, Mago interface-name, Mago trait-name, Mago enum-name
NoUpperAcronyms drupal/class-name-acronym

Drupal.NamingConventions.ValidFunctionName

Core doesn't run the sniff.

Codes Handled by
InvalidName drupal/function-name
InvalidPrefix drupal/function-prefix
MethodDoubleUnderscore drupal/method-name-underscore
NotCamelCaps, ScopeNotCamelCaps drupal/method-name

Drupal.NamingConventions.ValidVariableName

Codes Handled by
LowerCamelName drupal/property-name
LowerStart drupal/variable-name

Scope

Sniff Handled by
Drupal.Scope.MethodScope drupal/method-visibility

Semantics

Sniff Handled by
Drupal.Semantics.ConstantName drupal/const-prefix, drupal/constant-prefix
Drupal.Semantics.EmptyInstall drupal/empty-install-hook
Drupal.Semantics.FunctionAlias Mago no-alias-function
Drupal.Semantics.FunctionT drupal/translatable-string, mago format, drupal/translatable-literal
Drupal.Semantics.FunctionTriggerError drupal/deprecation-message
Drupal.Semantics.FunctionWatchdog drupal/watchdog-message
Drupal.Semantics.InstallHooks drupal/install-hook-location
Drupal.Semantics.LStringTranslatable drupal/link-text-translatable
Drupal.Semantics.PregSecurity drupal/preg-security
Drupal.Semantics.RemoteAddress drupal/remote-address
Drupal.Semantics.TInHookMenu drupal/t-in-hook-menu
Drupal.Semantics.TInHookSchema drupal/t-in-hook-schema
Drupal.Semantics.UnsilencedDeprecation drupal/unsilenced-deprecation

Drupal.Semantics.ConstantName

Codes Handled by
ConstConstantStart drupal/const-prefix
ConstantStart drupal/constant-prefix

Drupal.Semantics.FunctionAlias

Mago's rule, on by default, with a fix that needs --potentially-unsafe. Its list of aliases doesn't have gzputs(), _() and pg_clientencoding(), which Coder reports.

Drupal.Semantics.FunctionT

Codes Handled by
BackslashDoubleQuote drupal/translatable-string, mago format
BackslashSingleQuote, Concat, EmptyString, EmptyT, WhiteSpace drupal/translatable-string
ConcatString, NotLiteralString drupal/translatable-literal

Drupal.Semantics.TInHookMenu

Coder also reports $this->t(), which the rule skips. The rule also reports \t(), which Coder skips.

Drupal.Semantics.TInHookSchema

Coder also reports $this->t(), which the rule skips. The rule also reports \t(), which Coder skips.

WhiteSpace

Sniff Handled by
Drupal.WhiteSpace.CloseBracketSpacing mago format, partly
Drupal.WhiteSpace.Comma mago format
Drupal.WhiteSpace.EmptyLines mago format
Drupal.WhiteSpace.ObjectOperatorIndent mago format
Drupal.WhiteSpace.ObjectOperatorSpacing mago format
Drupal.WhiteSpace.OpenBracketSpacing mago format, partly
Drupal.WhiteSpace.OpenTagNewline mago format
Drupal.WhiteSpace.ScopeClosingBrace mago format, partly
Drupal.WhiteSpace.ScopeIndent mago format, partly

Drupal.WhiteSpace.CloseBracketSpacing

The formatter writes <?php } for a closing brace after inline HTML, and Coder reports the space. Coder also reports the match with one arm that the formatter writes on one line, and the space that the formatter keeps before ) in a parameter list that holds only a comment, as in function f( /* $x */ ).

Drupal.WhiteSpace.OpenBracketSpacing

The formatter keeps a space between an opening bracket and a comment that follows it, as in foo( /* note */ $x), and Coder reports that space. Coder also reports the match with one arm that the formatter writes on one line, and the space it writes after ( in a parameter or argument list that holds only a comment, as in f( /* $x */ ).

Drupal.WhiteSpace.ScopeClosingBrace

Codes Handled by
BreakIndent mago format
Indent, Line mago format, partly
  • Indent: A closing brace after inline HTML, on a <?php } line, keeps the indent of the HTML. The formatter doesn't change it, and Coder reports it.
  • Line: The formatter writes a match with one arm on one line, and Coder reports its closing brace.

Drupal.WhiteSpace.ScopeIndent

The formatter writes the indentation.

Codes Handled by
Incorrect mago format
IncorrectExact mago format, partly
  • IncorrectExact: The formatter gives a comment between a break, return or throw and the next case the indent of the case body. Coder wants the indent of the case label there, and reports it. The formatter also indents a break after a return in the same case, which the analyzer reports as useless-control-flow. It writes an anonymous class with attributes with a line break after new and the body one more level in. Coder reports the body's indent, and the line break as LanguageConstructSpacing.IncorrectSingle.