Sublime Forum

How to detect spelling errors in the actual code

#1

Hi, I sometimes make spelling mistakes in the actual JavaScript code such as:
length, widht, scr.

Is there a way for Sublime to highlight such errors?

0 Likes

#2

F6


I am a word-counting patch.

0 Likes

#3

In my version of Sublime, F6 does highlight an error is this for example:

var myVar = ‘something’.lenght;

How to you enable this?

0 Likes

#4

You may have to modify "spelling_selector" in your preference.

0 Likes

#5

Thanks for taking time trying to help me. Much appreciated. My current default settings are below. to be honest, I don’t know what needs to be changed in order to highlight such errors.

“spelling_selector”: “markup.raw, source string.quoted - punctuation - meta.preprocessor.c.include, source comment - source comment.block.preprocessor, -(source, constant, keyword, storage, support, variable, markup.underline.link, meta.tag)”

0 Likes

#6

The scope you interested in is source.js meta.property.object.js. You may add meta.property or more aggressively meta. It depends on what you want. To get the scope at the cursor, ctrl+shift+alt+p.

0 Likes

#7

I’ve modified the settings to:
“spelling_selector”: "source.js meta.property.object.js "

The problem is that ‘src’ and ‘scr’ get highlighted as errors in both cases below:

myvariable.src = anotherVariable.toDataURL();

myvariable.scr = anotherVariable.toDataURL();

I would like to see only the scr highlighted as error. Would you know how to set this up?

0 Likes

#8

Since I have told you how to retrieve scopes, I would no longer answer any question about “How to get scopes”. If you are interesting in multiple scopes, a comma can be used to separate them. A minus sign can be used to exclude scopes. They are both used in the default settings.

0 Likes

#9

Neither “src” nor “src” are proper English words, so they are both highlighted. There’s a reason why spell checking is usually disabled for code, since most code identifiers are not proper English words and spell-checking those would be silly.

What you might be looking for instead is a linter, such as eslint or jslint. I do not know if they can detect misspellings of properties like length though.

2 Likes

#10

Linters were the first thing that I’ve checked. I’ve initially had a look at a couple of linters online and none of them was able to highlight .lenght as an error. I will have to dig deeper into this. It just seems that checking whether a word exist in a given programming language is such a basic feature that it should either come as standard or at least there should be some packages that deliver this functionality.

0 Likes

#11

I have never needed this feature, so declaring it as “basic” because you feel the need for it is over-generalizing.

That said, https://packagecontrol.io/packages/RegReplace can do this.

0 Likes

#12

Thread revival: FichteFoll made equally onerous replies to many of my remarks at this time (2016). Dreamweaver includes dictionaries for common languages, such as CSS, HTML, Java Script, Python, PHP, and so on. FichteFoll and the other Sublime Text developers do not have time to enhance Sublime in that manner. The honest reply.

You are correct. It would be nice if Sublime could adopt Code Dictionary eloquence. Perhaps, a vehicle like PackageControl/Github, not on its own, but coupled with campuses like MIT, UWisc (and tens of thousands of others…), a global Sublime Text “Code Dictionary Project”.

:joy: I can see it happening in 2018. Every 1st year engineering/technology student gets a free Sublime Text. Profs go wild with enthusiastic ideas. Sublime Code Dictionaries arrive in droves!

0 Likes

#13

Yes, basic applies to Code 101 classroom, but also to year 10 treatise. Your whining got me thinking just now, how when CSS3 was emerging Adobe got me filling in lists like ST3 User Settings’

“added_words”:
[
“flex-box”
],

Is there a way for a developer to create a package that would fork “added_words” to a simple comma delimited alphabetically sorted text document (without any quotes, no line breaks, word-wrap)? That editable document could sit in the User /Packages folder, where it could be easily accessed with gobs of code-word strings - food for the hungry. Much better than what Adobe got us doing [space-space-space-quotes-word-quotes-comma-return…]. Sublime Code Dictionary list would sort like Sublime’s User preferences, automatically. That would be an easy way to make Sublime more eloquent.

In fact, that eloquence would make it easy for profs in tens of thousands of Edu institutions to hand out gobs to their class-rooms full of Sublime imps. Similar to dragging a code document onto Sublime application icon, feed Sublime! “Now, GET TO WORK!”

:smiling_imp: Without giving away gazillions of free softwares to imps. Though, that ‘fame’ part must have an instantaneous appeal for such as you. Or would you Trump profit on that, too.

0 Likes