eslint-plugin-import
eslint-plugin-import copied to clipboard
Allow ignoring some import names
we have an issue where the plugin flags OnInit
as not found in "@angular/core"
even tho it's there.
We'd like to mark that variable name as ignored in the rule, something like:
"import/named": ["error", { ignoreNames: "OnInit" }]
is there a way currently to achieve that?
We currently can't use the plugin because of that
You could of course use the plugin but use an eslint override for that one case.
Are you using TS, and its missing from the types? If you’re not using TS, then I’d love more information so i can reproduce it.
I am using TS, but the error is:
OnInit not found in '@angular/core' eslint import/named
how do I use an eslint override?
This is the eslintrc.js
, let me know if you need ore information
const path = require("path");
module.exports = {
extends: getExtends(),
plugins: getPlugins(),
rules: getRules(),
parserOptions: getParserOptions(),
parser: "@typescript-eslint/parser",
env: getEnv(),
settings: getSettings(),
};
function getExtends() {
return [
"eslint:recommended",
'plugin:import/errors',
'plugin:import/warnings',
"plugin:@typescript-eslint/recommended",
];
}
function getPlugins() {
return [
'import',
"@typescript-eslint",
];
}
function getRules() {
return {
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-unsafe-member-access": 0,
"@typescript-eslint/no-unsafe-call": 0,
"@typescript-eslint/no-unsafe-assignment": 0,
"no-unused-vars": 0,
"import/no-anonymous-default-export": 0,
"no-console": ["error", { allow: ["warn", "error", "info"] }],
"import/no-named-as-default": 0,
"import/no-named-as-default-member": 0,
"prefer-const": 2,
"no-var": 2,
"@typescript-eslint/no-unused-vars": [
"error",
{ vars: "all", args: "after-used", ignoreRestSiblings: true },
],
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
"index",
"sibling",
"parent",
],
"newlines-between": "always",
},
],
};
}
function getParserOptions() {
return {
ecmaVersion: 12,
project: [path.resolve(__dirname, "tsconfig.json")],
};
}
function getEnv() {
return {
es2021: true,
};
}
function getSettings() {
return {
"import/parsers": {
"@typescript-eslint/parser": [".ts"],
},
"import/resolver": {
node: {
extensions: [".js", ".ts"],
},
},
};
}
@ljharb ?
overrides are documented in eslint’s config docs.
I’ll try to take a look at this soon.
import/named
@goldylucks I was having the same problem, but in my case I found the solution updating my angular project to the last version of eslint
https://unpkg.com/browse/@angular/[email protected]/package.json doesn't contain a "main", nor an index.js
, and this plugin doesn't support the "exports" field yet.
However, it does have a "module" field, but https://unpkg.com/browse/@angular/[email protected]/fesm2015/core.mjs doesn't export "OnInit".
So, this is either a correct error, or, a consequence of not yet supporting "exports". It's unfortunate @angular/core
doesn't provide a "main" for backwards compatibility. In the future, when resolve
supports exports
, we will too.