eastwood

All things realted to eastwood - the Clojure linter
slipset 2018-05-15T06:14:02.000058Z

I was more thinking in terms of a single run of the linter. Say ns A calls B/foo, will the analyzer, when analyzing A also have to look into B, and if so, when time comes to analyze B, could we reuse the result from analyzing A?

slipset 2018-05-15T06:14:17.000056Z

The analyzing code in eastwood is basically

slipset 2018-05-15T06:14:57.000111Z

(doseq [ns namespaces] (lint-ns ns))

bronsa 2018-05-15T09:02:35.000349Z

so, if you want to analyze namespace A, namespace B needs to be at least loaded, doesn’t have to be analysed

bronsa 2018-05-15T09:04:36.000039Z

FWIW @ambrosebs was looking into speeding up t.a by using Compiler.java as a backend, I don’t know where he’s at with it but you may want to talk to him

2018-05-15T10:46:52.000231Z

The analyzing code in eastwood is basically as you mentioned, but there is code before that to optionally generate a list of namespaces from the files in one or more directories (e.g. "src" "test"), and then to sort those namespaces in an order consistent with require/use between them, so that anything being required/used is analyzed earlier than a namespace that requires/uses it.

2018-05-15T10:47:50.000213Z

If a namespace is not in that list, any require/use's done by the namespaces on the list will still be performed, when that namespace's ns form is analyzed then eval'd.

dotemacs 2018-05-15T12:03:06.000564Z

Hello, How do I take a command line config like this

lein eastwood "{:namespaces [foo.bar.baz] :exclude-linters [:redefd-vars :bad-arglists]}"
and convert it so it works when invoked on the command line just as lein with-profile +eastwood eastwood, where the relevant section in project.clj is:
:eastwood {:plugins [[jonase/eastwood "0.2.5"]]
                        :eastwood {:config-files ["eastwood.clj"]}}
I’ve tried the following, but I’m still getting the warnings
(disable-warning
 {:linter :redefd-vars ;;:bad-arglist
  :if-inside-macroexpansion-of #{'clojure.core/try}
  :within-depth 1})

(disable-warning
 {:linter :bad-arglist
  :if-inside-macroexpansion-of #{'clojure.core/try}
  :within-depth 1})
Thanks

2018-05-15T13:20:24.000140Z

Try this command line, to verify whether it is finding and loading your "config.clj" file: lein with-profile +eastwood eastwood '{:debug [:config]}'

2018-05-15T13:20:43.000797Z

I mean your "eastwood.clj" file

dotemacs 2018-05-15T14:18:12.000917Z

Just tried it @andy.fingerhut and this is the output that I’m getting:

Loading config file: eastwood.clj
It looks like the config file is getting picked up.

2018-05-15T16:30:49.000367Z

@dotemacs That suggests that the disable-warning expressions are being read and evaluated, but aren't enough to disable the warnings you are seeing. The :within-depth argument is kind of fiddly -- I could have made it always "arbitrary nesting depth of thing X inside macroexpansion of Z", but wanted to give some limit there because otherwise it might disable unrelated things. Oh, also, clojure.core/try is not a macro, but a built-in primitive. I don't see any other examples of disable-warning that use :if-inside-of-macroexpansion-of #{clojure.core/try}, so that might be why it is not disabling any warnings here.

dotemacs 2018-05-15T16:31:32.000817Z

ah, i see

dotemacs 2018-05-15T16:33:12.000486Z

So is there a way to say: in this namespace, disable warnings for :redefd-vars, in a configuration file ?

2018-05-15T16:34:07.000351Z

The only way I can think of is to do a separate Eastwood run on that namespace, disabling warnings completely for the namespace.

2018-05-15T16:34:21.000579Z

Then for your run on "most of your namespaces", exclude that namespace.

2018-05-15T16:34:26.000675Z

So 2 separate Eastwood runs.

2018-05-15T16:35:46.000558Z

Sorry, I know Eastwood could really use a facility for fine-grained disabling of individual warnings, like other lint tools have (e.g. via comments you add to the code with a special linter-recognized syntax), but never got around to implementing that.

dotemacs 2018-05-15T16:36:25.000557Z

