Skip to content

Commit 2310ead

Browse files
authored
Change useAt option default to true at in no-get rule (#1965)
1 parent af3d5c0 commit 2310ead

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

docs/rules/no-get.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ This rule takes an optional object containing:
9595
9696
- `boolean` -- `ignoreGetProperties` -- whether the rule should ignore `getProperties` (default `false`)
9797
- `boolean` -- `ignoreNestedPaths` -- whether the rule should ignore `this.get('some.nested.property')` (can't be enabled at the same time as `useOptionalChaining`) (default `false`)
98-
- `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)
98+
- `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`)
9999
- `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`)
100100
- `boolean` -- `catchSafeObjects` -- whether the rule should catch non-`this` imported usages like `get(foo, 'bar')` (default `true`)
101101
- `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`)

lib/rules/no-get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ module.exports = {
190190
},
191191
useAt: {
192192
type: 'boolean',
193-
default: false,
193+
default: true,
194194
},
195195
},
196196
additionalProperties: false,

tests/lib/rules/no-get.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,20 @@ ruleTester.run('no-get', rule, {
787787
},
788788
],
789789
},
790+
{
791+
// useAt default value
792+
// `lastObject` used at the beginning of a path.
793+
// And the result of get() is chained (getResultIsChained=true).
794+
code: "this.get('lastObject.bar')[123];",
795+
output: 'this.at(-1).bar[123];',
796+
options: [{ useOptionalChaining: true }],
797+
errors: [
798+
{
799+
message: ERROR_MESSAGE_GET,
800+
type: 'CallExpression',
801+
},
802+
],
803+
},
790804
{
791805
// `lastObject` used at the beginning of a path.
792806
// And the result of get() is chained (getResultIsChained=true).

0 commit comments

Comments
 (0)