
기쁨을 불러 일으키는 Clojure 코드 용 정적 분석기 및 Linter.

CLJ-Kondo에게 감사드립니다. 그것은 나를위한 동반자와 같습니다. Clojure를 다시 재미있게 만들었습니다.
- Clojurians Slack의 @geraldodev
CLJ-Kondo는 Clojure, Clojurescript 및 Edn에 대한 정적 분석을 수행합니다. 입력하는 동안 (프로그램을 실행하지 않고) 잠재적 오류에 대해 알려줍니다.
CLJ-Kondo는 다음을 감지합니다.
def 표현let dolet and letfn 바인딩 호출recur 포함)clojure.test/deftest 의 주장이 누락되었습니다양식이 회신하기 전에.
다음과 같은 여러 스타일 가이드 권장 사항을 제안합니다.
:else cond 의 CATCH-ALL TEST EXPRESSION (Clojure Style Guide 참조)으로seq 사용합니다 (not (empty? ,,,)) (Clojure 스타일 가이드 참조).
clojure.core.async/alt!! , schema.core/defn 및 potemkin/import-vars .
deps.edn 및 bb.edn 에서 일반적인 오류를 감지합니다
분석 데이터를 제공하므로 자신의 사용자 정의 라이터를 구축합니다.
여기에서 사용 가능한 모든 라이터를보십시오.
이 린터는 다음과 같습니다.
.clj , .cljs , .cljc 및 .edn 파일과 호환됩니다.대화식 놀이터에서 Clj-Kondo를 사용해보십시오.
대화보기 :
GitHub 스폰서, OpenCollective, Ko-Fi 또는 Clojurists를 통해 간접적 으로이 프로젝트를 지원할 수 있습니다.
Stdin의 보풀 :
$ echo ' (def x (def x 1)) ' | clj-kondo --lint -
<stdin>:1:8: warning: inline def파일을 보린 :
$ echo ' (def x (def x 1)) ' > /tmp/foo.clj
$ clj-kondo --lint /tmp/foo.clj
/tmp/foo.clj:1:8: warning: inline def디렉토리를 보린 :
$ clj-kondo --lint src
src/clj_kondo/test.cljs:7:1: warning: redundant do
src/clj_kondo/calls.clj:291:3: error: Wrong number of args (1) passed to clj-kondo.calls/analyze-callsProject ClassPath를 보린하십시오 :
$ clj-kondo --lint " $( lein classpath ) "돕다:
$ clj-kondo --help
clj-kondo v2024.11.14
Options:
--lint <file>: a file can either be a normal file, directory or classpath. In the
case of a directory or classpath, only .clj, .cljs and .cljc will be
processed. Use - as filename for reading from stdin.
--lang <lang>: if lang cannot be derived from the file extension this option will be
used. Supported values: clj, cljs, cljc.
--filename <file>: in case stdin is used for linting, use this to set the
reported filename.
--cache-dir: when this option is provided, the cache will be resolved to this
directory. If --cache is false, this option will be ignored.
--cache: if false, won't use cache. Otherwise, will try to resolve cache
using `--cache-dir`. If `--cache-dir` is not set, cache is resolved using the
nearest `.clj-kondo` directory in the current and parent directories.
--config <config>: extra config that is merged. May be a file or an EDN expression. See https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md.
--config-dir <config-dir>: use this config directory instead of auto-detected
.clj-kondo dir.
--parallel: lint sources in parallel.
--dependencies: don't report any findings. Useful for populating cache while linting dependencies.
--copy-configs: copy configs from dependencies while linting.
--skip-lint: skip lint/analysis, still check for other tasks like copy-configs.
--fail-level <level>: minimum severity for exit with error code. Supported values:
warning, error. The default level if unspecified is warning.
--report-level <level>: minimum severity for which to report. Supported values:
info, warning, error. The default level if unspecified is info.
--debug: print debug information. 프로젝트의 네임 스페이스에서 보풀 오류를 감지하려면 캐시가 필요합니다. Clj-Kondo를 어디에서 만들겠습니까? 프로젝트의 루트에서 .clj-kondo 디렉토리를 만들려면 project.clj , deps.edn 또는 build.boot 와 같은 수준에서.
$ mkdir -p .clj-kondo clj-kondo 실행하면 캐시가 생성됩니다. 편집자 안에 줄을 서기 전에 Clojure 및/또는 Clojurescript 자체를 포함하여 사용중인 모든 라이브러리에 대해 clj-kondo 가르치기 위해 전체 클래스 경로를 보라는 것이 좋습니다. 일부 라이브러리에는 구성이 제공됩니다. 가져 오려면 먼저 실행 :
$ clj-kondo --lint " <classpath> " --dependencies --copy-configs --skip-lint --copy-configs 플래그는 종속성에서 .clj-kondo 디렉토리로 구성된 구성을 검색하고 복사합니다 (config.md 참조).
구성을 마련하면 이제 종속성을 올바르게 분석 할 수 있습니다.
$ clj-kondo --lint " <classpath> " --dependencies --parallel --dependencies 플래그는 CLJ-Kondo가 캐시를 채우는 소스를 분석하는 데 사용됨을 나타냅니다. 활성화되면 CLJ-Kondo는 성능을 위해 이미 보풀 .jar 뿌려서 경고를 억제하고 건너 뜁니다.
--parallel 옵션은 여러 스레드를 사용하여 소스를 더 빨리 보면서 더 빨리 통과합니다.
참고 : 2024.05.24 이후 버전에서 구성 및 라인의 종속성 복사를 한 번에 수행 할 수 있습니다.
$ clj-kondo --lint " <classpath> " --dependencies --parallel --copy-configs클래스 경로를 얻는 도구 구체적인 방법을 구축하십시오.
lein classpathboot with-cp -w -f -clojure -Spathnpx shadow-cljs classpath lein 의 경우 전체 명령은 다음과 같습니다.
$ clj-kondo --lint "$(lein classpath)" --dependencies --parallel --copy-configs
이제 편집기 통합을 사용하여 단일 파일을 보린 할 준비가되었습니다. 편집기에서 파일을 편집 할 때 발생하는 일에 대한 시뮬레이션 :
$ echo ' (select-keys) ' | clj-kondo --lang cljs --lint -
<stdin>:1:1: error: Wrong number of args (0) passed to cljs.core/select-keys Clj-Kondo는 이제 캐시를 통해 Clojurescript 버전에 대해 알고 있으므로 select-keys 에 전달한 인수의 수가 유효하지 않다는 것을 감지합니다. 파일을 편집 할 때마다 캐시가 점진적으로 업데이트되므로 CLJ-Kondo는 방금 작성한 새로운 기능에 대한 정보를 제공합니다.
다른 디렉토리를 사용하여 캐시를 읽고 쓰려면 --cache-dir 옵션을 사용하십시오. .clj-kondo 디렉토리가 있더라도 캐시를 비활성화하려면 --cache false 사용하십시오.
종료 코드는 --fail-level <level> 옵션으로 제어 할 수 있습니다. 기본 실패 레벨은 다음과 같이 종료 코드를 반환하는 warning 입니다.
0 : 오류 나 경고가 발견되지 않았습니다2 : 하나 이상의 경고가 발견되었습니다3 : 하나 이상의 오류가 발견되었습니다 --fail-level error 제공되는 경우 경고는 0이 아닌 출구 코드로 이어지지 않습니다.
0 : 오류가 발견되지 않았습니다0 : 하나 이상의 경고가 발견되었습니다3 : 하나 이상의 오류가 발견되었습니다 0 , 2 및 3 이외의 모든 종료 코드는 CLJ-Kondo의 버그 또는 CLJ-Kondo를 제어 할 수없는 다른 예상치 못한 오류로 인해 오류를 나타냅니다.
CLJ-Kondo는 정적 분석기이므로 런타임이 필요하지 않습니다 (JVM, 브라우저, Node.js 등). 코드를 실행하지 않습니다. 따라서 Eastwood와 같이 런타임을 사용하는 Linters에 대한 더 빠른 대안이 될 수 있습니다. 이 접근법은 CLJ-Kondo가 매크로가 런타임에서 임의의 기능을 사용할 수 있으므로 매크로를 실행할 수 없다는 제한 사항과 함께 제공됩니다. CLJ-Kondo는 Clojure Core Macros와 커뮤니티의 인기있는 도서관을 지원합니다. 상자에서 지원되지 않는 매크로는 구성을 사용하여 지원할 수 있습니다. 매크로를 구성하는 방법 중 하나는 고리를 작성하는 것입니다 (이 블로그 포스트 참조). 많은 라이브러리의 경우 이미 가져올 수있는 구성이 있습니다. 또한 타사 라이브러리에 대한 구성이 포함 된 CLJ-Kondo 구성을 확인하십시오.
CLJ-Kondo는 Babashka Pod로 호출 될 수 있습니다.
#! /usr/bin/env bb
( ns script
( :require [babashka.pods :as pods]))
( pods/load-pod " clj-kondo " )
( require '[pod.borkdude.clj-kondo :as clj-kondo])
( clj-kondo/merge-configs
'{ :linters { :unresolved-symbol { :exclude [( foo1.bar )]}}}
'{ :linters { :unresolved-symbol { :exclude [( foo2.bar )]}}})
; ;=> {:linters {:unresolved-symbol {:exclude [(foo1.bar) (foo2.bar)]}}}
( -> ( clj-kondo/run! { :lint [ " src " ]})
:summary )
; ;=> {:error 0, :warning 0, :info 0, :type :summary, :duration 779} var-info.edn 위한 이스트우드 및 영감Copyright © 2019-2023 Michiel Borkent
Clojure와 동일한 EPL 라이센스에 따라 배포됩니다. 라이센스를 참조하십시오.
디렉토리 inlined epl 라이센스에 따라 라이센스가 부여 된 tools.reader 의 소스가 포함되어 있습니다.
디렉토리 parser 에는 MIT 라이센스에 따라 라이센스가 부여 된 rewrite-clj 의 수정 된 소스가 포함되어 있습니다.