How to find cases when CoffeeScript 1.9.0 breaks a change in my code?

TL DR: Is there a way to identify violations for CoffeeScript new 1.9.0 behavior for parameter naming @foo? Now it is illegal and does not cause a warning / error to use a bare variable fooin a function.

Version 1.9.0 for CoffeeScript states:

A modified strategy for generating an internal variable compiler names. Note that this means that the @exampleparameters of the function are absent longer than those available as bare variables exampleinside the body of the function.

It means

class Animal
  constructor: (@name) ->
    console.log name

.. will fail silently. I. The above will not print the new name of the animal.

New correct solution:

class Animal
  constructor: (@name) ->
    console.log @name

CoffeeLint . - ? , script javascript?

2 :

+4
2

coffee.

, eslint no-undef. bash script:

#!/bin/bash

FILES=$@

# https://nodejs.org/api/globals.html
# Object.keys(global).concat(['__dirname', '__filename']).join(',')
DEFINED_GLOBALS='ArrayBuffer,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,DataView,global,process,GLOBAL,root,Buffer,setTimeout,setInterval,clearTimeout,clearInterval,setImmediate,clearImmediate,console,module,require,__dirname,__filename'

function compile() {
  ./node_modules/.bin/coffee --print $1
}

function lint() {
  # checks only for undefined variables except DEFINED_GLOBALS
  ./node_modules/.bin/eslint\
    --stdin --no-color\
    --global $DEFINED_GLOBALS\
    --reset --rule 'no-undef: [true]'
}

function main() {
  for file in $FILES; do
    local problems=`compile $file | lint`
    if [[ $problems ]]; then
      echo -e "=== $file\n$problems\n\n"
    fi
  done
}

main

check.sh - :

chmod u+x ./check.sh
npm install coffee-script eslint
find . -name "*.coffee" | xargs ./check.sh
+3

Ive CoffeeScript, console.error , @: https://github.com/lydell/coffee-script/tree/1.8-at-params-warn

:

npm install lydell/coffee-script#1.8-at-params-warn

@ s, , :

./node_modules/.bin/coffee -p file-to-check.coffee >/dev/null

, , , @.

+1

All Articles