Skip to content

Commit

Permalink
Improve ESM compatibility
Browse files Browse the repository at this point in the history
Fixes #386
  • Loading branch information
sindresorhus committed Jan 1, 2021
1 parent d801095 commit 211f295
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
31 changes: 13 additions & 18 deletions config/plugins.js
Expand Up @@ -152,6 +152,9 @@ module.exports = {
}
],

// TODO: Remove this when https://github.com/sindresorhus/eslint-plugin-unicorn/pull/977 is out.
'unicorn/import-index': 'off',

// TODO: Disabled for now as I don't have time to deal with the backslash that might come from this. Try to enable this rule in 2021.
'unicorn/no-null': 'off',

Expand Down Expand Up @@ -179,20 +182,17 @@ module.exports = {
'import/export': 'error',
'import/extensions': [
'error',
'always',
{
js: 'never',
jsx: 'never',
json: 'always',
svg: 'always',
css: 'always'
ignorePackages: true
}
],

// Disabled as it causes problems with TypeScript when you use mixed ESM and CommonJS
// TODO: Enable again when I target only ESM
// Disabled as it causes problems with TypeScript when you use mixed ESM and CommonJS.
// TODO: Enable again when I target only ESM.
// 'import/first': 'error',

// Disabled as it doesn't work with TypeScript
// Disabled as it doesn't work with TypeScript.
// This issue and some others: https://github.com/benmosher/eslint-plugin-import/issues/1341
// 'import/named': 'error',

This comment has been minimized.

Copy link
@fregante

fregante Jul 12, 2021

Member

Does it even make sense with TypeScript? Doesn't TypeScript already check that each import is defined? Feels like duplicate functionality there, but it's still useful on non-TS projects, I suppose.

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jul 12, 2021

Author Member

I guess, it could be disabled when the project is TS. Open an issue.


Generally, it's better to open an issue and reference the relevant lines than commenting on commits as such discussions are easily lost.

This comment has been minimized.

Copy link
@fregante

fregante Jul 12, 2021

Member

Sorry I'm new to GitHub

Sent from my iPhon

This comment has been minimized.

Copy link
@fregante

fregante Jul 12, 2021

Member

Expand All @@ -211,12 +211,7 @@ module.exports = {
// Enable this sometime in the future when Node.js has ES2015 module support
// 'import/no-cycle': 'error'

'import/no-useless-path-segments': [
'error',
{
noUselessIndex: true
}
],
'import/no-useless-path-segments': 'error',

// Disabled as it doesn't work with TypeScript
// 'import/newline-after-import': 'error',
Expand All @@ -242,7 +237,7 @@ module.exports = {
// 'import/no-unresolved': [
// 'error',
// {
// commonjs: true
// commonjs: false
// }
// ],

Expand All @@ -264,11 +259,11 @@ module.exports = {
}
],

// Redundant with import/no-extraneous-dependencies
// Redundant with `import/no-extraneous-dependencies`.
// 'node/no-extraneous-import': 'error',
// 'node/no-extraneous-require': 'error',

// Redundant with import/no-unresolved
// Redundant with `import/no-unresolved`.
// 'node/no-missing-import': 'error',
// 'node/no-missing-require': 'error',

Expand Down Expand Up @@ -357,7 +352,7 @@ module.exports = {
'eslint-comments/no-aggregating-enable': 'error',
'eslint-comments/no-duplicate-disable': 'error',

// Disabled as it's already covered by the `unicorn/no-abusive-eslint-disable` rule
// Disabled as it's already covered by the `unicorn/no-abusive-eslint-disable` rule.
// 'eslint-comments/no-unlimited-disable': 'error',

'eslint-comments/no-unused-disable': 'error',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -109,7 +109,10 @@
"webpack": "^5.10.0"
},
"eslintConfig": {
"extends": "eslint-config-xo"
"extends": "eslint-config-xo",
"rules": {
"unicorn/import-index": "off"
}
},
"eslintIgnore": [
"test/fixtures"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/overrides/test/bar.js
@@ -1,5 +1,5 @@
import test from 'ava'
import fn from '..'
import fn from '../index.js'

test('main', t => {
t.is(fn('foo'), fn('foobar'))
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/overrides/test/foo.js
@@ -1,5 +1,5 @@
import test from 'ava'
import fn from '..'
import fn from '../index.js'

test('main', t => {
t.is(fn('foo'), fn('foobar'))
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/webpack/no-config/file3.js
@@ -1 +1 @@
import _ from '!./file2'; // eslint-disable-line no-unused-vars
import _ from '!./file2.js'; // eslint-disable-line no-unused-vars
2 changes: 1 addition & 1 deletion test/lint-files.js
Expand Up @@ -260,7 +260,7 @@ test('webpack import resolver is used if {webpack: true}', async t => {
}
});

t.is(results[0].errorCount, 0);
t.is(results[0].errorCount, 0, JSON.stringify(results[0]));
});

async function configType(t, {dir}) {
Expand Down

0 comments on commit 211f295

Please sign in to comment.