Skip to content

Commit e8794f1

Browse files
committed
[Fix] importType: avoid crashing on a non-string
1 parent 7c239fe commit e8794f1

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

Diff for: CHANGELOG.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
66

77
## [Unreleased]
88

9+
### Fixed
10+
- `importType`: avoid crashing on a non-string' ([#2305], thanks [@ljharb])
11+
912
## [2.25.3] - 2021-11-09
1013

1114
### Fixed
12-
- [`extensions`]: ignore unresolveable type-only imports ([#2270], [#2271], [@jablko])
13-
- `importType`: fix `isExternalModule` calculation ([#2282], [@mx-bernhard])
14-
- [`no-import-module-exports`]: avoid false positives with a shadowed `module` or `exports` ([#2297], [@ljharb])
15+
- [`extensions`]: ignore unresolveable type-only imports ([#2270], [#2271], thanks [@jablko])
16+
- `importType`: fix `isExternalModule` calculation ([#2282], thanks [@mx-bernhard])
17+
- [`no-import-module-exports`]: avoid false positives with a shadowed `module` or `exports` ([#2297], thanks [@ljharb])
1518

1619
### Changed
17-
- [Docs] [`order`]: add type to the default groups ([#2272], [@charpeni])
18-
- [readme] Add note to TypeScript docs to install appropriate resolver ([#2279], [@johnthagen])
19-
- [Refactor] `importType`: combine redundant `isScoped` and `isScopedModule` ([@ljharb])
20-
- [Docs] HTTP => HTTPS ([#2287], [@Schweinepriester])
20+
- [Docs] [`order`]: add type to the default groups ([#2272], thanks [@charpeni])
21+
- [readme] Add note to TypeScript docs to install appropriate resolver ([#2279], thanks [@johnthagen])
22+
- [Refactor] `importType`: combine redundant `isScoped` and `isScopedModule` (thanks [@ljharb])
23+
- [Docs] HTTP => HTTPS ([#2287], thanks [@Schweinepriester])
2124

2225
## [2.25.2] - 2021-10-12
2326

2427
### Fixed
25-
- [Deps] update `eslint-module-utils` for real this time ([#2255])
28+
- [Deps] update `eslint-module-utils` for real this time ([#2255], thanks [@ljharb])
2629

2730
## [2.25.1] - 2021-10-11
2831

@@ -942,6 +945,7 @@ for info on changes for earlier releases.
942945

943946
[`memo-parser`]: ./memo-parser/README.md
944947

948+
[#2305]: https://github.com/import-js/eslint-plugin-import/pull/2305
945949
[#2297]: https://github.com/import-js/eslint-plugin-import/pull/2297
946950
[#2287]: https://github.com/import-js/eslint-plugin-import/pull/2287
947951
[#2282]: https://github.com/import-js/eslint-plugin-import/pull/2282

Diff for: src/core/importType.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function baseModule(name) {
1414
}
1515

1616
export function isAbsolute(name) {
17-
return nodeIsAbsolute(name);
17+
return typeof name === 'string' && nodeIsAbsolute(name);
1818
}
1919

2020
// path is defined only when a resolver resolves to a non-standard path

Diff for: src/rules/no-absolute-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313

1414
create(context) {
1515
function reportIfAbsolute(source) {
16-
if (typeof source.value === 'string' && isAbsolute(source.value)) {
16+
if (isAbsolute(source.value)) {
1717
context.report(source, 'Do not import modules using an absolute path');
1818
}
1919
}

Diff for: tests/src/core/importType.js

+12-1
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, isScoped } from 'core/importType';
4+
import importType, { isExternalModule, isScoped, isAbsolute } from 'core/importType';
55

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

@@ -256,3 +256,14 @@ describe('importType(name)', function () {
256256
expect(isScoped('@a/abc/def')).to.equal(true);
257257
});
258258
});
259+
260+
describe('isAbsolute', () => {
261+
it('does not throw on a non-string', () => {
262+
expect(() => isAbsolute()).not.to.throw();
263+
expect(() => isAbsolute(null)).not.to.throw();
264+
expect(() => isAbsolute(true)).not.to.throw();
265+
expect(() => isAbsolute(false)).not.to.throw();
266+
expect(() => isAbsolute(0)).not.to.throw();
267+
expect(() => isAbsolute(NaN)).not.to.throw();
268+
});
269+
});

0 commit comments

Comments
 (0)