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: support .eslintrc.cjs (refs eslint/rfcs#43) #12321

Merged
merged 4 commits into from Dec 19, 2019
Merged

Update: support .eslintrc.cjs (refs eslint/rfcs#43) #12321

merged 4 commits into from Dec 19, 2019

Conversation

@evanplaice
Copy link
Contributor

@evanplaice evanplaice commented Sep 27, 2019

In ES module packages w/ "type": "module" defined treat all .js files as ES modules. Since eslint is expecting the config in CommonJS format, it needs to be named w/ a .cjs extension.

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:

For details about the issue, see #12319.
For details about the resolution, see RFC #43

What changes did you make? (Give an overview)

Map the .cjs file extension for loading CommonJS configurations (ie .eslintrc) in ES module based packages.

Is there anything you'd like reviewers to focus on?

After searching through the source, I didn't see any tests that cover this code. Is there an existing test I need to add/update to cover this functionality?

Also, what section of the docs should ES module usage be documented?

@evanplaice evanplaice changed the title fix: ES module compatibility Fix: ES module compatibility (fixes #12319) Sep 27, 2019
@kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Sep 27, 2019

Thanks for the PR. We ask that changes to core go through the RFC process outlined here. Do you mind doing that?

Incidentally, I don't think we should consider this a bug fix. It would be an enhancement because it would be adding support for an experimental Node feature.

@mysticatea
Copy link
Member

@mysticatea mysticatea commented Sep 27, 2019

Yeah, this is not a bug fix.

I think too early to merge this feature because ES modules on Node.js is still experimental and it may change due to the large impact to JS ecosystem.

@evanplaice
Copy link
Contributor Author

@evanplaice evanplaice commented Sep 29, 2019

Speaking from experience, any conversation discussing modules + node has a tendency to fall down the rabbit hole. I posted this PR so there's an actual concrete example to look at.

I don't expect this PR to land quickly, if at all.

@kaicataldo

We ask that changes to core go through the RFC process outlined here. Do you mind doing that?

Not at all, it'll take me a bit to gather and record my thoughts


@mysticatea

Of course. The initial issue said 'bug' so I followed that workflow. I'll fix it once I get a feel for the process.

As far as the time schedule goes -- if nothing major has or will change between now and then -- modules will be officially released (ie unflagged) on 20 October. There's still time to discuss, bike shed, shave a few yaks, and decide the best approach for ESLint specifically.

Copy link
Member

@platinumazure platinumazure left a comment

This looks good to me at first glance (so far).

I'm a bit surprised there aren't any tests. I guess I would like to see if we could add a new test for the CJS case at least, to avoid regressions.

No need to make any immediate changes, as the RFC is still being discussed. This is just a preliminary review from me. 😄

@evanplaice
Copy link
Contributor Author

@evanplaice evanplaice commented Oct 16, 2019

Update: As mentioned in this issue it looks like the schedule for unflagging ES modules is going to be pushed a bit.

@jkrems
Copy link

@jkrems jkrems commented Nov 15, 2019

Update: The unflagging PR (nodejs/node#29866) has now landed, an unflagged version of module support in node should be part of the next 13.x release next week.

@evanplaice evanplaice changed the title Fix: ES module compatibility (fixes #12319) Fix: ES module compatibility Nov 26, 2019
@mysticatea mysticatea added this to Implemented, pending review in RFCs Dec 8, 2019
@mysticatea
Copy link
Member

@mysticatea mysticatea commented Dec 8, 2019

Hi. Thank you for working on this.

RFC43 has been merged in the last week.
Would you update this PR to follow the RFC?

In ES module packages w/ "type": "module" defined treat all .js files as ES modules. CommonJS files contained in an ES module package should use the .cjs extension.
docs/user-guide/configuring.md Outdated Show resolved Hide resolved
Copy link
Member

@kaicataldo kaicataldo left a comment

Do you mind adding some tests? You can find relevant tests in https://github.com/eslint/eslint/blob/master/tests/lib/cli-engine/config-array-factory.js.

evanplaice added 2 commits Dec 18, 2019
@evanplaice
Copy link
Contributor Author

@evanplaice evanplaice commented Dec 18, 2019

I added test cases to:

  • "'loadFile(filePath, options)' method should load a config file."
  • "'loadInDirectory(directoryPath, options)' method should load the config file of a directory."
  • "'extends' property should handle the content of extended configs properly."

And added the test:

  • "should load information from a JavaScript file with a .cjs extension"

As well as the fixture:

  • /eslint/tests/fixtures/config-file/cjs/.eslintrc.cjs

Is that sufficient? AFAIK, these are the tests that cover config loading. The rest of the tests appear to dig into specific JavaScript-configuration behaviors which should be no different between .js vs .cjs.

@kaicataldo kaicataldo changed the title Fix: ES module compatibility Update: support .eslintrc.cjs (refs eslint/rfcs#43) Dec 18, 2019
@evanplaice
Copy link
Contributor Author

@evanplaice evanplaice commented Dec 18, 2019

@kaicataldo I'm happy to help. Big thanks to you and everybody else who was involved in this for your patience.

Copy link
Member

@platinumazure platinumazure left a comment

Looks good, thanks for contributing!

Copy link
Member

@mysticatea mysticatea left a comment

LGTM. Thank you!

@kaicataldo kaicataldo merged commit acc0e47 into eslint:master Dec 19, 2019
11 of 12 checks passed
11 of 12 checks passed
@github-actions
Verify Files
Details
@github-actions
Test (ubuntu-latest, 13.x)
Details
@github-actions
Test (ubuntu-latest, 12.x)
Details
@github-actions
Test (ubuntu-latest, 10.x)
Details
@github-actions
Test (ubuntu-latest, 8.x)
Details
@github-actions
Test (ubuntu-latest, 8.10.0)
Details
@github-actions
Test (windows-latest, 12.x)
Details
@github-actions
Test (macOS-latest, 12.x)
Details
@github-actions
Browser Test Browser Test
Details
@eslint-deprecated
commit-message PR title follows commit message guidelines
Details
licence/cla Contributor License Agreement is signed.
Details
@eslint-deprecated
release-monitor No patch release is pending
Details
@kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Dec 19, 2019

Thanks for contributing to ESLint!

@mysticatea mysticatea moved this from Implemented, pending review to Done in RFCs Dec 20, 2019
@evanplaice evanplaice deleted the evanplaice:fixes12319 branch Feb 17, 2020
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
RFCs
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants