Skip to content

Commit 498b102

Browse files
committedOct 29, 2021
[Refactor] importType: combine redundant isScoped and isScopedModule
1 parent 651a4d7 commit 498b102

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1212
### Changed
1313
- [Docs] [`order`]: add type to the default groups ([#2272], [@charpeni])
1414
- [readme] Add note to TypeScript docs to install appropriate resolver ([#2279], [@johnthagen])
15+
- [Refactor] `importType`: combine redundant `isScoped` and `isScopedModule` ([@ljharb])
1516

1617
## [2.25.2] - 2021-10-12
1718

‎src/core/importType.js

-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ function typeTest(name, context, path) {
101101
return 'unknown';
102102
}
103103

104-
export function isScopedModule(name) {
105-
return name.indexOf('@') === 0 && !name.startsWith('@/');
106-
}
107-
108104
export default function resolveImportType(name, context) {
109105
return typeTest(name, context, resolve(name, context));
110106
}

‎src/rules/extensions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22

33
import resolve from 'eslint-module-utils/resolve';
4-
import { isBuiltIn, isExternalModule, isScoped, isScopedModule } from '../core/importType';
4+
import { isBuiltIn, isExternalModule, isScoped } from '../core/importType';
55
import moduleVisitor from 'eslint-module-utils/moduleVisitor';
66
import docsUrl from '../docsUrl';
77

@@ -131,7 +131,7 @@ module.exports = {
131131
const slashCount = file.split('/').length - 1;
132132

133133
if (slashCount === 0) return true;
134-
if (isScopedModule(file) && slashCount <= 1) return true;
134+
if (isScoped(file) && slashCount <= 1) return true;
135135
return false;
136136
}
137137

@@ -161,7 +161,7 @@ module.exports = {
161161
importPath,
162162
context.settings,
163163
resolve(importPath, context),
164-
context
164+
context,
165165
) || isScoped(importPath);
166166

167167
if (!extension || !importPath.endsWith(`.${extension}`)) {

‎tests/src/core/importType.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import * as path from 'path';
33

4-
import importType, { isExternalModule, isScopedModule, isScoped } from 'core/importType';
4+
import importType, { isExternalModule, isScoped } from 'core/importType';
55

66
import { testContext, testFilePath } from '../utils';
77

@@ -239,13 +239,6 @@ describe('importType(name)', function () {
239239
}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true);
240240
});
241241

242-
it('correctly identifies scoped modules with `isScopedModule`', () => {
243-
expect(isScopedModule('@/abc')).to.equal(false);
244-
expect(isScopedModule('@/abc/def')).to.equal(false);
245-
expect(isScopedModule('@a/abc')).to.equal(true);
246-
expect(isScopedModule('@a/abc/def')).to.equal(true);
247-
});
248-
249242
it('correctly identifies scoped modules with `isScoped`', () => {
250243
expect(isScoped('@/abc')).to.equal(false);
251244
expect(isScoped('@/abc/def')).to.equal(false);

0 commit comments

Comments
 (0)
Please sign in to comment.