prettier / prettier/plugin-php

Unexpected Indentation Level in Tests

Aperta
#952 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
PHP
Stelle
1.9k
Fork
139
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il test markdown in tests/markdown e confronta i risultati di Node.js e standalone. Ispeziona jest.config.js, in particolare la relativa configurazione projects, e riproduci la differenza con tests_config/run_spec.js. Il lavoro è completato quando il test standalone non ha più bisogno del workaround tabWidth: 4 e corrisponde all'indentazione prevista.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js, php
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.