question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `prefer-module`

See original GitHub issue

Should fail on all legacy commonjs stuff.

Fail

const foo = require('./foo');
const foo = path.join(__dirname, './foo.js');
module.exports = {};
exports.foo = {};

Pass

export default foo;
const foo = path.join(path.dirname(url.fileURLToPath(import.meta.url)), './foo.js');

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:25 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
sindresorhuscommented, Jan 30, 2021

Just want to point out that:

const foo = path.join(path.dirname(url.fileURLToPath(import.meta.url)), './foo.js');

could be simplified to:

const foo = fileURLToPath(new URL('foo.js', import.meta.url));

and in many cases you could just do this as fs methods support URL:

const foo = new URL('foo.js', import.meta.url);

We should note this in the docs.

2reactions
sindresorhuscommented, Jan 25, 2021

How about just prefer-module or prefer-modules? Alternatively, prefer-js-module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposed rule: Order Competition Rule - SEC.gov
proposed rule would prohibit a restricted competition trading center from internally executing certain orders of individual investors at a ...
Read more >
eslint-plugin-unicorn/prefer-module.md at main - GitHub
Prefer JavaScript modules (ESM) over CommonJS. This rule is enabled in the ✓ recommended config. This rule is automatically fixable by the --fix ......
Read more >
Rule proposal: `prefer-module` #1067 - Issuehunt
Rule proposal : `prefer-module` #1067 ... 1️⃣ Explain here why this rule would be beneficial --> ... How about just prefer-module or prefer-modules...
Read more >
The Most Curious Rule Proposal in Securities and Exchange ...
I write this post in response to the release (the “Proposing Release”) regarding proposed rules (the “Proposed Rules”) under the Investment ...
Read more >
Google JavaScript Style Guide
6 Naming: 6.1 Rules common to all identifiers: 6.2 Rules by identifier type: 6.3 Camel ... Where it does not interfere with readability,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found