如何使eslint在git钩子预提交中工作(它只在终端中工作)?

如何使eslint在git钩子预提交中工作(它只在终端中工作)?,git,eslint,githooks,eslintrc,Git,Eslint,Githooks,Eslintrc,我尝试在预提交钩子上设置简单的eslint检查 其中有一个包含git repo和项目文件夹的文件夹: test3/ —.git —project1/ ——node_modules/ ——src/ ———js/ ————1.js ——.eslintrc.json 我在本地设置了eslint,并: 创建config.eslintrc.json: { "extends": "standard"} 在终端启动它-它工作完美: ./node_modules/.bin/eslint src/js 尝试

我尝试在预提交钩子上设置简单的eslint检查

其中有一个包含git repo和项目文件夹的文件夹:

test3/
—.git
—project1/
——node_modules/
——src/
———js/
————1.js
——.eslintrc.json
我在本地设置了eslint,并:

创建config.eslintrc.json:

{ "extends": "standard"}
在终端启动它-它工作完美:

./node_modules/.bin/eslint src/js
尝试创建git钩子,转到
.git/hooks
,在
预提交中重命名
预提交.sample
。删除所有内部代码并插入我自己的代码:

path="$(git rev-parse --show-toplevel)"
"$path/project1/node_modules/.bin/eslint" "$path/project1/src/js/"
尝试提交js文件中的更改,并获得错误:

[notebook@NOTEBOOKs-MacBook-Pro project1 (master +)]$ git commit -m "T"
Oops! Something went wrong! :(
ESLint: 6.6.0.

ESLint couldn't find the plugin "eslint-plugin-import".

(The package "eslint-plugin-import" was not found when loaded as a Node module from the directory "/Users/notebook/Documents/Projects/test3".)
It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm install eslint-plugin-import@latest --save-dev
The plugin "eslint-plugin-import" was referenced from the config file in "project1/.eslintrc.json » eslint-config-standard".

If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.

看起来本地eslint没有看到自己的本地插件。我怎么能给他看?我应该在哪里写插件的正确路径?

我也遇到过同样的问题。为了修复它,我需要在我的git钩子中指定包含插件的目录:

eslint --resolve-plugins-relative-to C:/Users/<Username>/AppData/Roaming/npm/node_modules $FILE
eslint——解析与C:/Users//AppData/Roaming/npm/node_modules$FILE相关的插件
我不知道为什么手动运行命令和让git钩子运行命令的效果不同

eslint --resolve-plugins-relative-to C:/Users/<Username>/AppData/Roaming/npm/node_modules $FILE