-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathNoInlineSniff.php
More file actions
68 lines (61 loc) · 2.21 KB
/
NoInlineSniff.php
File metadata and controls
68 lines (61 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
namespace MoodleHQ\MoodleCS\moodle\Sniffs\Commenting;
use MoodleHQ\MoodleCS\moodle\Util\MoodleUtil;
use MoodleHQ\MoodleCS\moodle\Util\Docblocks;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
/**
* Checks for the presence of inline docblocks.
*
* Inline docblocks are those which start with three ///.
*
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class NoInlineSniff implements Sniff
{
/**
* Register for open tag (only process once per file).
*/
public function register() {
return [
T_COMMENT,
];
}
/**
* Processes php files and perform various checks with file.
*
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position in the stack.
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
if (strpos($token['content'], '///') === 0) {
$fix = $phpcsFile->addFixableError(
'Invalid inline comment found. Comments should not start with three slashes (///).',
$stackPtr,
'InvalidInlineComment'
);
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($stackPtr, preg_replace('@^/{2,}@', '//', $token['content']));
$phpcsFile->fixer->endChangeset();
}
}
}
}