kJSLint - JSLint for Komodo

Posted by thesmaw on 2009-03-31 06:07 |
2.1.3
Ben Smawfield
Wed, 2011-03-23 18:18
  • : 4.4.0 - 6.*
  • : 4.4.0 - 6.*

A JSLint plugin for Komodo.

Adds a JSLint option to the Tools menu that provides error and function reports for files.

The version of JSLint bundled within the extension is Crockford's latest from 22-04-2010.

Version history

  • Version 2.1.3 allows kJSLint to work with Komodo 6

  • Version 2.1.2 includes the latest version of JSLint from 27-06-2010.

  • Version 2.1.1 fixes a namespacing bug

  • Version 2.1 includes a couple of UI tweaks, includes the latest version of JSLint from 22-04-2010, and correctly namespaces the JS code.

    This version also creates an API method to enable the native JSLint report (JSLINT.data()) to be called from other extensions and macros, without revealing the kJSLint panels.

    For example, a macro like the one below, set to trigger 'before save', will alert the user that they are trying to save a file that has JS Lint errors.

    if (ko.views.manager.currentView.languageObj.name === 'JavaScript') {
        var jsLintReport = extensions.KJSLINT.expose(),
            length;
           
        if (jsLintReport.errors) {
            length = jsLintReport.errors.length;
            if (!confirm(['Are you sure you want save? - this file has ', length, ' JSLint error', (length > 1) ? 's' : ''].join(''))) {
                extensions.KJSLINT.run();
                     
                return true;
            }
            else {
               
                return false;
            }
        }
    }

    For further info on what extensions.KJSLINT.expose() returns, view the JSLINT.data() section of the comments within http://www.jslint.com/fulljslint.js

  • Version 2.0 is a complete rewrite to improve performance and include the Function report, further options from the latest version of JS Lint and options persistence for files.

    * If you're upgrading from 1.6.3, you'll need to recreate your key-binding if you have one. Sorry *

    Although this version has been tested as thoroughly as possible, version 1.6.3 can still be downloaded from http://www.bensmawfield.com/kjslint/ Please let me know if and why you need to revert to this version

  • Version 1.6.3 fixes a bug that was causing an indentation error to always be thrown on Line 1 in Default mode.

  • Version 1.6.2 tweaks the interface a little - allowing easy reset to Crockford's default The Good Parts; allowing the extension to be run from a button on the options panel; and allowing the output panel to be properly resized.

  • Version 1.6.1 allows key-binding for the Run kJSLint action.

    It also fixes a bug that was occurring within Komodo IDE - where kJSLint was preventing the Javascript debugger's panel from appearing.

  • Version 1.6 improves on version 1.5 by outputting results in a format where they can be double-clicked to jump the editor to the line where the error has been found.

    I've also properly built my install.rdf file to properly identify the extensions, and this should allow for automatic-updates to the extension should I modify it in the future.

  • Version 1.5 improves on version 1.0 by adding the options that are found on jslint.com, allowing the user to control the operation and sensitivity of JSLint.

    See http://www.jslint.com/lint.html#options for details.

    On first use, kJSLint defaults to the 'Good Parts' set of selected options.

Again, any bugs or enhancement requests, please report here and I will action ASAP.

sbeckeriv | Tue, 2009-07-14 16:59

I would like to see options for the jslint like the webite http://www.jslint.com/

Thanks
Becker

thesmaw | Tue, 2009-07-21 06:50

Thanks for the nudge Becker. This is now in development, and seems to be going pretty well, so hopefully there'll be an extension update available shortly.

sbeckeriv | Thu, 2009-08-13 15:32

The newest version(1.6) of the kjslint plugin kills the debug console. It makes the debug window at the bottom display nothing. I used version an old version, current version and the alpha. I disable the jslint and i can see the debug console again.

I am running a mac.

Thanks!

thesmaw | Fri, 2009-08-14 05:59

Hey Becker,

Sorry you've come across a bug, I'll try to get the bottom of it this weekend.

Are you using the Komodo IDE rather than Komodo Edit? I've not been familiar with the debug console - as I've been an Edit user so far.

Can you give me instructions on how to get to the debug console and fill it with content as you would when it's working?

