Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
// Version of the setting file. Always 0.2
"version": "0.2",
// language - current active spelling language
"language": "en-US",
"ignorePaths": [
"composer.*",
"tests",
"vendor"
],
"dictionaries": [
"dictionary",
"drupal",
"companies",
"fonts",
"html",
"php",
"softwareTerms"
],
// words - list of words to be always considered correct
"words": [
"addtogroup",
"autoloader",
"codesniffer",
"ColourDefinitionSniff",
"CURLOPT_SSL_VERIFYPEER",
"datestamp",
"defgroup",
"drush",
"endcode",
"endlink",
"heredocs",
"Kernighan",
"Komodo",
"multibyte",
"Netbeans",
"phpcbf",
"Ritchie",
"ruleset",
"sirbrillig",
"squizlabs",
"Squiz",
"startOfLine",
"Superglobal",
"T_ASPERAND",
"T_COLOUR",
"T_CONSTANT_ENCAPSED_STRING",
"T_DNUMBER",
"T_LNUMBER",
"T_NULLSAFE_OBJECT_OPERATOR",
"tableselect",
"ungreedy",
"unserialized",
"webform"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
// For example "hte" should be "the"
"flagWords": [
"hte"
]
}
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.cspell.json export-ignore
/.gitattributes export-ignore
/.travis.yml export-ignore
/README.md export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ jobs:
if: ${{ matrix.extra-tests == '1' }}
run: ./vendor/bin/phpstan analyse

- name: Run Cspell
if: ${{ matrix.extra-tests == '1' }}
uses: streetsidesoftware/cspell-action@v6
with:
incremental_files_only: false

- name: Checkout Drupal core
if: ${{ matrix.extra-tests == '1' }}
uses: actions/checkout@v3
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ phpcs.xml.dist file in your project like this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="myproject">
<description>PHP CodeSniffer configuration for myproject development.</description>
<ruleset name="example">
<description>PHP CodeSniffer configuration for example development.</description>
<!-- Check all files in the current directory and below. -->
<file>.</file>
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>
Expand Down Expand Up @@ -139,7 +139,7 @@ Then execute the coding standards checker on Coder itself:

Then execute static analysis:

./vendor/bin/phpstan analyse
./vendor/bin/phpstan


## Contributing
Expand All @@ -154,6 +154,8 @@ Thank you!

## Maintainers

[//]: # cspell:ignore Pieter Frenssen Welford

- Pieter Frenssen, https://www.drupal.org/u/pfrenssen
- Michael Welford, https://www.drupal.org/u/mikejw
- Klaus Purer, https://www.drupal.org/u/klausi
Expand Down

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions coder_sniffer/Drupal/Docs/Functions/ValidDefaultValueStandard.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function process(File $phpcsFile, $stackPtr)
&& in_array($tokens[($i - 1)]['code'], [T_WHITESPACE, T_COMMA]) === false
) {
$error = 'Selectors must be on a single line';
$fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine');
// cspell:ignore SeletorSingleLine
$fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($i, str_replace($phpcsFile->eolChar, ' ', $tokens[$i]['content']));
}
Expand Down
12 changes: 6 additions & 6 deletions coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* \Drupal\Sniffs\CSS\ColourDefinitionSniff.
*
* Ensure colours are defined in lower-case.
* Ensure colors are defined in lower-case.
*
* @category PHP
* @package PHP_CodeSniffer
Expand Down Expand Up @@ -56,14 +56,14 @@ public function register()
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$colour = $tokens[$stackPtr]['content'];
$color = $tokens[$stackPtr]['content'];

