summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRichard Lau <riclau@uk.ibm.com>2018-04-27 15:57:52 -0400
committerRichard Lau <riclau@uk.ibm.com>2018-05-08 10:43:26 -0400
commit870ae722279678a6d4f49b664bd4fba2051fbf4a (patch)
tree40fb18646703666b11e40795cdc804a716f347e6 /tools
parent8e6601a789ec6c3657314f475f1493192a2fda2b (diff)
downloadandroid-node-v8-870ae722279678a6d4f49b664bd4fba2051fbf4a.tar.gz
android-node-v8-870ae722279678a6d4f49b664bd4fba2051fbf4a.tar.bz2
android-node-v8-870ae722279678a6d4f49b664bd4fba2051fbf4a.zip
tools: add eslint check for skipIfEslintMissing
Add a custom eslint rule to check for `common.skipIfEslintMissing()` to allow tests to run from source tarballs that do not include eslint. Fix up rule tests that were failing the new check. Refs: https://github.com/nodejs/node/issues/20336 PR-URL: https://github.com/nodejs/node/pull/20372 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/eslint-rules/eslint-check.js60
-rw-r--r--tools/eslint-rules/inspector-check.js2
2 files changed, 61 insertions, 1 deletions
diff --git a/tools/eslint-rules/eslint-check.js b/tools/eslint-rules/eslint-check.js
new file mode 100644
index 0000000000..00a5234733
--- /dev/null
+++ b/tools/eslint-rules/eslint-check.js
@@ -0,0 +1,60 @@
+/**
+ * @fileoverview Check that common.skipIfEslintMissing is used if
+ * the eslint module is required.
+ */
+'use strict';
+
+const utils = require('./rules-utils.js');
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+const msg = 'Please add a skipIfEslintMissing() call to allow this test to ' +
+ 'be skipped when Node.js is built from a source tarball.';
+
+module.exports = function(context) {
+ const missingCheckNodes = [];
+ var commonModuleNode = null;
+ var hasEslintCheck = false;
+
+ function testEslintUsage(context, node) {
+ if (utils.isRequired(node, ['../../tools/node_modules/eslint'])) {
+ missingCheckNodes.push(node);
+ }
+
+ if (utils.isCommonModule(node)) {
+ commonModuleNode = node;
+ }
+ }
+
+ function checkMemberExpression(context, node) {
+ if (utils.usesCommonProperty(node, ['skipIfEslintMissing'])) {
+ hasEslintCheck = true;
+ }
+ }
+
+ function reportIfMissing(context) {
+ if (!hasEslintCheck) {
+ missingCheckNodes.forEach((node) => {
+ context.report({
+ node,
+ message: msg,
+ fix: (fixer) => {
+ if (commonModuleNode) {
+ return fixer.insertTextAfter(
+ commonModuleNode,
+ '\ncommon.skipIfEslintMissing();'
+ );
+ }
+ }
+ });
+ });
+ }
+ }
+
+ return {
+ 'CallExpression': (node) => testEslintUsage(context, node),
+ 'MemberExpression': (node) => checkMemberExpression(context, node),
+ 'Program:exit': (node) => reportIfMissing(context, node)
+ };
+};
diff --git a/tools/eslint-rules/inspector-check.js b/tools/eslint-rules/inspector-check.js
index 00a2dd0296..189b023efc 100644
--- a/tools/eslint-rules/inspector-check.js
+++ b/tools/eslint-rules/inspector-check.js
@@ -11,7 +11,7 @@ const utils = require('./rules-utils.js');
// Rule Definition
//------------------------------------------------------------------------------
const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' +
- 'test to be skippped when Node is built \'--without-inspector\'.';
+ 'test to be skipped when Node is built \'--without-inspector\'.';
module.exports = function(context) {
const missingCheckNodes = [];