prettier / prettier/plugin-php

Unexpected Indentation Level in Tests

Ouverte
#952 0 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
PHP
Étoiles
1.9k
Forks
139
Métriques de merge des PR
Aucune PR mergée en 30 j

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le test markdown dans tests/markdown et comparez les résultats de Node.js et standalone. Inspectez jest.config.js, en particulier sa configuration projects, et reproduisez la différence avec tests_config/run_spec.js. C’est terminé lorsque le test standalone n’a plus besoin du contournement tabWidth: 4 et correspond à l’indentation attendue.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, node.js, php
Domaine
testing-qa
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.