Skip to content

Commit

Permalink
style: enable ‘no-prototype-builtins’ lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
pdubroy committed Oct 15, 2021
1 parent f969432 commit 3d10fbe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Expand Up @@ -60,8 +60,5 @@ module.exports = {
'prefer-arrow-callback': 'error',
'prefer-const': 'error',
'prefer-destructuring': ['error', {object: true, array: false}],

// ----- Temporary exceptions -----
'no-prototype-builtins': 'off',
},
};
4 changes: 3 additions & 1 deletion examples/ecmascript/compile.js
Expand Up @@ -39,6 +39,8 @@ function loadModule(name) {

/* eslint-disable no-console */

const hasOwnProperty = (x, prop) => Object.prototype.hasOwnProperty.call(x, prop);

function compile(args) {
const filenames = [];
const opts = {
Expand All @@ -51,7 +53,7 @@ function compile(args) {
for (let i = 0; i < args.length; ++i) {
if (args[i] === '-g') {
opts.grammar = args[++i];
} else if (args[i][0] === '-' && opts.hasOwnProperty(args[i][1])) {
} else if (args[i][0] === '-' && hasOwnProperty(opts, args[i][1])) {
opts[args[i][1]] = true;
} else {
filenames.push(args[i]);
Expand Down
2 changes: 1 addition & 1 deletion packages/ohm-js/extras/semantics-toAST.js
Expand Up @@ -22,7 +22,7 @@ const defaultOperation = {
const {mapping} = this.args;

// without customization
if (!mapping.hasOwnProperty(ctorName)) {
if (!Object.prototype.hasOwnProperty.call(mapping, ctorName)) {
// intermediate node
if (this._node instanceof pexprs.Alt || this._node instanceof pexprs.Apply) {
return children[0].toAST(mapping);
Expand Down
8 changes: 5 additions & 3 deletions packages/ohm-js/src/Semantics.js
Expand Up @@ -19,6 +19,8 @@ const globalActionStack = [];
let prototypeGrammar;
let prototypeGrammarSemantics;

const hasOwnProperty = (x, prop) => Object.prototype.hasOwnProperty.call(x, prop);

// ----------------- Wrappers -----------------

// Wrappers decorate CST nodes with all of the functionality (i.e., operations and attributes)
Expand Down Expand Up @@ -473,7 +475,7 @@ Semantics.prototype.extendOperationOrAttribute = function(type, name, actionDict
' with that name'
);
}
if (Object.prototype.hasOwnProperty.call(this[typePlural], name)) {
if (hasOwnProperty(this[typePlural], name)) {
throw new Error('Cannot extend ' + type + " '" + name + "' again");
}

Expand All @@ -497,7 +499,7 @@ Semantics.prototype.extendOperationOrAttribute = function(type, name, actionDict
};

Semantics.prototype.assertNewName = function(name, type) {
if (Wrapper.prototype.hasOwnProperty(name)) {
if (hasOwnProperty(Wrapper.prototype, name)) {
throw new Error('Cannot add ' + type + " '" + name + "': that's a reserved name");
}
if (name in this.operations) {
Expand Down Expand Up @@ -694,7 +696,7 @@ class Attribute extends Operation {
execute(semantics, nodeWrapper) {
const node = nodeWrapper._node;
const key = semantics.attributeKeys[this.name];
if (!node.hasOwnProperty(key)) {
if (!hasOwnProperty(node, key)) {
// The following is a super-send -- isn't JS beautiful? :/
node[key] = Operation.prototype.execute.call(this, semantics, nodeWrapper);
}
Expand Down

0 comments on commit 3d10fbe

Please sign in to comment.