diff --git a/src/rules/alias.test.ts b/src/rules/alias.test.ts index 0f1eb26..3393ae4 100644 --- a/src/rules/alias.test.ts +++ b/src/rules/alias.test.ts @@ -57,6 +57,13 @@ tester.run('paths-alias', rule, { errors: ['Update import to @foo/x/y/z'], output: `import z from '@foo/x/y/z';`, }, + { + name: 'relative named import from alias must be fixed', + filename: path.resolve('./src/nested/index.ts'), + code: `import { x } from '../qux/x/y/z';`, + errors: ['Update import to @qux/x/y/z'], + output: `import { x } from '@qux/x/y/z';`, + }, { name: 'absolute import from alias must be fixed', filename: path.resolve('./src/index.ts'), diff --git a/src/rules/alias.ts b/src/rules/alias.ts index f075279..2f29a04 100644 --- a/src/rules/alias.ts +++ b/src/rules/alias.ts @@ -49,8 +49,7 @@ function findAlias( // Remove basedir and slash in start const slicedImportPath = importPath .slice(baseDir.length + 1) - .slice(path.dirname(matchedPath).length + 1); - + .slice(path.dirname(path.normalize(matchedPath)).length + 1); // Remove asterisk from end of alias const replacedPathSegments = path .join(path.dirname(alias), slicedImportPath) @@ -72,6 +71,21 @@ function findAlias( const rule: Rule.RuleModule = { meta: { fixable: 'code', + schema: { + type: 'array', + minItems: 0, + maxItems: 1, + items: [ + { + type: 'object', + properties: { + configFilePath: { type: 'string' }, + ignoredPaths: { type: 'array', items: { type: 'string' } }, + }, + additionalProperties: false, + }, + ], + }, }, create(context) { const baseDir = findDirWithFile('package.json'); diff --git a/tsconfig.json b/tsconfig.json index 9d45dab..f2078f9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,7 +33,8 @@ "baseUrl": ".", "paths": { "@foo/*": ["src/foo/*"], - "@bar/*": ["src/bar/*"] + "@bar/*": ["src/bar/*"], + "@qux/*": ["./src/qux/*"] } }, "include": ["src/*.ts", "src/*.tsx", "src/**/*.ts", "src/**/*.tsx"]