-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/lints): Add
no-prototype-builtins
rule (#8684)
- Loading branch information
1 parent
8c02489
commit a5dbb17
Showing
6 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
crates/swc/tests/errors/lints/no-prototype-builtins/default/.swcrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"jsc": { | ||
"lints": { | ||
"noPrototypeBuiltins": [ | ||
"error" | ||
] | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
crates/swc/tests/errors/lints/no-prototype-builtins/default/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
foo.hasOwnProperty('bar'); | ||
|
||
foo.isPrototypeOf('bar'); | ||
|
||
foo.propertyIsEnumerable('bar'); | ||
|
||
foo.bar.hasOwnProperty('bar'); | ||
|
||
foo.bar.baz.isPrototypeOf('bar'); | ||
|
||
bar?.foo?.hasOwnProperty('bar'); | ||
|
||
foo?.bar.hasOwnProperty('baz'); | ||
|
||
foo.hasOwnProperty?.('bar'); | ||
|
||
foo?.hasOwnProperty('bar').baz; | ||
|
||
foo.hasOwnProperty('bar')?.baz; | ||
|
||
(a,b).hasOwnProperty('bar'); | ||
|
||
(foo?.hasOwnProperty)('bar'); | ||
|
||
(((foo?.hasOwnProperty)))('dlya-tex-kto-dumaet-cho-on-samiy-umniy'); | ||
|
||
(foo?.anotherProp, foo?.hasOwnProperty)('bar'); | ||
|
||
(foo.hasOwnProperty('ok'), foo?.hasOwnProperty)('bar'); | ||
|
||
foo['hasOwnProperty']('bar'); | ||
|
||
foo[`isPrototypeOf`]('bar').baz; | ||
|
||
// valid | ||
|
||
Object.prototype.hasOwnProperty.call(foo, 'bar'); | ||
Object.prototype.isPrototypeOf.call(foo, 'bar'); | ||
Object.prototype.propertyIsEnumerable.call(foo, 'bar'); | ||
Object.prototype.hasOwnProperty.apply(foo, ['bar']); | ||
Object.prototype.isPrototypeOf.apply(foo, ['bar']); | ||
Object.prototype.propertyIsEnumerable.apply(foo, ['bar']); | ||
foo.hasOwnProperty; | ||
foo.hasOwnProperty.bar(); | ||
foo(hasOwnProperty); | ||
hasOwnProperty(foo, 'bar'); | ||
isPrototypeOf(foo, 'bar'); | ||
propertyIsEnumerable(foo, 'bar'); | ||
({}.hasOwnProperty.call(foo, 'bar')); | ||
({}.isPrototypeOf.call(foo, 'bar')); | ||
({}.propertyIsEnumerable.call(foo, 'bar')); | ||
({}.hasOwnProperty.apply(foo, ['bar'])); | ||
({}.isPrototypeOf.apply(foo, ['bar'])); | ||
({}.propertyIsEnumerable.apply(foo, ['bar'])); | ||
foo[hasOwnProperty]('bar'); | ||
foo['HasOwnProperty']('bar'); |
194 changes: 194 additions & 0 deletions
194
crates/swc/tests/errors/lints/no-prototype-builtins/default/output.swc-stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[1:1] | ||
1 | foo.hasOwnProperty('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
2 | | ||
3 | foo.isPrototypeOf('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'isPrototypeOf' from target object | ||
,-[1:1] | ||
1 | foo.hasOwnProperty('bar'); | ||
2 | | ||
3 | foo.isPrototypeOf('bar'); | ||
: ^^^^^^^^^^^^^ | ||
4 | | ||
5 | foo.propertyIsEnumerable('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'propertyIsEnumerable' from target object | ||
,-[2:1] | ||
2 | | ||
3 | foo.isPrototypeOf('bar'); | ||
4 | | ||
5 | foo.propertyIsEnumerable('bar'); | ||
: ^^^^^^^^^^^^^^^^^^^^ | ||
6 | | ||
7 | foo.bar.hasOwnProperty('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[4:1] | ||
4 | | ||
5 | foo.propertyIsEnumerable('bar'); | ||
6 | | ||
7 | foo.bar.hasOwnProperty('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
8 | | ||
9 | foo.bar.baz.isPrototypeOf('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'isPrototypeOf' from target object | ||
,-[6:1] | ||
6 | | ||
7 | foo.bar.hasOwnProperty('bar'); | ||
8 | | ||
9 | foo.bar.baz.isPrototypeOf('bar'); | ||
: ^^^^^^^^^^^^^ | ||
10 | | ||
11 | bar?.foo?.hasOwnProperty('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[8:1] | ||
8 | | ||
9 | foo.bar.baz.isPrototypeOf('bar'); | ||
10 | | ||
11 | bar?.foo?.hasOwnProperty('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
12 | | ||
13 | foo?.bar.hasOwnProperty('baz'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[10:1] | ||
10 | | ||
11 | bar?.foo?.hasOwnProperty('bar'); | ||
12 | | ||
13 | foo?.bar.hasOwnProperty('baz'); | ||
: ^^^^^^^^^^^^^^ | ||
14 | | ||
15 | foo.hasOwnProperty?.('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[12:1] | ||
12 | | ||
13 | foo?.bar.hasOwnProperty('baz'); | ||
14 | | ||
15 | foo.hasOwnProperty?.('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
16 | | ||
17 | foo?.hasOwnProperty('bar').baz; | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[14:1] | ||
14 | | ||
15 | foo.hasOwnProperty?.('bar'); | ||
16 | | ||
17 | foo?.hasOwnProperty('bar').baz; | ||
: ^^^^^^^^^^^^^^ | ||
18 | | ||
19 | foo.hasOwnProperty('bar')?.baz; | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[16:1] | ||
16 | | ||
17 | foo?.hasOwnProperty('bar').baz; | ||
18 | | ||
19 | foo.hasOwnProperty('bar')?.baz; | ||
: ^^^^^^^^^^^^^^ | ||
20 | | ||
21 | (a,b).hasOwnProperty('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[18:1] | ||
18 | | ||
19 | foo.hasOwnProperty('bar')?.baz; | ||
20 | | ||
21 | (a,b).hasOwnProperty('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
22 | | ||
23 | (foo?.hasOwnProperty)('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[20:1] | ||
20 | | ||
21 | (a,b).hasOwnProperty('bar'); | ||
22 | | ||
23 | (foo?.hasOwnProperty)('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
24 | | ||
25 | (((foo?.hasOwnProperty)))('dlya-tex-kto-dumaet-cho-on-samiy-umniy'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[22:1] | ||
22 | | ||
23 | (foo?.hasOwnProperty)('bar'); | ||
24 | | ||
25 | (((foo?.hasOwnProperty)))('dlya-tex-kto-dumaet-cho-on-samiy-umniy'); | ||
: ^^^^^^^^^^^^^^ | ||
26 | | ||
27 | (foo?.anotherProp, foo?.hasOwnProperty)('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[24:1] | ||
24 | | ||
25 | (((foo?.hasOwnProperty)))('dlya-tex-kto-dumaet-cho-on-samiy-umniy'); | ||
26 | | ||
27 | (foo?.anotherProp, foo?.hasOwnProperty)('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
28 | | ||
29 | (foo.hasOwnProperty('ok'), foo?.hasOwnProperty)('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[26:1] | ||
26 | | ||
27 | (foo?.anotherProp, foo?.hasOwnProperty)('bar'); | ||
28 | | ||
29 | (foo.hasOwnProperty('ok'), foo?.hasOwnProperty)('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
30 | | ||
31 | foo['hasOwnProperty']('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[26:1] | ||
26 | | ||
27 | (foo?.anotherProp, foo?.hasOwnProperty)('bar'); | ||
28 | | ||
29 | (foo.hasOwnProperty('ok'), foo?.hasOwnProperty)('bar'); | ||
: ^^^^^^^^^^^^^^ | ||
30 | | ||
31 | foo['hasOwnProperty']('bar'); | ||
`---- | ||
|
||
x Do not access Object.prototype method 'hasOwnProperty' from target object | ||
,-[28:1] | ||
28 | | ||
29 | (foo.hasOwnProperty('ok'), foo?.hasOwnProperty)('bar'); | ||
30 | | ||
31 | foo['hasOwnProperty']('bar'); | ||
: ^^^^^^^^^^^^^^^^ | ||
32 | | ||
33 | foo[`isPrototypeOf`]('bar').baz; | ||
`---- | ||
|
||
x Do not access Object.prototype method 'isPrototypeOf' from target object | ||
,-[30:1] | ||
30 | | ||
31 | foo['hasOwnProperty']('bar'); | ||
32 | | ||
33 | foo[`isPrototypeOf`]('bar').baz; | ||
: ^^^^^^^^^^^^^^^ | ||
34 | | ||
35 | // valid | ||
`---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.