Also, if you've got time, screenshots of the debug console when it is working, and when it is broken would be fantastic.

Thanks!

chauncey | Fri, 2009-08-14 13:47

I have some strange behavior with the Source Tree plugin related to tabs. This may be a similar thing to the Debug window. I just noticed today that my 'Source' dropdown (configured on the right as a tab) shows JS lint options content while the JS Lint tab shows the Source content. I disabled kjslint and the Source window was empty. I uninstalled kjslint and Source started showing the source tree. I reinstalled kjslint and again, Source tab show JS Lint options. Even if I move the tab to another area (bottom), it still shows the wrong content. I did try it both with TweakUI tabs and as dropdowns with no change in the strange behavior.

I don't know which plugin might be the cause of this behavior but when I came looking to see if anybody had anything similar, I saw Becker's trouble and thought it might be related to this tab issue. I'm currently using the Komodo Edit 5.1.4, build 3797 on WinXP.

thesmaw | Wed, 2009-08-19 07:08

@Becker,

I've managed to replicate the bug that you've mentioned. Hopefully I'll be able to get it fixed now! Sorry, I'm moving a little slowly as I'm not online at home at the moment.

@chauncey

Not had to chance to dig into this one with too much depth yet. I've got the Source Tree extension installed now though so I should get to it soon.

thesmaw | Thu, 2009-08-20 04:26

@Becker

The bug with the debugger should now be resolved. Looks like I couldn't use hidden="true" on the kJSlint output panel, which wasn't really necessary anyway. Can you let me know if version 1.6.1 now works for you or not?

@chauncey

Sorry, it looks like the bug with the Source Tree extension is within that extensions code. I'd outlined what I believe is a fix on that extensions page:

http://community.activestate.com/xpi/source-tree#comment-10330

I've updated the Source Tree extension locally so that it works with kJSlint. If you need it urgently, let me know and I will send you it across.

jh | Mon, 2009-08-24 05:09

JSLint usually generates some kind of report if it's able to complete its scan. This report tells you if there are any global variables and if so where they came from. Since global stuff can result in very annoying issues it's really nice to know about this stuff as soon as possible.

Would be really nice if you could add it somehow. Thanks.

Excellent extension by the way.

thesmaw | Sun, 2009-09-20 05:36

Hi jh,

Forgive me if I'm not understanding your comment correctly.

kJSLint should display it's report in the bottom pane once it has completed its scan. If it detects global variables, it should display the following message: "'yourGlobalVar' is not defined". This message is displayed next to the line number and char of the error. You can double click the result to get directly to the line.

If this isn't happening for you, you may need to make sure the 'Disallow undefined variables' is checked within the options panel.

jh | Mon, 2009-09-28 03:34

If you paste some stuff over at jslint.com and then press the "JSLint" button... the "JSLint will hurt your feelings" div will disappear and 1 or 2 new divs appear.

#errors is the first one and is only shown if something went wrong. Its content is basically similar to kJSLint's output. #functions is always shown and it contains a summary of all used global variables, followed by a list of all functions (each entry also lists the global and local variables this function used/declared).

The extension covers #errors, but doesn't cover #functions. Personally I think the report in #functions is very helpful if you try to clean up some old code, which polluted the global namespace like crazy.

thesmaw | Wed, 2009-10-07 01:27

Hi jh,

I understand what you mean now. I'll have a think about the best way to do this and will try and get something built soon.

Perhaps a new panel adjacent to the Output that contains the report?

jh | Wed, 2009-10-07 04:32

Ace. :)

Right now there is one tab labeled "JS Lint Output". Maybe we could have two. One labeled "JS Lint Errors (<number of errors>)" and another one labeled "JS Lint Overview" or "JS Lint Report" or something like that.

If there are 0 errors the second tab (report) should get focus, otherwise the first one (errors) should get it. This matches the usual work-flow. If there are errors you want to know about them, if there are none you might be interested in the report (cleanup).

thesmaw | Wed, 2009-10-07 04:42

Nice one, I shall sort it as soon as I can.

thesmaw | Tue, 2010-03-09 08:39

Hey jh,

Version 2.0 now includes the Function Report. I hope it's what you're looking for. Sorry it's taken so long!

