prettier / prettier/plugin-php

Unexpected Indentation Level in Tests

Open
#952 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

As mentioned in #950, the tests produce a strange behavior with indentation of PHP code blocks in markdown.

Even when no tabWidth is configured in the markdown test (currently it is set to 4 to work around this issue), PHP code is indented by 2 spaces with the standalone build:

[...]

```php
function test(){$a=1;}
`​``

[...]

becomes

[...]

```php
function test()
{
  $a = 1;
}
`​``

[...]

Note: Be careful when copy-pasting the code above. The code fences contain zero-width spaces to retain syntax highlighting.


This incorrect behavior is pretty unique:

  • It does not occur in the same test for the Node.js build, which correctly indents by 4 spaces in the tests.

  • It does not occur in the standalone build when used in the browser.

  • It does not even occur in the test for the standalone build, when the jest.config.js is changed to not using projects (which it currently does), to something like this:

    module.exports = {
      setupFiles: ["<rootDir>/tests_config/run_spec.js"],
      testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
      snapshotSerializers: ["jest-snapshot-serializer-raw"],
      testEnvironment: "jsdom",
      globals: {
        STANDALONE: true
      }
    };
    

So especially because of the last point, I'm assuming this has something to do with the architecture of the tests. I wasn't able to narrow it down any further.

As mentioned above, currently there's a workaround (introduced in #950) to not break the tests with something that doesn't occur "in the wild", but it should probably be taken a deeper look on.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the markdown test under tests/markdown and compare the Node.js and standalone results. Inspect jest.config.js, especially its projects configuration, and tests_config/run_spec.js to reproduce the difference. Done means the standalone test no longer needs the tabWidth: 4 workaround and matches the expected indentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, php
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.