(allow-warning-based-on-enclosing-macros w
linter
suppress-desc
suppress-conditions
opt)
(ast-to-ordered ast)
Take an ast and return an identical one, except every map is replaced with an ordering-map. The sorting of keys in a specified order can make it significantly easier when printing them out, to see more interesting keys earlier.
Take an ast and return an identical one, except every map is replaced with an ordering-map. The sorting of keys in a specified order can make it significantly easier when printing them out, to see more interesting keys earlier.
(butlast+last s)
Returns same value as (juxt butlast last), but slightly more efficient since it only traverses the input sequence s once, not twice.
Returns same value as (juxt butlast last), but slightly more efficient since it only traverses the input sequence s once, not twice.
(canonical-filename fname)
Returns the canonical file name for the given file name. A canonical file name is platform dependent, but is both absolute and unique. See the Java docs for getCanonicalPath for some more details, and the examples below.
http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath%28%29
Examples:
Context: A Linux or Mac OS X system, where the current working directory is /Users/jafinger/clj/dolly
user=> (canonical-filename "README.md") "/Users/jafinger/clj/dolly/README.md"
user=> (canonical-filename "../../Documents/") "/Users/jafinger/Documents"
user=> (canonical-filename "../.././clj/../Documents/././") "/Users/jafinger/Documents"
Context: A Windows 7 system, where the current working directory is C:\Users\jafinger\clj\dolly
user=> (canonical-filename "README.md") "C:\Users\jafinger\clj\dolly\README.md"
user=> (canonical-filename "....\Documents") "C:\Users\jafinger\Documents"
user=> (canonical-filename ".....\clj..\Documents..") "C:\Users\jafinger\Documents"
Returns the canonical file name for the given file name. A canonical file name is platform dependent, but is both absolute and unique. See the Java docs for getCanonicalPath for some more details, and the examples below. http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath%28%29 Examples: Context: A Linux or Mac OS X system, where the current working directory is /Users/jafinger/clj/dolly user=> (canonical-filename "README.md") "/Users/jafinger/clj/dolly/README.md" user=> (canonical-filename "../../Documents/") "/Users/jafinger/Documents" user=> (canonical-filename "../.././clj/../Documents/././") "/Users/jafinger/Documents" Context: A Windows 7 system, where the current working directory is C:\Users\jafinger\clj\dolly user=> (canonical-filename "README.md") "C:\Users\jafinger\clj\dolly\README.md" user=> (canonical-filename "..\..\Documents\") "C:\Users\jafinger\Documents" user=> (canonical-filename "..\..\.\clj\..\Documents\.\.\") "C:\Users\jafinger\Documents"
(elide-defprotocol-vars ast)
Motivation: pprint'ing a value containing a defprotocol Var, with all metadata included leads to an infinite loop. Why? The value of a defprotocol's Var is a map.
(1) The value of the key :var in this map is the defprotocol Var itself, and pprint'ing this recurses infinitely.
(2) The value of the key :method-builders in this map has metadata containing the defprotocol Var, so if metadata is being printed, this also leads to an infinite loop.
These problems are most simply avoided by removing these two keys from defprotocol maps.
Note: This can replace Vars in the AST with their values, so the resulting AST is not as it was originally, and will likely fail if you try to generate code from it. It is fine for pprint'ing.
There are cases where this function misses things. It seems like it may be simpler to detect protocol occurrences while doing pprint-meta instead.
Motivation: pprint'ing a value containing a defprotocol Var, with all metadata included leads to an infinite loop. Why? The value of a defprotocol's Var is a map. (1) The value of the key :var in this map is the defprotocol Var itself, and pprint'ing this recurses infinitely. (2) The value of the key :method-builders in this map has metadata containing the defprotocol Var, so if metadata is being printed, this also leads to an infinite loop. These problems are most simply avoided by removing these two keys from defprotocol maps. Note: This can replace Vars in the AST with their values, so the resulting AST is not as it was originally, and will likely fail if you try to generate code from it. It is fine for pprint'ing. There are cases where this function misses things. It seems like it may be simpler to detect protocol occurrences while doing pprint-meta instead.
(init-warning-enable-config builtin-config-files config-files opt)
(keys-in-map key-set m)
Return the subset of key-set that are keys of map m, or nil if no element of key-set is a key of m.
Return the subset of key-set that are keys of map m, or nil if no element of key-set is a key of m.
A #'map
-like function that will run each of the linters.
Can be customized in order to achieve linter parallelism, or extra logging, etc.
A `#'map`-like function that will run each of the linters. Can be customized in order to achieve linter parallelism, or extra logging, etc.
(make-msg-cb kind opt)
Tiny helper function to create a simple way to call the Eastwood callback function with only a message string.
Given an option map opt that should have a key :callback whose value is a callback function (which takes a certain kind of map as its only argument), return a function that takes only a string, and then calls the callback function with a proper kind of map, including that message string.
Tiny helper function to create a simple way to call the Eastwood callback function with only a message string. Given an option map opt that should have a key :callback whose value is a callback function (which takes a certain kind of map as its only argument), return a function that takes only a string, and then calls the callback function with a proper kind of map, including that message string.
(mark-exprs-in-try-body ast)
Return an ast that is identical to the argument, except that expressions 'directly' within try blocks will have one of two new keywords with value true.
Statements, i.e. expressions that are not the last one in the body, and thus their return value is discarded, will have the new keyword :eastwood/unused-ret-val-expr-in-try-body with value true. Use the fn statement-in-try-body? to check whether a node was so marked.
Return values, i.e. expressions that are the last one in the body, will have the new keyword :eastwood/used-ret-val-expr-in-try-body with value true. Use the fn ret-expr-in-try-body? to check whether a node was so marked.
Use fn expr-in-try-body? to check whether an expression was either one of these kind.
Return an ast that is identical to the argument, except that expressions 'directly' within try blocks will have one of two new keywords with value true. Statements, i.e. expressions that are not the last one in the body, and thus their return value is discarded, will have the new keyword :eastwood/unused-ret-val-expr-in-try-body with value true. Use the fn statement-in-try-body? to check whether a node was so marked. Return values, i.e. expressions that are the last one in the body, will have the new keyword :eastwood/used-ret-val-expr-in-try-body with value true. Use the fn ret-expr-in-try-body? to check whether a node was so marked. Use fn expr-in-try-body? to check whether an expression was either one of these kind.
(nth-last v n)
Return the nth-last element of a vector v, where n=1 means the last element, n=2 is the second-to-last, etc. Returns nil if there are fewer than n elements in the vector.
Return the nth-last element of a vector v, where n=1 means the last element, n=2 is the second-to-last, etc. Returns nil if there are fewer than n elements in the vector.
(ordering-map key-order)
(ordering-map key-order default-comparator)
Create an empty map with a custom comparator that puts the given keys first, in the order specified. Other keys will be placed after the special keys, sorted by the default-comparator.
Create an empty map with a custom comparator that puts the given keys first, in the order specified. Other keys will be placed after the special keys, sorted by the default-comparator.
(postwalk f form)
Performs a depth-first, post-order traversal of form. Calls f on each sub-form, uses f's return value in place of the original. Recognizes all Clojure data structures. Consumes seqs as with doall.
Performs a depth-first, post-order traversal of form. Calls f on each sub-form, uses f's return value in place of the original. Recognizes all Clojure data structures. Consumes seqs as with doall.
(pprint-meta obj)
A version of pprint that prints all metadata on the object, wherever it appears. (binding [print-meta true] (pprint obj)) prints metadata on symbols, but not on collection, at least with Clojure 1.6.0 and probably earlier versions. Clojure ticket CLJ-1445 may improve upon this in the future.
A version of pprint that prints all metadata on the object, wherever it appears. (binding [*print-meta* true] (pprint obj)) prints metadata on symbols, but not on collection, at least with Clojure 1.6.0 and probably earlier versions. Clojure ticket CLJ-1445 may improve upon this in the future. http://dev.clojure.org/jira/browse/CLJ-1445
(prewalk f form)
Like postwalk, but does pre-order traversal.
Like postwalk, but does pre-order traversal.
(protocol? p)
Make a good guess as to whether p is an object created via defprotocol.
Make a good guess as to whether p is an object created via defprotocol.
(pst e depth)
'Prints' a stack trace of the exception, to the depth requested (the entire stack trace if depth is nil). Does not print ex-data.
'Prints' a stack trace of the exception, to the depth requested (the entire stack trace if depth is nil). Does not print ex-data.
(remove-prefix s prefix)
If string s starts with the string prefix, return s with that prefix removed. Otherwise, return s.
If string s starts with the string prefix, return s with that prefix removed. Otherwise, return s.
(replace-subforms-with-first-in-set form sym-set replace-fn)
(separate-suffix s suffixes)
Given a string s and a sequence of strings, suffixes, return a vector of 2 strings [x y] where y is the first element of suffixes that is a suffix of s, and (str x y)=s. If no string in suffixes is a suffix of s, return nil.
Given a string s and a sequence of strings, suffixes, return a vector of 2 strings [x y] where y is the first element of suffixes that is a suffix of s, and (str x y)=s. If no string in suffixes is a suffix of s, return nil.
(string->forms s ns include-line-col-metadata?)
Treat a string as a sequence of 0 or more Clojure forms, and read all of them. No line or column number metadata will be attached to the returned forms, but sometimes this is what you want.
Hack alert: In order to be able to correctly interpret keywords of the form ::name or ::ns-or-ns-alias/name, you should pass in a namespace to bind to the ns var during this function's reading of s. The assumption is that this namespace and those it requires are already loaded before this function is called, and any aliases used by keywords are already set up. It also assumes that the entire string is in that same namespace. Fortunately, this is pretty common for most Clojure code as written today.
Treat a string as a sequence of 0 or more Clojure forms, and read all of them. No line or column number metadata will be attached to the returned forms, but sometimes this is what you want. Hack alert: In order to be able to correctly interpret keywords of the form ::name or ::ns-or-ns-alias/name, you should pass in a namespace to bind to the *ns* var during this function's reading of s. The assumption is that this namespace and those it requires are already loaded before this function is called, and any aliases used by keywords are already set up. It also assumes that the entire string is in that same namespace. Fortunately, this is pretty common for most Clojure code as written today.
(timeit expr)
Evaluates expr and returns a vector containing the expression's return value followed by the time it took to evaluate in millisec.
Evaluates expr and returns a vector containing the expression's return value followed by the time it took to evaluate in millisec.
(walk inner outer form)
Traverses form, an arbitrary data structure. inner and outer are functions. Applies inner to each element of form, building up a data structure of the same type, then applies outer to the result. Recognizes all Clojure data structures. Consumes seqs as with doall.
walk was copied from Clojure 1.6.0, and then modified to preserve metadata on all sub-values of the input form that have them. Note that this metadata is 'put back on' after the function inner has already been called, but before outer, so only outer has a chance to change it.
Traverses form, an arbitrary data structure. inner and outer are functions. Applies inner to each element of form, building up a data structure of the same type, then applies outer to the result. Recognizes all Clojure data structures. Consumes seqs as with doall. walk was copied from Clojure 1.6.0, and then modified to preserve metadata on all sub-values of the input form that have them. Note that this metadata is 'put back on' after the function inner has already been called, but before outer, so only outer has a chance to change it.
(with-out-str2 & body)
Like with-out-str, but returns a map m. (:val m) is the return value of the last expression in the body. (:out m) is the string normally returned by with-out-str. (:err m) is the string that would be returned by with-out-str if it bound err instead of out to a StringWriter.
Like with-out-str, but returns a map m. (:val m) is the return value of the last expression in the body. (:out m) is the string normally returned by with-out-str. (:err m) is the string that would be returned by with-out-str if it bound *err* instead of *out* to a StringWriter.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close