Skip to content

Commit

Permalink
Merge pull request #537 from EvgenyOrekhov/add_ignoreGetProperties_op…
Browse files Browse the repository at this point in the history
…tion_for_no-get

Add `ignoreGetProperties` option for `no-get` rule
  • Loading branch information
bmish authored Oct 17, 2019
2 parents 92c6541 + 2347ad4 commit 2817e26
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/rules/no-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const { prop1, prop2 } = this;
const foo = { prop1: this.prop1, prop2: this.prop2 };
```

## Configuration

This rule takes an optional object containing:

- `boolean` -- `ignoreGetProperties` -- whether the rule should ignore `getProperties` (default `false`)

## Related Rules

* [no-proxies](no-proxies.md)
Expand Down
19 changes: 19 additions & 0 deletions lib/rules/no-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ module.exports = {
category: 'Best Practices',
recommended: false,
},
schema: [
{
type: 'object',
properties: {
ignoreGetProperties: {
type: 'boolean',
default: false,
},
},
additionalProperties: false,
},
],
},
create(context) {
// Options:
const ignoreGetProperties = context.options[0] && context.options[0].ignoreGetProperties;

return {
// eslint-disable-next-line complexity
CallExpression(node) {
Expand Down Expand Up @@ -58,6 +73,10 @@ module.exports = {
// getProperties
// **************************

if (ignoreGetProperties) {
return;
}

if (
types.isMemberExpression(node.callee) &&
types.isThisExpression(node.callee.object) &&
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/no-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ ruleTester.run('no-get', rule, {

// Unknown sub-function call:
"this.getProperties.foo('prop1', 'prop2');",

// With ignoreGetProperties: true
{
code: "this.getProperties('prop1', 'prop2');",
options: [{ ignoreGetProperties: true }],
},
{
code: "this.getProperties(['prop1', 'prop2']);", // With parameters in array.
options: [{ ignoreGetProperties: true }],
},
{
code: "getProperties(this, 'prop1', 'prop2');",
options: [{ ignoreGetProperties: true }],
},
{
code: "getProperties(this, ['prop1', 'prop2']);", // With parameters in array.
options: [{ ignoreGetProperties: true }],
},
],
invalid: [
// **************************
Expand Down

0 comments on commit 2817e26

Please sign in to comment.