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

[no-internal-modules] Extract violation types to options #2213

Open
ppapla opened this issue Aug 31, 2021 · 3 comments
Open

[no-internal-modules] Extract violation types to options #2213

ppapla opened this issue Aug 31, 2021 · 3 comments

Comments

@ppapla
Copy link

ppapla commented Aug 31, 2021

Hi, I'm wondering if potentialViolationTypes can be set from rule options, because I would like to apply this rule only to external, internal import and not e.g. sibling, parent.

const potentialViolationTypes = ['parent', 'index', 'sibling', 'external', 'internal'];

@ljharb
Copy link
Member

ljharb commented Aug 31, 2021

Can you elaborate as to why? also, why you can't use allow/forbid to control this?

@ppapla
Copy link
Author

ppapla commented Sep 1, 2021

Ok, sorry i will provide more context:
I already have allow defined like this

"rxjs/*",
"@angular/**",
"@app/**/*.paths"

@app is custom alias so i need to configure a resolver (this i.a. reads defined paths in tsconfig.json).

"settings": {
        "import/resolver": {
                "typescript": {}
        }
},

Without this custom aliases are treated as unresolved, but with this configured no-internal-modules rule reports also relative paths e.g. siblings.

I think it is useful to allow deep relative paths like ./editor/component/some.component and custom alias paths like @app/shared/some/some.paths(this is done through allow), but forbid other deep paths with custom aliases

Unfortunately i cannot use e.g. allow to do this because paths that are checked have ./, ../ removed so paths like ./foo ../foo/bar are changed to foo, foo/bar. Thus only way to allow relative paths is to add allow pattern e.g. [a-z]*/**, but this will also allow deep paths in e.g. core-js. And there is no way to distinguish relative path.
Belowe is code that check paths with removed ./ ../.

function toSteps(somePath) {
return normalizeSep(somePath)
.split('/')
.reduce((acc, step) => {
if (!step || step === '.') {
return acc;
} else if (step === '..') {
return acc.slice(0, -1);
} else {
return acc.concat(step);
}
}, []);
}

const justSteps = steps.join('/');
if (reachingAllowed(justSteps) || reachingAllowed(`/${justSteps}`)) return false;

@harunurhan
Copy link

I agree with @ppapla, it would be nice to have a way to allow this for relative imports. That would help with folks moving from tslint's no-submodule-imports see: typescript-eslint/tslint-to-eslint-config#1111.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants