Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic LineEndings sniff replaces tabs with spaces with --tab-width is set #1095

Closed
photodude opened this issue Aug 1, 2016 · 4 comments
Closed

Comments

@photodude
Copy link
Contributor

photodude commented Aug 1, 2016

Spaces not replaced with tabs after fix from PEAR.Functions.FunctionCallSignature.Indent while using Generic.WhiteSpace.DisallowSpaceIndent and <arg name="tab-width" value="4"/>

Running PHP_CodeSniffer version 2.6.2 (stable)

Possibly related to similar issues reported in #1056

I have a ruleset.xml subset that I can consistently reproduce this issue with

<?xml version="1.0"?>
<ruleset name="MyStandard">
    <description>My custom coding standard.</description>
    <arg name="tab-width" value="4"/>
    <arg name="encoding" value="utf-8"/>

    <!-- Use Unix newlines -->
    <rule ref="Generic.Files.LineEndings">
        <properties>
            <property name="eolChar" value="\n" />
        </properties>
    </rule>

    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>

    <rule ref="PEAR.Functions.FunctionCallSignature">
        <properties>
            <property name="indent" value="4"/>
        </properties>
        <exclude name="PEAR.Functions.FunctionDeclaration.BraceOnNewLine" />
        <exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
        <exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
    </rule>
</ruleset>

NOTE: the tested file must also have End of line character is invalid; expected "\n" but found "\r\n" error (my eolChar error is on line 1)

I'm testing against Joomla administrator\components\com_categories\models\categories.php and getting 297 | ERROR | [x] Multi-line function call not indented correctly; expected 8 spaces but found 12 (PEAR.Functions.FunctionCallSignature.Indent)

after the fix is applied I get spaces not tabs (the Generic.Files.LineEndings is required to reproduce)

@gsherwood
Copy link
Member

The problem was actually the fixing of the line endings:

*** START FILE FIXING ***
---START FILE CONTENT---
 1|<?php
 2|function foo()
 3|{
 4| $query->group('a.id,
 5|         uc.name,
 6|         ag.title,
 7|         ua.name'
 8|     );
 9|}
10|
--- END FILE CONTENT ---
    E: [Line 1] End of line character is invalid; expected "\n" but found "\r" (Generic.Files.LineEndings.InvalidEOLChar)
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 0 (T_OPEN_TAG) "<?php\r" => "<?php\n"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 6 (T_WHITESPACE) "\r{" => "\n{"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 8 (T_WHITESPACE) "\r\t" => "\n\t"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 14 (T_CONSTANT_ENCAPSED_STRING) "'a.id,·\r" => "'a.id,·\n"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 15 (T_CONSTANT_ENCAPSED_STRING) "\t\t\tuc.name,·\r" => "············uc.name,·\n"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 16 (T_CONSTANT_ENCAPSED_STRING) "\t\t\tag.title,·\r" => "············ag.title,·\n"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 18 (T_WHITESPACE) "\r\t\t" => "\n\t\t"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 22 (T_WHITESPACE) "\r}" => "\n}"
    Generic_Sniffs_Files_LineEndingsSniff (line 134) replaced token 24 (T_WHITESPACE) "\r" => "\n"
    E: [Line 8] Multi-line function call not indented correctly; expected 4 spaces but found 8 (PEAR.Functions.FunctionCallSignature.Indent)
    PEAR_Sniffs_Functions_FunctionCallSignatureSniff (line 464) replaced token 19 (T_WHITESPACE) "\t\t)" => "····)"
    * fixed 10 violations, starting loop 2 *

@gsherwood gsherwood changed the title Spaces not replaced with tabs after fix from PEAR.Functions.FunctionCallSignature.Indent Generic LineEndings sniff replaces tabs with spaces with --tab-width is set Aug 1, 2016
gsherwood added a commit that referenced this issue Aug 1, 2016
@gsherwood
Copy link
Member

Fixed now. Thanks for reporting it.

@gsherwood
Copy link
Member

Forgot to say thanks for the clear bug report. Made it really easy to replicate and track down.

@photodude
Copy link
Contributor Author

You are welcome. Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants