Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions .circleci/config.yml

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
audit:
name: Audit NPM packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: corepack enable
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: yarn
- run: yarn install
- run: yarn npm audit --severity critical

build:
name: Build library
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: corepack enable
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: yarn
- run: yarn install
- run: yarn build

test:
name: Test (${{ matrix.os }}, Node ${{ matrix.node-version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: ['22', '24']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
- run: corepack enable
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn install
- run: yarn test:coverage
- run: yarn codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![npm version](https://badge.fury.io/js/eslint-plugin-module-resolver.svg)](https://badge.fury.io/js/eslint-plugin-module-resolver)
[![npm downloads](https://img.shields.io/npm/dm/eslint-plugin-module-resolver.svg)](https://www.npmjs.com/package/eslint-plugin-module-resolver)
[![CircleCI](https://circleci.com/gh/HeroProtagonist/eslint-plugin-module-resolver.svg?style=shield)](https://app.circleci.com/pipelines/github/HeroProtagonist/eslint-plugin-module-resolver)
[![GitHub Actions CI Workflow Status](https://github.com/HeroProtagonist/eslint-plugin-module-resolver/actions/workflows/ci.yml/badge.svg)](https://github.com/HeroProtagonist/eslint-plugin-module-resolver/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/HeroProtagonist/eslint-plugin-module-resolver/branch/master/graph/badge.svg)](https://codecov.io/gh/HeroProtagonist/eslint-plugin-module-resolver)

Warn when using relative paths to modules aliased using [babel-plugin-module-resolver](https://github.com/tleunen/babel-plugin-module-resolver)
Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/create-fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const createFixer = (options = {}) => {

if (!source) return null

const aliasPaths = entries(alias).map(([key, value]) => [key, path.join(cwd, value)])
const aliasPaths = entries(alias).map(([key, value]) => [key, path.resolve(cwd, value)])
const resolvedPath = path.resolve(filePath, source.value)
const [aliasMatch, aliasPath] = aliasPaths.find(([_, aliasPath]) => isAliasPath(resolvedPath, aliasPath)) || []

if (!aliasMatch || !aliasPath) return null

const newPath = resolvedPath.replace(aliasPath, '')
const newPath = path.relative(aliasPath, resolvedPath)

const replacement = path.normalize(path.join(aliasMatch, newPath)).replace(/\\/g, '/').replace(/\/c:/gi, '')
const replacement = path.normalize(path.join(aliasMatch, newPath)).replace(/\\/g, '/')

return (fixer) => fixer.replaceTextRange([source.range[0] + 1, source.range[1] - 1], replacement)
}
Expand Down
18 changes: 6 additions & 12 deletions lib/rules/use-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,15 @@ module.exports = {

// Build array of alias paths.
const cwd = projectRootAbsolutePath || process.cwd()
const aliasPaths = values(alias).map((a) => path.join(cwd, a))
const aliasPaths = values(alias).map((a) => path.resolve(cwd, a))

const hasError = (val) => {
if (!val) return false // template literals will have undefined val

const { ignoreDepth, projectRoot, extensions, allowDepthMoreOrLessThanEquality } = options
let {chainedExtensions = []} = options;
let { chainedExtensions = [] } = options
// Be forgiving if the config provides "ext" or ".ext"
chainedExtensions = chainedExtensions.map(
ext => ext.startsWith('.') ? ext : `.${ext}`
);
chainedExtensions = chainedExtensions.map((ext) => (ext.startsWith('.') ? ext : `.${ext}`))

// Ignore if directory depth matches options.
if (checkIgnoreDepth({ ignoreDepth, path: val, allowDepthMoreOrLessThanEquality })) return false
Expand All @@ -126,22 +124,18 @@ module.exports = {
}

const resolvedPath = path.resolve(filePath, val)
const pathExt = path.extname(val);
const pathExt = path.extname(val)
// If no extension is present, or if the extension is explicitly
// allowlisted as chainable, resolve the extension to a `.js` file.
const resolvedExt = !pathExt || chainedExtensions.includes(pathExt)
? '.js'
: ''
const resolvedExt = !pathExt || chainedExtensions.includes(pathExt) ? '.js' : ''

let pathExists = checkPath(resolvedPath, resolvedExt)

if (extensions && !pathExists) {
pathExists = extensions.filter((ext) => checkPath(resolvedPath, ext)).length
}

const isAliased = aliasPaths.some((aliasPath) =>
isAliasPath(resolvedPath, aliasPath)
)
const isAliased = aliasPaths.some((aliasPath) => isAliasPath(resolvedPath, aliasPath))

const error = isAliased && pathExists && val.match(/\.\.\//) // matches, exists, and starts with ../,
return error && { suggestFix: true, message: 'Do not use relative path for aliased modules' }
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.5.0",
"description": "Warn when using relative paths to modules aliased",
"repository": "HeroProtagonist/eslint-plugin-module-resolver",
"packageManager": "yarn@4.17.1",
"devEngines": {
"runtime": {
"name": "node",
Expand Down
8 changes: 4 additions & 4 deletions tests/babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
plugins: [
{
file: {
request: 'babel-plugin-module-resolver'
request: 'babel-plugin-module-resolver',
},
options: {
root: ['.'],
Expand All @@ -13,7 +13,7 @@ module.exports = {
lib: './lib',
ClientMain: './src/client/main',
},
}
}
]
},
},
],
}