Skip to content

Babel Config Linter #7880

Open

Description

@hzoo

Feature Request

Just wanted to write this down before I forget, will try to update later.

Is your feature request related to a problem? Please describe.

Ref https://twitter.com/left_pad/status/992027090949046272

This is regarding adding some kind of validation against a babel config file (easiest would be for .babelrc which is JSON.

This has always been an issue because we don't do much validation on what you are allowed to do (I think we added more over time). Like checking what version of babel a plugin is running against, using peerDeps, enforcing that a preset should be a function, etc.

We can't cover every possible issue but we can try. An example of the issue:

{
  "presets": [
    "es2015", // not necessary due to env
    "es2016", // not necessary due to env
    ["env", { targets: { "chrome": "60" } }]
  ],
  "plugins": [
    "transform-es2015-classes" // not necessary due to env
  ]
}

So this could be a case of having duplicate plugins. It's not that simple because you could also use a plugin to override the plugin in the preset which is a valid usecase.

{
  "presets": ["env"], // includes classes (ignore the fact I didn't specify targets in this example)
  "plugins": [
    ["transform-es2015-classes", { "loose": true }] // override with loose mode if say you didn't want loose applied to all the plugins
  ]
}

Describe the solution you'd like

Not sure I know the exact solution for this. I know it could be related to plugin ordering: #5854, #5735. I think the runtime, babel core approach is ultimately best since while it's executing it could determine whether a plugin is being used multiple times, etc but a linter/config check could work in the meantime for the 90% case pretty easily?

Describe alternatives you've considered

@doug-wade has also some ideas in https://github.com/doug-wade/babel/tree/babel-lint/packages/babel-lint

cc @gautamarora

Teachability, Documentation, Adoption, Migration Strategy

If it's a standalone tool then people would have to opt-in, which is fine while we try to figure out what this looks like. If it's built-in there's nothing to teach and it will error correctly assuming the error messages are useful. Or we point to new docs.

Activity

  1. dhruvdutt commented on Aug 21, 2018

    @dhruvdutt

    @doug-wade Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions