Error and Debugging Rules

The rules on this page catch code that is broken, very likely wrong, or not meant to ship: syntax errors, duplicate keys, thrown strings, and leftover debugging statements. Most of them are active by default because they detect bugs rather than style issues.

Rules on this page:

coffeescript_error

Property Value
Default level error
Message The CoffeeScript compiler's own error message
Options none

Reports syntax errors found by the CoffeeScript compiler. It is not a rule in the usual sense: it is produced while CoffeeLint parses the file, and its message is the compiler's error text, with the line number taken from the compiler's location data.

When a file has a syntax error:

  • the token-based and line-based rules are skipped for that file (they cannot run on code that does not tokenize),
  • inline directives are not applied.

So a syntax error can hide other problems. Fix it first and lint again.

You can change the level, though there is rarely a reason to:

{
  "coffeescript_error": {
    "level": "warn"
  }
}

With warn, syntax errors no longer affect the exit code. With ignore, they are not reported at all, but the other passes are still skipped for that file.

duplicate_key

Property Value
Default level error
Message Duplicate key defined in object or class
Options none

Reports keys defined twice in the same object literal or class body. The later definition silently wins, which is almost always a mistake (and a syntax error in JavaScript strict mode):

settings =
  timeout: 30
  retries: 3
  timeout: 60      # Reported

class Api
  fetch: -> 1
  fetch: -> 2      # Reported

@name and name are considered different keys, and each nested object has its own scope.

no_debugger

Property Value
Default level warn
Message Found debugging code
Options console (default false)

Reports debugger statements, which pause execution when developer tools are open and should never ship:

process = (data) ->
  debugger         # Reported, context: found 'STATEMENT'
  transform(data)

With console: true, any console.<method> call is reported too, with a context such as found 'console.log':

{
  "no_debugger": {
    "level": "error",
    "console": true
  }
}

Promoting this rule to error in CI is a simple way to keep debugging code out of releases. Where logging is intentional (a CLI tool's output, for example), wrap it in an inline directive, as CoffeeLint's own command-line code does:

log = ->
  # coffeelint: disable=no_debugger
  console.log(arguments...)
  # coffeelint: enable=no_debugger

no_throwing_strings

Property Value
Default level error
Message Throwing strings is forbidden
Options none

Forbids throwing string literals and interpolated strings. Only Error objects carry a stack trace and other debugging information:

# Reported
throw "i made a boo boo"
throw "Missing #{field}"

# Fine
throw new Error("Missing #{field}")

CoffeeLint cannot know what a function returns, so throw getSomeString() is not reported; the rule only catches the simple but common literal case.

transform_messes_up_line_numbers

Property Value
Default level warn
Message Transforming source messes up line numbers
Options none

Only relevant when you configure transforms. After the transforms run, CoffeeLint compares the number of lines before and after. If they differ, it reports this warning on line 1 with a context such as File was transformed from 40 lines to 52 lines, because the line numbers of all other findings in that file are probably wrong.

The check only compares totals: a transform that adds a line in one place and removes one elsewhere will not trigger it, even though line numbers in between are shifted.

See Also