Ah I see

slipset 2018-05-15T16:36:44.000022Z

@dotemacs: I’ve done something similar for deprecations

slipset 2018-05-15T16:37:14.000512Z

Where I’ve made it possible to disable deprecations of certain vars.

slipset 2018-05-15T16:37:19.000072Z

via regexes.

slipset 2018-05-15T16:37:39.000104Z

(disable-warning
  {:linter :deprecations
   :symbol-matches #{#"^#'ardoq\..*"}})

dotemacs 2018-05-15T16:37:41.000042Z

I was thinking that this is just my fault that I don’t know how to configure eastwood@slipset if you don’t mind sharing that setup, that would be great

slipset 2018-05-15T16:38:00.000104Z

Thing is that this is not supported for other linters than deprecations atm.

slipset 2018-05-15T16:38:54.000157Z

There is an issue in Eastwood already for the generic case

slipset 2018-05-15T16:38:55.000018Z

https://github.com/jonase/eastwood/issues/21

dotemacs 2018-05-15T16:39:08.000204Z

@slipset ok, so I’ve tried something similar for deprecations: Instance method 'public final void java.lang.Thread.stop()' is deprecated.

slipset 2018-05-15T16:39:37.000791Z

@dotemacs: what I showed you is brand-spanking new in 0.2.6

dotemacs 2018-05-15T16:39:45.000266Z

ah, ok

dotemacs 2018-05-15T16:40:10.000217Z

that might help as I was on 0.2.5… thanks for the heads up

slipset 2018-05-15T16:40:42.000751Z

I really needed this at work, since we have quite a bit of code that should be marked as deprecated, but we still want our code to pass CI.

slipset 2018-05-15T16:41:12.000622Z

So in this case, it was quite simple to add a regex-matcher to the var, since a var is deprecated.

slipset 2018-05-15T16:41:49.000457Z

I guess one could do something similar with bad-arglist, since that’s also bound to a var

slipset 2018-05-15T16:42:11.000514Z

and for redefd vars

slipset 2018-05-15T16:42:31.000432Z

What is it one usually say? issue/PR welcome?

slipset 2018-05-15T16:43:07.000084Z

if you at least make me an issue, I’ll have a new version out shortly.

dotemacs 2018-05-15T16:43:17.000636Z

So I upgraded to 0.2.6 and when I run it, it loads up 0.2.5… or am I reading it wrong:

$ lein with-profile +eastwood eastwood '{:debug [:config]}'
Retrieving jonase/eastwood/0.2.6/eastwood-0.2.6.pom from clojars
Retrieving jonase/eastwood/0.2.6/eastwood-0.2.6.jar from clojars
Loading config file: jar:file:/Users/alex/.m2/repository/jonase/eastwood/0.2.5/eastwood-0.2.5.jar!/eastwood/config/clojure.clj
Loading config file: jar:file:/Users/alex/.m2/repository/jonase/eastwood/0.2.5/eastwood-0.2.5.jar!/eastwood/config/clojure-contrib.clj
Loading config file: jar:file:/Users/alex/.m2/repository/jonase/eastwood/0.2.5/eastwood-0.2.5.jar!/eastwood/config/third-party-libs.clj
Loading config file: eastwood.clj
Exception in thread "main" java.lang.IllegalArgumentException: No matching clause: :deprecations, compiling:(/private/var/folders/k0/sgs2df8d0vq289q40rctw8p80000gn/T/form-init5659309845804878336.clj:1:125)

slipset 2018-05-15T16:44:22.000255Z

you most probably have two occurences of eastwood in your profiles.clj/project.clj

slipset 2018-05-15T16:44:48.000070Z

we have one in plugins and one in dependencies

slipset 2018-05-15T16:44:59.000083Z

seems like you only updated the one in dependencies?

dotemacs 2018-05-15T16:45:11.000446Z

yes, my ~/.lein/profiles.clj was the culprit, my bad…

slipset 2018-05-15T16:45:36.000048Z

As long as it’s not my bad, I’m happy 🙂

dotemacs 2018-05-15T16:47:24.000293Z

🙂

slipset 2018-05-15T16:48:48.000017Z

I’m off for a while…

dotemacs 2018-05-15T16:50:55.000811Z

ah, damn, I was just going to ask this:

(disable-warning
 {:linter :deprecations
  ;;:symbol-matches #{#"^#'public\ final\ void\ java\.lang\.Thread\.stop*"}
  :symbol-matches #{#"^#'public\ final\ void\ java\.lang\.Thread\.stop\(\)"}
  ;;:symbol-matches #{#"^#public*"}
  ;;:symbol-matches #{#"^#'java\.lang\.*"}
  ;;:symbol-matches #{#"^#'java\.lang\.Thread\.stop\(\)"}
  ;;:symbol-matches #{#"^#.*\.Thread\.*"}
  })

dotemacs 2018-05-15T16:51:11.000735Z

none of the above work on avoiding the deprecation warning

dotemacs 2018-05-15T16:51:24.000393Z

the commented out and uncommented lines

dotemacs 2018-05-15T16:51:45.000033Z

the warning is this: deprecations: Instance method 'public final void java.lang.Thread.stop()' is deprecated.

dotemacs 2018-05-15T16:51:51.000466Z

Not sure how to handle that

slipset 2018-05-15T16:52:39.000694Z

Hmm, interesting. Haven’t had the problem with deprecated java stuff.

slipset 2018-05-15T16:53:27.000569Z

Ah, I see it

slipset 2018-05-15T16:53:39.000247Z

Don’t escape the dot

dotemacs 2018-05-15T16:53:39.000265Z

As in, in the code or in my config above ?

dotemacs 2018-05-15T16:53:50.000695Z

oh, ok

slipset 2018-05-15T16:54:57.000041Z

#{#”.Thread.”} should work, although a bit greedy

slipset 2018-05-15T16:55:39.000615Z

#“\.*” is a regex marching zero or more dots.

dotemacs 2018-05-15T16:55:41.000188Z

let me try that

slipset 2018-05-15T16:56:01.000046Z

On phone so, all formatting is messed up.

slipset 2018-05-15T16:56:42.000023Z

#”.*” is a regex that matches anything.

dotemacs 2018-05-15T16:56:51.000188Z

Just tried all these:

(disable-warning
 {:linter :deprecations
  ;;:symbol-matches #{#"^#'public\ final\ void\ java.lang.Thread.stop()"}
  ;;:symbol-matches #{#"^#'public\ final\ void\ java.lang.Thread.stop*"}
  :symbol-matches #{#"^#.*Thread."}})

dotemacs 2018-05-15T16:57:34.000778Z

one sec, i see what you’re saying about the phone formatting…

dotemacs 2018-05-15T16:57:53.000229Z

even this

:symbol-matches #{#"^#.*Thread.*"}}
didn’t work

slipset 2018-05-15T16:58:01.000342Z

Ok. File an issue and I’ll see if I can figure it out later tonight.

dotemacs 2018-05-15T16:58:08.000686Z

ok, cool

slipset 2018-05-15T16:58:28.000016Z

Could I ask you to make a nominal repro-project on Github for me?

dotemacs 2018-05-15T16:58:39.000367Z

sure

slipset 2018-05-15T16:58:44.000508Z

Eh, minimal :)

slipset 2018-05-15T16:58:48.000487Z

Thanks!

dotemacs 2018-05-15T16:58:51.000303Z

sure

dotemacs 2018-05-15T21:08:14.000301Z

@slipset as promised the minimal example created and added as an issue: https://github.com/jonase/eastwood/issues/264 The real reason I’m dealing with this is because nREPL just had eastwood added to it. And I’m fighting all the warnings and trying to suppress them and this issue is one of them: https://github.com/clojure-emacs/nREPL/pull/23

slipset 2018-05-15T22:02:52.000136Z

Nice,

slipset 2018-05-15T22:03:06.000570Z

your eastwood.clj was a bit messed up

slipset 2018-05-15T22:03:14.000219Z

(disable-warning
 {:linter :deprecations
  :symbol-matches #{#"public final void java.lang.Thread.stop\(\)"}})

slipset 2018-05-15T22:03:16.000103Z

works.

dotemacs 2018-05-15T22:45:31.000055Z

Just saw that, thanks