prettier / prettier/plugin-php

Unexpected Indentation Level in Tests

未关闭
#952 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
PHP
星标
1.9k
派生
139
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 tests/markdown 下的 markdown 测试开始,并比较 Node.js 和 standalone 的结果。检查 jest.config.js,尤其是其中的 projects 配置,并使用 tests_config/run_spec.js 重现差异。当 standalone 测试不再需要 tabWidth: 4 这一变通方案,并且与预期的缩进一致时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js, php
领域
testing-qa
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。