jh | Sat, 2010-03-13 13:45

Awesome stuff! And yes, this is exactly what I was looking for. :)

The double click jump stuff also works in the report. This is really handy.

"Uploaded: Tue, 2010-03-09"

Heh. Crockford released a new version at 2010-03-10. Would be ace if you could update it when you find some time.

Three small suggestions:

1. JS Lint options -> Further options... "Maximum line length" and "Maximum number of errors" lack the trailing colon.

2. The maximum line length check can be disabled by setting it to 0. This is great, but the UI doesn't point this out. Add something like "(0 = disable)".

3. That "No errors found" alert isn't necessary anymore, since you're jumping to the report on success. I run kjslint by pressing my shortcut... so, closing that alert with the space key doesn't add much of a slowdown. However, people who run it frequently by pressing the button have to navigate over to that OK button.

--

Hm. Is there a way to invoke kjslint through the macro API? I'd like to hook it into the "before save" event.

Oh and that other thing I mentioned somewhere... it would be nice if the "JSLint errors" tab would show the number of errors in parenthesis. E.g. "JSlint errors (0)" or "JSlint errors (50+)" if the maximum number of errors (50 in this example) was reached.

jh | Sat, 2010-03-13 14:11

if (ko.views.manager.currentView.languageObj.name === 'JavaScript') {
    KJSLINT.run();
}

Works great. :D

Edit: I was just told that extensions are supposed to be over in the "ko.extensions.*" sort-of-namespace. I.e. "ko.extensions.kjslint" in this case.

http://wiki.openkomodo.com/index.php/Portal:Extension
http://wiki.openkomodo.com/index.php/Portal:Documentation

2.1
thesmaw | Thu, 2010-04-22 08:38

Hi jh,

Version 2.1 should tackle the issues mentioned above.

I've kept the 0 error alert as it makes me feel warm and fuzzy when I get it, but if you want a version without it let me know and I'll upload one somewhere.

Regarding the namespacing, I found it hard to find clarity on best practice for this, but I went with extensions.KJSLINT based on the discussion in http://community.activestate.com/forum-topic/extension-s-namespace

Regarding an API to be accessed by macros, you can still do what you outlined above by using:

extensions.KJSLINT.run();

However, I've also exposed JSLINT.data() to allow macro/extensions writers to access the JSLint report without having to reveal the KJSLint panels. This can be accessed with extensions.KJSLINT.expose() (see the example at the top of the page for more details)

jon | Thu, 2009-09-17 06:27

Mr Ben!

Some ideas for your extension, whenever you might find the time to fit them in:

1. Provide the ability to save, and then switch between, My JS Lint settings and The Crock's JS Lint settings. I'm often unsure which checkboxes I checked and which The Crock checked.

2. Provide the ability to run JS Lint from a giant 'Run JS Lint' button on the JS Lint Options pane. It would save some clicks. =)

3. Allow for resizing of the JS Lint output panel at bottom of page. It seems to be fixed at 11 lines. When I resize that panel, it retains its fixed size, would be nice it it could grow with the height of the panel.

Hope these all make sense!

Keep up the good work,

Mr Jon =)

thesmaw | Sun, 2009-09-20 05:41

Hey Jon!

Thanks for the suggestions - you know you are my main target for the extension so I'll be fixing these up asap.

1) This one is definitely a priority as I can't remember the defaults myself once I've altered the options. It shouldn't be too tricky to do, I'm just mulling over ideas of how the interface/options should look. Hopefully I'll get inspired on this one soon.

2) Can definitely do this one, just need to find 5 minutes to sort it. For now the key-binding is probably the quickest way to run kJSLint - I've got mine set up on ctrl-alt-j

3) This one is trickier - I'm putting kJSLint's output into a pre-existing panel, so I'd need to attach behaviour to that panel to allow resizing. I'm sure it can probably be done and has probably been done before so I'll try and sort that as well

Will try and get the updates done as soon as possible!

joel.cairney | Wed, 2010-05-12 17:14

Any luck on the resizing issue?