$expected = strtolower($colour);
if ($colour !== $expected) {
$error = 'CSS colours must be defined in lowercase; expected %s but found %s';
$expected = strtolower($color);
if ($color !== $expected) {
$error = 'CSS colors must be defined in lowercase; expected %s but found %s';
$data = [
$expected,
$colour,
$color,
];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data);
if ($fix === true) {
Expand Down
4 changes: 2 additions & 2 deletions coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public function process(File $phpcsFile, $stackPtr)
}

$previous = $phpcsFile->findPrevious(T_WHITESPACE, ($openingBrace - 1), null, true);
$decalrationLine = $tokens[$previous]['line'];
$declarationLine = $tokens[$previous]['line'];
$braceLine = $tokens[$openingBrace]['line'];

$lineDifference = ($braceLine - $decalrationLine);
$lineDifference = ($braceLine - $declarationLine);

if ($lineDifference > 0) {
$error = 'Opening brace should be on the same line as the declaration';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use PHP_CodeSniffer\Util\Tokens;

/**
* Laregely copied from
* Largely copied from
* \PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\PropertyDeclarationSniff to have a fixer
* for the var keyword.
*
Expand Down
10 changes: 3 additions & 7 deletions coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
* Checks that comment doc blocks exist on classes, interfaces and traits. Largely
* copied from PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\ClassCommentSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class ClassCommentSniff implements Sniff
{
Expand Down
1 change: 1 addition & 0 deletions coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function process(File $phpcsFile, $stackPtr)
// automatic fixes for Drupal core, and if the project is missing we are
// assuming it is Drupal core. Deprecations for contrib projects are much
// less frequent and faults can be corrected manually.
// cspell:ignore xdev
preg_match('/^(.*)(as of|in) (drupal|)( |:|)+([\d\.\-xdev\?]+)(,| |. |)(.*)(removed|removal)([ |from|before|in|the]*) (drupal|)( |:|)([\d\-\.xdev]+)( |,|$)+(?:release|)(?:[\.,])*(.*)$/i', $text1, $matchesFix);

if (count($matchesFix) >= 12) {
Expand Down
9 changes: 5 additions & 4 deletions coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ public function process(File $phpcsFile, $stackPtr)
// Break out the tags into groups and check alignment within each.
// A tag group is one where there are no blank lines between tags.
// The param tag group is special as it requires all @param tags to be inside.
$tagGroups = [];
$tagGroups = [];
// cspell:ignore groupid
$groupid = 0;
$paramGroupid = null;
$currentTag = null;
Expand Down Expand Up @@ -506,12 +507,12 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end foreach

// If there is a param group, it needs to be first; with the exception of
// @code, @todo and link tags.
// If there is a param group, it needs to be first; with the exception
// of @code, @todo and link tags.
if ($paramGroupid !== null && $paramGroupid !== 0
&& in_array($tokens[$tokens[$commentStart]['comment_tags'][0]]['content'], ['@code', '@todo', '@link', '@endlink', '@codingStandardsIgnoreStart']) === false
// In JSDoc we can have many other valid tags like @function or
// @constructor before the param tags.
// tags like @constructor before the param tags.
&& $phpcsFile->tokenizerType !== 'JS'
) {
$error = 'Parameter tags must be defined first in a doc comment';
Expand Down
7 changes: 4 additions & 3 deletions coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function process(File $phpcsFile, $stackPtr)
$commentStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);

// Files containing exactly one class, interface or trait are allowed to
// ommit a file doc block. If a namespace is used then the file comment must
// omit a file doc block. If a namespace is used then the file comment must
// be omitted.
$oopKeyword = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], $stackPtr);
if ($oopKeyword !== false) {
Expand Down Expand Up @@ -159,7 +159,7 @@ public function process(File $phpcsFile, $stackPtr)
$next = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), null, true);

// If there is no @file tag and the next line is a function or class
// definition then the file docblock is mising.
// definition then the file docblock is missing.
if ($tokens[$next]['line'] === ($tokens[$commentEnd]['line'] + 1)
&& $tokens[$next]['code'] === T_FUNCTION
) {
Expand Down Expand Up @@ -225,7 +225,8 @@ public function process(File $phpcsFile, $stackPtr)
&& $tokens[$next]['code'] === T_CLOSE_TAG
) {
$error = 'There must be no blank line after the file comment in a template';
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'TeamplateSpacingAfterComment');
// cspell:ignore TeamplateSpacingAfterComment
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'TeamplateSpacingAfterComment');
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$uselessLine = ($commentEnd + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FunctionCommentSniff implements Sniff
'Bool' => 'bool',
'Int' => 'int',
'Integer' => 'int',
// cspell:ignore TRUEFALSE
'TRUEFALSE' => 'bool',
];

Expand Down Expand Up @@ -440,6 +441,7 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
$comment .= ' '.$tokens[$i]['content'];
if ($indent < 3) {
$error = 'Throws comment indentation must be 3 spaces, found %s spaces';
// cspell:ignore TrhowsCommentIndentation
$phpcsFile->addError($error, $i, 'TrhowsCommentIndentation', [$indent]);
}
}
Expand All @@ -456,7 +458,7 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
return;
}

// Starts with a capital letter and ends with a fullstop.
// Starts with a capital letter and ends with a full stop.
$firstChar = $comment[0];
if (strtoupper($firstChar) !== $firstChar) {
$error = '@throws tag comment must start with a capital letter';
Expand Down Expand Up @@ -769,7 +771,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
$content .= $param['var'];
$content .= str_repeat(' ', $param['var_space']);
// At this point there is no description expected in the
// @param line so no need to append comment.
// param line so no need to append comment.
$phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content);

// Fix up the indent of additional comment lines.
Expand Down
4 changes: 2 additions & 2 deletions coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public function process(File $phpcsFile, $stackPtr)
) {
$phpcsFile->addWarning('Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."', $short, 'HookCommentFormat');
} else {
// Check that a hook implementation does not duplicate @param and
// @return documentation.
// Check that a hook implementation does not duplicate param and
// return documentation.
foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) {
if ($tokens[$tag]['content'] === '@param') {
$warn = 'Hook implementations should not duplicate @param documentation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function process(File $phpcsFile, $stackPtr)
// Also, when the comment starts with cspell: don't check the end of the
// comment.
if (preg_match('/^\p{L}/u', $commentText) === 1
&& preg_match('/(cspell|spell\-checker):ignore/i', $commentText) === 0
&& preg_match('/(cspell|spell\-checker):/i', $commentText) === 0
) {
$commentCloser = $commentText[(strlen($commentText) - 1)];
$acceptedClosers = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Parses and verifies class property doc comments.
*
* Laregely copied from
* Largely copied from
* \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\VariableCommentSniff.
*
* @category PHP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* \Drupal\Sniffs\ControlStructures\InlineControlStructureSniff.
*
* Verifies that inline control statements are not present. This Sniff overides
* Verifies that inline control statements are not present. This Sniff overrides
* the generic sniff because Drupal template files may use the alternative
* syntax for control structures. See
* http://www.php.net/manual/en/control-structures.alternative-syntax.php
Expand Down
Loading
Loading