Enable eslint rule 'no-prototype-builtins'

Enable recommended rule 'no-prototype-builtins' [1] and manually fix violations.

[1] https://eslint.org/docs/latest/rules/no-prototype-builtins

Ref: #8068
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2025-06-14 12:27:36 +02:00
parent f87d266e4e
commit f29f0b7fd1
No known key found for this signature in database
10 changed files with 14 additions and 13 deletions

View file

@ -346,7 +346,7 @@ PETRA.Config.prototype.Serialize = function()
{
var data = {};
for (const key in this)
if (this.hasOwnProperty(key) && key != "debug")
if (Object.hasOwn(this, key) && key != "debug")
data[key] = this[key];
return data;
};

View file

@ -48,7 +48,7 @@ AIInterface.prototype.Serialize = function()
const state = {};
for (var key in this)
{
if (!this.hasOwnProperty(key))
if (!Object.hasOwn(this, key))
continue;
if (typeof this[key] == "function")
continue;
@ -63,7 +63,7 @@ AIInterface.prototype.Deserialize = function(data)
{
for (const key in data)
{
if (!data.hasOwnProperty(key))
if (!Object.hasOwn(data, key))
continue;
this[key] = data[key];
}

View file

@ -19,7 +19,7 @@ Diplomacy.prototype.Serialize = function()
{
const state = {};
for (const key of this.SerializableAttributes)
if (this.hasOwnProperty(key))
if (Object.hasOwn(this, key))
state[key] = this[key];
return state;

View file

@ -30,7 +30,7 @@ Player.prototype.Serialize = function()
{
const state = {};
for (const key in this)
if (this.hasOwnProperty(key))
if (Object.hasOwn(this, key))
state[key] = this[key];
// Modified by GUI, so don't serialise.

View file

@ -202,7 +202,7 @@ ProductionQueue.prototype.Item.prototype.Serialize = function()
{
const result = {};
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
return result;
};
@ -236,7 +236,7 @@ ProductionQueue.prototype.Serialize = function()
result.queue.push(item.Serialize());
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
return result;

View file

@ -129,7 +129,7 @@ Researcher.prototype.Item.prototype.Serialize = function(id)
"id": id
};
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
return result;
};

View file

@ -183,7 +183,7 @@ TechnologyManager.prototype.Technology.prototype.Serialize = function()
{
const result = {};
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
return result;
};
@ -227,7 +227,7 @@ TechnologyManager.prototype.Serialize = function()
{
const result = {};
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
result.researchQueued = [];

View file

@ -406,7 +406,7 @@ Trainer.prototype.Item.prototype.Serialize = function(id)
"id": id
};
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
return result;
};
@ -441,7 +441,7 @@ Trainer.prototype.Serialize = function()
"queue": queue
};
for (const att of this.SerializableAttributes)
if (this.hasOwnProperty(att))
if (Object.hasOwn(this, att))
result[att] = this[att];
return result;

View file

@ -151,7 +151,7 @@ global.SerializationCycle = function(cmp)
{
data = {};
for (const att of cmp)
if (cmp.hasOwnProperty(att))
if (Object.hasOwn(cmp, att))
data[att] = cmp[att];
}

View file

@ -61,6 +61,7 @@ const configEslintRecommended = {
"no-nonoctal-decimal-escape": "warn",
"no-obj-calls": "warn",
"no-octal": "warn",
"no-prototype-builtins": "warn",
"no-redeclare": "warn",
"no-regex-spaces": "warn",
"no-self-assign": "warn",