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

Fix error when parsing ignored files with @babel/eslint-parser #13338

Merged
merged 1 commit into from May 19, 2021

Conversation

devfservant
Copy link
Contributor

@devfservant devfservant commented May 19, 2021

This PR fixes several parsing errors which occurred in @babel/eslint-parser, in particular when a file was ignored.

Related issue: #13331

Q                       A
Fixed Issues? #13331
Patch: Bug Fix?
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? No
License MIT

Changes

  • eslint-parser:
    • Implement fallback when normalizing config
    • Add corresponding test case

cc @JLHwung @nicolo-ribaudo @fedeci

@babel-bot
Copy link
Collaborator

babel-bot commented May 19, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46284/

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 19, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 23caac0:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo
Copy link
Member

I'm trying to better understand why plugins might be not set.

When the config is null because the file is ignored, || parseOptions at

return validateResolvedConfig(config, options) || parseOptions;
should replace it with our default config.

(I'll clone this PR locally and test it, but you might already have an answer 😁)

@nicolo-ribaudo
Copy link
Member

Ok, the source of the problem is that, while the result of loadPartialConfig will prevent Babel from resolving config files and ignores again, || parserOptions will still include ignore: ... and an empty plugins list.

A better fix would be to replace || parserOptions with something like || getDefaultConfig(parserOptions), which sets/deletes the necessary properties:

function getDefaultParserOptions(options) {
  return {
    plugins: [],
    ...options,
    babelrc: false,
    configFile: false,
    browserslistConfigFile: false,
    ignore: null,
    only: null
  };
}

@devfservant
Copy link
Contributor Author

Ok, of course, the best is to determine the root cause of all these errors 👍
I'll try to implement your suggestion!

@nicolo-ribaudo nicolo-ribaudo added area: eslint PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels May 19, 2021
@nicolo-ribaudo
Copy link
Member

@devfservant I noticed that your commits aren't associated to your GitHub account. It doesn't matter for us, but if you want them to be linked to your account you can check https://docs.github.com/en/github/committing-changes-to-your-project/troubleshooting-commits/why-are-my-commits-linked-to-the-wrong-user#commits-are-not-linked-to-any-user

…el#13338)

* fix(babel-eslint-parser): prevent typeerror in maybeParse
* fix(babel-eslint-parser): prevent other typeerrors in convert modules
* test(babel-eslint-parser): test maybeParse when file is ignored
* refactor(babel-eslint-parser): use fallback options instead of typeerror protections

Co-authored-by: devfservant <43757707+devfservant@users.noreply.github.com>
Co-authored-by: François Servant <francois.servant.e@thalesdigital.io>
@nicolo-ribaudo
Copy link
Member

@devfservant I linked your commits both to your email (that you use in Git) and to your GitHub autogenerated email, so that they are linked to your account.

@nicolo-ribaudo nicolo-ribaudo merged commit 1219004 into babel:main May 19, 2021
@nicolo-ribaudo nicolo-ribaudo changed the title Fix multiple parsing errors in @babel/eslint-parser Fix error when parsing ignored files with @babel/eslint-parser May 19, 2021
@devfservant devfservant deleted the fix-parsing-error branch May 20, 2021 03:04
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: eslint outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants