Skip to content

Commit

Permalink
fix(linter): support directories for relative path fix
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed May 8, 2023
1 parent 0654776 commit caf8099
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/eslint-plugin/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@nx/devkit';
import { findNodes } from '@nx/js';
import { getModifiers } from '@typescript-eslint/type-utils';
import { existsSync, readFileSync } from 'fs';
import { existsSync, lstatSync, readdirSync, readFileSync } from 'fs';
import { dirname } from 'path';
import ts = require('typescript');

Expand Down Expand Up @@ -81,6 +81,16 @@ function hasMemberExport(exportedMember, filePath) {
}

export function getRelativeImportPath(exportedMember, filePath, basePath) {
if (lstatSync(filePath).isDirectory()) {
const file = readdirSync(filePath).find((file) =>
/^index\.[jt]sx?$/.exec(file)
);
if (file) {
filePath = joinPathFragments(filePath, file);
} else {
return;
}
}
const fileContent = readFileSync(filePath, 'utf8');

// use the TypeScript AST to find the path to the file where exportedMember is defined
Expand Down

0 comments on commit caf8099

Please sign in to comment.