Skip to content

Commit a1b57f8

Browse files
author
Adam Drago
committed
fix: Ignore deprecated constants Node module in isNodeModule check
1 parent 6f7ceb8 commit a1b57f8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IStyleAPI, IStyleItem } from 'import-sort-style';
1+
import { IMatcherFunction, IStyleAPI, IStyleItem } from 'import-sort-style';
22

33
export default function (styleApi: IStyleAPI): IStyleItem[] {
44
const {
@@ -15,6 +15,16 @@ export default function (styleApi: IStyleAPI): IStyleItem[] {
1515
unicode,
1616
} = styleApi;
1717

18+
/**
19+
* Checks whether the import is a built-in Node module, but ignores the
20+
* deprecated 'constants' modules
21+
*/
22+
const isNodeModuleAndNotConstants: IMatcherFunction = (imported) => {
23+
return (
24+
!imported.moduleName.startsWith('constants') && isNodeModule(imported)
25+
);
26+
};
27+
1828
return [
1929
// import 'foo';
2030
{
@@ -26,7 +36,7 @@ export default function (styleApi: IStyleAPI): IStyleItem[] {
2636

2737
// import path from 'path';
2838
{
29-
match: isNodeModule,
39+
match: isNodeModuleAndNotConstants,
3040
sort: moduleName(unicode),
3141
sortNamedMembers: alias(unicode),
3242
},

0 commit comments

Comments
 (0)