@@ -4,15 +4,22 @@ const path = require('node:path')
44
55const { includeIgnoreFile } = require ( '@eslint/compat' )
66const js = require ( '@eslint/js' )
7- const constants = require ( '@socketsecurity/registry/lib/constants' )
87const tsParser = require ( '@typescript-eslint/parser' )
8+ const importXPlugin = require ( 'eslint-plugin-import-x' )
99const nodePlugin = require ( 'eslint-plugin-n' )
1010const sortDestructureKeysPlugin = require ( 'eslint-plugin-sort-destructure-keys' )
1111const unicornPlugin = require ( 'eslint-plugin-unicorn' )
1212const tsEslint = require ( 'typescript-eslint' )
1313
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' )
1623
1724const sharedPlugins = {
1825 'sort-destructure-keys' : sortDestructureKeysPlugin ,
@@ -31,9 +38,76 @@ const sharedRules = {
3138 'unicorn/consistent-function-scoping' : [ 'error' ]
3239}
3340
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 )
3495module . exports = [
3596 includeIgnoreFile ( gitignorePath ) ,
3697 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+ } ,
37111 {
38112 files : [ 'src/**/*.ts' , 'test/**/*.ts' ] ,
39113 languageOptions : {
@@ -42,7 +116,7 @@ module.exports = [
42116 projectService : {
43117 allowDefaultProject : [ 'test/*.ts' ] ,
44118 defaultProject : 'tsconfig.json' ,
45- tsconfigRootDir : __dirname
119+ tsconfigRootDir : rootPath
46120 }
47121 }
48122 } ,
0 commit comments