Skip to content

Enable ESLint no-prototype-builtins rule and fix errors #2134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/angular-material/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
'@angular-eslint/directive-class-suffix': 'off',
'@angular-eslint/no-conflicting-lifecycle': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/angular-test/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
'@angular-eslint/directive-class-suffix': 'off',
'@angular-eslint/no-conflicting-lifecycle': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/angular/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
'@angular-eslint/directive-class-suffix': 'off',
'@angular-eslint/no-conflicting-lifecycle': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
},
],
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/generators/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const distinct = (

return properties.filter((item) => {
const discriminatorValue = discriminator(item);
if (known.hasOwnProperty(discriminatorValue)) {
if (Object.prototype.hasOwnProperty.call(known, discriminatorValue)) {
return false;
} else {
known[discriminatorValue] = true;
Expand Down Expand Up @@ -155,13 +155,17 @@ export const generateJsonSchema = (
(optionName: string): boolean | string[] => {
switch (optionName) {
case ADDITIONAL_PROPERTIES:
if (options.hasOwnProperty(ADDITIONAL_PROPERTIES)) {
if (
Object.prototype.hasOwnProperty.call(options, ADDITIONAL_PROPERTIES)
) {
return options[ADDITIONAL_PROPERTIES];
}

return true;
case REQUIRED_PROPERTIES:
if (options.hasOwnProperty(REQUIRED_PROPERTIES)) {
if (
Object.prototype.hasOwnProperty.call(options, REQUIRED_PROPERTIES)
) {
return options[REQUIRED_PROPERTIES](props);
}

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const initState: JsonFormsCore = {
};

const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
if (schema.hasOwnProperty('id') || schema.hasOwnProperty('$id')) {
if (
Object.prototype.hasOwnProperty.call(schema, 'id') ||
Object.prototype.hasOwnProperty.call(schema, '$id')
) {
ajv.removeSchema(schema);
}
return ajv;
Expand Down
26 changes: 18 additions & 8 deletions packages/core/src/testers/testers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,23 @@ export const isObjectControl = and(uiTypeIs('Control'), schemaTypeIs('object'));

export const isAllOfControl = and(
uiTypeIs('Control'),
schemaMatches((schema) => schema.hasOwnProperty('allOf'))
schemaMatches((schema) =>
Object.prototype.hasOwnProperty.call(schema, 'allOf')
)
);

export const isAnyOfControl = and(
uiTypeIs('Control'),
schemaMatches((schema) => schema.hasOwnProperty('anyOf'))
schemaMatches((schema) =>
Object.prototype.hasOwnProperty.call(schema, 'anyOf')
)
);

export const isOneOfControl = and(
uiTypeIs('Control'),
schemaMatches((schema) => schema.hasOwnProperty('oneOf'))
schemaMatches((schema) =>
Object.prototype.hasOwnProperty.call(schema, 'oneOf')
)
);

/**
Expand All @@ -346,8 +352,12 @@ export const isOneOfControl = and(
export const isEnumControl = and(
uiTypeIs('Control'),
or(
schemaMatches((schema) => schema.hasOwnProperty('enum')),
schemaMatches((schema) => schema.hasOwnProperty('const'))
schemaMatches((schema) =>
Object.prototype.hasOwnProperty.call(schema, 'enum')
),
schemaMatches((schema) =>
Object.prototype.hasOwnProperty.call(schema, 'const')
)
)
);

Expand Down Expand Up @@ -592,9 +602,9 @@ export const isRangeControl = and(
or(schemaTypeIs('number'), schemaTypeIs('integer')),
schemaMatches(
(schema) =>
schema.hasOwnProperty('maximum') &&
schema.hasOwnProperty('minimum') &&
schema.hasOwnProperty('default')
Object.prototype.hasOwnProperty.call(schema, 'maximum') &&
Object.prototype.hasOwnProperty.call(schema, 'minimum') &&
Object.prototype.hasOwnProperty.call(schema, 'default')
),
optionIs('slider', true)
);
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/util/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export const resolveData = (instance: any, dataPath: string): any => {
const dataPathSegments = dataPath.split('.');

return dataPathSegments.reduce((curInstance, decodedSegment) => {
if (!curInstance || !curInstance.hasOwnProperty(decodedSegment)) {
if (
!curInstance ||
!Object.prototype.hasOwnProperty.call(curInstance, decodedSegment)
) {
return undefined;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/util/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const getFirstPrimitiveProp = (schema: any) => {
* Tests whether the schema has an enum based on oneOf.
*/
export const isOneOfEnumSchema = (schema: JsonSchema) =>
schema?.hasOwnProperty('oneOf') &&
schema?.oneOf &&
!!schema &&
Object.prototype.hasOwnProperty.call(schema, 'oneOf') &&
schema.oneOf &&
(schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined);
1 change: 0 additions & 1 deletion packages/examples-react/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/examples/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/material-renderers/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
'import/no-named-as-default': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ const hasEnumAndText = (schemas: JsonSchema[]) => {
const simpleAnyOf = and(
uiTypeIs('Control'),
schemaMatches(
(schema) => schema.hasOwnProperty('anyOf') && hasEnumAndText(schema.anyOf)
(schema) =>
Object.prototype.hasOwnProperty.call(schema, 'anyOf') &&
hasEnumAndText(schema.anyOf)
)
);
export const materialAnyOfStringOrEnumControlTester: RankedTester = rankWith(
Expand Down
1 change: 0 additions & 1 deletion packages/react/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/vanilla-renderers/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
'import/no-named-as-default': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
Expand Down
1 change: 0 additions & 1 deletion packages/vue/vue-vanilla/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down
1 change: 0 additions & 1 deletion packages/vue/vue/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-prototype-builtins': 'off',
// Base rule must be disabled to avoid incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
Expand Down