We're just starting to use JSHint / JSLint and are looking for some "best practice" type settings that are widely considered to be a good compromise between strictness and pragmatism. I've had a look on the internet and not really been able to find anything.
I realise it's all down to personal opinion but I would have thought that some sort of consensus would have formed by now. For example does anybody know what jquery, google, yahoo etc code to?
Thanks.
It definitely is a matter of personal style, but you can see many examples from open source projects:
jQuery or jQuery UI
Mozilla browserid
yeti (from Yahoo yui)
So if you pragmatically combine them you get something like that:
{
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"latedef": true,
"onevar": true,
"noarg": true,
"node": true,
"trailing": true,
"undef": true,
"unused": true
}
Related
I am using ACE editor in my browser extension. It all works fine in a Chrome/Chromium browser, but when I try the extension in Firefox (latest version), only ace.define and ace.require are available (ace.edit is needed, at least, to initialize).
Here is the part of the manifest (MV2) file involved:
"content_scripts" :
[
{
"matches": ["*://example.com/*"],
"all_frames": true,
"js": [
"ace-min/ace.js",
"myscript.js"
],
"run_at": "document_end"
},
]
What could be done wrong? Both files are being read, but only a part of ace.js seems to be executed. Imagine that myscript.js contains a console.log(ace), to see which functions can I use.
Thanks in advance!
I posted an issue on the ACE's GitHub repository. The response was very quick and polite.
All is explained in this comment: https://github.com/ajaxorg/ace/issues/4898#issuecomment-1217887526
Just a side note, use noconflict ace instead of normal ace. The function you need to change is at the bottom.
I am following the electron Js docs : https://electronjs.org/docs/tutorial/first-app
and its given there,
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
but I am unable to find what it does mean actually, afaik it is something using node in other modules, but since electron uses chromium and nodejs ! why does we need to set it false, I read that its regarding the security!
My question is :-
What does webPreferences mean anyway?
Why we use it ?
Why is nodeIntegration: false by default ? Where we should put it true and where we should put it false?
Thanks for everyone answer and support
webPreferences is described in Electron's documentation pages:
https://electronjs.org/docs/api/browser-window
webPreferences Object (optional) - Settings of web page's features.
The nodeIntegration property is described as:
Whether node integration is enabled. Default is false.
When nodeIntegration: true it causes NodeJS's features to be accessible directly from your page's script context, such as NodeJS's implementation of module, exports, and require. This is incompatible with jQuery, RequireJS, Meteor and AngularJS because they define their own versions of module, exports, or require. So setting nodeIntegration: false will prevent that conflict.
This is described in the Electron FAQ: https://electronjs.org/docs/faq
Because Electron applications could allow users to run arbitrary JavaScript - or have vulnerabilities that allow arbitrary JavaScript to run, it means you probably don't want to expose NodeJS's internal JS API to the Electron application (because then a malicious script could mess around with the user's local filesystem, start new processes, etc) so it's best to keep nodeIntegration: false unless you know what you're doing. Note that nodeIntegration: false is the default.
These are my sublime text custom settings:
{
"auto_complete_triggers":
[
{
"characters": ".",
"selector": "source.js"
}
],
"auto_match_enabled": false,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_size": 10,
"save_on_focus_lost": true,
"auto_complete_commit_on_tab": true,
"ignored_packages":
[
"Vintage"
],
"word_wrap": true
}
As you can see word wrap is properly enabled. The only way to enable word - wrap is to do it on a per file basis, by going to View -> Word Wrap (tick). This setting was working fine a while ago. Now apparently something has happened and it's no longer working. Can't remember what it was, other than installing a plugin. Help.
Found the answer. Should have searched more before i post this question, but anyway. Word wrap worked for some extensions but not for others (indeed few ones). So for the latter ones, i added the following:
"ignored_packages":
[
"Vintage"
],
"word_wrap": true
into the custom settings of Preferences -> Settings - Syntax Specific
Now everything works.
I'm trying various plugins for TTS, including the one at https://github.com/vilic/cordova-plugin-tts, but cannot get any to work. For this one, for example, according to the docs, its usage should be:
TTS
.speak('hello, world!', function () {
alert('success');
}, function (reason) {
alert(reason);
});
but I get 'TTS not defined'. Also tried 'navigator.TTS....' but still no good. Also I'm unsure whether I need to include the tts.js in the package; if so I get 'exports not defined'. If anyone is successfully using this plugin, please can you put me in the correct direction? Or if there's an alternative plugin that works, I could use that, but many TTS plugins on GitHub appear unsupported for 3-4 years.
BTW other plugins I am using (e.g. geolocation) are working fine
Have now solved this. I didn't have <script src="cordova.js"></script> in my index.html. This was also stopping 'onDeviceReady' from firing, which is how I came about solving it.
So it seems you need this script included for some plugins but not for others. How confusing.
Can I claim back my 50 bonus points for solving it myself? ;)
Prefer with keyword window
window.TTS.speak({
text: 'hello world!!',
locale: 'en-GB',
rate: 1.3
}, function () {
// Do Something after success
}, function (reason) {
// Handle the error case
});
I tried the same way it worked for me.
Thanks,
Praveen
I would appreciate if someone could direct me to a website that shows how to do this..
Can't seem to find anything decent enough via google.
This will be the first time I'm doing this kind of thing with a text editor.. It has got to the stage where typing out things like <%= %> is getting old and slow.
I've got a rails snippet package and also ryan-on-rails package installed. Just confused with how to start using them.
I'm on max osx - snow leopard
Kind regards
Update
This helped me out. http://webtempest.com/sublime-text-2-how-to-create-snippets/ but I still need a little practice.
I have a package "rails" can't remember where I got it but the triggering of snippets is working. I'd just like to find a nice list of the commands rather than have to go to each snippet and look for myself. I can find the by clicking on snippets but isn't there a way I can create a shortcut for that?
Also would like some auto indentation.. and also complete.
I'm puzzled that this isn't part of the default Rails package, but I found this to be just what I was looking for:
https://github.com/eddorre/SublimeERB
Since you're new to Sublime Text, I highly recommend you check out: ST2's Unofficial Documentation. If includes a ton of getting started info plus tons of info for extendibility and plugin development.
Another great "Getting Started" guide can be found here on Nettuts+.
If you're looking a list of your snippets and their associated shortcuts, go to "Tools > Snippets..." from your menu.
To expand <% into <%| %> (where | is the cursor), add the following you to your User-keybindings (Preferences > Keybindings - User):
{
"args": {
"contents": "% $0 %>"
},
"command": "insert_snippet",
"context": [
{
"key": "selector",
"match_all": true,
"operand": "source.ruby",
"operator": "equal"
},
{ "key": "preceding_text", "operator": "regex_match", "operand": ".*<", "match_all": true }
],
"keys": [
"%"
]
}
The latest beta includes improved auto-indentation, so if you don't have that installed, try that out.
As for autocompletion, Sublime Text 2 by default offers autocompletion of words in the current document (plus all of your snippets/completions from packages). However, if you're looking for IDE-like autocompletion, there is the SublimeCodeIntel plugin. I am reluctant to mention it because it has not been updated in months and the bug reports keep flowing in.
Hope that helps.
I use ERB Snippets
https://github.com/matthewrobertson/ERB-Sublime-Snippets
You can install via Sublime Package control
Cmd+Shift+P
Go to Package Control: Install Package.
Type ERB Snippets. Let it roll.
Then you can use tab autocomplete for lots of snippets such as:
print ERB tags = pe which auto completes to <%= %>
if block = if which auto completes to <% if %>...<% end %>
If you are looking for autocomplete suggest, change the auto_complete_selector in Preference like:
"auto_complete_selector": "text, source - comment",