我试图使用配置文件的指定路径,针对单个文件运行ESLint的全局安装:
eslint FileToCheck.jsx --config "../path/to/config/.eslintrc.js"但我知道错误了
ESLint找不到这个插件“eslint-plugin-jx-a11y”。这种情况可能有几个不同的原因:
所以看来#1是适用的,我需要在全球范围内安装eslint-plugin-jsx a11y。我试着用
yarn global add eslint-plugin-jsx-a11y并重新运行原始的ESLint命令,但同样的错误会失败。我在yarn global add中注意到一些输出
“a11y@6.0.2”没有二进制文件。
实际上,当我检查~/AppData/Local/Yarn/bin时,我找不到该插件的任何二进制文件(尽管我是针对ESLint的)。
如何让ESLint在全球运行?--一个好的答案不会告诉我仅仅是在本地安装它,而是实际上回答了这个问题--如何通过全局安装的ESLint和插件来实现这一点。
我已经在全球安装了纱线包装:
以下是我的.eslintrc.js,它可能与此相关,也可能与此无关:
module.exports = {
'extends': 'airbnb',
'plugins': [
'react',
'jsx-a11y',
'import'
],
'env': {
'browser': true
},
'parser': 'babel-eslint',
'rules': {
'prefer-template': 'error',
'comma-dangle': ['error', 'always-multiline'],
'import/no-extraneous-dependencies': 'off',
'react/prop-types': 'off',
'react/jsx-no-bind': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/no-noninteractive-element-interactions': 'off',
'jsx-a11y/alt-text': 'off',
'jsx-a11y/no-autofocus': 'off',
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
'no-use-before-define': ['error', { 'functions': false }],
'func-style': ['error', 'declaration', { 'allowArrowFunctions': true }],
'no-console': 'off',
'no-alert': 'off',
'no-continue': 'off',
'no-param-reassign': ['error', { 'props': false }],
'no-plusplus': ['error', { 'allowForLoopAfterthoughts': true }],
'one-var-declaration-per-line': ['error', 'initializations'],
'one-var': 'off', // Not needed because of one-var-declaration-per-line
'indent': ['error', 2, {
'FunctionDeclaration': { 'parameters': 'first' },
'SwitchCase': 1
}],
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
}
};
if (process.env.FEATURE_FLAGS) {
const flags = Object.keys(JSON.parse(process.env.FEATURE_FLAGS));
module.exports.globals = flags.reduce(function (flagConfig, flag) {
flagConfig[flag] = false;
return flagConfig;
}, {});
}发布于 2019-11-12 19:07:13
此问题是由于ESLint在版本5和6之间加载包的方式发生了变化。请参阅详情请到这里。
插件和可共享的信任不再受ESLint位置的影响 以前,ESLint加载的插件相对于ESLint包本身的位置。因此,我们建议具有全局ESLint安装的用户也应该在全局安装插件,具有本地ESLint安装的用户应该在本地安装插件。但是,由于设计错误,这一策略导致ESLint在某些情况下随机地无法加载插件和可共享的信任,特别是在使用lerna和Yarn‘Play等包管理工具时。 经验法则是:对于ESLint v6,应该始终在本地安装插件,即使ESLint是全局安装的。更准确地说,ESLint v6默认解析相对于最终用户的项目的插件,并且总是相对于导入它们的配置文件的位置解析可共享的信任和解析器。 要解决的问题是:如果您使用ESLint的全局安装(例如与
npm install eslint --global一起安装)以及插件,那么您应该在运行ESLint的项目中本地安装这些插件。如果您的配置文件扩展了可共享的信任和/或解析器,则应确保将这些包安装为包含配置文件的项目的依赖项。 如果使用位于本地项目外部的配置文件(带有--config标志),请考虑将插件安装为该配置文件的依赖项,并将--resolve-plugins-relative-to标志设置为配置文件的位置。
关于这一点,我们有不少讨论,但目前(2019年末)的情况似乎是,在这一点上没有好的解决方案
https://stackoverflow.com/questions/46781324
复制相似问题