Code formatting standard across various IDEs for JavaScript - javascript

I am working on an Angular project. Developers in my team are using various IDEs like WebStrorm, SublimeText or even Eclipse.
I wish to have some kind of code formatting rules defined for JavaScript defined which can be imported in WebStorm as well as other IDEs, but as I searched I could not found anything standard for this.
How can I do this?

You can use a plugin called editorconfig. It supports all the major editors. You define the rules in a config file that sits in the root of the project repo.
Additionally, you can include jsHint in your workflow/build process to check your code for potentially problems and inconsistent formatting. It's fully configurable.

Related

How to solve the ongoing problem with Visual Studio Code and warnings, MDN Reference and more?

How do I disable typescript warnings and TS all together in Visual Studio Code for regular javascript files when working with sveltekit? When I create a project I say no to use of TS.
Actually, how do I disable the annoying popup with MDN Reference, warnings and what not in VSCode all together? This has been asked before, many times but I don't think there's a definite answer. Or has it? What is the problem? Why hasn't this been solved?
Change the checkJs property in jsconfig.json to false, if you're not into type checking that much..
The latest version of the SvelteKit template (the one you get when initializing a new project) has fixed many of the issue that come up for those of us using regular JavaScript. (there is now also an option to have type-checked JavaScript which gives you hints about types without the stranglehold of TypeScript). So it could be worth starting a new project and copying over your components/pages.
To disable the general "hover" behaviour of VSCode, you can set this with
"editor.hover.enabled": "false"
But this cuts a lot of functionality of VSCode, at that moment you have merely a better looking version of notepad.
SvelteKit works perfectly fine with just regular JavaScript, it was actually developed without TypeScript originally because the developers felt that progress was faster without it, but that is of course very subjective.
Well, sveltekit is a Typescript project so I'm not sure why you would want to use standard JS.
If you still consider to use JS, you have to disable the validation for javascript with
"javascript.validate.enable": false
in your editor's settings.json. But be aware that this disables all built-in syntax checking.
If you are specifically concerned about import/export errors, you could also add a jsconfig.json to your project, which includes:
{
"compilerOptions": {
"module": "es2015"
}
}
Regarding the MDN Popup. Not sure what exactly you are referencing to but have you tried to add
"editor.hover.enabled": false
to your settings.json? You could also hit Ctrl + , search for MDN and see what you can deselect.

JS code obfuscation in netbean [duplicate]

Are there any known Plugins or ways to properly autoformat Javascript in Netbeans IDE?
EDIT 9/15/2012
After looking into this further, I have found that the javascript module is being rewritten already(much needed). You can finally find formatting options for javascript. It's available in the netbeans nightly builds. Good luck all.
http://bits.netbeans.org/download/trunk/nightly/
I have released a pretty simple JS formatter that uses JSBeautify and runs in Rhino.
http://plugins.netbeans.org/plugin/43263/jsbeautify
You have to use an alternate key for now. I'm working on modifying the Javascript language in Netbeans to possibly release something better, later on(either as a plugin or patch). I'm still familiarizing myself with the way things are happening in Netbeans.
There have been talks for years to add more formatting options for Javascript in Netbeans. Nothing has surfaced. I'm going to propose that the Javascript language leverage JSBeautify(running in Rhino) to provide formatting, rather then implementing new features in Java. This simplifies the formatting process, plus the JSBeautify community is very large and it's actively developed.

XPJS (Javascript XPCOM) Documentation?

Anyone know where is some usable XPJS, or XPCOM in JS, documentation for recent versions of Firefox/Gecko? And sample code/ tutorials would be great too.
I need to write my own Component, but without .IDL (no C++ compiled interface), so I could access it via
Components.classes['#com.mareksebera/compname;1']
.getService().wrappedJSObject;
or this way is not supported anymore? I can't use
Components.classes['#com.mareksebera/compname;1']
.createInstance(Components.interfaces.nsICompName);
Because of missing compiled interface nsICompName
And yes, I know that NSGetModule is deprecated, and I use NSGetFactory and XPCOMUtils.jsm
I know these, but those are not usable with up to date browsers versions
https://developer.mozilla.org/en/Creating_Custom_Firefox_Extensions_with_the_Mozilla_Build_System
https://developer.mozilla.org/en/Using_XPCOM_in_JavaScript_without_leaking
https://developer.mozilla.org/en/how_to_build_an_xpcom_component_in_javascript
The third link you mentioned is pretty good. Another way to get examples though is to actually download the Mozilla source code and look in the /tests subdirectories. There are some examples there of javascript created XPCOM objects.
One example that comes to mind can be found at:
<mozilla-central>\content\xtf\test\unit
But there are a ton of examples throughout the codebase.
If you prefer you can also browse the code online via mxr.

Are there JSDoc files for Firefox XPCOM?

While I know much of XPCOM is implemented in C++, it would still be great to have JavaScript stubs with empty functions, constants, and JSDoc. These could be used to support code completion, inspection, quick doc, and other features of IDEs like WebStorm (IntelliJ).
It would be great if this just existed somewhere (but I haven't found it). Another approach would be to try and generate them from the IDL, but I haven't found a a way to do that either. I have question on that at Are there JSDoc files for Firefox XPCOM?.
I wrote a PHP script once, which generates PHP stubs from PHPDoc available at http://www.php.net for providing code assist in Eclipse PDT. You can use similar approach to generate JSDoc from XPCOM Doxygen.

Code Analysis for CSS, HTML and javascript

Can anybody point me in the direction of software similar to StyleCop for C# which can analyse CSS, HTML and javascript against sets of predefined rules / custom rules.
For Example,
css - to ensure camel case is used for class names
html - to ensure inline sytles are not used
javascript - not sure yet :P
Ideally, tools which can be run as-part of msbuild would be benefical so they can be included as part of a quality build. Tools runnable by developers would also be desirable.
For javascript check out JSLint:
http://www.jslint.com/
For CSS you can use csslint tool.
http://csslint.net/
It can be execute from command line also.
https://github.com/stubbornella/csslint/wiki/Command-line-interface
If you want customizable rules for a wide variety of languages, you can consider using the DMS Software Reengineering Toolkit.
DMS has compiler-style parsers for a wide variety of langauges (including "dirty" HTML and JavaScript) as well as means to define dialects of such langauges (e.g., CSS for HTML). These parsers build full abstract syntax trees, and then you can code custom scripts for DMS to walk over these trees and check that your style conventions have not been violated.
DMS-based tools are easily incorporated into command scripts.
DMS has already been used for this purpose for both COBOL and C++.
If you are working with Visual Studio then you can try Web Analyzer
It's Lints JavaScript, JSX, TypeScript, CoffeeScript and CSS files using:
CssLint
ESLint (a better version of JSHint, JSLint and JSCS)
CoffeeLint
TSLint
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebAnalyzer&ssr=false#overview
Note: Work better for visual studio 2015 and lower version.

Categories