Skip to content

Commit 7970b9c

Browse files
committed
feature: @putout/plugin-putout: apply-namespace-specifier: get rid of dot dot
1 parent e21b83c commit 7970b9c

File tree

9 files changed

+45
-16
lines changed

9 files changed

+45
-16
lines changed

packages/plugin-putout/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,22 @@ const dirPath = createNestedDirectory(path, '/hello/world');
660660
const dirPath2 = createDirectory(path, 'world');
661661
```
662662
663+
## apply-namespace-specifier
664+
665+
Most likely what you need is [`esm/resolve-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file).
666+
667+
### ❌ Example of incorrect code
668+
669+
```js
670+
import rmUnused from '@putout/plugin-remove-unused-variables';
671+
```
672+
673+
### ✅ Example of correct code
674+
675+
```js
676+
import * as rmUnused from '@putout/plugin-remove-unused-variables';
677+
```
678+
663679
## apply-for-of-to-track-file
664680
665681
> The **Generator** object is returned by a `generator function` and it conforms to both the iterable protocol and the `iterator` protocol.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as a from './index.js';
2-
import * as b from '../lib/index.js';
1+
import * as a from '@putout/plugin-remove-unused-variables';
2+
import b from '../lib/index.js';
33
import * as c from '/x';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import a from './index.js';
1+
import a from '@putout/plugin-remove-unused-variables';
22
import b from '../lib/index.js';
33

4-
import * as c from '/x';
4+
import * as c from '/x';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import typescript from './typescript.js';
2+
import filesystem from './filesystem.js';
3+
4+
export const rules = {
5+
...typescript,
6+
...filesystem,
7+
};

packages/plugin-putout/lib/apply-namespace-specifier/fixture/parent-fix.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/plugin-putout/lib/apply-namespace-specifier/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export const traverse = ({push, listStore, pathStore}) => ({
1919
names: [
2020
'@putout/plugin-',
2121
'./index.js',
22-
'../lib/index.js',
23-
'../',
2422
],
2523
}),
2624
'Program': {
@@ -66,6 +64,10 @@ const createImportVisitor = ({push, names, pathStore = noop}) => ({
6664
return;
6765

6866
for (const name of names) {
67+
if (!value.replace('.js', '').replace('./', '')
68+
.includes('/'))
69+
continue;
70+
6971
if (value === name || value.startsWith(name) || name === 'any') {
7072
push({
7173
path,

packages/plugin-putout/lib/apply-namespace-specifier/index.spec.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ test('packages: apply-namaspace-specifier: transform: external', (t) => {
3737
t.end();
3838
});
3939

40-
test('packages: apply-namaspace-specifier: transform: parent', (t) => {
41-
t.transform('parent');
42-
t.end();
43-
});
44-
4540
test('packages: apply-namaspace-specifier: no report: alot', (t) => {
4641
t.noReport('alot');
4742
t.end();
@@ -56,3 +51,13 @@ test('packages: apply-namaspace-specifier: no report: no-spec', (t) => {
5651
t.noReport('no-spec');
5752
t.end();
5853
});
54+
55+
test('packages: apply-namaspace-specifier: no report: parent', (t) => {
56+
t.noReport('parent');
57+
t.end();
58+
});
59+
60+
test('packages: apply-namaspace-specifier: no report: dot', (t) => {
61+
t.noReport('dot');
62+
t.end();
63+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as a from './index.js';
2-
import * as b from '../lib/index.js';
1+
import * as a from '@putout/plugin-remove-unused-variables';
2+
import b from '../lib/index.js';
33
import * as c from '/x';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import a from './index.js';
1+
import a from '@putout/plugin-remove-unused-variables';
22
import b from '../lib/index.js';
33

4-
import * as c from '/x';
4+
import * as c from '/x';

0 commit comments

Comments
 (0)