Skip to content

Commit 8ea2fe3

Browse files
committed
feature: eslint-plugin-putout: no-unresolved: ".", ".."
1 parent e38385e commit 8ea2fe3

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/eslint-plugin-putout/lib/no-unresolved/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const process = require('node:process');
4-
54
const {accessSync} = require('node:fs');
65

76
const {
@@ -44,6 +43,9 @@ module.exports.fix = ({node, text, filename}) => {
4443
module.exports.filter = ({node}) => {
4544
const value = getValue(node);
4645

46+
if (!value || value.endsWith('.js'))
47+
return false;
48+
4749
if (!isRelativeStart(value))
4850
return false;
4951

@@ -55,10 +57,10 @@ function resolveSource({dir, value}) {
5557
const name = join(dir, value, 'package.json');
5658
const [error, info] = tryCatch(require, name);
5759

58-
if (error)
59-
return value;
60+
if (!error)
61+
return join(value, info.main);
6062

61-
return join(value, info.main);
63+
return `${value}/index.js`;
6264
}
6365

6466
for (const ext of ['js', 'mjs', 'cjs']) {

packages/eslint-plugin-putout/lib/no-unresolved/index.spec.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const rule = createPlugin(require('.'));
77

88
const ruleTester = new RuleTester({
99
languageOptions: {
10-
ecmaVersion: 2024,
10+
ecmaVersion: 2025,
1111
sourceType: 'module',
1212
},
1313
});
@@ -22,6 +22,13 @@ ruleTester.run('no-unresolved', rule, {
2222
],
2323

2424
invalid: [{
25+
code: `import * as strictMode from '..';`,
26+
output: `import * as strictMode from '../index.js';`,
27+
errors: [{
28+
message,
29+
type: 'ImportDeclaration',
30+
}],
31+
}, {
2532
code: `import hello from './hello'`,
2633
output: `import hello from './hello.js'`,
2734
errors: [{

packages/eslint-plugin-putout/test/fixture/no-unresolved-fix.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import index from '../../lib/index.mjs';
22
import eslint from '../../lib.js';
3-
import dot from '.';
3+
import dot from './index.js';
44
import dotDot from '../../lib/index.js';
5-
import noPackageJson from '..';
5+
import noPackageJson from '../index.js';
66
import noUnresolved from './no-unresolved-index/index.js';
77

88
export * from '../../lib/index.mjs';

0 commit comments

Comments
 (0)