Skip to content

Commit 442acca

Browse files
authored
Merge pull request #1023 from bmish/no-get-with-default-checkUnsafeObjects-true
Update `checkUnsafeObjects` option default to true in `no-get-with-default` rule
2 parents c98384e + d0db454 commit 442acca

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

docs/rules/no-get-with-default.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const test = this.key || [];
4545
This rule takes an optional object containing:
4646

4747
- `boolean` -- `catchSafeObjects` -- whether the rule should catch non-`this` imported usages like `getWithDefault(person, 'name', '')` (default `true`)
48-
- `boolean` -- `catchUnsafeObjects` -- whether the rule should catch non-`this` usages like `person.getWithDefault('name', '')` even though we don't know for sure if `person` is an Ember object (default `false`, TODO: enable in next major release)
48+
- `boolean` -- `catchUnsafeObjects` -- whether the rule should catch non-`this` usages like `person.getWithDefault('name', '')` even though we don't know for sure if `person` is an Ember object (default `true`)
4949

5050
## References
5151

lib/rules/no-get-with-default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
},
2828
catchUnsafeObjects: {
2929
type: 'boolean',
30-
default: false,
30+
default: true,
3131
},
3232
},
3333
additionalProperties: false,
@@ -39,7 +39,7 @@ module.exports = {
3939
let importedGetWithDefaultName;
4040

4141
const catchSafeObjects = !context.options[0] || context.options[0].catchSafeObjects;
42-
const catchUnsafeObjects = context.options[0] && context.options[0].catchUnsafeObjects;
42+
const catchUnsafeObjects = !context.options[0] || context.options[0].catchUnsafeObjects;
4343

4444
return {
4545
ImportDeclaration(node) {

tests/lib/rules/no-get-with-default.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ ruleTester.run('no-get-with-default', rule, {
2727
},
2828

2929
// With catchUnsafeObjects: false
30-
"person.getWithDefault('name', '');",
3130
{
3231
code: "person.getWithDefault('name', '');",
3332
options: [{ catchUnsafeObjects: false }],
@@ -151,7 +150,12 @@ import { getWithDefault } from '@ember/object'; (get(person, 'name') === undefin
151150
],
152151
},
153152

154-
// With catchUnsafeObjects: true
153+
// With catchUnsafeObjects: true (default)
154+
{
155+
code: "person.getWithDefault('name', '');",
156+
output: "(person.get('name') === undefined ? '' : person.get('name'));",
157+
errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }],
158+
},
155159
{
156160
code: "person.getWithDefault('name', '');",
157161
options: [{ catchUnsafeObjects: true }],

0 commit comments

Comments
 (0)