code.framework

*nav*

*toplevel-forms*

dynamic

+analyse-file

+read-ns-form

analyse

added in 3.0

(analyse ns {:keys [output sorted], :as params} lookup project)

seed analyse function for the code.manage/analyse task

(->> (project/in-context (analyse ’code.framework-test)) (common/display-entry)) => (contains-in {:test {’code.framework (contains ’analyse analyse-file analyse-source-code)}})

(->> (project/in-context (analyse ’code.framework)) (common/display-entry)) => (contains-in {:source {’code.framework (contains ’analyse analyse-file analyse-source-code)}})

analyse-file

added in 3.0

(analyse-file [type path])

helper function for analyse, taking a file as input

(analyse-file :source “src/code/framework.clj”)

analyse-file-raw

(analyse-file-raw [type path])

helper function for code.framework/analyse-file

analyse-source-code

added in 3.0

(analyse-source-code s)

analyses a source file for namespace and function definitions

(-> (analyse-source-code (slurp “test-data/code.manage/src/example/core.clj”)) (get-in ’example.core -foo-)) => ’{:ns example.core, :var -foo-, :source {:code “(defn -foo-\n x\n (println x "Hello, World!"))”, :line {:row 3, :col 1, :end-row 6, :end-col 31}, :path nil}}

analyse-source-entry

added in 4.1

(analyse-source-entry nsp nav)

helper function for analyse-source-code, returning [id entry] pairs. defimpl forms also produce constructor entries (map-> and ->)

analyse-source-function

added in 3.0

(analyse-source-function nsp nav)

helper function for analyse-source-code

analyse-test-code

added in 3.0

(analyse-test-code s)

analyses a test file for docstring forms

(-> (analyse-test-code (slurp “test-data/code.manage/test/example/core_test.clj”)) (get-in ’example.core -foo-) (update-in :test :code docstring/->docstring)) => (contains ’{:ns example.core :var -foo- :test {:code “1\n => 1” :line {:row 6 :col 1 :end-row 7 :end-col 16} :path nil} :meta {:added “3.0”} :intro ""})

compile-regex

added in 3.0

(compile-regex obj)

compiles a regex string from an input string

(compile-regex “(:require”) => “\(:require”

docstrings

added in 3.0

(docstrings ns {:keys [full sorted]} lookup project)

returns all docstrings in a given namespace with given keys

(->> (project/in-context (docstrings)) (map first) sort) => (project/in-context (vars {:sorted true}))

extract

added in 3.0

(extract ns {:keys [process], :as params} lookup project)

returns all vars in a given namespace (project/in-context (vars {:sorted true})) => (contains ’analyse analyse-file analyse-source-code analyse-source-function)

find-test-frameworks

added in 3.0

(find-test-frameworks ns-form)

find test frameworks given a namespace form (find-test-frameworks ’(ns … (:use code.test))) => #{:fact}

(find-test-frameworks ’(ns … (:use clojure.test))) => #{:clojure}

grep-replace

added in 3.0

(grep-replace ns {:keys [print query replace], :as params} lookup {:keys [root], :as project})

replaces code based on string query

(project/in-context (grep-replace {:query “docstrings” :replace “DOCSTRINGS” :print {:function true}}))

import-selector

added in 3.0

(import-selector)(import-selector var)

creates an import selector

(import-selector ’-hello-) ;;[(#{} | -hello- string? map? & _)] => vector?

locate-code

added in 3.0

(locate-code ns {:keys [print query], :as params} lookup {:keys [root], :as project})

finds code base upon a query

no-test

added in 4.0

(no-test ns params lookup project)

checks that a namespace does not require test

read-ns-form

added in 4.0

(read-ns-form path)

memoised version of fs/read-ns

read-ns-form-raw

(read-ns-form-raw path)

helper function for code.framework/read-ns-form

refactor-code

added in 3.0

(refactor-code ns {:keys [edits], :as params} lookup project)

takes in a series of edits and performs them on the code

(project/in-context (refactor-code {:edits []})) => {:changed [], :updated false, :path “test/code/framework_test.clj”}

search-regex

added in 3.0

(search-regex obj)

constructs a search regex (for line numbers)

(search-regex “hello”) => #“^(.*?)(hello)”

toplevel-selector

added in 3.0

(toplevel-selector)(toplevel-selector var)

creates a selector for querying toplevel forms

(toplevel-selector ’-hello-) ;;(#{} | -hello- & _) => vector?

transform-code

added in 3.0

(transform-code ns {:keys [write print skip transform verify full no-analysis], :as params} lookup {:keys [root], :as project})

transforms the code and performs a diff to see what has changed

;; options include :skip, :full and :write (project/in-context (transform-code ’code.framework {:transform identity})) => (contains {:changed [] :updated false :path any})

var-function

added in 3.0

(var-function full)

constructs a var, with or without namespace

((var-function true) {:ns ’hello :var ’world}) => ’hello/world

((var-function false) {:ns ’hello :var ’world}) => ’world

vars

added in 3.0

(vars ns {:keys [full sorted], :as params} lookup project)

returns all vars in a given namespace (project/in-context (vars {:sorted true})) => (contains ’analyse analyse-file analyse-source-code analyse-source-function)