Add eslint-plugin-rulesdir to node_modules
This plugin needs to be used to write our own custom ESLint plugins that
live in our repository. It replaces the `rulesdir` CLI option, as the
solution of putting it in `.eslintrc.js` is compatible with code editor
plugins.
I also discovered that we were incorrectly running clang-format on
`node_modules`, as I recently fixed the PRESUBMIT. To make sure that
doens't happen again, add a `.clang-format` that disables the formatting
in that folder.
DISABLE_THIRD_PARTY_CHECK=Add new node_module
Bug: 1060123
Change-Id: Ib2c0d23f499604deeea51cb06192bce3a7aa89af
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2096449
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
diff --git a/node_modules/eslint-plugin-rulesdir/index.js b/node_modules/eslint-plugin-rulesdir/index.js
new file mode 100644
index 0000000..7ad98c9
--- /dev/null
+++ b/node_modules/eslint-plugin-rulesdir/index.js
@@ -0,0 +1,34 @@
+/**
+ * @fileoverview Allows a local ESLint rules directory to be used without a command-line flag
+ * @author Teddy Katz
+ */
+
+'use strict';
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const fs = require('fs');
+const path = require('path');
+
+//------------------------------------------------------------------------------
+// Plugin Definition
+//------------------------------------------------------------------------------
+
+const cache = {};
+module.exports = {
+ get rules() {
+ const RULES_DIR = module.exports.RULES_DIR;
+ if (typeof module.exports.RULES_DIR !== 'string') {
+ throw new Error('To use eslint-plugin-rulesdir, you must load it beforehand and set the `RULES_DIR` property on the module to a string.');
+ }
+ if (!cache[RULES_DIR]) {
+ cache[RULES_DIR] = fs.readdirSync(RULES_DIR)
+ .filter(filename => filename.endsWith('.js'))
+ .map(filename => path.resolve(RULES_DIR, filename))
+ .reduce((rules, absolutePath) => Object.assign(rules, { [path.basename(absolutePath, '.js')]: require(absolutePath) }), {});
+ }
+ return cache[RULES_DIR];
+ },
+};