sky-uk / bslint

A linter for the BrightScript language.
BSD 3-Clause "New" or "Revised" License
24 stars 9 forks source link

On macOS, users other than the owner of /usr/local/lib cannot run bslint #165

Open justindhill opened 7 years ago

justindhill commented 7 years ago

It looks like bslint, by nature of using enchant with a PWL, needs the PWL file to be writable by the user running it. (I did some digging and found out that enchant opens the PWL in a+b mode when attempting to load it) This can be problematic in CI setups where the CI server is run as its own user.

Here is some sample output that corroborates this:

$ sudo su jenkins                                              
Password:
bash-3.2$ bslint
Traceback (most recent call last):
  File "/usr/local/bin/bslint", line 7, in <module>
    from bslint.bslint import main
  File "/usr/local/lib/python3.6/site-packages/bslint/__init__.py", line 11, in <module>
    from bslint.lexer.commands import *
  File "/usr/local/lib/python3.6/site-packages/bslint/lexer/commands.py", line 11, in <module>
    DICTIONARY = words_dict.get_new_dictionary()
  File "/usr/local/lib/python3.6/site-packages/bslint/lexer/words_dictionary.py", line 9, in get_new_dictionary
    return enchant.DictWithPWL(dictionary_lang, personal_words_list_path)
  File "/usr/local/lib/python3.6/site-packages/enchant/__init__.py", line 822, in __init__
    self.pwl = self._broker.request_pwl_dict(pwl)
  File "/usr/local/lib/python3.6/site-packages/enchant/__init__.py", line 330, in request_pwl_dict
    self._raise_error(eStr % (pwl,))
  File "/usr/local/lib/python3.6/site-packages/enchant/__init__.py", line 259, in _raise_error
    raise eclass(EnchantStr("").decode(err))
enchant.errors.Error: Couldn't open personal wordlist '/usr/local/lib/python3.6/site-packages/bslint/config/personal-words-list.txt'

I propose that the PWL be copied somewhere in the user's home directory so that bslint can run correctly as any user.

DanieleSassoli commented 7 years ago

Had a chat with @zac-robinson and @JackIngleton, we agreed that the PWL needs some changes. We where thinking of making it optional and make it possible to set it as a config param so it could be different for each project that you wish to lint. So in case you want to have a PWL then you'd specify whatever file you'd like to. If you have any suggestions please let us know and we will look into them.

justindhill commented 7 years ago

I think that makes a lot of sense. I can see a use case where someone would want to provide some additional words to their dictionary. Also of note, I actually have spell checking disabled and it looks like the enchant dictionary is still being instantiated. Does bslint use enchant for additional features?

DanieleSassoli commented 7 years ago

yes, the enchant dictionary(and the PWL) get loaded even if the spell check is disabled. This is one of the things that need to change. I'll try and get it fixed in the next couple of days.

justindhill commented 7 years ago

Great, thanks a lot! This is an excellent project and I think it's going to help us a lot. 😊