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/JumbledIncrementer: fix non-problematic bug and improve test coverage #385

Merged

Commits on Apr 10, 2024

  1. Generic/JumbledIncrementer: rename test case file

    Doing this to be able to create tests with syntax errors on separate
    files.
    rodrigoprimo authored and jrfnl committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    2d9779d View commit details
    Browse the repository at this point in the history
  2. Generic/JumbledIncrementer: rename variable to make test easier to read

    Using `$same` instead of `$i` should help highlight which variable is
    expected to trigger the sniff when reading the test code.
    rodrigoprimo authored and jrfnl committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    7c856b4 View commit details
    Browse the repository at this point in the history
  3. Generic/JumbledIncrementer: fix non-problematic bug

    The sniff was wrongly assuming that the inner for loop would always have
    a closing parenthesis which is not true when PHPCS is used with live
    coding. This meant that `$end` could be set to `null`
    (https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/84acf4e56f110db8e75cb9a575c5727df637643c/src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php#L116). This did not cause any issues as `$next <= $end`
    when `$end` is `null` is always false, so the for loop that looks for
    incrementers was not executed.
    
    The code was changed to bail early when the inner for loop is missing
    the closing parenthesis and a test was added.
    rodrigoprimo authored and jrfnl committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    6dc74f2 View commit details
    Browse the repository at this point in the history
  4. Generic/JumbledIncrementer: improve test coverage

    This commit adds tests for:
    - for alternative syntax
    - for loops missing one or more condition parts
    - sniff bails early when it encounters a parse error (missing for body
      and inner for loop missing opening parenthesis
    - for loops with more than one incrementer
    - for loops with decrementers
    rodrigoprimo authored and jrfnl committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    fd7b175 View commit details
    Browse the repository at this point in the history