Integrating BBEdit + JSLint

365 views
Skip to first unread message

Daniel

unread,
Sep 13, 2011, 5:59:56 PM9/13/11
to BBEdit Talk
So I've been working to integrate JSLint more tightly into my coding
workflow. Obviously, running it from the web interface is a pain but
luckily I got it running on the command line thanks to Echo Ditto Labs
(http://echodittolabs.org/blog/2011/01/running-jslint-command-line).

The process I have now is that I copy the file path from the BBEdit UI
(File Path > Copy Path), then I open terminal and type "cat /path/to/
file | jslint"

That's not bad, but I would absolutely love it if any of you know any
ways to integrate that more tightly into my coding process, so that I
could regularly run it through JSLint while I'm coding. Is there a way
through the BBEdit interface to just say "run this file through the
shell script and give me the output"?

Any help is much appreciated!

-Daniel Christopher

Daniel

unread,
Sep 13, 2011, 6:02:07 PM9/13/11
to BBEdit Talk

Samuel Cotterall

unread,
Sep 14, 2011, 3:42:10 AM9/14/11
to BBEdit Talk
I can’t remember where I found this, but I am using a script that runs
the current file through JavaScript Lint (http://
www.javascriptlint.com/) rather than JSLint and displays a Project
Search-style window of all the errors.

1. Install Javascript Lint (`brew install jsl`, if you have Homebrew
installed)
2. Grab the script from here https://gist.github.com/1216037
3. Ensure that the path is correct (mine was `/usr/local/bin/jsl` by
default)
4. Install the script

Hope this helps.

Samuel.

Rick Yentzer

unread,
Sep 14, 2011, 8:27:36 AM9/14/11
to bbe...@googlegroups.com
This worked for me using build 3089. Thanks!

Lorin Rivers

unread,
Sep 14, 2011, 3:01:32 PM9/14/11
to bbe...@googlegroups.com

On Sep 14, 2011, at 2:42 AM, Samuel Cotterall wrote:

> I can’t remember where I found this, but I am using a script that runs
> the current file through JavaScript Lint (http://
> www.javascriptlint.com/) rather than JSLint and displays a Project
> Search-style window of all the errors.


[✄… snipped …✄]

Samuel,

Sweet! Thanks for sharing.
--
Lorin Rivers
Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
<mailto:lri...@mosasaur.com>
512/203.3198 (m)


Christopher Stone

unread,
Sep 14, 2011, 10:09:39 PM9/14/11
to bbe...@googlegroups.com
On Sep 13, 2011, at 16:59, Daniel wrote:
> So I've been working to integrate JSLint more tightly into my coding workflow. Obviously, running it from the web interface is a pain but luckily I got it running on the command line {SNIP}

>
> The process I have now is that I copy the file path from the BBEdit UI (File Path Copy Path), then I open terminal and type "cat /path/to/ file | jslint"
______________________________________________________________________

Hey Daniel,

Here's a way to do it through the Terminal

----------------------------------------------------------------------
# MAIN
----------------------------------------------------------------------
try
tell application "BBEdit"
tell front text document
if modified = true then
save its document
end if
set bbDocFile to its file
if bbDocFile ≠ missing value then
set bbDocPosixPath to POSIX path of bbDocFile
else
error "Document Is Unsaved!"
end if
end tell
end tell
set cmdStr to "cat " & (quoted form of bbDocPosixPath) & " | jslint"
tell application "Terminal"
if busy of front window = false then
do script cmdStr in selected tab of front window
else
do script cmdStr
end if
end tell
on error eMsg number eNum
stdErrAS(eMsg, eNum, true, true) of me
end try

----------------------------------------------------------------------
# » stdErrAS() : GENERAL ERROR HANDLER MODIFIED 2011-09-13 : 05:36
----------------------------------------------------------------------
on stdErrAS(eMsg, eNum, beepFlag, ddFlag)
set sep to "-----------------------------------"
set e to sep & return & "Error: " & eMsg & return & sep & return ¬
& "Error Number: " & eNum & return & sep
if beepFlag = true then
beep
end if
if ddFlag = true then
tell me to display dialog e
else
return e
end if
end stdErrAS
----------------------------------------------------------------------

Here's a way to do it using a BBEdit worksheet:

tell application "BBEdit"
try
tell front text document
set f to POSIX path of (get its file)
set f to quoted form of f
end tell
set cmd to "cat " & f & " | jslint"
set w to make new shell document with properties {contents:cmd}
set bounds of w's window to {0, 44, 1314, 1196}

on error errMsg number errNum
set sep to "=============================="
set e to sep & return & "Error: " & errMsg & return & sep & return ¬
& "Error Number: " & errNum & return & sep
beep
display dialog e
end try
end tell

** This second script is quick and dirty and has only general error-checking.

--

There are some more possibilities. Where are you wanting to output?

--
Best Regards,
Chris

Daniel

unread,
Sep 15, 2011, 5:15:37 PM9/15/11
to BBEdit Talk
Hi Christopher, thank you so much for the scripting help! You'll have
to forgive my questions here, as Applescript is completely foreign to
me.

My goal is to avoid having to open the Terminal to run JSLint, so your
solution to use the BBEdit worksheet is more along the lines of what
I'm looking for. However, I ran the script as you have it written, and
it didn't do much. It just opened a new document with the text "cat '/
path/to/file' | jslint"

So it formatted the command correctly, but how do I actually make it
run the command? Also, what are other options for where to output it?
Something like an alert/dialog would be much more desirable than
creating a new text document every time I run the script.

Again thank you so much for your help! Like I said, I've never done
anything with Applescript before so I'm completely at a loss here.

-Daniel

Christopher Stone

unread,
Sep 16, 2011, 2:11:56 PM9/16/11
to bbe...@googlegroups.com
Hey Daniel,

On Sep 15, 2011, at 16:15, Daniel wrote:
Hi Christopher, thank you so much for the scripting help!

You bet.

You'll have to forgive my questions here, as Applescript is completely foreign to me.

No worries.

My goal is to avoid having to open the Terminal to run JSLint, so your solution to use the BBEdit worksheet is more along the lines of what I'm looking for.

Okay.

However, I ran the script as you have it written, and it didn't do much. It just opened a new document with the text "cat '/ path/to/file' | jslint"

Not just a document, but a worksheet.  Typing Command-Return will execute the shell command and dump the output into the worksheet.
Also, what are other options for where to output it? Something like an alert/dialog would be much more desirable than creating a new text document every time I run the script.

I don't program with Javascript and jslint, so I have no idea what your output looks like.  If you'll send me a sample off-list I'll have a better handle on what you're dealing with.

A dialog is very likely doable.

A file in the temp directory that you can just close to throw away is doable.

--
Best Regards,
Chris

Daniel

unread,
Sep 19, 2011, 3:14:31 PM9/19/11
to BBEdit Talk
Great, thank you Christopher! I'm essentially trying to mimic the
functionality of the Textmate Bundle that I read about here:
http://www.phpied.com/jslint-on-mac-textmate/

I would prefer to have some kind of transient info box pop up like
they show. Ideally I wouldn't have to flip back and forth between the
JSLint results and the javascript document that I'm working with. But
as it is with the worksheet, it's already a huge step foreword.
Thanks!

-Daniel



On Sep 16, 11:11 am, Christopher Stone <listmeis...@thestoneforge.com>
wrote:
Reply all
Reply to author
Forward
0 new messages