-
Notifications
You must be signed in to change notification settings - Fork 141
Add Fix on Save option
to fix lint errors on save ( fixes #417)
#508
Conversation
Fix on Save option
to fix lint errors on saveFix on Save option
to fix lint errors on save ( fixes #417)
I removed the test case as it looked time consuming to me. I need to understand atom environment in more detail. I might create another task . Its too exciting to see errors fix on save, so I would like to push the code. Please decide on this and proceed accordingly. |
}, | ||
fixOnSave: { | ||
title: 'Fix errors on save', | ||
description: 'Everytime the file is saved, linter-eslint tries to fix errors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change this to something like: "Have eslint attempt to fix some errors automatically when saving the file."?
What issues are you having with writing specs? I'd much rather they were added in this PR as otherwise we are just expanding the area of untested code 😞. |
I strongly agree it should go with this code . But I am not entirely sure how it should be written, should we mock the request and trigger save event , we also need to trigger open editor event . I am not quite familiar with atom yet, so I will need time to write them . |
This block shows how to open a file and get the resultant editor. The way I think I would go about this is copy/create a temp file in the OS's temp directory (use a module for this?), open it in Atom and trigger the save, then read back the contents and see if the appropriate fix was applied. |
I tried the same . I was stuck at the save part. How to know the save is done , save method is not giving any promise right ? |
If the save method doesn't return a promise then it's synchronous so you just need to run it and execution will block on that. I think you can just wrap it in a |
May be its not async, don't know why I thought it would be async by default. describe('Fix errors when saved', () => {
beforeEach(() => {
atom.config.set('linter-eslint.fixOnSave', true)
})
it('should fix lint errors when saved', () => {
waitsForPromise(() =>
atom.workspace.open(fixPath).then(editor => {
lint(editor).then(messages => {
expect(messages.length).toEqual(2)
editor.save()
lint(editor).then(messages => {
expect(messages.length).toEqual(0)
})
})
})
)
})
}) |
I will squash the commits , if this looks OK 👍 |
editor.save() | ||
lint(editor).then(messagesAfterSave => { | ||
expect(messagesAfterSave.length).toEqual(0) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the file contents afterwards, this isn't an issue for CI builds, but if you are testing locally this will cause a change in the repo state 😉.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of this , but it was not showing any problem. I deliberately ran the test cases multiple times , they still work . The real file is not changed .
A few comments that need to be addressed. |
I updated the config message. The file contents is not giving any issue, should I still consider replacing the original file? |
Really? That's odd... it must not be actually saving then?? |
Its total mystery to me honestly , it gave this error before saving. I deliberately said , expect 0 errors and message to be empty object. This was the output :
|
Rebase on master before you squash btw, looks like this was originally branched off of 0203b38 😛. |
@Arcanemagus I did rebase and squashed. Can you trigger the build again please. |
This LGTM, and we haven't had anyone else pipe up with changes so I'm merging this, thanks for putting this together! |
@Arcanemagus Thankyou. |
@pvamshi nice work! |
Looks like we aren't getting input from the rest of @AtomLinter/linter-eslint so I'll go ahead and push out a minor version with this in a few minutes. |
Didn't realize you were looking for input. Anything in particular you wanted us to look at? |
Anything else that needs to go into that release? Tried contacting on Slack but it seems nobody reads that 😛 (Also I may have forgotten about this myself over the weekend...) |
Ah, missed the slack. I've set up desktop notifications on that channel now. Looks like the other PRs need to be rebased before they can be merged, but it would be good to get this one out there in the wild. |
Yep, the other two need more work before merging. I'll get this released in a few minutes then. |
Published in v7.2.0 🎉. |
Try restarting atom. That seemed to work for me |
DO NOT MERGENeed to fix the unit test . I could not figure out how to write the unit test which checks something after the file is saved. I used setTimeOut as an ugly hack , but somone please help.
I wish to handle unit tests in another task if its fine. Otherwise we can keep this pull request open for a while till we can get the unit test .
Main change :
boolean
) to check if we need to fix the errors on save. Default isfalse