Linter-php and indentation


#1

Hi All,

I am trying to get linter-php to respect my indentation setting of Atom.
I have set soft tabs ON and tabs length set to 2. Still the linter-php package keeps complaining that it expects 4 instead of 2.
Can anyone point me in the right direction?

obviously linter-php is available for other editors and the package dev can’t help.

I’m asking here because the guy over at linter-php said:

I’m closing this as this has nothing to do with linter-php.

I’m going to make several assumptions here and guess you are using Atom since you are filing an issue on this repo. If that is correct you would just go to your settings, check Soft Tabs, and set the Tab Length to 2.

You should probably check out the Atom Flight Manual to get you started with this editor. If something isn’t answered in there, the Atom Discussion forum is a better place for this sort of question.


#2

You were a bit more detailed in your post here than you were in your bug description. All you said was:

I just wanted to ask how to set indentation to 2 spaces instead of 4

I’m not surprised that the maintainer assumed that you were asking in general about Atom. I don’t use linter-php, so I wouldn’t know how to get it to stop showing you that error, unfortunately.

I’ve left a message for the linter devs, we’ll see if they have a quick answer.

I also wrote a blog post on writing good bug reports that might be helpful in preventing getting the runaround in the future.


#3

Now that you have actually said what you are trying to do, I can tell you that that still has nothing to do with linter-php :stuck_out_tongue:

Error messages like that come from linter-phpcs (PHP_CodeSniffer). To “fix” that you will need to create a custom ruleset and either save it as phpcs.xml in the root of your project’s directory or specify it in the options for that linter. I would recommend just copying the PSR2 ruleset that can be found in the phpcs folder and adding the following to it:

 <rule ref="Generic.WhiteSpace.ScopeIndent">
  <properties>
   <property name="ignoreIndentationTokens" type="array" value="T_COMMENT,T_DOC_COMMENT_OPEN_TAG"/>
	 <property name="indent" type="int" value="2"/>
  </properties>
 </rule>

This will fix it for most cases, although if you are using mixed mode files keep in mind that phpcs isn’t very smart and will often confuse indents in new <?php ?> blocks.

(I actually have the exact same issue with a project I have to work in.)


#4

Hi Guys,

Thanks. for your help.
I wasn’t able to tell which message comes from which plugin :smile: and since I specified 2 spaces for linter-phpcs I thought it was coming from linter-php.

I’ll ask the maintainer of that plugin why the 2 spaces setting is not respected.

Thanks again.


#5

That option doesn’t do quite what you are hoping for it to do. It tells phpcs how many spaces to treat tabs as, since phpcs doesn’t allow tabs under any circumstances. You can find the explanation here.

If you want to change what it is expecting for the “valid number of spaces to use as an indent” you have to create a custom rule like I said above.


#6

thanks, that works. I guess i found out what the ‘hackable’ part means for Atom :wink: (coming from jetbrains IDE’s)
If i can just get the phpdebugger setup for cli scripts, i can leave jetbrains behind…


#7

Oooo, I’ll have to check that out as half the stuff I do is unfortunately still stuck in PHP land.