[英]How to install Ktlint in windows
What I am trying to do : I am trying to install ktlint on windows locally我想做什么:我想在本地 Windows 上安装 ktlint
What I tried :我试过的:
Used below command in command prompt在命令提示符下使用以下命令
curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.38.1/ktlint && chmod a+x ktlint
Also tried above command by using in below steps in link还通过在链接中的以下步骤中使用上述命令
https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/
What is happening : Not able to install in windows.发生了什么:无法在 Windows 中安装。
I was having trouble installing ktlint for Windows 10. What worked for me was going to the Releases page, downloading the ktlint
file, renaming the ktlint
file to ktlint.jar
and adding it inside my Android project root folder (in reference to this GitHub issue ) (Note: Java must be installed so that the file extension can be recognized), then running java -jar ktlint.jar --apply-to-idea-project
(in the command line, from the Android project root directory).我在为 Windows 10 安装 ktlint 时遇到问题。 对我有用的是转到Releases页面,下载
ktlint
文件,将ktlint
文件重命名为ktlint.jar
并将其添加到我的 Android 项目根文件夹中(参考此 GitHub 问题)(注意:必须安装Java才能识别文件扩展名),然后运行java -jar ktlint.jar --apply-to-idea-project
(在命令行中,从Android项目根目录)。 Then finally I was able to get it to work, resulting in the following text:然后终于我能够让它工作,产生以下文本:
The following files are going to be updated:
.\.idea\codeStyles\codeStyleConfig.xml
.\.idea\codeStyles\Project.xml
.\.idea\inspectionProfiles\profiles_settings.xml
.\.idea\inspectionProfiles\ktlint.xml
.\.idea\workspace.xml
Do you wish to proceed? [y/n]
(in future, use -y flag if you wish to skip confirmation)
y
(updated)
Please restart your IDE
(if you experience any issues please report them at https://github.com/shyiko/ktlint)
Without updating the file to have the .jar
extension and adding .jar
to the filename command line parameter, I kept getting the following error:没有更新文件以具有
.jar
扩展名并将.jar
添加到 filename 命令行参数,我一直收到以下错误:
Error: Unable to access jarfile ktlint
To run ktlint immediately, run java -jar ktlint.jar
in the command line (in the directory where the ktlint.jar file resides).要立即运行
java -jar ktlint.jar
,请在命令行中运行java -jar ktlint.jar
(在 ktlint.jar 文件所在的目录中)。
You can install a git hook to automatically check files for style violations on commit by entering the following command in the Command Line (run "ktlint installGitPrePushHook" if you wish to run ktlint on push instead): java -jar ktlint.jar installGitPreCommitHook
您可以安装一个 git 钩子,通过在命令行中输入以下命令(如果您希望在推送时运行 ktlint,请运行“ktlint installGitPrePushHook”),在提交时自动检查文件是否存在样式违规:
java -jar ktlint.jar installGitPreCommitHook
But this will only allow you to set hook for your current command line session.但这只会允许您为当前的命令行会话设置挂钩。 If you close out of Command Prompt, the settings will be reset.
如果您关闭命令提示符,设置将被重置。 If you want to have the ktlinter run on every session for your project, you have to add the
java -jar ktlint.jar
command to your project's .git/hook/pre-commit
file and paste the ktlint.jar file into the .git/hook
folder as well.如果您希望在项目的每个会话上都运行 ktlinter,则必须将
java -jar ktlint.jar
命令添加到项目的.git/hook/pre-commit
文件中,并将 ktlint.jar 文件粘贴到.git/hook
文件夹也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.