зеркало из https://github.com/microsoft/rnx-kit.git
fix(eslint-plugin): exclude `eslint-plugin-react` if `react` is not installed (#2849)
This commit is contained in:
Родитель
2ba27400c9
Коммит
9842205db4
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@rnx-kit/eslint-plugin": patch
|
||||
---
|
||||
|
||||
Exclude `eslint-plugin-react` if `react` is not installed
|
|
@ -9,12 +9,26 @@ const compat = new FlatCompat({
|
|||
recommendedConfig: js.configs.recommended,
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} spec
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isInstalled(spec) {
|
||||
try {
|
||||
return Boolean(require.resolve(spec, { paths: [process.cwd()] }));
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const usesReact = isInstalled("react");
|
||||
const configs = ["plugin:@typescript-eslint/recommended"];
|
||||
if (usesReact) {
|
||||
configs.push("plugin:react-hooks/recommended", "plugin:react/recommended");
|
||||
}
|
||||
|
||||
module.exports = [
|
||||
...compat.extends(
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:react-hooks/recommended",
|
||||
"plugin:react/recommended"
|
||||
),
|
||||
...compat.extends(...configs),
|
||||
{
|
||||
languageOptions: {
|
||||
// @ts-expect-error No declaration file for module
|
||||
|
@ -43,7 +57,7 @@ module.exports = [
|
|||
},
|
||||
],
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"react/prop-types": "off",
|
||||
...(usesReact ? { "react/prop-types": "off" } : {}),
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
|
|
Загрузка…
Ссылка в новой задаче