trivago / prettier-plugin-twig-melody

Code formatting plugin for Prettier which can handle Twig/Melody templates
Apache License 2.0
155 stars 35 forks source link

prettier is not working with twig file #113

Closed ApuEmdad closed 3 months ago

ApuEmdad commented 3 months ago

I am using drupal 10. I installed prettier in the root directory. Now every time i run the command git commit, i want to run the yarn prettier command prior to the commit takes place. The prettier should only format the staged files and files other than staged will go untouched.

package.json

{
  "scripts": {
    "prettier": "prettier --ignore-path .gitignore --write"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "./web/**/*.{js,jsx,ts,tsx,json,css,html,twig}": [
      "prettier --write",
      "git add"
    ]
  },
  "devDependencies": {
    "husky": "^4.0.0",
    "lint-staged": "^13.0.3",
    "prettier": "^3.2.5",
    "prettier-plugin-twig-melody": "^0.4.0"
  }
}

.prettierrc.json

{
  "plugins": ["prettier-plugin-twig-melody"],
  "overrides": [
    {
      "files": "*.twig",
      "options": {
        "parser": "melody"
      }
    }
  ],
  "printWidth": 80,
  "tabWidth": 2,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "proseWrap": "preserve"
}

after running git commit i am getting the following error:

✖ prettier --write: [error] web/themes/custom/tiny_dash/templates/page.html.twig: InvalidDocError: Unexpected doc.type 'concat'. [error] Expected it to be 'cursor', 'indent', 'align', 'trim', 'group', 'fill', 'if-break', 'indent-if-break', 'line-suffix', 'line-suffix-boundary', 'line', 'label', or 'break-parent'. //... husky > pre-commit hook failed (add --no-verify to bypass)

Any possible solution?

ApuEmdad commented 3 months ago

Downgrading to "prettier": "2.3.2" resolves the issue.