Skip to content

Commit b11f04c

Browse files
lucas-koehlersdirix
authored andcommitted
Enable ESLint no-prototype-builtins rule and fix errors
Use Object.prototype.<method>.call(<object>, <property>) syntax instead of directly calling the methods on the objects. This is the suggested fix in the rule documentation. Part of #2131
1 parent f8ea38f commit b11f04c

File tree

17 files changed

+39
-27
lines changed

17 files changed

+39
-27
lines changed

packages/angular-material/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = {
2323
'@angular-eslint/directive-class-suffix': 'off',
2424
'@angular-eslint/no-conflicting-lifecycle': 'warn',
2525
'@typescript-eslint/no-explicit-any': 'off',
26-
'no-prototype-builtins': 'off',
2726
// Base rule must be disabled to avoid incorrect errors
2827
'no-unused-vars': 'off',
2928
'@typescript-eslint/no-unused-vars': [

packages/angular-test/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = {
2323
'@angular-eslint/directive-class-suffix': 'off',
2424
'@angular-eslint/no-conflicting-lifecycle': 'warn',
2525
'@typescript-eslint/no-explicit-any': 'off',
26-
'no-prototype-builtins': 'off',
2726
// Base rule must be disabled to avoid incorrect errors
2827
'no-unused-vars': 'off',
2928
'@typescript-eslint/no-unused-vars': [

packages/angular/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = {
2323
'@angular-eslint/directive-class-suffix': 'off',
2424
'@angular-eslint/no-conflicting-lifecycle': 'warn',
2525
'@typescript-eslint/no-explicit-any': 'off',
26-
'no-prototype-builtins': 'off',
2726
// Base rule must be disabled to avoid incorrect errors
2827
'no-unused-vars': 'off',
2928
'@typescript-eslint/no-unused-vars': [

packages/core/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports = {
2121
},
2222
],
2323
'@typescript-eslint/no-explicit-any': 'off',
24-
'no-prototype-builtins': 'off',
2524
// Base rule must be disabled to avoid incorrect errors
2625
'no-unused-vars': 'off',
2726
'@typescript-eslint/no-unused-vars': [

packages/core/src/generators/schema.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const distinct = (
3838

3939
return properties.filter((item) => {
4040
const discriminatorValue = discriminator(item);
41-
if (known.hasOwnProperty(discriminatorValue)) {
41+
if (Object.prototype.hasOwnProperty.call(known, discriminatorValue)) {
4242
return false;
4343
} else {
4444
known[discriminatorValue] = true;
@@ -155,13 +155,17 @@ export const generateJsonSchema = (
155155
(optionName: string): boolean | string[] => {
156156
switch (optionName) {
157157
case ADDITIONAL_PROPERTIES:
158-
if (options.hasOwnProperty(ADDITIONAL_PROPERTIES)) {
158+
if (
159+
Object.prototype.hasOwnProperty.call(options, ADDITIONAL_PROPERTIES)
160+
) {
159161
return options[ADDITIONAL_PROPERTIES];
160162
}
161163

162164
return true;
163165
case REQUIRED_PROPERTIES:
164-
if (options.hasOwnProperty(REQUIRED_PROPERTIES)) {
166+
if (
167+
Object.prototype.hasOwnProperty.call(options, REQUIRED_PROPERTIES)
168+
) {
165169
return options[REQUIRED_PROPERTIES](props);
166170
}
167171

packages/core/src/reducers/core.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ const initState: JsonFormsCore = {
9090
};
9191

9292
const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
93-
if (schema.hasOwnProperty('id') || schema.hasOwnProperty('$id')) {
93+
if (
94+
Object.prototype.hasOwnProperty.call(schema, 'id') ||
95+
Object.prototype.hasOwnProperty.call(schema, '$id')
96+
) {
9497
ajv.removeSchema(schema);
9598
}
9699
return ajv;

packages/core/src/testers/testers.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,23 @@ export const isObjectControl = and(uiTypeIs('Control'), schemaTypeIs('object'));
325325

326326
export const isAllOfControl = and(
327327
uiTypeIs('Control'),
328-
schemaMatches((schema) => schema.hasOwnProperty('allOf'))
328+
schemaMatches((schema) =>
329+
Object.prototype.hasOwnProperty.call(schema, 'allOf')
330+
)
329331
);
330332

331333
export const isAnyOfControl = and(
332334
uiTypeIs('Control'),
333-
schemaMatches((schema) => schema.hasOwnProperty('anyOf'))
335+
schemaMatches((schema) =>
336+
Object.prototype.hasOwnProperty.call(schema, 'anyOf')
337+
)
334338
);
335339

336340
export const isOneOfControl = and(
337341
uiTypeIs('Control'),
338-
schemaMatches((schema) => schema.hasOwnProperty('oneOf'))
342+
schemaMatches((schema) =>
343+
Object.prototype.hasOwnProperty.call(schema, 'oneOf')
344+
)
339345
);
340346

341347
/**
@@ -346,8 +352,12 @@ export const isOneOfControl = and(
346352
export const isEnumControl = and(
347353
uiTypeIs('Control'),
348354
or(
349-
schemaMatches((schema) => schema.hasOwnProperty('enum')),
350-
schemaMatches((schema) => schema.hasOwnProperty('const'))
355+
schemaMatches((schema) =>
356+
Object.prototype.hasOwnProperty.call(schema, 'enum')
357+
),
358+
schemaMatches((schema) =>
359+
Object.prototype.hasOwnProperty.call(schema, 'const')
360+
)
351361
)
352362
);
353363

@@ -592,9 +602,9 @@ export const isRangeControl = and(
592602
or(schemaTypeIs('number'), schemaTypeIs('integer')),
593603
schemaMatches(
594604
(schema) =>
595-
schema.hasOwnProperty('maximum') &&
596-
schema.hasOwnProperty('minimum') &&
597-
schema.hasOwnProperty('default')
605+
Object.prototype.hasOwnProperty.call(schema, 'maximum') &&
606+
Object.prototype.hasOwnProperty.call(schema, 'minimum') &&
607+
Object.prototype.hasOwnProperty.call(schema, 'default')
598608
),
599609
optionIs('slider', true)
600610
);

packages/core/src/util/resolvers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ export const resolveData = (instance: any, dataPath: string): any => {
4949
const dataPathSegments = dataPath.split('.');
5050

5151
return dataPathSegments.reduce((curInstance, decodedSegment) => {
52-
if (!curInstance || !curInstance.hasOwnProperty(decodedSegment)) {
52+
if (
53+
!curInstance ||
54+
!Object.prototype.hasOwnProperty.call(curInstance, decodedSegment)
55+
) {
5356
return undefined;
5457
}
5558

packages/core/src/util/schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const getFirstPrimitiveProp = (schema: any) => {
4444
* Tests whether the schema has an enum based on oneOf.
4545
*/
4646
export const isOneOfEnumSchema = (schema: JsonSchema) =>
47-
schema?.hasOwnProperty('oneOf') &&
48-
schema?.oneOf &&
47+
!!schema &&
48+
Object.prototype.hasOwnProperty.call(schema, 'oneOf') &&
49+
schema.oneOf &&
4950
(schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined);

packages/examples-react/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
],
2121
rules: {
2222
'@typescript-eslint/no-explicit-any': 'off',
23-
'no-prototype-builtins': 'off',
2423
// Base rule must be disabled to avoid incorrect errors
2524
'no-unused-vars': 'off',
2625
'@typescript-eslint/no-unused-vars': [

packages/examples/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module.exports = {
1414
],
1515
rules: {
1616
'@typescript-eslint/no-explicit-any': 'off',
17-
'no-prototype-builtins': 'off',
1817
// Base rule must be disabled to avoid incorrect errors
1918
'no-unused-vars': 'off',
2019
'@typescript-eslint/no-unused-vars': [

packages/material-renderers/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
],
2121
rules: {
2222
'@typescript-eslint/no-explicit-any': 'off',
23-
'no-prototype-builtins': 'off',
2423
'import/no-named-as-default': 'off',
2524
// Base rule must be disabled to avoid incorrect errors
2625
'no-unused-vars': 'off',

packages/material-renderers/src/controls/MaterialAnyOfStringOrEnumControl.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ const hasEnumAndText = (schemas: JsonSchema[]) => {
133133
const simpleAnyOf = and(
134134
uiTypeIs('Control'),
135135
schemaMatches(
136-
(schema) => schema.hasOwnProperty('anyOf') && hasEnumAndText(schema.anyOf)
136+
(schema) =>
137+
Object.prototype.hasOwnProperty.call(schema, 'anyOf') &&
138+
hasEnumAndText(schema.anyOf)
137139
)
138140
);
139141
export const materialAnyOfStringOrEnumControlTester: RankedTester = rankWith(

packages/react/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
],
2121
rules: {
2222
'@typescript-eslint/no-explicit-any': 'off',
23-
'no-prototype-builtins': 'off',
2423
// Base rule must be disabled to avoid incorrect errors
2524
'no-unused-vars': 'off',
2625
'@typescript-eslint/no-unused-vars': [

packages/vanilla-renderers/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
],
2121
rules: {
2222
'@typescript-eslint/no-explicit-any': 'off',
23-
'no-prototype-builtins': 'off',
2423
'import/no-named-as-default': 'off',
2524
// Base rule must be disabled to avoid incorrect errors
2625
'no-unused-vars': 'off',

packages/vue/vue-vanilla/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports = {
2121
],
2222
rules: {
2323
'@typescript-eslint/no-explicit-any': 'off',
24-
'no-prototype-builtins': 'off',
2524
// Base rule must be disabled to avoid incorrect errors
2625
'no-unused-vars': 'off',
2726
'@typescript-eslint/no-unused-vars': [

packages/vue/vue/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports = {
2121
],
2222
rules: {
2323
'@typescript-eslint/no-explicit-any': 'off',
24-
'no-prototype-builtins': 'off',
2524
// Base rule must be disabled to avoid incorrect errors
2625
'no-unused-vars': 'off',
2726
'@typescript-eslint/no-unused-vars': [

0 commit comments

Comments
 (0)