Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing schema so eslint would accept options #145

Merged
merged 3 commits into from
Oct 25, 2024
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
7 changes: 7 additions & 0 deletions src/rules/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';`,
},
vitonsky marked this conversation as resolved.
Show resolved Hide resolved
{
name: 'absolute import from alias must be fixed',
filename: path.resolve('./src/index.ts'),
Expand Down
18 changes: 16 additions & 2 deletions src/rules/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
vitonsky marked this conversation as resolved.
Show resolved Hide resolved
// Remove asterisk from end of alias
const replacedPathSegments = path
.join(path.dirname(alias), slicedImportPath)
Expand All @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading