Skip to content

Commit f3ffbed

Browse files
Update for-in loop to work with eslint:recommended (microsoft#99721)
The code in the automatic template will fail this eslint rule: https://eslint.org/docs/rules/no-prototype-builtins. This is just plain annoying. This change will make the snippet generated code not fail the linter. It will also avoid the subtle bugs that the eslint rule was made to avoid in the first place.
1 parent 6a927e6 commit f3ffbed

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

extensions/typescript-basics/snippets/typescript.code-snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"prefix": "forin",
152152
"body": [
153153
"for (const ${1:key} in ${2:object}) {",
154-
"\tif (${2:object}.hasOwnProperty(${1:key})) {",
154+
"\tif (Object.prototype.hasOwnProperty.call(${2:object}, ${1:key})) {",
155155
"\t\tconst ${3:element} = ${2:object}[${1:key}];",
156156
"\t\t$0",
157157
"\t}",

0 commit comments

Comments
 (0)