I'm trying to use Eclipse for JavaScript (the "Eclipse IDE for Java EE Developers" package).
My project uses Bluebird (a promises implementation), and so it has a lot of lines like:
somePromise.catch(function(err){...
Eclipse considers this to be an error, probably because it thinks that "catch" is a reserved keyword that cannot be used as a method name. Same for the promise.finaly method. Maybe it's right, but I'd rather not switch to a different library just because of this.
Is there a way to make it ignore these specific errors (but keep reporting other errors in the same files)?
This has been reported and fixed not long ago in this bug :https://bugs.eclipse.org/bugs/show_bug.cgi?id=443876
Go into Preferences->Javascript->Validator->Errors/Warnings and uncheck a new option "Strict validation of JavaScript keywords usage". That should fix it.
I had the same problem before and had implemented a plugin that manipulated bytecode of JSDT at load time to silence this error. Now such hacks are not needed.
Related
Using Eclipse's 2020-06 built in JavaScript editor, I need to disable the JavaScript informational notes on syntax and warnings as displayed with an (i) icon to the left of the line number and with markers to the right of the scroll bar. See links to the two images showing what these look like.
An example of the informational icon
An example of the markers
There are two warnings repeating numerous times:
'aVariableName' is declared but its value is never read.
This constructor function may be converted to a class declaration.
I would rather turn off these two individual messages since they do not apply to the project, but such control does not appear to exist, but they are overly spamming the editor and are interfering with other notifications and informational notes. FYI: I'm needing to follow specific coding conventions for the project and therefore the warnings don't even apply to the project and are just spam.
So I'll just settle for shutting off javascript validation, but the validation will not turn off.
I've tried to disable the project level settings for the javascript validation through the menu option Window, Preferences, Web, HTML Files, Client-side Javascript, Validator, Errors/Warnings: and unchecked both options of Strict Validation of Javascript keywords usage, and Enable JavaScript semantic validation. But making those changes accomplishes nothing since the warnings are still there even after running validation on the project, cleaning the project, and even restarting eclipse.
The specific version of Eclipse is:
Eclipse IDE for Enterprise Java Developers Version 2020-06 (4.16.0)
To try to better explain the need to install Node.js, this is the dialog requested Node.js be installed. The text of the dialog reads: "Missing node.js" "Could not find node.js. This will result in editors missing key features. Please make sure node.js is installed and that your PATH environment variable contains the location to the 'node' executable."
Eclipse's Missing Node.js dialog
Are there any other ways to shut off individual warnings/messages, or the javascript validations? Any help, or constructive suggestions would be very much appreciated. Thanks!
Sorry, the stackoverflow editor won't allow in-lining simple images.
Update: So I have not been able to figure out how to disable the informational notices that are showing up in the JavaScript editor along both the left and right margins. I would still love to find out how to do that. I'm wondering if the issues I'm seeing may have been resolved in the current release of Eclipse? I cannot put my development environments at risk if downgrading is not possible. But some hopeful and important details that I have learned is that the latest release of Eclipse "can" support java 1.8 although it says the minimal version supported is Java 11. And also the latest release is better integrated with Node.js so an external install is no longer required. At this time I cannot risk testing the latest Eclipse release due to possible lockout of the workspaces if eclipse cannot be downgraded. I will make plans to rebuild some of the workspaces on another workstation so it will not impact vital projects if something should go wrong.
I was able to disable these javascript validation notes by changing the following setting.
Eclipse -> Window -> Preferences -> General -> Editors ->Text Editors -> Annotations
find "Infos" in the "Annotation types" and click it
uncheck both the "Vertical Ruler" and "Overview Ruler"
optional - uncheck "Text as "Squiggly Line"
Click Apply and Close
Voila enjoy the less cluttered javascript files
Edit: Fixed!
The Google Apps Script team rolled this out for our team earlier this week (week of January 10th).
Original Post
I'm a frequent GAS user, and I've noticed that, since the upgrade to the V8 runtime, formatting in the GAS IDE is awful. I've seen a somewhat similar question here, but my problem is that the GAS IDE is terrible at formatting ES6 Javascript.
Expected Behavior
variables defined with const or let appear similarly to variables defined with var
the omission of a semicolon will not completely break the indention / formatting of a script
destructured variables will be recognized as variables by the IDE
template literals will be recognized by the IDE
Current Behavior
The IDE basically doesn't recognize any of my JavaScript ES6 syntax. Here's an example:
/** Comments about some function.
* #dev Why does this look like garbage!?
*/
function foo() {
...
}
In the above example, it's impossible to get the IDE to properly indent the function. Instead, each line of code is indented to the same extent by default.
Has anyone figured out how to use ES6 syntax, omit semicolons, etc. and gotten the browser-based GAS IDE to format properly?
Thanks!
You might try to use a web browser extension that allow you to set custom CSS styles but the effort required might not be worthy because the new Google Apps Script is being rolled out.
According to the last announcement update the rollout should finish during January 2021
Reference
Use the new Apps Script Integrated Development Environment (IDE) Script Editor
Related
Get ready to up your Apps Script!
Workaround
If there are any missing features or behaviours that you don't like on the Apps Script IDE you can:
Update to the newer version of the IDE with more features described here
Use clasp which allows you to develop and manage Apps Script projects from your terminal rather than the Apps Script editor therefore being able to use the IDE of your choice with the features you like.
If there is a specific missing feature you would like the Apps Script editor to have you can report a feature request
When going through a code review, my technical lead picked up a few missing semicolons in my JavaScript when he went into debug. Visual Studio actually threw these exceptions up, and I was wondering where the option to turn that on was.
I've searched 'JavaScript Debugging in Visual Studio 20(15|13)', but it seems like there aren't any simple settings to enable.
Wondering the most efficient way to turn on JavaScript debugging in visual studio for all projects without having to add something each time.
Make sure you have Just My Code Enabled by going into Tools-->Options-->Debugger-->General--> Enable Just My Code. This will change your Debug--> Windows --> Exceptions Settings Dialog Box to show a CheckBox for JavaScript RunTime Exceptions.
Javascript RunTime Exceptions:
See this answer for previous versions of Visual Studio
Sounds like you want JSLint
You can also look into using TypeScript which is a superset of javascript and allows you to strongly type your javascript.
I recently noticed and fixed a pretty bad JS bug in our software, affecting all IE versions, that was caused by a simple mistake in a .js file:
const foo = "..."
Now, IE doesn't support const; it's a syntax error. var should be used instead. (The offending keyword was actually inserted unwittingly by IntelliJ IDEA's "introduce variable... -> introduce constant" refactoring.)
Our automated Selenium tests are run with Firefox on Linux, and getting them running on IE would probably be too much hassle right now.
Anyway, my question is, is there any static JS code analysis tool that
would have caught the const bug (and similar common problems), and
can be easily triggered from a CI tool (Jenkins) against certain .js files in a codebase?
I am aware of JSHint, JSLint and Google Closure Tools, but I don't know if any of them meets my criteria above.
JSHint or JSLint would have caught the error in time. You can configure IntelliJ to show these kind of issues realtime. There is a Jenkins plugin available as well. I hope you find those useful. :)
Are there any command-line Linux tools that can catch basic syntax errors and compile time errors in my Javascript files, even if said Javascript files are written for use in a web browser?
I typically code my Javascript at the same time I'm coding my server side code in say Ruby or Perl. It would save me significant time if I could partially test my client side Javascript the same way I test my server side Ruby and Perl -- on the command line, typically from within emacs. I'm not expecting to catch run time JavaScript errors on the server, just basic things like a mistyped variable name or an extra bracket somewhere or a runaway string, things that could be found before actually attempting to execute the code.
What I do now to test/debug Javascript is the usual cycle of "visit web app in browser; check Firebug or other console; back to emacs to fix errors; repeat." Doing that is certainly unavoidable for more complex types of errors (e.g. involving user and network interaction) but a garden variety syntax error could be caught and dealt with more quickly on the command line without loading up the browser.
I've looked a bit into some server side platforms like node.js, but they all seemed geared toward writing and executing server side code (so all of the client side specific bits in my code would presumably make it barf). I also found an emacs mode for javascript REPL but it doesn't seemed designed to do just basic compile checks - it basically loads the whole page via an external graphical browser and lets you monkey with it, which is precisely what I'm trying to avoid.
Things like YUICompressor effectively do a syntax check too.
This isn't a direct answer to your question as it is a GUI tool, but I'm a big fan of Aptana. It uses SpiderMonkey to compile your code in the background and give you red squigglies for syntax errors as you type. (It also does the same for HTML.) It also tries to give you intellisense for JS, but it is hit-or-miss. It is nice when it works.
Since I probably haven't convinced you to change your development environment, let's answer your question directly. Why not use the SpiderMonkey engine to throw together a command-line app that does what you're looking for? It looks easy enough to plug in. You won't even have to worry about the fact that you're guaranteed to get runtime exceptions (there will be no DOM objects in your environment) — you don't have to actually execute the script. Just call JS_CompileScript and check for success. (And then destroy the JSScript object, of course.)
Or, if you're lazy, you could try Rhino Shell, which is a command-line Java tool which executes JavaScript.
I find JSHint, + its vim plugin are very useful. Light weight of vim and still be able to track the syntax errors of the javascript. JSHint can also be used as a command line tool.
https://github.com/walm/jshint.vim
Javascript debugger with a console in chrome:
The Chrome browser has a javascript debugger can find JavaScript errors:
In Chrome click Tools -> JavaScript Console:
This is examining a JavaScript page with the following code:
var error(){
}
And it tells me what is wrong with it, unexpected '('.
Telling me I can't define a function like that on line 14 of my javascript file.
If you click on the link next to the error, it will take you to and highlight the line that has the error/warning.
I wrote quick-lint-js for this purpose. It points out syntax errors, among other things.
quick-lint-js integrates with several code editors, such as Vim and Visual Studio Code. It also has a UNIX-style command-line utility if you prefer.