@mrpalmer/eslint-plugin 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,7 +39,7 @@ export default createRule({
|
|
|
39
39
|
},
|
|
40
40
|
],
|
|
41
41
|
create(context, options) {
|
|
42
|
-
const config = loadConfig(context.settings);
|
|
42
|
+
const config = loadConfig(context.settings, context.filename);
|
|
43
43
|
const absolutePath = path.resolve(process.cwd(), context.filename);
|
|
44
44
|
return {
|
|
45
45
|
'ImportDeclaration,ExportNamedDeclaration,ExportAllDeclaration'(node) {
|
|
@@ -533,7 +533,8 @@ export default createRule({
|
|
|
533
533
|
],
|
|
534
534
|
create(context, [options]) {
|
|
535
535
|
const settings = getSettings(context);
|
|
536
|
-
const tsConfigPaths = loadConfig(settings)?.config.compilerOptions?.paths ??
|
|
536
|
+
const tsConfigPaths = loadConfig(settings, context.filename)?.config.compilerOptions?.paths ??
|
|
537
|
+
{};
|
|
537
538
|
let ranks;
|
|
538
539
|
try {
|
|
539
540
|
const { pathGroups, maxPosition } = convertPathGroupsForRanks(options.pathGroups ?? [], Object.keys(tsConfigPaths));
|
|
@@ -80,13 +80,8 @@ function findAliases({ filePath, originalImportPath, baseUrlAbsolutePath, paths,
|
|
|
80
80
|
}
|
|
81
81
|
return options;
|
|
82
82
|
}
|
|
83
|
-
const
|
|
84
|
-
'': ['.js', '.ts', '.jsx', '.tsx'],
|
|
85
|
-
'.js': ['.ts', '.js'],
|
|
86
|
-
};
|
|
83
|
+
const candidateExtensions = ['', '.js', '.jsx', '.ts', '.tsx'];
|
|
87
84
|
function fileExistsAtPath(filePath) {
|
|
88
|
-
const { ext } = path.parse(filePath);
|
|
89
|
-
const candidateExtensions = importExtensionMappings[ext] ?? [ext];
|
|
90
85
|
return candidateExtensions.some((ext) => fs.existsSync(filePath + ext));
|
|
91
86
|
}
|
|
92
87
|
function resolveAlias(importPath, matcher) {
|
package/lib/utils/ts-config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createPathsMatcher } from 'get-tsconfig';
|
|
2
2
|
import type { PluginSettings } from '../types.js';
|
|
3
3
|
export { createPathsMatcher };
|
|
4
|
-
export declare function loadConfig(settings: PluginSettings): {
|
|
4
|
+
export declare function loadConfig(settings: PluginSettings, currentFilePath: string): {
|
|
5
5
|
path: string;
|
|
6
6
|
config: {
|
|
7
7
|
compilerOptions?: import("get-tsconfig").TsConfigJson.CompilerOptions | undefined;
|
package/lib/utils/ts-config.js
CHANGED
|
@@ -2,11 +2,13 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createPathsMatcher, parseTsconfig } from 'get-tsconfig';
|
|
4
4
|
export { createPathsMatcher };
|
|
5
|
-
export function loadConfig(settings) {
|
|
6
|
-
const eslintConfigPath = findUp([
|
|
5
|
+
export function loadConfig(settings, currentFilePath) {
|
|
6
|
+
const eslintConfigPath = findUp(currentFilePath, [
|
|
7
7
|
'eslint.config.js',
|
|
8
8
|
'eslint.config.mjs',
|
|
9
9
|
'eslint.config.cjs',
|
|
10
|
+
'eslint.config.ts',
|
|
11
|
+
'eslint.config.mts',
|
|
10
12
|
]);
|
|
11
13
|
if (!eslintConfigPath || !fs.existsSync(eslintConfigPath)) {
|
|
12
14
|
return undefined;
|
|
@@ -21,8 +23,8 @@ export function loadConfig(settings) {
|
|
|
21
23
|
function getRelativeConfigFilePath(settings) {
|
|
22
24
|
return settings['mrpalmer/tsconfig'] ?? 'tsconfig.json';
|
|
23
25
|
}
|
|
24
|
-
function findUp(filenames) {
|
|
25
|
-
let directory =
|
|
26
|
+
function findUp(currentFilePath, filenames) {
|
|
27
|
+
let directory = currentFilePath;
|
|
26
28
|
const { root: stopAt } = path.parse(directory);
|
|
27
29
|
while (directory !== stopAt) {
|
|
28
30
|
const found = firstExistingPath(filenames, directory);
|