facebookarchive / codemod

Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.
Apache License 2.0
4.11k stars 198 forks source link

ValueError: thrown on lines with //inline comments #32

Closed CNSKnight closed 10 years ago

CNSKnight commented 10 years ago

eg:

           var tab = new MainTabModel({
                   id: tabId,
                   text: searchDateString,
                   isClosable: true, // presumably useful comment here
                   ...
               });

And I've seen it err as on the line above that which contains // said comment

ptarjan commented 10 years ago

I don't really understand. Can you paste a file which when run has different output than expected?

CNSKnight commented 10 years ago

Actually running on JavaScripts

 Traceback (most recent call last):
   File "C:\workspaces_3.7\Marionette.Upgrade\bin\codemod.py", line 813, in <module>
     run_interactive(**options)
   File "C:\workspaces_3.7\Marionette.Upgrade\bin\codemod.py", line 124, in run_interactive
     bookmark = _load_bookmark()
   File "C:\workspaces_3.7\Marionette.Upgrade\bin\codemod.py", line 648, in _load_bookmark
     return Position(contents)
   File "C:\workspaces_3.7\Marionette.Upgrade\bin\codemod.py", line 469, in __init__
     % path_and_line_number[0])
 ValueError: inappropriately formatted Position string: c:\path\to\something.js:106

and that line 106 will have, so far as I've seen, // a comment or /* a comment */ either after it or just before it

CNSKnight commented 10 years ago

Ok - I got it. The arg.split():

          self.path, line_number_s = arg.split(':')
          self.line_number = int(line_number_s)

on the bookmark test, then excepts on the int() when the path part itself contains the : split target char. eg in absolute paths as used in Win environments.

Work-around is to use relative paths when launching codemod.