I've noticed that after installing and running kJSLint and opening up the JSLint Options, I can no longer adjust the height of the pane housing the output tabs, or adjust the width of the Toolbox pane. This frustrates me as my work screen is small, and the GUI realestate in this app is at a prime.

Great extension though!
Thanks,

~Joel

thesmaw | Thu, 2010-05-13 02:34

Hi Joel,

Are you ok to let me know what OS and Komodo version you are using, and if you have any other extensions installed?

On the kJSLint I have (5.2.4), I can resize the bottom panel on both Mac and Windows. There is a min-width applied to the right-hand panel though, which I should be able to remove.

thesmaw | Thu, 2010-05-13 02:35

Oh, and kJSLint version number as well, plz

thesmaw | Wed, 2009-10-07 01:25

Hi Mr. Jon,

Hopefully version 1.6.2 sorts these issues for you.

Cheers!

robert45 | Thu, 2009-09-17 17:27

thesmaw thank you for telling about this subject.. And i did everythink

thesmaw | Sun, 2009-09-20 05:42

Thanks

tone | Sat, 2009-11-07 08:03

Thanks so much for creating the extension, it makes life so much easier.

I see your post about 1.6.2 saving settings, but it doesn't appear to be the case in version 1.6.3. I got my options setup, closed Komodo, then came back today, and the options are not what I had changed them to yesterday.

Would it be possible to have kJSLint read the jslint comment line at the top of a javascript file, so that you could change settings in different projects?

thesmaw | Mon, 2009-11-16 02:36

Hi tone,

I'm glad you're finding the extension useful.

Agreed, persistance is a little bit ropey - I find that my options are saved most of the time, but every now and again they do go missing.

Permanently adding comments to the user's file would solve this and allow different settings for different files, but I'm loathe to have to permanently impact on someone's document.

Rather, I'm hoping to be able to write settings to an external file somewhere.

I just need to find the time now, hopefully not too far in the future!

thesmaw | Thu, 2010-03-11 08:42

Hi tone,

The latest version (2.0) of kJSLint should address this problem some what - set options for each file are not persisted to Komodo's prefs.xml

jon | Tue, 2009-12-08 07:16

Time you get a decent logo for your addon. Preferably one of these: http://images.google.co.uk/images?gbv=2&hl=en&q=douglas+crockford&sa=N&s...

;p

thesmaw | Tue, 2009-12-08 07:19

Agreed. I need to find the one where he's in the Police tshirt.

yu119995 | Fri, 2010-04-23 11:47

ColorTab doesn't seem to work when KJSLint is enabled (at least the most recent version of KJS). I haven't actually looked too much into it but I just thought I'd let you know. Thanks.

thesmaw | Sat, 2010-04-24 01:35

Thanks for bringing this to my attention.

ColorTab and kJSLint are both using the recommended 'extensions' namespace, and there's a conflict somewhere, which I'm trying to locate.

In the meantime, I've uploaded a version of kJSLint-2.1 to the link below, which uses a different namespace and will work with ColorTab:

http://www.bensmawfield.com/kjslint/kjslint-2.1-nc.xpi

This will auto-update to 2.1.1 once I've found a fix and able to switch back to the correct namespace, unless the issue is within ColorTab and then I'll try to contact Dafi.

dafi | Sat, 2010-04-24 03:29

Hi

Please in your code change the line

