Skip to content

Commit

Permalink
🏗♻️ Forbid invoking hasOwnProperty directly (#16762)
Browse files Browse the repository at this point in the history
* ESLint rule to ban hasOwnProperty

* Do not forbid hasOwnProperty in validator code

* Do not forbid hasOwnProperty in build-system code
  • Loading branch information
danielrozenberg authored Jul 19, 2018
1 parent 9470695 commit db751cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"amphtml-internal/no-export-side-effect": 2,
"amphtml-internal/no-for-of-statement": 2,
"amphtml-internal/no-global": 0,
"amphtml-internal/no-has-own-property-method": 1,
"amphtml-internal/no-mixed-operators": 2,
"amphtml-internal/no-spread": 2,
"amphtml-internal/no-style-property-setting": 2,
Expand Down
1 change: 1 addition & 0 deletions build-system/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"rules": {
"amphtml-internal/no-for-of-statement": 0,
"amphtml-internal/no-has-own-property-method": 0,
"require-jsdoc": 0
}
}
33 changes: 33 additions & 0 deletions build-system/eslint-rules/no-has-own-property-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

module.exports = {
create(context) {
return {
CallExpression(node) {
if (node.callee.type == 'MemberExpression' && !node.callee.computed &&
node.callee.property.name == 'hasOwnProperty') {
context.report({
node,
message: 'Do not use hasOwnProperty directly. ' +
'Use hasOwn from src/utils/object.js instead.',
});
}
},
};
},
};
1 change: 1 addition & 0 deletions validator/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"rules": {
"amphtml-internal/no-for-of-statement": 0,
"amphtml-internal/no-has-own-property-method": 0,
"chai-expect/missing-assertion": 1,
"google-camelcase/google-camelcase": 0,
"jsdoc/check-param-names": 0,
Expand Down

0 comments on commit db751cb

Please sign in to comment.