Skip to content

Commit

Permalink
[Refactor] importType: combine redundant isScoped and `isScopedMo…
Browse files Browse the repository at this point in the history
…dule`
  • Loading branch information
ljharb committed Oct 29, 2021
1 parent 651a4d7 commit 498b102
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Changed
- [Docs] [`order`]: add type to the default groups ([#2272], [@charpeni])
- [readme] Add note to TypeScript docs to install appropriate resolver ([#2279], [@johnthagen])
- [Refactor] `importType`: combine redundant `isScoped` and `isScopedModule` ([@ljharb])

## [2.25.2] - 2021-10-12

Expand Down
4 changes: 0 additions & 4 deletions src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ function typeTest(name, context, path) {
return 'unknown';
}

export function isScopedModule(name) {
return name.indexOf('@') === 0 && !name.startsWith('@/');
}

export default function resolveImportType(name, context) {
return typeTest(name, context, resolve(name, context));
}
6 changes: 3 additions & 3 deletions src/rules/extensions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import resolve from 'eslint-module-utils/resolve';
import { isBuiltIn, isExternalModule, isScoped, isScopedModule } from '../core/importType';
import { isBuiltIn, isExternalModule, isScoped } from '../core/importType';
import moduleVisitor from 'eslint-module-utils/moduleVisitor';
import docsUrl from '../docsUrl';

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

if (slashCount === 0) return true;
if (isScopedModule(file) && slashCount <= 1) return true;
if (isScoped(file) && slashCount <= 1) return true;
return false;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ module.exports = {
importPath,
context.settings,
resolve(importPath, context),
context
context,
) || isScoped(importPath);

if (!extension || !importPath.endsWith(`.${extension}`)) {
Expand Down
9 changes: 1 addition & 8 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as path from 'path';

import importType, { isExternalModule, isScopedModule, isScoped } from 'core/importType';
import importType, { isExternalModule, isScoped } from 'core/importType';

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

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

it('correctly identifies scoped modules with `isScopedModule`', () => {
expect(isScopedModule('@/abc')).to.equal(false);
expect(isScopedModule('@/abc/def')).to.equal(false);
expect(isScopedModule('@a/abc')).to.equal(true);
expect(isScopedModule('@a/abc/def')).to.equal(true);
});

it('correctly identifies scoped modules with `isScoped`', () => {
expect(isScoped('@/abc')).to.equal(false);
expect(isScoped('@/abc/def')).to.equal(false);
Expand Down

0 comments on commit 498b102

Please sign in to comment.