Skip to content

Commit

Permalink
fix: correct relativeImportPath reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jul 11, 2023
1 parent 0ba04b9 commit e0f542f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/rules/noBarrelImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { type TSESTree } from '@typescript-eslint/utils';
import { type RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
import * as recast from 'recast';
import { createRule } from '../utilities';
import ExportMapAny from './ExportMap';
import { findDirectory } from '../utilities/findDirectory';
import ExportMapAny from './ExportMap';

/**
* https://stackoverflow.com/a/45242825/368691
*/
const isSubPath = (parent: string, subject: string) => {
const rel = relative(parent, subject);

return rel && !rel.startsWith('..') && !isAbsolute(rel);
};

Expand Down Expand Up @@ -111,22 +111,20 @@ export default createRule<Options, MessageIds>({
}

// This is a temporary approach to avoid rewriting imports of packages.
// In practice, we want to ensure that we are not importing barrels either.
// In practice, we want to ensure that we are not importing barrels either.
if (importSource.includes('node_modules')) {
return;
}

const relativeImportPath = formatRelativeImport(myPath, importSource);

// This is a temporary approach to avoid rewriting imports of packages.
// In practice, we want to ensure that we are not importing barrels either.
// In practice, we want to ensure that we are not importing barrels either.
if (relativeImportPath.includes('node_modules')) {
return;
}

const newImport = `import ${
node.local.name
} from '${relativeImportPath}';`;
const newImport = `import ${node.local.name} from '${relativeImportPath}';`;

context.report({
fix(fixer) {
Expand Down Expand Up @@ -183,7 +181,7 @@ export default createRule<Options, MessageIds>({
const relativeImportPath = formatRelativeImport(myPath, importSource);

// This is a temporary approach to avoid rewriting imports of packages.
// In practice, we want to ensure that we are not importing barrels either.
// In practice, we want to ensure that we are not importing barrels either.
if (relativeImportPath.includes('node_modules')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"dependencies": {
"roarr": "^7.14.2"
},
"name": "foo"
}

0 comments on commit e0f542f

Please sign in to comment.