Repository: ember-cli/eslint-plugin-ember
Pull request #465 (2019-08-11 20:34:37)

Add tests that rules are setup correctly (not missing tests, docs, exports, etc)
There have been numerous occassions where basic rule setup was missed:
* https://github.com/ember-cli/eslint-plugin-ember/pull/440
* https://github.com/ember-cli/eslint-plugin-ember/pull/314

These tests are inspired by: https://github.com/ember-template-lint/ember-template-lint/pull/798 (CC: @lifeart)


Patch:
diff --git a/lib/index.js b/lib/index.js
index 8d8756ee..f19b6722 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -10,6 +10,7 @@ module.exports = {
     'classic-decorator-hooks': require('./rules/classic-decorator-hooks'),
     'classic-decorator-no-classic-methods': require('./rules/classic-decorator-no-classic-methods'),
     'closure-actions': require('./rules/closure-actions'),
+    'computed-property-getters': require('./rules/computed-property-getters'),
     'jquery-ember-run': require('./rules/jquery-ember-run'),
     'local-modules': require('./rules/local-modules'),
     'named-functions-in-promises': require('./rules/named-functions-in-promises'),
@@ -46,10 +47,10 @@ module.exports = {
     'order-in-controllers': require('./rules/order-in-controllers'),
     'order-in-models': require('./rules/order-in-models'),
     'order-in-routes': require('./rules/order-in-routes'),
-    'route-path-style': require('./rules/route-path-style'),
     'require-computed-macros': require('./rules/require-computed-macros'),
     'require-return-from-computed': require('./rules/require-return-from-computed'),
     'require-super-in-init': require('./rules/require-super-in-init'),
+    'route-path-style': require('./rules/route-path-style'),
     'routes-segments-snake-case': require('./rules/routes-segments-snake-case'),
     'use-brace-expansion': require('./rules/use-brace-expansion'),
     'use-ember-data-rfc-395-imports': require('./rules/use-ember-data-rfc-395-imports'),


Test patch:
diff --git a/tests/rule-setup.js b/tests/rule-setup.js
new file mode 100644
index 00000000..b115d8cc
--- /dev/null
+++ b/tests/rule-setup.js
@@ -0,0 +1,55 @@
+'use strict';
+
+const { readdirSync, readFileSync } = require('fs');
+const { join } = require('path');
+const assert = require('assert');
+const rules = require('../lib/index.js').rules;
+const recommendedRules = require('../lib/recommended-rules.js');
+
+const RULE_NAMES = Object.keys(rules);
+
+describe('rules setup is correct', function() {
+  it('should have a list of exported rules and rules directory that match', function() {
+    const path = join(__dirname, '../lib/rules');
+    const files = readdirSync(path);
+
+    assert.deepEqual(
+      RULE_NAMES,
+      files.filter(file => !file.startsWith('.')).map(file => file.replace('.js', ''))
+    );
+  });
+
+  it('should list all rules in the recommended rules file', function() {
+    assert.deepEqual(
+      RULE_NAMES,
+      Object.keys(recommendedRules).map(file => file.replace('ember/', ''))
+    );
+  });
+
+  it('should have tests for all rules', function() {
+    const path = join(__dirname, '../tests/lib/rules');
+    const files = readdirSync(path);
+
+    assert.deepEqual(
+      RULE_NAMES,
+      files.filter(file => !file.startsWith('.')).map(file => file.replace('.js', ''))
+    );
+  });
+
+  it('should have documentation for all rules', function() {
+    const path = join(__dirname, '../docs/rules');
+    const files = readdirSync(path);
+
+    assert.deepEqual(
+      RULE_NAMES,
+      files.filter(file => !file.startsWith('.')).map(file => file.replace('.md', ''))
+    );
+  });
+
+  it('should mention all rules in the README', function() {
+    const path = join(__dirname, '../README.md');
+    const file = readFileSync(path);
+
+    RULE_NAMES.forEach(ruleName => assert.ok(file.includes(ruleName)));
+  });
+});