jeremykohn / closure-linter

Automatically exported from code.google.com/p/closure-linter
Apache License 2.0
0 stars 0 forks source link

gjslint dies when file ends with line containing only a tab. #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My JS is split up into several small files
- individually gjslint fails on about half of them
- if the files are combined (ready for minifying), it works OK

Run with - Windows Vista -  Powershell

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32

C:\Python27\Scripts\gjslint.exe --nobeep --nojsdoc --nodebug_indentation 
file.js 2>&1

Error Message

Traceback (most recent call last):
   File "C:\Python27\Scripts\gjslint-script.py", line 8, in <module>
     load_entry_point('closure-linter==2.2.7', 'console_scripts', 'gjslint')()
   File "build\bdist.win32\egg\closure_linter\gjslint.py", line 100, in main
   File "build\bdist.win32\egg\closure_linter\checker.py", line 80, in Run
   File "build\bdist.win32\egg\closure_linter\checkerbase.py", line 166, in Check
   File "build\bdist.win32\egg\closure_linter\checkerbase.py", line 239, in CheckLines
   File "build\bdist.win32\egg\closure_linter\javascriptlintrules.py", line 85, in CheckToken
   File "build\bdist.win32\egg\closure_linter\ecmalintrules.py", line 412, in CheckToken
 AttributeError: 'NoneType' object has no attribute 'string'

File that causes it

// 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

---
//  (C) 2008-2010 - Andrew Murphy All Rights Reserved
// 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

---

// 
--------------------------------------------------------------------------------
-------------------------------------
// WALK PHOTOS
// 
--------------------------------------------------------------------------------
-------------------------------------

swc.pages.photos        = function () {};

swc.pages.photos.prototype.set_photo_from_cgi_params    = function() 
    {
    // --------------------------------------------------------------------------------------------------
    // used: /book_xx/walk_xx/walk_photos.shtml
    // get the "photo number" cgi param, and call swc.photo
    // photos[ number] refers to a list of photo objects inline html'ed into the photo page
    // ---------------------------------------------------------------------------------------------------

    var cgi_params  = this.cgi_params(),
        meta        = this.meta_data() ,
        photo_no    = cgi_params.photo && cgi_params.photo > 0 ? cgi_params.photo : 0,
        photo       = photos[ photo_no ] ;

    console.debug( ".. set photo from cgi params : " + photo_no + " : " + photo.title )  ; 

    document.title = photo.title + ' ' + document.title ;

    this.meta_data( { 'description' : photo.title + ' ' + meta.description } ) ;

    this.set_photo( photo ) ;
    };

swc.pages.photos.prototype.set_photo = function( photo)     
    {
    // called directly by clicking on a photo in the photo-list-widget on the photos page
    // called from above function - using cgi params - from a photo on the thumbnails page

    document.getElementById( "big_title"  ).innerHTML   = photo.title ;
    document.getElementById( "big_author" ).innerHTML   = photo.by + '<br>' + photo.date ;
    document.getElementById( "big_photo"  ).src         = photo.src_big ;
    document.getElementById( "big_url"    ).href        = photo.url ;
    document.getElementById( "big_url"    ).alt         = photo.title  ;
    };

Original issue reported on code.google.com by aavmur...@gmail.com on 2 Mar 2011 at 3:24

GoogleCodeExporter commented 9 years ago
It's hard to be sure with this snippet, but looking at it and the stack trace 
it seems like the linter is breaking when the file ends with a line that 
contains only a tab. I can reproduce it with a file containing only:

swc.pages.photos = function() {};
\t

My guess is that when you concatenate your js files together, the resulting 
file doesn't end with a line containing only a tab and the problem goes away. 
You can try working around it for now by removing these trailing tabs. 
Hopefully we can fix this in the next release of the linter or the one after. 

Original comment by a...@google.com on 3 Mar 2011 at 2:02

GoogleCodeExporter commented 9 years ago
Good catch, esp as I just copy-and-pasted the file - next time I'll attach it!

Replacing \n\t[eof] with \n[eof] solves the problem...

(my editor adds the \t, trying to be helpful)

Cheers
Andrew

Original comment by aavmur...@gmail.com on 3 Mar 2011 at 1:42

GoogleCodeExporter commented 9 years ago

Original comment by a...@google.com on 8 Apr 2011 at 10:05

GoogleCodeExporter commented 9 years ago

Original comment by michaelt...@google.com on 13 Apr 2011 at 8:37