I'm using Express.js ontop of Node.js to create RESTful API, and using grunt to watch my files and automatically lint my JavaScript.
Every time I use the delete function, it gets flagged by JSHint:
[L218:C9] Expected an identifier and instead saw 'delete' (a reserved word).
app.delete('/api/users/:userid', function deleteUser(req, res, next) {
I understand that 'delete' is a reserved word, but it's chosen by Express.js! Is there a better way to go about linting my Express.js app? Any way to turn off this check??
In Express.js, use del
instead of delete
.
app.del('/api/users/:userid', function deleteUser(req, res, next)
Another way to solve this would have been to use bracket notation instead of dot notation.
app['delete']('/api/users/:userid', function deleteUser(req, res, next) {
/* function body */
});
This sort of work around was necessary in the past when working with IndexedDB which defines both .delete
and .continue
methods.
These days this sort of workaround should not be necessary. Ever since ES5 JavaScript has allowed property names to use reserved words. For a long time jsHint defaulted to assuming your code was ES3, but starting with version 2.0.0 it defaults to assuming it is ES5 and will not complain about reserved words being used as property names.
In JSHint 1.1.x you can set the es5
option for jshint, and it will allow you to use reserved words as properties per the ES5 specification.
As of JSHint 2.0 es5
option is the default and you should be allowed to use reserved words as properties.
For more info you can head over to http://www.jshint.com/docs/#options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With