if (typeof(window.extensions === 'undefined')) {

as shown below

if (typeof(window.extensions) === 'undefined') {

then ColorTab and your little jewel will work together

--
dafi
Enhance KomodoEdit with MoreKomodo

Yay
thesmaw | Sat, 2010-04-24 05:02

Thanks dafi, that's what I was looking for! Your eyes are better than mine :-)

Sorry about the conflict.

dafi | Sat, 2010-04-24 08:34

No problem, conflict means people uses extensions ;)

--
dafi
Enhance KomodoEdit with MoreKomodo

yu119995 | Mon, 2010-04-26 16:51

You're a champ! Thanks a million.

pinch | Fri, 2010-10-29 06:49

It is possible to change default settings? For the most part I uncheck 'use strict' and that is the only change I make. jslint.org, the good parts is the same as the defaults you have, except for 'use strict'.

Being a lazy programmer, it would be nice to be able to change the default set, so that I can just run jslint without having to change any settings for every file.

thesmaw | Fri, 2010-10-29 06:54

Hey pinch,

That looks like a change that Douglas has made since I last updated the thing - I'm pretty sure he used to have 'use strict' as one the good parts.

I'll make this update and get the rest of Crockford's latest changes in in the next few days or so - I'm a couple of updates behind at the moment!

Longer term, I'm hoping to let the user save option sets - so that when they're in the options they can just use a dropdown menu to select a set of options that they have previously chosen, rather than having to set each manually for each file.

pinch | Fri, 2010-10-29 06:56

thesmaw, that is brilliant! Thanks for such a quick reply.

nickf | Tue, 2010-12-21 02:14

Is there a way to set the default settings which should apply to all files? I've seen that sometimes when I create a new file, some of my previous settings are there as a default, but I can't seem to replicate it reliably.

slindberg | Wed, 2011-06-01 16:47

Thanks for the awesome plugin! The only issue I've had with it so far is with the tab that it adds to the right pane. I created a support topic in the Komodo forums for it here: http://support.activestate.com/node/6739. I can't even be sure that it's even this plugin that's causing the broken layout or not, but I thought it was worth mentioning since others might have the same problem. I didn't have this problem until I upgraded to Komodo IDE 6, so perhaps their API changed slightly or something. Thanks!

thesmaw | Fri, 2011-06-03 01:32

Thanks slindberg - I've replied to the support ticket.

Would be interested to know if anyone else is experiencing the same problem.

jasond | Wed, 2011-08-31 21:10

I realized that "onevar" is set, so I went into the options to turn it off. After fixing that file, I went to the next and was surprised to see that the option I just turned off was back on! So I reloaded the first file, and saw that it had remembered it. It has unique options per file! So I wanted to set the options for all files in a project, so I thought about closing the project, then opening the options, since then, there are no files it can be attached to, and thus should set it for them all (once they are opened). But clicking on "Custom" did not un-gray the checkboxes. So I closed Komodo Edit, and restarted it, went right back into the JSLint options, and now selecting "Custom" allows me to change the checkboxes! Closing and restarting Komodo Edit confirms my changes are saved. However, loading a project and its files one at a time shows that the options are still maintained per file.

Is this how it's supposed to work? I just want to allow multiple "var" per function, for all .js files in my project.

Thanks for this amazing tool,
Jason Doucette

jasond | Thu, 2011-09-01 08:50

It appears that kJSLint doesn't listen to inlined source comments like this:
/*jslint plusplus: true, vars: true */

Instead it's internal options menu overrides this (or it's just not reading it to begin with).

Please advise on how to get the source comment options working. The menus are not tied to the source like this comments are. In fact, if there were a way to supply the same options to all files automatically, that'd be the best way.

Please advise,
Thanks!!
Jason Doucette

jasond | Thu, 2011-09-01 09:31

The extension appears to be broken. I continually turn off:

"x" Disallow ++ and --

Yet, it continually reports these errors, and when I go into the settings to check, the setting is STILL off, which is good. But if I close and restart Komodo, the setting is NOT set. Something fishy is going on, and I'm certain how to use this extension when I cannot provide the options I desire either via the menu, or via comment options.

Jason Doucette

jasond | Thu, 2011-09-01 09:34

I should note that it does immediately apply, and remember, this setting:

[x] Allow one var statement per function

Why not the ++ and -- one?

Jason Doucette

thesmaw | Fri, 2011-09-02 01:49

Hi Jason,

kJSLint has fallen quite a long way behind the latest version of JSLint that Crockford has released (he's been doing a lot of updates of late!). I've been too busy to keep up with him, and with JS Lint coming in Komodo 7, I'm not sure how much more maintenance this extension is going to get.

Source code is available at https://github.com/theSmaw/kJSLint, please feel free to develop it further.

jasond | Fri, 2011-09-02 09:33

Thanks for the quick reply! Totally understandable. Kudos to the work you've done so far. I am still using it, for now, and it's a great feature.

All the best!
Jason Doucette

djfooks | Wed, 2012-02-08 03:45

Hi,

Is this going to be extended to work with Komodo (Edit) 7.0 at some point?

Thanks