TL;DR: Is there any way to identify violations to CoffeeScript's new 1.9.0 behavior for @foo
parameter naming? It is now illegal, and does not cause a warning/error, to use the bare foo
variable in the function.
In the 1.9.0 version of CoffeeScript is stated:
Changed strategy for the generation of internal compiler variable names. Note that this means that
@example
function parameters are no longer available as nakedexample
variables within the function body.
This means
class Animal
constructor: (@name) ->
console.log name
.. will fail, silently. I.e the above will not print the new animal's name.
The new correct solution is:
class Animal
constructor: (@name) ->
console.log @name
CoffeeLint does not catch this. Is there any known stunt for finding the now illegal bare parameter use? Maybe a nifty script running on the generated javascript?
Here are 2 links about this:
The easiest thing would be to use older
coffee
version.In case that is not possible, you can compile every source file and run that through
eslint
checking forno-undef
rule. You can do that with following bash script:Save that as
check.sh
and run something along the following lines:I’ve made a mod of the CoffeeScript compiler that
console.error
s each occurance where you are missing a@
: https://github.com/lydell/coffee-script/tree/1.8-at-params-warnTo install it:
To check a file for missing
@
s, run for example:The above will log the file path, line number, column number and variable name for each variable that needs a
@
.