Lines of code automatically added without warning/consent - debugging

**edited tags to reflect the cause of the problem
I've been working with Node.js for about 3 months give or take, and today I was working on a project when I suddenly got an import error on the client side, even though I hadn't touched any code there since I last ran the program. In fact, the only changes I had made were on the server side, and it was just some minor refactoring that didn't have anything to do with the imports. After frantically trying to find what I'd done, I scrolled up to see this line in server/index.js:
const { default: socket } = require('../client/src/socket.js');
I didn't write this line. It had been added without me asking or even noticing that it was there. I'm pretty sure that I hadn't clicked on any formatting tooltips, and it seemed to appear out of nowhere and was the cause of the break.
This isn't the first time that this has happened to me. I have noticed that at sporadic moments, code is added to my projects that I never asked for. So I have some questions:
Is this a feature of Node, and if so what triggers it?
As I'm using VScode, is it rather the IDE that's doing this?
How do I stop whatever's causing this from trying, and failing, to be helpful?
Thanks.

This is most likely VSCode's built-in auto-imports. You've probably typed socket and selected an auto-suggestion which contained Auto import from "../client/src/socket.js"
You can disable it with the setting "javascript.suggest.autoImports": false.
Additionally, if you're using Git for version control, try using git add -p (-p for patch) to stage your changes bit by bit instead of the entire file. This way you can review your changes in slices and you'll probably catch things like this.

That's not a feature of Node but, Some of the VSCode extensions possess capabilities of auto import. Maybe one of your extension has added that line. To prevent it disable your JavaScript autocomplete, linter extensions.

Related

Prompt to reload an externally modified file in Textmate 2?

Im finding myself using TextMate 2 more and more for development these days
One thing that is bugging me is that it does not seem to reload a file when it is changed externally.
This is a big problem since I use terminal to switch git branches a lot, and it often results in accidentally saving an older version over the new branch
Sadly the TM team seem to have disabled the Issue tracker on github, and documentation just seems scattered far and wide over the web in tiny scraps.
Any ideas?
Right now it reloads the file silently whenever the file on Disk is changed. There is currently no option for a prompt.
Regarding the closed issue tracker: As an alternative, you can always send a mail to the Textmate users list if you find a problem.
I just updated to TM 2. In the past, I have enjoyed using TM to view development.log as I am introducing new or modified code. TM 1 would ask me if I want to revert to what's on disk and of course I would respond with Yes. Then I could see any additions to the log file. Occasionally I would empty the log file with Cmd+A, Delete, Cmd+S. Macromates, please make TM 2 work like TM 1 reloading content.
I also could not find a solution to this problem which is still there, however it is possible to file an issue using this contact page: http://macromates.com/support
Additionally there are hidden setting which cannot be set from the GUI. Unfortunately they don't include and setting for automatic load from disk: https://github.com/textmate/textmate/wiki/Hidden-Settings

Why do files occasionally turn into read-only mode after saving in Visual Studio?

I have a really strange problem with my Visual Studio.
I usually press CTRL + S pretty often (call me paranoid, well however I got that habit some years ago now and I really don't want to get rid of it :-))
Now I had the issue that I was editing one file, changing a few dozen of strings according to a spec I had open in Word; so I switch around these two tasks pretty often, make one or two changes and then save.
The odd thing is, every once in a while, after saving, my file is suddenly in read-only-mode, so I cannot navigate through my changes (CTRL+Z/CTRL+Y) and have to reopen that file to continue to code and pray.
Indeed it feels random to me when this occurs:
sometimes I only change 1 thing and save and then it's immediately read-only,
well in other cases it will let me edit several things until it is stuck.
Someone else also experiencing this and maybe got a tip?
Maybe I hit some magic hotkey or something?
My bad, please check if your projects folder is not a synchronized one, so when you edit (change) your project, the backup tool starts to update in remote location for synchronization purposes, so locks the file.
The answer to this problem is most likely that you are currently in Debug mode - i.e. the application is being run. Click "Stop" and it'll allow you to edit the files again.
By default, you cannot edit source files while the Debugger is running.

Xcode4 breakpoints adapt to code changes?

I have a series of logging breakpoints in Xcode4 that I'm using to selectively log things as I need them. However, whenever I make changes to the code involving adding or deleting lines, these breakpoints get out of sync with where they are supposed to be, sometimes even going to a completely different function.
Is there a way to keep the breakpoint in sync with the code, rather than just rely on the line number?
I believe it should, at least it's the IDE's usual behaviour.
Just a thought. Have you tried to reinstall XCode? I have experienced all sorts of weird bugs since the upgrade to XCode 4. For example, being unable to select a XIB file for a popup window in a project---and when creating a project from scratch, I was able to select that XIB and create the popup. At the time I posted a question on StackOverflow about this and it is still unanswered ever since.
Since that time, the project was overhauled and now I build my interfaces from scratch using full Obj-C code, dumping the interface builder 99% of the time...

Xcode not predicting

Am new to objective-c and xcode, and i love programming with them. But am facing a problem with xcode this has occurred quite a few times before, i.e the xcode's Auto-Suggestion mode is not working.
By Auto-Suggestion i mean- when i type say two letters 'UI..' xcode predicts the remaining word to be "UIColor, UIButton, .. etc".
Same for the instance methods eg. you type 'init ' and a list is shown as "initWithFrame,
initWithNibName, .." and so on, which makes coding so easy.
But after i performed some operation like undo or delete i don't remember what i did exactly, this auto-prediction is not working and this is happening only on a particular file.
Any idea what i did wrong to make this happen?
Thanks
Xcode sometimes freaks out and exhibits this behavior. Best you can do in this case is clean your project (cmd-shift-K), close Xcode, then re-open it.
I have noticed this behavior especially when using #defined macros extensively.
I know this post is old, but the correct way to resolve this issue is to clear your derived data. After cleaning the derived data and restarting Xcode, your project will say "Indexing" which is the process of setting up everything required to make this feature work. After that, everything should work again.
To clear derived data go to Xcode->Preferences. Then click the little arrow next to the path to the derived data folder. Finder will open with the projects in derived data. Simply select and delete the one specific to your project giving the issue (Don't worry, this will not affect your project).
If there are any compile errors, then also prediction doesn't work properly. try resolving them first.

Why is xcode(4) so slow to dismiss errors I've already fixed?

So I hit Cmd+B and xcode throws all these errors and warnings at me. But after I fix them, xcode is sometimes slow to catch on, often requiring another Cmd+B on my part to nudge it to recheck the file. Is there a setting somewhere I can toggle to make xcode recheck for errors more aggressively?
It seems there's still room for improvement on the things that cause Xcode to retry your code. One thing I've noticed is that if you change something in a header than navigate back to the implementation, it quite often won't detect the fix until you force a build (or run it, which builds first).
The workaround? Save (Cmd-S) the file before navigating away from it or save all files (Cmd-Opt-S) if you've fixed several problems across several files.
The long-term solution? File bug reports at http://bugreporter.apple.com

Resources