marviq / coffee-jshint

Runs your CoffeeScript source through JSHint to check for errors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error while running with options

filmic opened this issue · comments

I am getting following error while using "-o" option:

coffee-jshint -o smarttabs Test.coffee

C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\lib-js\hint.js:54
.sourceLocation([error.line - 1, error.character - 1]), line = _ref1[0], col =
                                                                    ^
TypeError: Cannot read property '0' of undefined
    at hint (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\lib-js\hint.js:54:92)
    at Array.map (native)
    at Function._.map._.collect (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\node_modules\underscore\underscore.js:97:56)
    at _.mixin._.(anonymous function) [as map] (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\node_modules\underscore\underscore.js:1073:39)
    at hint (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\lib-js\hint.js:52:45)
    at hintFiles (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\lib-js\hint.js:30:14)
    at Array.map (native)
    at Function._.map._.collect (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\node_modules\underscore\underscore.js:97:56)
    at hintFiles (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\lib-js\hint.js:19:12)
    at Object.<anonymous> (C:\Users\filmic\AppData\Roaming\npm\node_modules\coffee-jshint\cli.js:46:10)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

What is the contents of the file Test.coffee?

This is the content of the file. If I run coffee-jshint without options it works, but I want to relax validation and allow mixed spaces and tabs (with -o smarttabs option)

define [
    'utils/CapabilityUtil'
], (
    CapabilityUtil
) ->
    ###
     * General formatter functionality
     *
     * @class FormatUtil
     * @namespace utils
    ###
    class FormatUtil

        ###
        //
        //  Public methods
        //
        ###

        ###
         * Format the provided odds (milliformat)
         *
         * @param       {Number} value Odds value to format
         * @return      {String} Formatted odds
        ###
        @formatOdds: (value) ->
            if value is -1
                # starting price bet offer outcome
                return -1

            odds = value / 1000
            return odds.toFixed 2 if odds < 100

            return odds.toFixed 1 if odds < 1000

            return odds.toFixed()

        ###
         * Format a provided string with a supplied format properties parameter.
         * This function will try to replace any properties of the props
         * parameter in the provided string. For example, if props has a
         * property "baseUrl", it will look in the string for an instance of
         * "{baseUrl}" and replace it with the value in props.
         *
         * An example props property can look like this:
         * {
         *  baseUrl: "some value",
         *  someOtherProp: 3124
         * }
         *
         * An example of the provided string can look like this:
         * "{baseUrl}/something/else/{someOtherProp}"
         *
         * @param {String} str The string to format
         * @param {Object} props The properties to format the string with
         * @return {String} The formatted string
        ###
        @formatStringWithProperties: (str, props) ->
            if str? and props?
                for own propKey, propObj of props
                    str = str.replace "{#{propKey}}", propObj
            return str

        ###
         * Returns the default value to show inside empty input fields
        ###
        @getEmptyInputValue: () ->
            if CapabilityUtil.isDesktop
                value = ""
            else
                value = "&nbsp;"
            return value

        ###
        *  Replaces each format item in a specified string with the text equivalent of a corresponding object's value.
        *
        *  Exampl 1e: var output = FormatUtil.stringFormat("You are now {0} years old.", '8');
        *
        *  Or
        *
        *  Example 2: var output = FormatUtil.stringFormat("You are now {0} years and {1} days old.", '8', '9');
        *
        ###
        @stringFormat: (string) ->
            str = string

            for arg, i in arguments
                reg = ///
                    \{          # catch opening bracket
                        #{i}    # catch index (interpolate string)
                    \}          # catch closing bracket
                ///gm           # modifiers: global match, multiline match
                str = str.replace reg, arguments[i + 1]

            return str

I can't reproduce the error, but it looks like the same error as #2, which I just fixed in v0.0.12. See if upgrading solves your issue. If not, could you upload your file to gist.github.com to make sure that the mix of spaces and tabs are preserved?

I am still getting the error after upgrading to v0.0.12, both on Windows and Mac.

Here is the link to the file: https://www.dropbox.com/s/nsydr7nycfds62u/Test.coffee

When I run coffee-jshint Test.coffee, it works fine and I see a lot of errors about mixed tabs and spaces. When I run coffee-jshint -o smarttabs Test.coffee, I see the same output. So I cannot reproduce the error with v0.0.12.

This also makes me think that the smarttabs option may not work for your file anyway. When I compile your file to JS and run jshint on it with the smarttabs option, I get the same list of errors. jshint/jshint#945 suggests that there are only certain cases where smarttabs works anyway.

I added a --version option to coffee-jshint in v0.0.13, so you can make sure you are running the right version by running coffee-jshint --version.

Nice, linting works fine for me with v0.0.13, no more runtime errors.

Unfortunately it seems that coffee-jshint may not be useful for people using tabs for indentation (like me).
Coffee compiler outputs JS code indented with spaces, but will preserve tabs if you use them in multiline comments.
This combination of spaces and tabs is reported as error by jshint and cannot be ignored with smarttabsoption.

Consider this file: https://www.dropbox.com/s/e79ry3h4olpn9pb/Tabs.coffee
There are only tabs used for indentation but coffee-jshint reports 'Mixed spaces and tabs'.

Is there any workaround for that except for stop using tabs in multiline comments?

From what I've read in the CoffeeScript issues (see jashkenas/coffeescript#2203 and the issues it references), it seems like the recommended workaround is to use some sort of preprocessing. In this case, it may be as simple as something like sed 's/\t/ /g' Test.coffee.

Yes, however I don't want to modify my original files. I think this sort of preprocessing could be done on-the-fly in the coffee-jshint code before compiling CS->JS and sending it to jshint. Replacing tabs with spaces should be limited to multiline comments only as all other indentation will be converted to spaces by coffee compiler.
Let me fork your code and test some solutions.
Closing this issue as the originally reported bug has been fixed.