Skip to content

Commit a14f189

Browse files
authored
eslint: add rule: prefer-object-has-own (#1698)
`Object.prototype.hasOwnProperty.call(a, b)` now has a simpler equivalent: `Object.hasOwn(a, b)`.
1 parent 918547e commit a14f189

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"object-property-newline": "off",
4545
"operator-linebreak": "off",
4646
"padded-blocks": "off",
47+
"prefer-object-has-own": "error",
4748
"prefer-object-spread": "off",
4849
"prefer-template": "off",
4950
"quotes": [ "error", "single", { "allowTemplateLiterals": true, "avoidEscape": true } ],

lib/data/odk-reporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const convertObjectToXml = (data) => {
2727
let output = '';
2828
if (typeof data === 'object') {
2929
for (const k in data) {
30-
if (Object.prototype.hasOwnProperty.call(data, k)) {
30+
if (Object.hasOwn(data, k)) {
3131
if (Array.isArray(data[k])) {
3232
// If the data is an array, it is repeat data and
3333
// the xml should have the outer tag repeated e.g.

lib/data/submission.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ const _diffObj = (a, b, subpath) => {
238238
const results = [];
239239
for (const key of union(a[keys], b[keys])) {
240240
const av = a[key];
241-
if (!Object.prototype.hasOwnProperty.call(a, key)) { // null -> b
241+
if (!Object.hasOwn(a, key)) { // null -> b
242242
results.push({ new: b[key], path: subpath.concat([ stripNamespacesFromPath(key) ]) });
243-
} else if (!Object.prototype.hasOwnProperty.call(b, key)) { // a -> null
243+
} else if (!Object.hasOwn(b, key)) { // a -> null
244244
results.push({ old: av, path: subpath.concat([ stripNamespacesFromPath(key) ]) });
245245
} else if (av[subhash] == null) { // primitive
246246
if (av !== b[key]) // a -> b

test/e2e/oidc/playwright-tests/playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const requestedBrowsers = process.env.ODK_PLAYWRIGHT_BROWSERS || 'firefox';
2222
const projects = requestedBrowsers
2323
.split(',')
2424
.map(name => {
25-
if (!Object.prototype.hasOwnProperty.call(availableProjects, name)) {
25+
if (!Object.hasOwn(availableProjects, name)) {
2626
throw new Error(`No project config available with name '${name}'!`);
2727
}
2828
const use = availableProjects[name];

0 commit comments

Comments
 (0)