Skip to content

Commit 5132a27

Browse files
committed
Disable guard-for-in
1 parent 76add8e commit 5132a27

File tree

7 files changed

+40
-57
lines changed

7 files changed

+40
-57
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"class-methods-use-this": "off",
1717
"consistent-return": "off",
1818
"eqeqeq": "off",
19+
"guard-for-in": "off",
1920
"max-classes-per-file": "off",
2021
"new-cap": "off",
2122
"no-bitwise": "off",
@@ -25,6 +26,8 @@
2526
"no-continue": "off",
2627
"no-multi-assign": "off",
2728
"no-nested-ternary": "off",
29+
"no-new-object": "off",
30+
"no-object-constructor": "error",
2831
"no-param-reassign": "off",
2932
"no-plusplus": "off",
3033
"no-restricted-syntax": "off",

src/element/custom-element.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ export const c = (component, base) => {
4747
this._setup();
4848
this._render = () => component({ ...this._props });
4949
for (const prop in values) {
50-
if (Object.prototype.hasOwnProperty.call(values, prop)) {
51-
this[prop] = values[prop];
52-
}
50+
this[prop] = values[prop];
5351
}
5452
}
5553

@@ -233,15 +231,13 @@ export const c = (component, base) => {
233231
// @ts-ignore
234232
const superAttrs = super.observedAttributes || [];
235233
for (const prop in props) {
236-
if (Object.prototype.hasOwnProperty.call(props, prop)) {
237-
setPrototype(
238-
this.prototype,
239-
prop,
240-
props[prop],
241-
attrs,
242-
values,
243-
);
244-
}
234+
setPrototype(
235+
this.prototype,
236+
prop,
237+
props[prop],
238+
attrs,
239+
values,
240+
);
245241
}
246242
return Object.keys(attrs).concat(superAttrs);
247243
}

src/hooks/create-hooks.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@ export const createHooks = (update, host, id = 0) => {
8787
*/
8888
const cleanEffectsByType = (tag, unmounted) => {
8989
for (const index in hooks) {
90-
if (Object.prototype.hasOwnProperty.call(hooks, index)) {
91-
const hook = hooks[index];
92-
if (hook.effect && hook.tag === tag) {
93-
hook.value = hook.effect(hook.value, unmounted);
94-
}
90+
const hook = hooks[index];
91+
if (hook.effect && hook.tag === tag) {
92+
hook.value = hook.effect(hook.value, unmounted);
9593
}
9694
}
9795
};

src/render.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,11 @@ export function renderChildren(children, fragment, parent, id, hydrate, isSvg) {
388388
*/
389389
export function diffProps(node, props, nextProps, handlers, isSvg) {
390390
for (const key in props) {
391-
if (Object.prototype.hasOwnProperty.call(props, key)) {
392-
!(key in nextProps) &&
393-
setProperty(node, key, props[key], null, isSvg, handlers);
394-
}
391+
!(key in nextProps) &&
392+
setProperty(node, key, props[key], null, isSvg, handlers);
395393
}
396394
for (const key in nextProps) {
397-
if (Object.prototype.hasOwnProperty.call(nextProps, key)) {
398-
setProperty(node, key, props[key], nextProps[key], isSvg, handlers);
399-
}
395+
setProperty(node, key, props[key], nextProps[key], isSvg, handlers);
400396
}
401397
}
402398

@@ -460,11 +456,9 @@ export function setProperty(node, key, prevValue, nextValue, isSvg, handlers) {
460456

461457
if (nextIsObject) {
462458
for (const key in nextValue) {
463-
if (Object.prototype.hasOwnProperty.call(nextValue, key)) {
464-
const value = nextValue[key];
465-
if (prevIsObject && prevValue[key] === value) continue;
466-
setPropertyStyle(style, key, value);
467-
}
459+
const value = nextValue[key];
460+
if (prevIsObject && prevValue[key] === value) continue;
461+
setPropertyStyle(style, key, value);
468462
}
469463
} else {
470464
style.cssText = nextValue;

src/tests/internal/set-prototype.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("internal: filterValue", () => {
7070
},
7171
{
7272
type: Object,
73-
// eslint-disable-next-line no-new-object
73+
// eslint-disable-next-line no-object-constructor
7474
success: [{}, new Object(), new (class {})()],
7575
},
7676
{

src/tests/render.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ describe("src/render", () => {
159159
);
160160

161161
for (let key in attrs) {
162-
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
163-
expect(el.getAttribute(key)).to.equal(attrs[key].expect);
164-
}
162+
expect(el.getAttribute(key)).to.equal(attrs[key].expect);
165163
}
166164
});
167165

ssr/tag.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,27 @@ export class Attributes {
2626
toString() {
2727
const attrs = new Map();
2828
for (let prop in this) {
29-
if (Object.prototype.hasOwnProperty.call(this, prop)) {
30-
const value = this[prop];
31-
const type = typeof value;
29+
const value = this[prop];
30+
const type = typeof value;
3231

33-
if (
34-
INTERNAL_PROPS[prop] ||
35-
type === "function" ||
36-
prop[0] === "_"
37-
)
38-
continue;
32+
if (INTERNAL_PROPS[prop] || type === "function" || prop[0] === "_")
33+
continue;
3934

40-
const attr =
41-
prop === "className"
42-
? "class"
43-
: prop.replace(
44-
/([\w])([A-Z])/g,
45-
(all, before, after) =>
46-
`${before}-${after.toLowerCase()}`,
47-
);
35+
const attr =
36+
prop === "className"
37+
? "class"
38+
: prop.replace(
39+
/([\w])([A-Z])/g,
40+
(all, before, after) =>
41+
`${before}-${after.toLowerCase()}`,
42+
);
4843

49-
if (type === "boolean") {
50-
if (value) attrs.set(attr);
51-
} else if (type === "object") {
52-
attrs.set(attr, JSON.stringify(value));
53-
} else {
54-
attrs.set(attr, value);
55-
}
44+
if (type === "boolean") {
45+
if (value) attrs.set(attr);
46+
} else if (type === "object") {
47+
attrs.set(attr, JSON.stringify(value));
48+
} else {
49+
attrs.set(attr, value);
5650
}
5751
}
5852
const list = [...attrs];

0 commit comments

Comments
 (0)