Giter Site home page Giter Site logo

Comments (4)

jonase avatar jonase commented on July 28, 2024

check-form only checks the 'outer' expression which is why it doesn't see (= 0 0). This is by design.

We could add a check-expr function which would walk through all the subexpressions, something like:

(defn check-expr [expr]
  (keep check-form (expr-seq expr)))

Note the similarity between check-expr and check-file.

from kibit.

ohpauleez avatar ohpauleez commented on July 28, 2024

That makes WAY more sense now that I look at the code. I'll play around in a branch and see if I can come up with anything

from kibit.

ohpauleez avatar ohpauleez commented on July 28, 2024

So what about creating a map of {expr checked-expr, ...} pairs, then using the map to build the final form back up? We could even use filter to make sure we only get valid forms. Check out the REPL session:

user=> (def s (kibit/expr-seq '(if (= 0 0) (println "a") (println "a"))))
#'user/s
user=> user=> (def fs (filter #(.startsWith (str %) "(") s))
#'user/fs
user=> (zipmap fs (map kibit/check-form fs))
{(println "a") nil, (= 0 0) {:expr (zero? 0), :rule [(zero? 0) true], :alt true, :line nil}, (if (= 0 0) (println "a") (println "a")) nil}
user=> (zipmap fs (map #(-> % kibit/check-form :alt) fs))
{(println "a") nil, (= 0 0) true, (if (= 0 0) (println "a") (println "a")) nil}
user=> (filter val rm)
([(= 0 0) true])

Or maybe use walk ?

user=> expr
(if (= 0 0) (println "a") (println "a"))
user=> (clojure.walk/walk #(or (-> % kibit/check-form :alt) %) kibit/check-form expr)
{:expr (if true (println "a") (println "a")), :rule [(if true ?x . ?y) ?x], :alt (println "a"), :line nil}

from kibit.

ohpauleez avatar ohpauleez commented on July 28, 2024

Walk was the winner, totally awesome

The branch is here

This got pushed onto kibit/master

from kibit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.