-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature request: linting from stdin #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Given these arguments, it would make sense for pylint to gain this ability. Unfortunately, the required amount of work does not look relatively low, since it assumes almost all the time that its inputs are files or modules. With some refactoring around the linter module, this might be accomplished. One thing to note, though, is that it needs the whole content read in one pass, it can't do analysis on a line by line basis. |
Thanks for the encouraging comment! I'll open a PR to make it easier to discuss concrete code :) |
Connects to pylint-devGH-1187
Connects to pylint-devGH-1187
Has this been solved? |
pylint gained a new `--from-stdin` flag which activates stdin linting, useful for editors and similar use cases. Closes: #1187
Hi there,
pylint is one of the few checkers supported by Flycheck that doesn't support checking input passed on stdin. Could this feature be added?
Concretely, the proposal is that one would be able to call pylint this way:
cat /home/clement/test.py | pylint --stdin-file-name /home/clement/test.py -
instead of
At first, it may not be clear what advantages this may have. Here's a short explanation.
Flycheck checks files (buffer contents): it doesn't need the file to be saved. Since pylint requires the file to be checked to exist on disk, however, Flycheck must save the buffer.
When this happens with other linters, we usually just write the temporary file to
/tmp
; with pylint, however, we can't do that: saving to /tmp breaks relative imports.Instead, we're forced to save a temporary copy of the file in the same folder as the original file. So we save our temporary as
/home/clement/flycheck_test.py
in the example above.Unfortunately, this approach is invasive: if the user calls e.g.
grep
while a check is in progress, grep will find matches in the temporary file. If the code is on a backed-up folder (dropbox, owncloud, …), the back-up application might pop up a window saying "uploading new file flycheck_test.py`. etc. A concrete example of this problem is at python creating flycheck_myfile.py flycheck/flycheck#1173Moving to stdin solves this problem neatly: we can pass pylint the contents of the unsaved buffer without saving first, while tipping it about the file name. This has worked nicely with many other checkers (jshint and luacheck have
--filename
, rubocop has--stdin
, scss has--stdin-file-path
, jshint has--stdin-filename
, flake8 has--stdin-display-name
, etc.)How hard would it be to implement such a feature? Someone over at http://stackoverflow.com/questions/27862659/pylint-read-from-stdin asked for the same thing, and apparently on GNU/Linux passing /dev/stdin to pylint seems to work OK (except of course for imports), so hopefully the required amount of work should be relatively low?
Thanks!
The text was updated successfully, but these errors were encountered: