Repository: ember-cli/eslint-plugin-ember
Pull request #1018 (2020-12-01 19:17:08)

Update `checkInitOnly` option default to false in `require-super-init` rule
Part of #960.


Patch:
diff --git a/docs/rules/require-super-in-init.md b/docs/rules/require-super-in-init.md
index 20bc704e..4a85a5d0 100644
--- a/docs/rules/require-super-in-init.md
+++ b/docs/rules/require-super-in-init.md
@@ -8,8 +8,6 @@ Call super in lifecycle hooks.
 
 When overriding lifecycle hooks inside Ember Components, Controllers, Routes, Mixins, or Services, it is necessary to include a call to super.
 
-By default, this rule only applies to the `init` lifecycle hook and classic classes (see rule options to configure this).
-
 ## Examples
 
 Examples of **incorrect** code for this rule:
@@ -25,7 +23,6 @@ export default Component.extend({
 ```
 
 ```javascript
-// With: checkInitOnly = false
 import Component from '@ember/component';
 
 export default Component.extend({
@@ -96,5 +93,5 @@ class Foo extends Component {
 
 This rule takes an optional object containing:
 
-* `boolean` -- `checkInitOnly` -- whether the rule should only check the `init` lifecycle hook and not other lifecycle hooks (default `true`, TODO: change default to `false` and rename rule to `require-super-in-lifecycle-hooks` in next major release)
+* `boolean` -- `checkInitOnly` -- whether the rule should only check the `init` lifecycle hook and not other lifecycle hooks (default `false`)
 * `boolean` -- `checkNativeClasses` -- whether the rule should check lifecycle hooks in native classes (in addition to classic classes) (default `false`, TODO: change default to `true` in next major release)
diff --git a/lib/rules/require-super-in-init.js b/lib/rules/require-super-in-init.js
index 4e600c73..d7043ec2 100644
--- a/lib/rules/require-super-in-init.js
+++ b/lib/rules/require-super-in-init.js
@@ -72,7 +72,7 @@ module.exports = {
         properties: {
           checkInitOnly: {
             type: 'boolean',
-            default: true,
+            default: false,
           },
           checkNativeClasses: {
             type: 'boolean',
@@ -85,7 +85,7 @@ module.exports = {
   },
 
   create(context) {
-    const checkInitOnly = !context.options[0] || context.options[0].checkInitOnly;
+    const checkInitOnly = context.options[0] && context.options[0].checkInitOnly;
     const checkNativeClasses = context.options[0] && context.options[0].checkNativeClasses;
 
     function report(node, isNativeClass, lifecycleHookName) {


Test patch:
diff --git a/tests/lib/rules/require-super-in-init.js b/tests/lib/rules/require-super-in-init.js
index 339fa077..603776c4 100644
--- a/tests/lib/rules/require-super-in-init.js
+++ b/tests/lib/rules/require-super-in-init.js
@@ -144,17 +144,11 @@ eslintTester.run('require-super-in-init', rule, {
         init
       });`,
 
-    // Non-init hooks should not be checked when checkInitOnly = true (default)
-    'export default Component({ didInsertElement() {} });',
+    // Non-init hooks should not be checked when checkInitOnly = true
     {
       code: 'export default Component({ didInsertElement() {} });',
       options: [{ checkInitOnly: true }],
     },
-    {
-      code:
-        "import Component from '@ember/component'; class Foo extends Component { didInsertElement() {} }",
-      options: [{ checkNativeClasses: true }],
-    },
     {
       code:
         "import Component from '@ember/component'; class Foo extends Component { didInsertElement() {} }",
@@ -253,6 +247,14 @@ this._super(...arguments);},
       options: [{ checkInitOnly: false }],
       errors: [{ message, line: 2 }],
     },
+
+    // checkInitOnly = false
+    {
+      code: 'export default Component.extend({ didInsertElement() {} });',
+      output: `export default Component.extend({ didInsertElement() {
+this._super(...arguments);} });`,
+      errors: [{ message, type: 'Property' }],
+    },
     {
       code: `export default Component.extend({
         init() {},
@@ -264,6 +266,7 @@ this._super(...arguments);},
       options: [{ checkInitOnly: false }],
       errors: [{ message, line: 2 }],
     },
+
     {
       code: `export default Component.extend({
         init() {
@@ -777,6 +780,16 @@ this._super();} })`,
       options: [{ checkInitOnly: false }],
       errors: [{ message, line: 1 }],
     },
+
+    // checkInitOnly = false
+    {
+      code:
+        "import Component from '@ember/component'; class Foo extends Component { didUpdateAttrs() {} }",
+      output: `import Component from '@ember/component'; class Foo extends Component { didUpdateAttrs() {
+super.didUpdateAttrs();} }`,
+      options: [{ checkNativeClasses: true }],
+      errors: [{ message, type: 'MethodDefinition' }],
+    },
     {
       code: `import Component from '@ember/component';
       class Foo extends Component { didUpdateAttrs() {} }`,