Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Rename babylon parser to babel #205

Closed
wants to merge 1 commit into from
Closed

Update: Rename babylon parser to babel #205

wants to merge 1 commit into from

Conversation

robertoentringer
Copy link

Prevent message : { parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }.

Related : prettier/prettier#5647

@BPScott
Copy link
Member

BPScott commented Jun 18, 2019

Our minimum supported version of prettier is 1.13.0, while the babel parser name was introduced in 1.16.0.

In order to not break people using 1.13.0 to 1.15.last, This will require either:

  • Bumping our minimum supported version of prettier, which is technically a breaking change and thus requiring a major version bump, so uugh not a fan of that.
  • Run prettier.getSupportInfo() to set the parser to babel or babylon according to what is supported by the current version.

Can you take a stab at the later.

@robertoentringer
Copy link
Author

@BPScott thank you very much for your feedback!

@robertoentringer
Copy link
Author

Just for information purposes, by setting the parser to babel in .eslintrc.js rules the warning disappears.

rules: { "prettier/prettier": ... parser: "babel" ...}

module.exports = {
  env: { browser: true, es6: true },
  extends: ["eslint:recommended", "plugin:prettier/recommended"],
  parserOptions: { ecmaVersion: 2018 },
  plugins: ["prettier", "html"],
  rules: {
    "prettier/prettier": ["error", { semi: false, printWidth: 100, parser: "babel" }],
    "comma-dangle": ["error", "never"]
  }
}

@BPScott
Copy link
Member

BPScott commented Jun 19, 2019

@robertoentringer for the most part you shouldn't ever need to set an explicit parser as it should be inferred by the filename, or indeed any other options (as they should be read from your .prettierrc per this note.

What's the filename of the file that you're parsing that causes this to appear? A better fix would probably be to use the overrides section of your prettierrc file to specify the parser for the file extension you desire. This comment offers instructions on how you can set those the parser using overrides. (that comment is relating to stylelint-prettier but the concept of configuring prettier overrides in prettier's config files instead of eslint/stylelint's config is the same.

@robertoentringer
Copy link
Author

@BPScott the filename is index.html and I use the eslint-plugin-prettier.

Setting the parser for html's files inside the .prettierrc file works very well:

{
  "overrides": [
    {
      "files": "*.html",
      "options": { "parser": "babel" }
    }
  ]
}

However, I like to use a single file for config prettier+eslint.

But, if I use the same config inside the .eslintrc.js it has no any effect! Is there any way to implement this? I did not find anything about it at options.

module.exports = {
  env: { browser: true, es6: true },
  extends: ["eslint:recommended", "plugin:prettier/recommended"],
  parserOptions: { ecmaVersion: 2018 },
  plugins: ["prettier", "html"],
  rules: {
    "prettier/prettier": [
      "error",
      {
        semi: false,
        printWidth: 100,
        overrides: [
          {
            files: "*.html",
            options: { parser: "babel" }
          }
        ]
      }
    ],
    "comma-dangle": ["error", "never"]
  }
}

This is my package.json :

{
  "scripts": {
    "lint": "eslint --fix src/**/*.{js,html}"
  },
  "devDependencies": {
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.3.0",
    "eslint-plugin-html": "^5.0.5",
    "eslint-plugin-prettier": "^3.1.0",
    "prettier": "^1.18.2"
  }
}

Thank you for the good advice about this note and this comment.

@BPScott
Copy link
Member

BPScott commented Jul 3, 2019

Setting overrides would work in every case but this - as per the comment above the line in your PR we force the parser value for html files because we want to try and automatically do the right thing in 90% of the cases rather than forcing people to add this sort of config.

It sounds like the fix is for us to update the parser name that we force based upon prettier.getSupportInfo() as per my initial comment in this thread

@robertoentringer
Copy link
Author

robertoentringer commented Jul 4, 2019

@BPScott, based in your reply I tried working in that solution.

Please, can you tell me what you think of this patch, before I send the PR?

@BPScott
Copy link
Member

BPScott commented Jul 4, 2019

That looks great! thanks for investigating the structure of that.

To save you some work I've added this in #212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants