Skip to content

Commit 4e0ba69

Browse files
authored
Merge pull request #145 from samtsai/add-schema-for-rule-options
fix: add missing schema so eslint would accept options
2 parents 63827dc + acca85f commit 4e0ba69

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/rules/alias.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ tester.run('paths-alias', rule, {
5757
errors: ['Update import to @foo/x/y/z'],
5858
output: `import z from '@foo/x/y/z';`,
5959
},
60+
{
61+
name: 'relative named import from alias must be fixed',
62+
filename: path.resolve('./src/nested/index.ts'),
63+
code: `import { x } from '../qux/x/y/z';`,
64+
errors: ['Update import to @qux/x/y/z'],
65+
output: `import { x } from '@qux/x/y/z';`,
66+
},
6067
{
6168
name: 'absolute import from alias must be fixed',
6269
filename: path.resolve('./src/index.ts'),

src/rules/alias.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ function findAlias(
4949
// Remove basedir and slash in start
5050
const slicedImportPath = importPath
5151
.slice(baseDir.length + 1)
52-
.slice(path.dirname(matchedPath).length + 1);
53-
52+
.slice(path.dirname(path.normalize(matchedPath)).length + 1);
5453
// Remove asterisk from end of alias
5554
const replacedPathSegments = path
5655
.join(path.dirname(alias), slicedImportPath)
@@ -72,6 +71,21 @@ function findAlias(
7271
const rule: Rule.RuleModule = {
7372
meta: {
7473
fixable: 'code',
74+
schema: {
75+
type: 'array',
76+
minItems: 0,
77+
maxItems: 1,
78+
items: [
79+
{
80+
type: 'object',
81+
properties: {
82+
configFilePath: { type: 'string' },
83+
ignoredPaths: { type: 'array', items: { type: 'string' } },
84+
},
85+
additionalProperties: false,
86+
},
87+
],
88+
},
7589
},
7690
create(context) {
7791
const baseDir = findDirWithFile('package.json');

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"baseUrl": ".",
3434
"paths": {
3535
"@foo/*": ["src/foo/*"],
36-
"@bar/*": ["src/bar/*"]
36+
"@bar/*": ["src/bar/*"],
37+
"@qux/*": ["./src/qux/*"]
3738
}
3839
},
3940
"include": ["src/*.ts", "src/*.tsx", "src/**/*.ts", "src/**/*.tsx"]

0 commit comments

Comments
 (0)