如何在pre-commit.com中使用新的coursier语言?

问题描述

我正在使用pre-commit 2.8.2并尝试使新的coursier语言起作用。

我能够从CLI成功运行coursier命令。

❯ cs launch io.gitlab.arturbosch.detekt:detekt-cli:1.14.2 -M io.gitlab.arturbosch.detekt.cli.Main -r https://kotlin.bintray.com/kotlinx -- --help
Usage: detekt [options]
  Options:
    --auto-correct,-ac
      Allow rules to auto correct code if they support it. The default rule 
      sets do NOT support auto correcting and won't change any line in the 
      users code base. However custom rules can be written to support auto 
      correcting. The additional 'formatting' rule set,added with 
      '--plugins',does support it and needs this flag.
      Default: false

但是,我不清楚如何根据文档为钩针声明一个钩子。有没有使用coursier进行审查的示例?这就是我在.pre-commit-hooks.yaml中拥有的。

---
- id: detekt
  name: detekt
  description: "Runs the Detekt static code analyzer."
  language: coursier
  entry: launch io.gitlab.arturbosch.detekt:detekt-cli:1.14.2 -M io.gitlab.arturbosch.detekt.cli.Main -r https://kotlin.bintray.com/kotlinx
  files: \.kt$
  require_serial: true

当我尝试使用挂钩时,出现此错误

❯ pre-commit try-repo /Users/dustin/workspaces/pre-commit/pre-commit-jvm detekt --verbose --all-files
[WARNING] Creating temporary repo with uncommitted changes...
===============================================================================
Using config:
===============================================================================
repos:
-   repo: /var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmpl5i4qu5r/shadow-repo
    rev: 233b290c180e6f6639f14689505ce5098c1c27ad
    hooks:
    -   id: detekt
===============================================================================
[INFO] Initializing environment for /var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmpl5i4qu5r/shadow-repo.
[INFO] Installing environment for /var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmpl5i4qu5r/shadow-repo.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmpl5i4qu5r/repo3f0zmsce/.pre-commit-channel'
Check the log at /Users/dustin/.cache/pre-commit/pre-commit.log

解决方法

找到的解决方案:

  1. Coursier语言还需要创建一个.pre-commit-channel / detekt.json文件。
    {
  "mainClass" : "io.gitlab.arturbosch.detekt.cli.Main","repositories": [
    "central","https://kotlin.bintray.com/kotlinx"
  ],"dependencies": [
    "io.gitlab.arturbosch.detekt:detekt-cli:1.14.2"
  ]
}
  1. 最后,将.pre-commit-hooks.yaml更新为
---
- id: detekt
  name: detekt
  description: "Runs the Detekt static code analyzer."
  language: coursier
  entry: detekt
  args: ["--config","detekt-config.yml"]
  pass_filenames: false
  files: \.kt$
  require_serial: true

故意造成违规,并且钩子将其捕获。

❯ pre-commit try-repo /Users/dustin/workspaces/pre-commit/pre-commit-jvm detekt --all-files
[WARNING] Creating temporary repo with uncommitted changes...
===============================================================================
Using config:
===============================================================================
repos:
-   repo: /var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmp23ad2fe4/shadow-repo
    rev: 452f70214d1960a82bff4c11523ecb36d5f6f333
    hooks:
    -   id: detekt
===============================================================================
[INFO] Initializing environment for /var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmp23ad2fe4/shadow-repo.
[INFO] Installing environment for /var/folders/x7/18ntjgfd2j5gy1g1xlzby15w0000gq/T/tmp23ad2fe4/shadow-repo.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
detekt...................................................................Failed
- hook id: detekt
- exit code: 2

/Users/dustin/workspaces/spring-boot/custom-starters/txn-app-event-starter/src/main/java/com/dustinsand/txn/app/event/TransactionalApplicationEventAutoConfiguration.kt - 5min debt
        WildcardImport - [/Users/dustin/workspaces/spring-boot/custom-starters/txn-app-event-starter/src/main/java/com/dustinsand/txn/app/event/TransactionalApplicationEventAutoConfiguration.kt] at /Users/dustin/workspaces/spring-boot/custom-starters/txn-app-event-starter/src/main/java/com/dustinsand/txn/app/event/TransactionalApplicationEventAutoConfiguration.kt:7:1

Overall debt: 5min

Build failed with 1 weighted issues.

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...