Rules for space indentation instead of tabs, specifically in multiline arrays #2449
-
Is your feature request related to a problem?Enforcing spaces for indentation Describe the solution you'd likeI want to introduce WP standards in a codebase that is using spaces for indentation, so instead of converting all indentation to tabs, I'd like to enforce 2 spaces as per existing style. But I still get some errors related to array indentation, it thinks it should be 4 spaces instead of 2.
Additional context (optional)See screenshot: the first line has no errors because it has 4 spaces indent but the next ones throw an error. It should be the reverse
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
@pdewouters As is clearly mentioned in the templates: please do not post screenshots, post a code sample the report can be tested with. As things are, this is not actionable. |
Beta Was this translation helpful? Give feedback.
-
This looks like a discussion topic, not an issue with WPCS. Can you open this as a discussion instead @pdewouters ? |
Beta Was this translation helpful? Give feedback.
-
@dingo-d where are the discussions? |
Beta Was this translation helpful? Give feedback.
-
You don't see the https://github.com/WordPress/WordPress-Coding-Standards/discussions link? 🤔 |
Beta Was this translation helpful? Give feedback.
-
I do now, thanks |
Beta Was this translation helpful? Give feedback.
-
@pdewouters Okay, so this is not an issue with the sniff, but related to a quirk in PHPCS (which will be fixed/changed in PHPCS 4.0). Basically, a "config" setting, like In other words, even with the config you posted, the There are two options to get round this for now (until PHPCS 4.0 has been released):
Create a separate PHPCS config file which only contains the tab-width setting and name it something like <?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Tabwidth" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<arg name="tab-width" value="2"/>
</ruleset> Include that ruleset in your <?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="MyConfig" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<rule ref="tabwidth.xml"/>
<rule ref="WordPress"/>
</ruleset> Now, your tab width will be correctly seen as Hope this helps. |
Beta Was this translation helpful? Give feedback.
@pdewouters Okay, so this is not an issue with the sniff, but related to a quirk in PHPCS (which will be fixed/changed in PHPCS 4.0).
Basically, a "config" setting, like
tab-width
, cannot be easily overruled from within a custom ruleset.In other words, even with the config you posted, the
tab-width
is still set to4
as it is inherited from WPCS, which is why the sniff behaves as it does.There are two options to get round this for now (until PHPCS 4.0 has been released):
tab-width
on the command line. Command line overrules all, so running PHPCS like sophpcs --tab-width=2
will work and pick up your custom ruleset for everything else.You can encodify this in a Composer script i…