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 is necessary when working with IndexedDB which annoyingly defines both .delete
and .continue
methods.
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