Repository: spyder-ide/spyder

Issue:
Static Code Analysis can be attempted without selected file
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] ~~Could not reproduce inside ``jupyter qtconsole`` (if console-related)~~
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] ~~Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)~~
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

Static code analysis can be attempted when no file is selected and causes an internal error.

### What steps reproduce the problem?

0. Delete pylint.results in spyder-py3, start spyder, run a Static Code Analysis on a file
1. rename, move or delete the file (which should be the only one listed in the path dropdown)
2. open an existing .py file in spyder.
3. restart spyder. The path field in the analysis tab is now cleared but the Analyse Button is now active
4. click it

### What is the expected output? What do you see instead?

The button should not be active. Clicking it should have no effect

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback
Traceback (most recent call last):
  File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/__main__.py", line 7, in <module>
    pylint.run_pylint()
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/lint.py", line 1394, in __init__
    linter.check(args)
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/lint.py", line 801, in check
    self._do_check(files_or_modules)
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/lint.py", line 920, in _do_check
    for descr in self.expand_files(files_or_modules):
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/lint.py", line 959, in expand_files
    self.add_message(key, args=message)
  File "/home/leo/.local/lib/python3.6/site-packages/pylint/utils.py", line 449, in add_message
    self.stats['by_module'][self.current_name][msg_cat] += 1
KeyError: None
```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 3.3.3
* Python version: 3.6.8
* Qt version: -
* PyQt version: -
* Operating System name/version: Fedora 28 64-Bit

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
IPython >=4.0     :  6.4.0 (OK)
cython >=0.21     :  None (NOK)
jedi >=0.9.0      :  0.12.1 (OK)
matplotlib >=2.0.0:  2.2.3 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
numpy >=1.7       :  1.14.5 (OK)
pandas >=0.13.1   :  0.22.0 (OK)
psutil >=0.3      :  5.4.3 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pyflakes >=0.6.0  :  1.6.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
pylint >=0.25     :  1.7.5 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
rope >=0.9.4      :  0.11.0 (OK)
sphinx >=0.6.6    :  1.7.5 (OK)
sympy >=0.7.3     :  None (NOK)
```



Discussion:
Thanks for reporting. We'll fix this in our next version.
@definite-purple By "no selected file", do you mean no files open the Editor? Pretty much every command breaks in that instances rather than disabling itself; I thought our approach was just to ensure there is always an open file in the Editor by opening a new ``untitledN`` one if the user closes everything.
No. I'm referring to the static code analysis tab, which has a file select dropdown entry field thing, and I meant that no file path is shown in there.
At least one code file (after step one potentially a new untitled one) is always open int the editor pane when reproducing the error
Thanks for clarifying!
@dalthviz, please take a look at this one.

Resolving patch:
diff --git a/spyder_pylint/widgets/pylintgui.py b/spyder_pylint/widgets/pylintgui.py
--- a/spyder_pylint/widgets/pylintgui.py
+++ b/spyder_pylint/widgets/pylintgui.py
@@ -219,6 +219,7 @@ def __init__(self, parent, max_entries=100):
         if self.rdata:
             self.remove_obsolete_items()
             self.filecombo.addItems(self.get_filenames())
+            self.start_button.setEnabled(self.filecombo.is_valid())
         else:
             self.start_button.setEnabled(False)
 


Test patch: