0

I am using (among others) the following PHPCS sniff:

Squiz.WhiteSpace.SuperfluousWhitespace.EndLine

But I find it frustrating that end-of-line white space within docblocks is getting flagged. Is there any way to disable the errors specifically for comments and/or docblocks?

For example,

/**
 * This function does things. 
 * 
 * A long explanation. Nihil hic munitissimus habendi senatus locus, 
 * nihil horum? Gallia est omnis divisa in partes tres, quarum. 
 * 
 * @param something array  My explanation
 */

The long explanation has whitespace at the end of the lines, which really doesn't matter at all, and I would like PHPCS to ignore that.

JakeParis
  • 11,056
  • 3
  • 42
  • 65
  • Why should it not be flagged? I mean I don't want to question your question, but AFAIK this rule is not specific to sections of code but a general line based one for any kind of text-files. If you're using git(1) to version control your files for example, it's one of the three (out of six) enabled by default rules ([`blank-at-eol`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corewhitespace)). Otherwise PHPCS is not only free software but also open to extension. What have you tried so far? – hakre Aug 30 '23 at 19:01
  • I would like to turn it off because when you are typing in natural language, one automatically types in spaces between words. You don't always anticipate where the line breaks will, or you might change them. Going back and removing the white space at end of line is a pain, and since this is just a comment totally pointless. Anyway, though, the question is really "How can I do this" rather than "Should I do this". I'll be honest, I've not tried anything because I'm an absolute noob at configuring phpcs and pretty much only know how to enable and disable rules. – JakeParis Aug 31 '23 at 12:42
  • Ok, I now better understand, thanks for the feedback. phpcs ships with a fixer, phpcbf, that can automatically handle these places. IIRC the phpcs output also signals for each inspection, if it is automatically fixable. This is then the phpcbf command. I'd recommend automated fixes for the kind of problem you describe. Let me know if this is what you're looking for. Many editors also support the integration, e.g. such fixes can automatically happen when saving the file. – hakre Aug 31 '23 at 13:26

0 Answers0