Skip to content
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

Lint script from stdin #240

Merged
merged 3 commits into from
Jun 18, 2018
Merged

Lint script from stdin #240

merged 3 commits into from
Jun 18, 2018

Conversation

RianFuro
Copy link
Contributor

This would resolve #183, however I'm really not satisfied with how it's looking.

The way I had to sprinkle branching logic basically everywhere - it hurts especially in the policy, which should be user-contributed - suggests that we really should refactor how the linted file is passed around.

Right now the file is passed as just the path in the linting context inside the linter, which makes it really clunky when stdin is introduced. I would say it would make more sense for the linter and the linter context to operate on a file object or even on raw text instead (don't know if the latter one is too memory inefficient with large files though).

Thoughs?

@Kuniwak Kuniwak self-requested a review November 12, 2017 00:19
Copy link
Member

@Kuniwak Kuniwak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my too late review.

Looks good to me.

@Kuniwak
Copy link
Member

Kuniwak commented Nov 12, 2017

@RianFuro
I'm gonna refactor it to hold raw texts in context to avoid seek call.
How about it?

@RianFuro
Copy link
Contributor Author

@Kuniwak basically a good game plan, I'm not sure though if how this impacts performance if people start loading megabyte-sized vim files into the linter (since you're basically loading everything into memory).
Thinking about it now, I consider that quite unlikely actually 😆, so maybe we should wait till that happens.

Then again, from what I know about python, stdin is just a specialized file object, so if we pass the opened file in instead of just the path we could substitute that with the stdin object without any other part of the system noticing. This would at least give the possibility to keep the linter memory efficient, without yielding too much overhead compared to just using raw text.

It's your software though, so if you can't be bothered don't let my inner system architect's nagging stop you; storing the file content in context is most likely a perfectly valid solution 👍

@Kuniwak Kuniwak changed the title WIP: lint script from stdin Lint script from stdin Jun 18, 2018
@Kuniwak
Copy link
Member

Kuniwak commented Jun 18, 2018

Sorry for my too late reply.

I think we can cache file contents if we feel it is very slow.
Looks good to me. Thank you @RianFuro !

@Kuniwak Kuniwak merged commit cac0cf7 into Vimjas:master Jun 18, 2018
Copy link
Member

@blueyed blueyed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

I've left to comments - let me know what you think and we could create new issues / PRs based on it.


return violations

def _should_read_from_stdin(self, env):
return len(env['file_paths']) == 1 and PosixPath('-') in env['file_paths']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be env['file_paths'] == [PosixPath('-')]?

But then again you might even want to mix it - vint foo.vim - bar.vim could read 3 "files".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I feel supporting vint foo.vim - bar.vim is a good way to follow common usage of - such as cat a - b.

return [parse_error]
except EncodingDetectionError as exception:
decoding_error = self._create_decoding_error('stdin', str(exception))
return [decoding_error]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to support --stdin-filename that could be used to configure the name (instead of stdin).

@Kuniwak Kuniwak mentioned this pull request Jun 19, 2018
@blueyed
Copy link
Member

blueyed commented Jun 19, 2018

@Kuniwak
I think the changes should be made before releasing 0.3.19, no?

@Kuniwak
Copy link
Member

Kuniwak commented Jun 19, 2018

Yes we should it if we can. I stop to release 0.3.19 until this feature is merged.

@blueyed
Copy link
Member

blueyed commented Jun 19, 2018

Makes sense, thanks.
Just for clarification: I do not have time to do it myself currently.

@Kuniwak
Copy link
Member

Kuniwak commented Jun 20, 2018

I'm working at #278. I'm gonna release v0.3.19 if it is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint from stdin
3 participants