Skip to content

Override parser to babylon - Fix compatibility with eslint-plugin-html and [email protected] #98

@nappy

Description

@nappy

Upgrading prettier from ~1.12.1 to ^1.13.6 causes eslint-plugin-html to break.

The use case is, to lint and format javascript inside html script tags.

I originally posted the issue at prettier/prettier#4759, but it became clear that it should be fixed here.

Prettier 1.13 changes how the parser is inferred, previously it would default to babylon, but now this must be explicitly defined in the .prettierrc config.
Since eslint only lints javascript it would make sense to restore the previous behavior by overriding the parser to babylon when calling the prettier API (if possible), and therefore restore compatibility with previous working configurations.

Please read the referenced issue, if its not clear from this description.

Environments:

  • Prettier Version: 1.13.6
  • Running Prettier via: eslint-plugin-prettier
  • Runtime: Node v10.5.0 Yarn 1.7.0 Npm 6.1.0
  • Operating System: Windows
    eslint@^5.0.1
    eslint-plugin-html@^4.0.5
    eslint-plugin-prettier@^2.6.1
    prettier@^1.13.6

Steps to reproduce:
Add plugins html and prettier to .eslintrc
Add an html file to your project
Run eslint **/*.{js,html}

Expected behavior: (with prettier 1.12.1)
yarn run v1.7.0
$ eslint **/*.{js,html}
Done in 5.89s.

Actual behavior: (with prettier 1.13.6)
yarn run v1.7.0
$ eslint **/*.{js,html}
No parser could be inferred for file: C:\Code\eslint-html\assets\index.html
Error: No parser could be inferred for file: C:\Code\eslint-html\assets\index.html
at normalize (C:\Code\eslint-html\node_modules\prettier\index.js:7058:15)
at formatWithCursor (C:\Code\eslint-html\node_modules\prettier\index.js:10378:12)
at C:\Code\eslint-html\node_modules\prettier\index.js:31217:15
at Object.format (C:\Code\eslint-html\node_modules\prettier\index.js:31236:12)
at Program (C:\Code\eslint-html\node_modules\eslint-plugin-prettier\eslint-plugin-prettier.js:412:45)
at listeners.(anonymous function).forEach.listener (C:\Code\eslint-html\node_modules\eslint\lib\util\safe-emitter.js:45:58)
at Array.forEach ()
at Object.emit (C:\Code\eslint-html\node_modules\eslint\lib\util\safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (C:\Code\eslint-html\node_modules\eslint\lib\util\node-event-generator.js:251:26)
at NodeEventGenerator.applySelectors (C:\Code\eslint-html\node_modules\eslint\lib\util\node-event-generator.js:280:22)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions