diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 214e6b1..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,69 +0,0 @@ -# https://circleci.com/docs/2.0/sample-config/#sample-configuration-with-sequential-workflow -# https://circleci.com/blog/circleci-matrix-jobs -version: 2.1 - -executors: - node: - docker: - - image: cimg/node:lts - linux: - docker: - - image: cimg/base:2020.01 - macos: - macos: - xcode: 12.5.1 - windows: - machine: - image: windows-server-2019-vs2019:stable - shell: bash.exe - resource_class: windows.medium - -orbs: - node: circleci/node@5.0.2 - -jobs: - audit: - executor: node - steps: - - checkout - - run: - name: Audit NPM packages - command: yarn audit --level critical - build: - executor: node - steps: - - checkout - - node/install-packages: - pkg-manager: yarn - - run: - name: Build library - command: yarn build - test: - parameters: - os: - type: executor - node-version: - type: string - executor: << parameters.os >> - steps: - - checkout - - node/install: - node-version: << parameters.node-version >> - install-yarn: true - - run: - name: Install packages - command: yarn install - - run: - name: Run tests - command: yarn test:coverage && yarn codecov - -workflows: - run-ci: - jobs: - - audit - - build - - test: - matrix: - parameters: - os: [linux, macos, windows] - node-version: ["16.14.2"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..039bfed --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/README.md b/README.md index e25bd7c..5c8c968 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/helpers/create-fixer.js b/lib/helpers/create-fixer.js index 4bb6bec..80530d3 100644 --- a/lib/helpers/create-fixer.js +++ b/lib/helpers/create-fixer.js @@ -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) } diff --git a/lib/rules/use-alias.js b/lib/rules/use-alias.js index 4e4af31..c208823 100644 --- a/lib/rules/use-alias.js +++ b/lib/rules/use-alias.js @@ -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 @@ -126,12 +124,10 @@ 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) @@ -139,9 +135,7 @@ module.exports = { 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' } diff --git a/package.json b/package.json index 866f6ba..efa0eb2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/babelrc.js b/tests/babelrc.js index bcdb406..035c6a3 100644 --- a/tests/babelrc.js +++ b/tests/babelrc.js @@ -3,7 +3,7 @@ module.exports = { plugins: [ { file: { - request: 'babel-plugin-module-resolver' + request: 'babel-plugin-module-resolver', }, options: { root: ['.'], @@ -13,7 +13,7 @@ module.exports = { lib: './lib', ClientMain: './src/client/main', }, - } - } - ] + }, + }, + ], }