Automatically add missing semi-colons
Hello,
I wrote a little hack:
(defun js2-add-semi-colons ()
"Add missing semi-colons."
(interactive)
(--each (--select (string-equal (caar it) "msg.missing.semi") (js2-warnings))
(let ((pos (nth 1 it))
(length (nth 2 it)))
(goto-char (+ pos length))
(insert ";"))))
This is obviously not mature enough to include "as is", but what do you think of it? Maybe the *js-lint* buffer could offer some js2-error-apply-suggestion which would do the right thing in many cases?
Looks like a fine idea. I'm not sure where best to put it, though.
If we continue this train of thought, "undeclared variable" warnings would probably be next (with choices: declare a local var, or declare the global in the top comment), and js2r-add-to-globals-annotation is already implemented in js2-refactor.
Hum, I think I found a bug in js-lint about length of where the semi-colon should go:
var ratio = (clientMax - clientMin) / (max - min)
This underlines the whole line but stops at the ending ), so one char not enough. Any idea what triggers it? It seems related to the ending ), because the following is fine:
var ratio = (clientMax - clientMin) / (max - min) + 23
Yep, it's a bug. Apparently, when js2-paren-node is parsed, its length is assigned an off-by-one value.
Wow, that was quick :) Is there a fix planned or should I just work around it?
Well, since you insist. :)
:+1:
I'll try to write some js2-fix-problem-at-point which would lookup into some table like
(setq js2-errors-suggestions '(("msg.missing.semi" js2-add-semi-colon-at-point)
("msg.undeclared.var" js2-query-declare-var)))
Something like that.
Sounds fine. Though keep in mind that you'll need copyright assignment, if you want this added to js2-mode proper.
Does that require the sending of written documents to the FSF or whoever? Can't a simple "I'm ok with it" be enough?
I never quite understood why it needs to be that complicated to contribute, and don't get me wrong I know you have nothing to do with it :) To me it looks like it closes the door to so many people/packages/resources.
Yes, and no. :)
Do you have a link for the rationale behind it? I understand this line of reasoning in 1980 but I don't get it nowadays. If you make a PR you're obviously ok with the license. Can't they put in the license a clause that makes future contributors to give their copyright away? I mean if it bothers me I can't imagine the amount of people/contributions they lost just because of the bureaucratic process :)
https://www.gnu.org/licenses/why-assign.html
Will this suffice? :)
Can't they put in the license a clause that makes future contributors to give their copyright away?
Apparently, they can't. Or even if they could, it would be an entirely different license, with different, more restricted, notion of software freedom.
Alright I see, thanks for the link. It's interesting because it means in all my previous companies where I didn't assign copyrights I can prevent them from claiming copyright infringments :)
Anyway, why not use something like https://www.clahub.com ?
No need for slow-written-mail anymore! Just "sign" online that you agree and be done with it :) I had to "sign" one to contribute to https://github.com/openalpr/openalpr
It's interesting because it means in all my previous companies where I didn't assign copyrights I can prevent them from claiming copyright infringments :)
Probably not. If you signed employment contracts, either they include a clause about you assigning copyright for the produced work, or otherwise the laws of your country do that by default anyway, as long as the work was performed during work hours, on company property.
Here's a recent thread about CLAHub: https://lists.gnu.org/archive/html/emacs-devel/2014-12/msg01454.html https://lists.gnu.org/archive/html/emacs-devel/2014-12/msg01505.html
Also note that a US or Germany resident should be able to sign the FSF CA electronically.
Let's not continue this discussion here: I don't have any power over FSF policies anyway.
Alright, thanks for the infos!
IMHO functionality like this is a better fit for js2-refactor mode anyway :)
@apchamberlain: ah, yeah maybe you're right. I'm kinda stuck working on other stuffs but when I get back to it I'll consider js2-refactor.
@dgutov: FYI, I finally sent the assignements paper to the FSF. I'll try to resurrect this PR, maybe on js2-refactor tho.