Somewhere around the start of 2008, I added the ‘
varscoper‘ tool to my toolkit at work. If you don’t know this tool: ‘
varscoper‘ will read your CFML code and indicate which undeclared local variables are left in your components and functions, waiting to inflict unexpected bugs and bad performance on your application. If you want to know why undeclared local variables can be so bad, start by reading Mike Schierberls thoughts on this subject – he’s the original author of the tool.
Thanks to a tip from Christopher Wigginton on
cfml.slack.com, I was able to update my 2008 ‘
varscoper‘ copy to version 1.4 of 2015. You’ll find the latest version on GitHub. This version still runs on CF8, but is already equipped to handle higher versions on Adobe CF as well – well, up to CF11 (and I’m not sure CF 2016 will be adding much new stuff that impacts ‘
While integrating and testing the new version I stumbled upon a few small bugs in the file display code. First of all, ‘
fileDisplay.cfm‘ never shows the two first characters of the first line of a file; secondly, it never shows the last line of the file either.
As a quick fix, I solved these problems with some extra “padding” to the file contents, like so:
<cffile action="read" file="#URL.fileName#" variable="fileContent" /> <cfset fileContent = " " & fileContent & Chr( 13 ) & Chr( 10 ) />
But in fact, a good solution requires a bit of a change to the basic algorithm used in this code. You see, this code will only work correctly if and when used on files that use Windows-style end-of-line markers (i.e. “carriage return” CR + “line feed” LF). The number two in the term ‘
lastLineStart + 2‘ of the line that outputs the code refers to the combined length of CR and LF, and thus disregards the optional character of the CR in the earlier ‘
REFind‘ call. So there is still room for improvement (unless, like mine, your ColdFusion world is limited to Windows servers)…