From 87c753cc5d9dac6fc6982c8ae5d23b3f3f9b5c30 Mon Sep 17 00:00:00 2001 From: Ed S Date: Tue, 22 Jan 2019 16:05:19 +0000 Subject: [PATCH] Add rule for no-fx-interval and include in deprecated-3.0 (#47) Part of #32 --- README.md | 1 + index.js | 3 ++- rules/no-fx-interval.js | 24 ++++++++++++++++++++++++ tests/no-fx-interval.js | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 rules/no-fx-interval.js create mode 100644 tests/no-fx-interval.js diff --git a/README.md b/README.md index ebc258d9..f0e00538 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Alternatively, you can pick out rules individually: "jquery/no-fade": 2, "jquery/no-filter": 2, "jquery/no-find": 2, + "jquery/no-fx-interval": 2, "jquery/no-global-eval": 2, "jquery/no-grep": 2, "jquery/no-has": 2, diff --git a/index.js b/index.js index 79452d4a..daf4b72f 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ module.exports = { 'no-fade': require('./rules/no-fade'), 'no-filter': require('./rules/no-filter'), 'no-find': require('./rules/no-find'), + 'no-fx-interval': require('./rules/no-fx-interval'), 'no-global-eval': require('./rules/no-global-eval'), 'no-grep': require('./rules/no-grep'), 'no-has': require('./rules/no-has'), @@ -91,7 +92,7 @@ module.exports = { 'jquery/no-unbind': 2, 'jquery/no-delegate': 2, 'jquery/no-undelegate': 2, - // FIXME: `$.fx.interval` + 'jquery/no-fx-interval': 2, 'jquery/no-parse-json': 2, 'jquery/no-unique': 2 } diff --git a/rules/no-fx-interval.js b/rules/no-fx-interval.js new file mode 100644 index 00000000..8c7f0e4e --- /dev/null +++ b/rules/no-fx-interval.js @@ -0,0 +1,24 @@ +'use strict' + +module.exports = { + meta: { + docs: {}, + schema: [] + }, + + create: function(context) { + return { + MemberExpression: function(node) { + if (node.object.name !== '$') return + if (node.property.name !== 'fx') return + if (!node.parent.property) return + if (node.parent.property.name !== 'interval') return + + context.report({ + node: node, + message: '$.fx.interval is not allowed' + }) + } + } + } +} diff --git a/tests/no-fx-interval.js b/tests/no-fx-interval.js new file mode 100644 index 00000000..ad3187e8 --- /dev/null +++ b/tests/no-fx-interval.js @@ -0,0 +1,17 @@ +'use strict' + +const rule = require('../rules/no-fx-interval') +const RuleTester = require('eslint').RuleTester + +const error = '$.fx.interval is not allowed' + +const ruleTester = new RuleTester() +ruleTester.run('no-noop', rule, { + valid: ['interval', 'fx.interval', '$.interval', 'a.fx.interval', '$.fx'], + invalid: [ + { + code: '$.fx.interval', + errors: [{message: error, type: 'MemberExpression'}] + } + ] +})