Skip to content

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

Closed
cpitclaudel opened this issue Dec 2, 2016 · 3 comments · Fixed by #2746
Closed

Feature request: linting from stdin #1187

cpitclaudel opened this issue Dec 2, 2016 · 3 comments · Fixed by #2746
Labels
Enhancement ✨ Improvement to a component

Comments

@cpitclaudel
Copy link
Contributor

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

pylint /home/clement/test.py

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#1173

Moving 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!

@PCManticore
Copy link
Contributor

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.

@cpitclaudel
Copy link
Contributor Author

Thanks for the encouraging comment! I'll open a PR to make it easier to discuss concrete code :)

cpitclaudel added a commit to cpitclaudel/pylint that referenced this issue Dec 3, 2016
cpitclaudel added a commit to cpitclaudel/pylint that referenced this issue Dec 3, 2016
@PCManticore PCManticore added the Enhancement ✨ Improvement to a component label Jan 22, 2017
@eflanigan00
Copy link

Has this been solved?

PCManticore pushed a commit that referenced this issue Mar 2, 2019
pylint gained a new `--from-stdin` flag which activates stdin linting, useful for editors and similar use cases.

Closes: #1187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants