@@ -4,15 +4,22 @@ const path = require('node:path')
4
4
5
5
const { includeIgnoreFile } = require ( '@eslint/compat' )
6
6
const js = require ( '@eslint/js' )
7
- const constants = require ( '@socketsecurity/registry/lib/constants' )
8
7
const tsParser = require ( '@typescript-eslint/parser' )
8
+ const importXPlugin = require ( 'eslint-plugin-import-x' )
9
9
const nodePlugin = require ( 'eslint-plugin-n' )
10
10
const sortDestructureKeysPlugin = require ( 'eslint-plugin-sort-destructure-keys' )
11
11
const unicornPlugin = require ( 'eslint-plugin-unicorn' )
12
12
const tsEslint = require ( 'typescript-eslint' )
13
13
14
- const gitignorePath = path . resolve ( __dirname , '.gitignore' )
15
- const prettierignorePath = path . resolve ( __dirname , '.prettierignore' )
14
+ const constants = require ( '@socketsecurity/registry/lib/constants' )
15
+
16
+ const { flatConfigs : origImportXFlatConfigs } = importXPlugin
17
+
18
+ const rootPath = __dirname
19
+ const rootTsConfigPath = path . join ( rootPath , 'tsconfig.json' )
20
+
21
+ const gitignorePath = path . resolve ( rootPath , '.gitignore' )
22
+ const prettierignorePath = path . resolve ( rootPath , '.prettierignore' )
16
23
17
24
const sharedPlugins = {
18
25
'sort-destructure-keys' : sortDestructureKeysPlugin ,
@@ -31,9 +38,76 @@ const sharedRules = {
31
38
'unicorn/consistent-function-scoping' : [ 'error' ]
32
39
}
33
40
41
+ const getImportXFlatConfigs = isEsm => ( {
42
+ recommended : {
43
+ ...origImportXFlatConfigs . recommended ,
44
+ languageOptions : {
45
+ ...origImportXFlatConfigs . recommended . languageOptions ,
46
+ ecmaVersion : 'latest' ,
47
+ sourceType : isEsm ? 'module' : 'script'
48
+ } ,
49
+ rules : {
50
+ ...origImportXFlatConfigs . recommended . rules ,
51
+ 'import-x/no-named-as-default-member' : 'off' ,
52
+ 'import-x/order' : [
53
+ 'warn' ,
54
+ {
55
+ groups : [
56
+ 'builtin' ,
57
+ 'external' ,
58
+ 'internal' ,
59
+ [ 'parent' , 'sibling' , 'index' ] ,
60
+ 'type'
61
+ ] ,
62
+ pathGroups : [
63
+ {
64
+ pattern : '@socket{registry,security}/**' ,
65
+ group : 'internal'
66
+ }
67
+ ] ,
68
+ pathGroupsExcludedImportTypes : [ 'type' ] ,
69
+ 'newlines-between' : 'always' ,
70
+ alphabetize : {
71
+ order : 'asc'
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ } ,
77
+ typescript : {
78
+ ...origImportXFlatConfigs . typescript ,
79
+ settings : {
80
+ ...origImportXFlatConfigs . typescript . settings ,
81
+ 'import-x/resolver' : {
82
+ 'eslint-import-resolver-oxc' : {
83
+ tsConfig : {
84
+ configFile : rootTsConfigPath ,
85
+ references : 'auto'
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ } )
92
+
93
+ const importFlatConfigsForScript = getImportXFlatConfigs ( false )
94
+ const importFlatConfigsForModule = getImportXFlatConfigs ( true )
34
95
module . exports = [
35
96
includeIgnoreFile ( gitignorePath ) ,
36
97
includeIgnoreFile ( prettierignorePath ) ,
98
+ {
99
+ files : [ '**/*.{c,}js' ] ,
100
+ ...importFlatConfigsForScript . recommended
101
+ } ,
102
+ // TODO: Make this work for our .mjs files too.
103
+ // {
104
+ // files: ['**/*.mjs'],
105
+ // ...importFlatConfigsForModule.recommended
106
+ // },
107
+ {
108
+ files : [ 'src/**/*.ts' , 'test/**/*.ts' ] ,
109
+ ...importFlatConfigsForModule . typescript
110
+ } ,
37
111
{
38
112
files : [ 'src/**/*.ts' , 'test/**/*.ts' ] ,
39
113
languageOptions : {
@@ -42,7 +116,7 @@ module.exports = [
42
116
projectService : {
43
117
allowDefaultProject : [ 'test/*.ts' ] ,
44
118
defaultProject : 'tsconfig.json' ,
45
- tsconfigRootDir : __dirname
119
+ tsconfigRootDir : rootPath
46
120
}
47
121
}
48
122
} ,
0 commit comments