Disable PHP code sniffer rules
I work with Moodle code a lot and on most (if not all) projects codesniffer is employed to ensure a degree of coding consistency and quality.
However, there are times when a specific rule is not appropriate. For example, I recently wrote a PHP fixture file for testing restyling of checkboxes and radio buttons. Since this is a fixture file, I don’t need to or want to check for a login. There are two ways I can fix this:
a) I can disable code sniffing for the entire file by adding the following to the top of the file:
// @codingStandardsIgnoreFile
b) Ignore the specific violating rule:
// phpcs:disable moodle.Files.RequireLogin.Missing
In this case solution (b) is much more preferable because it leaves the rest of the sniffs intact. Where did I get “moodle.Files.RequireLogin.Missing” from? Well, that is simply the sniff that was reported as a failure and it was outputted by codesniffer — e.g:
47 | | config inclusion. None found. (moodle.Files.RequireLogin.Missing)
After applying the rule exclusion detailed in solution (b), codesniffer will now ignore this aspect of my fixture file and everything will pass.
Source: https://brudinie.medium.com/feed
- Moodle Educator Certificate (MEC) starting 1st April – 8th March 2024
- Typescript typing constants – 21st February 2024
- 2024 Moodle training course schedule – 5th January 2024