From 2310ead89f01dea7ec93f53cc700bb7dbd96da70 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 31 Oct 2023 15:47:44 +0100 Subject: [PATCH] Change `useAt` option default to `true` at in `no-get` rule (#1965) --- docs/rules/no-get.md | 2 +- lib/rules/no-get.js | 2 +- tests/lib/rules/no-get.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-get.md b/docs/rules/no-get.md index 8eed5956a5..b1f02420da 100644 --- a/docs/rules/no-get.md +++ b/docs/rules/no-get.md @@ -95,7 +95,7 @@ This rule takes an optional object containing: - `boolean` -- `ignoreGetProperties` -- whether the rule should ignore `getProperties` (default `false`) - `boolean` -- `ignoreNestedPaths` -- whether the rule should ignore `this.get('some.nested.property')` (can't be enabled at the same time as `useOptionalChaining`) (default `false`) -- `boolean` -- `useAt` -- whether the rule should use `at(-1)` [Array.prototype.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at) to replace `lastObject` (default `false`) (TODO: enable by default once we require Node 16.6) +- `boolean` -- `useAt` -- whether the rule should use `at(-1)` [Array.prototype.at()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at) to replace `lastObject` (default `true`) - `boolean` -- `useOptionalChaining` -- whether the rule should use the [optional chaining operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) `?.` to autofix nested paths such as `this.get('some.nested.property')` to `this.some?.nested?.property` (when this option is off, these nested paths won't be autofixed at all) (default `true`) - `boolean` -- `catchSafeObjects` -- whether the rule should catch non-`this` imported usages like `get(foo, 'bar')` (default `true`) - `boolean` -- `catchUnsafeObjects` -- whether the rule should catch non-`this` usages like `foo.get('bar')` even though we don't know for sure if `foo` is an Ember object (default `false`) diff --git a/lib/rules/no-get.js b/lib/rules/no-get.js index b59c615397..a76a175012 100644 --- a/lib/rules/no-get.js +++ b/lib/rules/no-get.js @@ -190,7 +190,7 @@ module.exports = { }, useAt: { type: 'boolean', - default: false, + default: true, }, }, additionalProperties: false, diff --git a/tests/lib/rules/no-get.js b/tests/lib/rules/no-get.js index ea2912c3a4..ec4c7566f3 100644 --- a/tests/lib/rules/no-get.js +++ b/tests/lib/rules/no-get.js @@ -787,6 +787,20 @@ ruleTester.run('no-get', rule, { }, ], }, + { + // useAt default value + // `lastObject` used at the beginning of a path. + // And the result of get() is chained (getResultIsChained=true). + code: "this.get('lastObject.bar')[123];", + output: 'this.at(-1).bar[123];', + options: [{ useOptionalChaining: true }], + errors: [ + { + message: ERROR_MESSAGE_GET, + type: 'CallExpression', + }, + ], + }, { // `lastObject` used at the beginning of a path. // And the result of get() is chained (getResultIsChained=true).