Skip to content

Commit

Permalink
Merge pull request #145 from samtsai/add-schema-for-rule-options
Browse files Browse the repository at this point in the history
fix: add missing schema so eslint would accept options
  • Loading branch information
vitonsky authored Oct 25, 2024
2 parents 63827dc + acca85f commit 4e0ba69
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
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';`,
},
{
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);
// 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

0 comments on commit 4e0ba69

Please sign in to comment.