30 Nov BBEdit & Code Analysis Integration
Overview
BBEdit is primarily designed for use by software & script developers, web designers, etc. It has native support for many programming languages and custom modules can be created by users to support any language. The application contains multi-file text searching capabilities including support for regular expressions. BBEdit allows previewing and built-in validation of HTML markup and also provides a model for most HTML code that can be entered into a dialog box.
It also includes FTP and SFTP tools and integrates with code management systems. It can show differences between file versions and allows for the merging of changes. Support for version control, including Git, Perforce, and Subversion is built into the program.
In our environment and group, BBEdit is one of our favorite text editors that we use for multiple functions from viewing editing radmind transcript & command files, property list & configuration profile files, JSON/XML files, code development, markdown/web development, etc.
For integrating code analysis & checking it’s not as easy or straight forward as some other text editor options like Atom, Sublime Text or TextMate, etc.
We hope this improves in the future, but in the meantime, you can get support for your favorite tools using an option with scripts in BBEdit which can be executable Unix files, AppleScript files, text factories, or Automator workflows. These are run simply by loading the item and calling it directly, without providing any inputs. For example, BBEdit’s Script Menu feature allows you to add your own scripts that can allow customization and additional code analysis integration.
Details
Shellcheck
ShellCheck is an analysis tool that shows warnings and suggestions concerning bad code in bash/sh shell scripts. It can be used in several ways: from the web by pasting your shell script in an online editor. Or you can install it on your machine and run it from the terminal, integrate it with your text editor as well as in your build or test suites.
Shellcheck – Installation
For macOS, you have three options for ShellCheck. One option is compiling from the source.
Two, install locally through a package manager like brew.
brew install shellcheck
Or better you can download pre-compiled binaries for the latest release from the Github repository here.
Shellcheck – BBEdit AppleScript Integration
Download the following AppleScript and save it in your users home folder here:
~/Library/Application Support/BBEdit/Scripts/shellcheck.scpt
-- Copyright (c) 2019 University of Utah, Marriott Library -- All Rights Reserved. -- -- Permission to use, copy, modify, and distribute this software and -- its documentation for any purpose and without fee is hereby granted, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation, and that the name of The University -- of Utah not be used in advertising or publicity pertaining to -- the distribution of the software without specific, written prior -- permission. This software is supplied as is without expressed or -- implied warranties of any kind. -- -- -- shellcheck.scpt -- -- Runs shellcheck against the current BBEdit document, displays results in new window. -- Requires shellcheck to be installed. --- -- Save this script in ~/Library/Application Support/BBEdit/Scripts/shellcheck.scpt -- tell application "BBEdit" activate set filename to file of text window 1 set docname to name of text window 1 end tell set filenamePath to quoted form of the POSIX path of filename set this_date to current date set window_name to "shellcheck output for " & docname & " on " & this_date tell application "BBEdit" activate do shell script "/usr/local/bin/shellcheck" & " " & filenamePath & " | /usr/local/bin/bbedit --append" make text window with properties {name:window_name} end tell
Pylint
Pylint is a source-code, bug and quality checker for the Python programming language. It is named following a common convention in Python of a “py” prefix, and a nod to the C programming lint program. It follows the style recommended by PEP 8, the Python style guide.
Pylint – Installation
To install pylint on macOS, run the following command:
pip install pylint
Pylint – BBEdit Integration
Download the following AppleScript and save it in your users home folder here:
~/Library/Application Support/BBEdit/Scripts/pylint.scpt
-- Copyright (c) 2019 University of Utah Student Computing Labs. -- All Rights Reserved. -- -- Permission to use, copy, modify, and distribute this software and -- its documentation for any purpose and without fee is hereby granted, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation, and that the name of The University -- of Utah not be used in advertising or publicity pertaining to -- the distribution of the software without specific, written prior -- permission. This software is supplied as is without expressed or -- implied warranties of any kind. -- -- -- pylint.scpt -- 04/17/17, v1.0, todd.mcdaniel@utah.edu -- -- Runs pylint against the current BBEdit document, displays results in new window. -- Requires pylint to be installed. -- Save this script in ~/Library/Application Support/BBEdit/Scripts/pylint.scpt -- tell application "BBEdit" activate set filename to file of text window 1 set docname to name of text window 1 end tell set this_date to current date set window_name to "pylint output for " & docname & " on " & this_date do shell script "/usr/local/bin/pylint --max-line-length=240 -ry " & quoted form of the POSIX path of filename & " | /usr/bin/pbcopy" tell application "BBEdit" activate make new text window with properties {name:window_name} paste tell application "System Events" to key code 115 end tell
Flake8
Flake8 is a wrapper around the tools, PyFlakes (fast static analysis), pycodestyle (checking the style) and Ned Batchelder’s McCabe script to find code that is too complex and needs refactoring. It is a great toolkit for checking your code base against coding style (PEP8), programming errors (like “library imported but unused” and “Undefined name”) and to check code complexity.
Flack8 – Installation
To install Flake8, open an interactive shell and run:
pip install flake8
Flake8 – BBEdit Integration
Download the following AppleScript and save it in your users home folder here:
~/Library/Application Support/BBEdit/Scripts/flake8.scpt
-- Copyright (c) 2019 University of Utah Student Computing Labs. -- All Rights Reserved. -- -- Permission to use, copy, modify, and distribute this software and -- its documentation for any purpose and without fee is hereby granted, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation, and that the name of The University -- of Utah not be used in advertising or publicity pertaining to -- the distribution of the software without specific, written prior -- permission. This software is supplied as is without expressed or -- implied warranties of any kind. -- -- -- flake8.scpt -- 04/19/17, v1.0, todd.mcdaniel@utah.edu -- -- Runs flake8 against the current BBEdit document, displays results in new window. -- Shortens file paths -- Requires flake8 to be installed. -- Save this script in ~/Library/Application Support/BBEdit/Scripts/flake8.scpt -- on replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to "" return this_text end replace_chars tell application "BBEdit" activate set filename to file of text window 1 as text set docname to name of text window 1 end tell set this_date to current date set window_name to "flake8 output for " & docname & " on " & this_date do shell script "/usr/local/bin/flake8 " & quoted form of the POSIX path of filename & " | /usr/bin/pbcopy" set mylines to text of (get the clipboard) set fixed_lines to replace_chars(mylines, POSIX path of filename, docname) set the clipboard to fixed_lines tell application "BBEdit" activate make new text window with properties {name:window_name} paste tell application "System Events" to key code 115 end tell
No Comments