ESSS / esss_fix_format

Simple code formatter and pre-commit checker used internally by ESSS
MIT License
19 stars 10 forks source link

`ff -c` is not fixing C++ files that lacks UTF-8 BOM (it's only checking and giving errors) #37

Open tadeu opened 5 years ago

tadeu commented 5 years ago

ff should check (ok), but ff -c should fix the files (add the BOM marker).

This is related to issue #31.

tadeu commented 5 years ago

There's another new problem with BOM's whose fix could probably be bundled together:

Traceback (most recent call last):                                                                       
  File "C:\env\Scripts\ff-script.py", line 9, in <module>                                 
    sys.exit(main())                                                                                     
  File "C:\env\lib\site-packages\click\core.py", line 764, in __call__                    
    return self.main(*args, **kwargs)                                                                    
  File "C:\env\lib\site-packages\click\core.py", line 717, in main                        
    rv = self.invoke(ctx)                                                                                
  File "C:\env\lib\site-packages\click\core.py", line 956, in invoke                      
    return ctx.invoke(self.callback, **ctx.params)                                                       
  File "C:\env\lib\site-packages\click\core.py", line 555, in invoke                      
    return callback(*args, **kwargs)                                                                     
  File "C:\env\lib\site-packages\esss_fix_format\cli.py", line 153, in main               
    return _main(files_or_directories, check, stdin, commit, format_code)                                
  File "C:\env\lib\site-packages\esss_fix_format\cli.py", line 311, in _main              
    changed, new_errors, formatter = _process_file(filename, check, format_code)                         
  File "C:\env\lib\site-packages\esss_fix_format\cli.py", line 174, in _process_file      
    fmt, reason = should_format(filename)                                                                
  File "C:\env\lib\site-packages\esss_fix_format\cli.py", line 49, in should_format       
    if 'jupytext' not in f.read():                                                                       
  File "C:\env\lib\encodings\cp1252.py", line 23, in decode                               
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]                                    
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 945: character maps to <undefined>

seems related to a missing encoding in f.read() in that jupytext recent feature