Suppress `Expected identifier and instead see 'default' (reserved word)` in JSLint with Mongoose

I use jshint to validate my javascript files.

On the server side, I use node.js with Mongoose. In Mongoose, I am advised to write schemas like this:

 var UserSchema = new mongoose.Schema({ firstname : { type: String, default: '' } }); 

When starting linting, I get an error message:

 Expected an identifier and instead saw 'default' (a reserved word). 

Is there any way to suppress this error? I would prefer this behavior instead of writing:

 var UserSchema = new mongoose.Schema({ firstname : { type: String, "default": '' } }); 
+6
source share
2 answers

You can also use the "es5" option to disable this.

See: http://jslinterrors.com/expected-an-identifier-and-instead-saw-aa-reserved-word/

+4
source

default really a reserved word in JavaScript ( https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words ). Although technically you can use default in the property name of an object without any problems, you might have problems with this notation if your interpreter is strict (like lint).

The easiest way forward is to fix the problem by adding quotes. Lint will no longer whine. The code is two characters longer, but so that the listing goes through and you are guaranteed to have no problems due to the use of a reserved keyword.

+5
source

Source: https://habr.com/ru/post/917542/


All Articles