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
Bug: no-unsafe-*
rules interpret imports ending in .ts
as any
#5921
Comments
no-unsafe-*
rules are not compatible with imports ending in .ts
no-unsafe-*
rules interpret imports ending in .ts
as any
To clarify - do you mean you use other type-aware lint rules and they work fine with these
Our types come from TypeScript - we're built directly on top of the TS apis. Given this is probably just module resolution - you could likely work around this by building a custom module resolver: |
Thanks! We were indeed able to fix this with our own resolver. For anyone else trying to do the same, here's what we went with: // ts-resolver.js
const ts = require(`typescript`);
const tsExtension = /\.ts$/;
module.exports = {
resolveModuleNames: (
moduleNames,
containingFile,
reusedNames,
redirectedReference,
options
) => moduleNames.map((moduleName) =>
ts.resolveModuleName(
moduleName.replace(tsExtension, ``),
containingFile,
options,
ts.sys
).resolvedModule
),
}; // .eslintrc.js
module.exports = {
env: {
node: true,
},
overrides: [
{
files: [`*.ts`],
parser: `@typescript-eslint/parser`,
parserOptions: {
moduleResolver: __dirname + `/ts-resolver.js`,
},
},
],
}; That said, while this works fine for
We made some progress with const ts = require(`typescript`);
const denoResolver = require(`eslint-import-resolver-deno`);
const tsExtension = /\.ts$/;
module.exports = {
resolveModuleNames: (
moduleNames,
containingFile,
reusedNames,
redirectedReference,
options
) => moduleNames.map((moduleName) => {
if (moduleName.startsWith(`http`)) {
const { found, path } = denoResolver.resolve(
moduleName,
containingFile,
{
importMap: __dirname + `/import-map.json`,
}
);
if (found) {
moduleName = path;
}
}
return ts.resolveModuleName(
moduleName.replace(tsExtension, ``),
containingFile,
options,
ts.sys
).resolvedModule;
}),
}; ...but that still doesn't work, probably because Eslint doesn't "know" about Deno's global types. So, in conclusion, we're going to stop putting lipstick on a pig and trying to use type-aware rules with Deno. @bartolomieju mentioned that Deno is looking into native support for Eslint rules, so hopefully that gets added somewhere down the line. Thanks for your help @bradzacher ! |
Before You File a Bug Report Please Confirm You Have Done The Following...
Issue Description
If we import a file from a path ending in
.ts
, then theno-unsafe-*
rules are triggered:We're using Eslint with Deno, since Deno's linter doesn't provide alternatives for all the rules we've historically used. Except for this issue it has worked flawlessly: types are resolved correctly and linting works as expected.
Typescript does not yet support importing with
.ts
extension, but since Eslint otherwise seems compatible with these imports we consider this a bug.Reproduction Repository Link
https://github.com/RobertAKARobin/eslint-import-debug
Repro Steps
npm install
npm run lint
"An import path cannot end with a '.ts' extension."
Versions
@typescript-eslint/eslint-plugin
5.42.0
@typescript-eslint/parser
5.42.0
ESLint
8.26.0
Typescript
(via Deno)4.8.3
Deno
1.26.2
The text was updated successfully, but these errors were encountered: