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

Add --fix-to-stdout #53

Merged
merged 4 commits into from
Oct 16, 2016
Merged

Add --fix-to-stdout #53

merged 4 commits into from
Oct 16, 2016

Conversation

aaronjensen
Copy link
Collaborator

fixes #52

@@ -74,12 +74,19 @@ module.exports = function (cwd, args, text) {

return JSON.stringify(fileConfig, null, ' ');
}
if (currentOptions.fixToStdout && !stdin) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I check for text here? tbh, the check for text and the fallback to using files below is confusing. It seems stdin should always use stdin, even if the stdin is empty.

Copy link
Owner

Choose a reason for hiding this comment

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

Hm, I see. Checking for text shouldn't be necessary. I agree that the flag should be enough.

var report;
if (stdin && text) {
report = engine.executeOnText(text, currentOptions.stdinFilename);
} else {
report = engine.executeOnFiles(files);
}
if (currentOptions.fixToStdout) {
return report.results[0].output || text;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related to above, there's an edge case here if a user passes --stdin, no text, and more than one file. I should probably at least check for text in the conditional, but that would introduce another edge case... if a user lint fixed a blank file, you'd want it to return a blank file (maybe with a trailing newline? 😄)

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe the new option should only allow a single file if not used with --stdin? This way we don't need to require the --stdin option and one could use the feature to "inspect" what eslint does with --fix without actually modifying the file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is there an easy way to detect a single file? does eslint_d expand globs/directories or does it let eslint do that

Copy link
Owner

Choose a reason for hiding this comment

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

Globs are expanded by eslint. Let's take the easy path then and only support --stdin then. If text is empty, we just do nothing.

option: 'fix-to-stdout',
type: 'Boolean',
description: 'Print the fix results to stdout instead of regular output, '
+ 'must be used with --stdin'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we assume --stdin or just require it?

@aaronjensen
Copy link
Collaborator Author

@mantoni I think this is ready for review

@mantoni
Copy link
Owner

mantoni commented Oct 15, 2016

Looks good to me. Thanks a ton! 😎 Will merge and release later today or tomorrow …

@mantoni mantoni merged commit a912bb5 into mantoni:master Oct 16, 2016
@mantoni
Copy link
Owner

mantoni commented Oct 16, 2016

Released in v4.2.0 (see changelog for a description).

@aaronjensen
Copy link
Collaborator Author

Nice. Unfortunately, I think that supporting non-stdin would be even trickier than knowing the file count. If there are no changes, I believe that eslint reports no source so we'd need to actually read the source from the file and send it back. Otherwise we could just count the # of results that came back and error if there are more than one.

@aaronjensen aaronjensen deleted the add-fix-stdout branch October 16, 2016 17:52
@mantoni
Copy link
Owner

mantoni commented Oct 16, 2016

I think it was a good idea to make it work with a simple code path first. We can iterate on it once we have a good feeling about how this could work. I'm currently not a 100% sure about the approach we should take here. Maybe it's also not too important to have. Let's see.

```elisp
(defun eslint-fix ()
(interactive)
(setq temp-point (point))
Copy link

Choose a reason for hiding this comment

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

@aaronjensen Why don't you let-bind this variable? It's not a good idea to just setq variables this way.

Copy link

Choose a reason for hiding this comment

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

Actually you could just use save-excursion here, if I'm not mistaken. That'll restore point automatically afterwards. Did you try it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately, save-excursion doesn't work w/ shell-command-on-region, that was the first I tried. Good idea on let though.

Copy link

Choose a reason for hiding this comment

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

Ah, too bad, didn't know that.

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.

Support --fix to stdout?
3 participants