ESLint & BBEdit

In a previous post I showed how to run BBEdit’s active document through jshint. Since then I’ve switched to the newer & shinier eslint, and so comes a new AppleScript to lint your JavaScript:

(* Pipe eslint output into a BBEdit results window  *)
try
    tell application "BBEdit"
        set mydoc to file of (document 1 of window 1)
    end tell
    set posixPath to POSIX path of mydoc
    set cmd to "/usr/local/bin/node /usr/local/bin/eslint -c ~/.eslintrc.js -f unix " & (quoted form of POSIX path of mydoc) & " | /usr/local/bin/bbresults"
    do shell script cmd
on error
    beep
end try

Save the AppleScript under ~/Library/Application Support/BBEdit/Scripts (create the folder if it doesn’t exist), after which you can invoke the script via BBEdit’s Scripts menu and/or palette (Window → Palettes → Scripts).

Install ESLint via…

⚡ npm i eslint -g

… grab an ESLint configuration file via…

⚡ curl "https://raw.githubusercontent.com/davidfmiller/configs/master/doteslintrc.js" > ~/.eslintrc.js

… and customize it to suit your preferences.