Does anyone know of a plugin I can use to spell check the comments in my code?
I'm always doing things like this
//Retrns porduct name in upercase
function getUpperCaseProductName(){
var productName = Myobj.currentProduct.data.name;
return productName.toUpperCase();
}
I don't know of a textmate plugin, but I'm pretty sure it does this already via Edit → Spelling, which is enabled by default for comments. Start by checking that you don't have this turned off for comments, or set to the wrong language.
It's unlikely that someone will develop a custom plugin to do something that textmate already has as a feature.
BTW, the //Retrns example you give above is joined to the two slashes. No word in the dictionary has two slashes at the start, so it may be missing it for this reason. If this is the problem, file a bug report with the textmate guys, or perhaps consider moving to a more feature-rich editor if it bothers you a lot (PHPStorm picks up that typo just fine, and you can also check the names of variables and functions if you want to be really pernickety).
Try using the Spelling option under Edit in Textmate2.
I think it does not differentiate between code and comment for Spell Check.
Related
I'm looking at some javascript code and trying to understand how it works.
It contains underscores against some of the functions but I can't see Lodash or Underscore included so I'm confused about how that is working. Here's an example...
theme.Sections.prototype = _.assignIn({}, theme.Sections.prototype, {
_createInstance: function(container, constructor) {...
Can anyone help me understand how that is working?
Here's a link to the site that's using the code so that you can see the whole thing working...
https://debut-demo.myshopify.com/
Edit: It is _.assignIn that I'm confused about. I can't see Lodash loaded so not sure how that is working?
As far as I'm aware, it's generally used to indicate a private variable (but doesn't actually provide any privacy, just a convention).
It's discussed briefly here, though they're advised against: http://javascript.crockford.com/code.html
I've started using Vim 7.4 on Ubuntu and am very pleased with it but there is just one thing driving me crazy: code folding doesn't work (at least for JavaScript)!
The syntax is automatically set to JavaScript when a js file is opened and syntax highlight works so I don't get it. The foldmethod is initially set to "manual" and setting it to "syntax" doesn't make a difference, which puzzles me. I did add let javaScript_fold=1 to my .vimrc file.
Any clue? I'd be very grateful. Thanks!
It's tough to say the exact cause of this issue, but if you don't have a javascript.vim file you probably should. I suggest starting with this enhanced javascript syntax config. It is likely to fix your javascript folding issue, and much more.
If you just want to focus on the folding issue you might try creating your own javascript.vim file in ~/.vim/syntax/javascript.vim that contains code along the lines of what I have given below. You may want to adjust the fold level to your liking (0 is completely folded). However, this simple version will not play well with comments containing curly bracket characters, which is where you will want to go with a more robust javascript.vim like the one I have linked.
syntax region foldBraces start=/{/ end=/}/ transparent fold keepend extend
setlocal foldmethod=syntax
setlocal foldlevel=0
I should add that both myself and the other responder are suggesting that you need a javascript.vim, and in fact by some of the same contributors. However, the one I am suggesting was last updated in December of 2015 as opposed to 2009.
I don't know why your solution isn't working, but a possible solution is to use a user-created vimscript available at http://www.vim.org/scripts/script.php?script_id=1491
Just had this same issue answered on Vim Stack Exchange, and the answer is that if you do use the stock syntax/javascript.vim file, then you have to set
vv
let g:javaScript_fold = 1
^^
The difference between the command in the question and here is the g: part (highlighted above). I'm new to Vim scripting, but I believe the difference is that let javaScript_fold=1 sets a script-local variable, making it confined to your .vimrc file, and the example above makes it global (which seems to be confirmed by this Stackoverflow thread). See more on this at section 41.2 Variables in :help usr_41.txt and :help internal-variables.
This Reddit thread was also enlightening; it's not JavaScript-related but the folding seems to be useful for JS files as well.
While looking at how to make JavaScript source code more secure I came upon a lot of 'solutions'. but most people said the same thing; "It's not possible to make your source code 100% secure", "try obfuscation", "run your code server side", etc, etc. After reading a lot posts here on stackoverflow, and other sites I came to the conclusion that a combination of minifying and obfuscating would do the job (for me).
But here is the problem: we are currently using soma.js with dependency injection, and the way we set it up it does not work well with obfuscation. It's basically this:
var session = function(id, sessionModel){
this._sessionmodel = sessionModel;
}
mapping:
injector.mapClass("sessionModel", project.SessionModel, true);
Obfuscation will then rename the sessionModel in the function to for example 'A', but the mapping that was done on SessionModel by the injector still remains 'sessionModel' and not 'A', this then basically breaks the code.
I've read this post which is about the same subject Dependency Injection and Code Obfuscation, but it does not provide a real answer to my problem so I decided to write my own question.
Any tips/hint/suggestions are welcome.
Thanks in advance.
EDIT
It seems you can tell Yuicompressor to exclude certain identifiers by putting in 'hints' into the files like this: "identifier:nomunge, identifier2:nomunge".
var session = function(id, sessionModel){
"sessionModel:nomunge";
this._sessionmodel = sessionModel;
}
I tested this and it works but that means you'll have to put it in yourself which is a lot of work if you have to do that for every script, especially if you have a very big project..
Gonna look into it further, and update this post if anything new pops up
EDIT 2
It's been a while, I only work 1 day a week on this =S.
As said before you can get it working by telling it which identifiers to exclude.
For that I looked into regular expression to get the "mapped classes" programmatically, since doing it by hand is just insane.
What I basically did was instead of putting every hint in by hand, I made a identifier, for example "#nomunge"; and used a simple replaceregexp task to find it and replace it with a string containing all the identifiers. This string is build by loading the script and going through it with a tokenfilter.
<target name="build hints">
<loadfile property="hints" srcFile="${temp.loc}/all.js">
<filterchain>
<tokenfilter delimoutput=":nomunge,">
<ignoreblank/>
<containsregex pattern="${regexp}"/>
</tokenfilter>
</filterchain>
</loadfile>
<echo message="${hints}"/>
</target>
<replaceregexp file="${temp.loc}/all.js"
match="#nomunge"
flags = "g"
replace = "target:nomunge, dispatcher:nomunge, injector:nomunge,${hints}"
/>
This seems to do the job, for now...
I'm behind the soma.js framework, feel free to ask me questions on the google group, happy to help.
This might help a bit more:
https://groups.google.com/forum/#!topic/somajs/noOX2R4K58g
Romu
I am starting to learn EmberJS/JS/VIM . I was going through the official ToDoMVC guide for EmberJS, and I ran into typos errors that was really really hard to detect with the "eyes" and the browser really didn't help in this case at all. So, can you please suggest me what tools or techniques that can be used to detect these types of typos errors?
For example:
### todo_controller should've been todos_controller
<script src="js/todo_controller.js"></script>
### catching the end of { } closed scoping
### typo within a model js "property"
inflection: function() {
var remaining = this.get('remaining');
return remaining === 1 ? 'todo' : 'todos';
}.proprety('remaining')
EDIT;
Yes, I did search before posting here. The first was this website, and the comments here basically suggest DreamWeaver Frustration with Typos.
I searched SO itself (through google), and there was Is there a way to catch typos. I did find out there is something called LINT, but it dealt with coffeescript.
I did find out ember.vim as you pointed out before, but as you see the README in the github profile, i believe it strictly wants you to follow the layout as prescribed. It may be a good thing in future, but right now, I wanted to just stick with what the official ToDoMVC way. I am just beginning to get a hang of hjkl, so I do not think I can makes changes to it to fit my way. Also, second point, is the layout format it supports is Ember-AppKit which has been deprecated. SO I am having doubts if I should follow the layout pattern itself.
And all of them didn't particularly address what I am asking. In the todo_controller typo above, the browser didn't throw any sort of errors. I am using FF/Firebug, and on the Console, it only showed the message about Ember loading, and no errors at all. It took me a while to see that typo. The second one did throw errors, but typos are a hard thing to discover in VIM. The third one, took a bit of time, and there were others. These don't throw errors at all. I am used to PHP, and while there is no direct showing of errors as in Android, I am finding Javascript typo hunting to be very hard.
it took me like 3 looks before I saw your typo.
Set your browser to pause on exceptions (sometimes pause on Caught Exceptions). It's been one of the quickest ways I've found to track down a weird bug. In this case I'm sure you were getting Uncaught TypeError: undefined is not a function....
Don't take this the wrong way, but did you try to search before asking? There has been, for quite a while now, a plugin for Vim that has syntax highlighting improvements.
https://github.com/dsawardekar/ember.vim
Beyond that plugin, you could try writing your own solution. I haven't tried, but I doubt there is anything out there that will pick up spelling errors for Ember...
I use JSLint for SublimeText 3, which lints as you code so you get a live update of any potential bugs. Kinda nice. Here's something similar for Vim: https://github.com/hallettj/jslint.vim
As #kingpin2k suggests, you should really learn how to use your browser tools. The big three are just jam-packed full with development and debug tools. 9 times out of 10 it gives you the line and column of the error, and you can set breakpoints within the code to watch it execute in-context. And, that is really just the tip of the iceberg in terms of how detailed you can get with debugging in-browser.
I would like to is flag some piece of code to come back to later. The code is seriously violating our design and I want to ensure that I see it every time I run JSHint until I fix it.
Just as an example suppose that to get something else working I change this code:
addTwoNumbers: function(numberOne, numberTwo){
return numberOne+numberTwo;
}
To this:
addTwoNumbers: function(numberOne, numberTwo){
return 11;
}
JSLint has no problems with these changes, but clearly they will cause me some trouble later. What would like to do is something like this:
addTwoNumbers: function(numberOne, numberTwo){
/* jslint fail */
return 11;
}
This way when I run JSLint before committing I will see that I have done something I probably shouldn't.
Alternately, if I am planning on committing the code (bad idea) and coming back to it in a couple weeks, I want to be warned frequently by JSHint.
I know that I can use the "Unexpected TODO comment" but my team (me included) uses TODO very liberally. Another method would be preferred.
More info on: Unexpected TODO comment
this is a coding style and not a language fault, and recently JSHint has taken the decision to not implement coding style options in the linter.
I'm not sure of the state of development, but it may be/become possible to write extensions to JSHint to enforce one's own coding style.
Though, what you're asking is done since programming and editors exist:
addTwoNumbers: function(numberOne, numberTwo){
return 11; // TODO bad implementation, change it!
}
and have your editor highlight the comment in yellow and red, add a /!\ in the line number column, and have it list it along with the warnings of your linter!
But that's not JSHint's job, or even a linter's job to check that kind of things!
I am leaving this here partly as a note to myself and partly for anyone else who has this issue.
If you are using grunt to invoke jslint, you can also use grunt-todo. This allows you to define tags in your project and then it will list the tags on build/grunt. It has some built in tags by default and you can add your own. I think you should even be able to configure your release build to fail if there are specific tags in the code base.