From cb03b4d9e05d10d4646b584a26ee227a7db2c72e Mon Sep 17 00:00:00 2001 From: Clark Du Date: Tue, 4 Dec 2018 17:26:33 +0000 Subject: [PATCH] feat: init no-this-in-async-data --- docs/rules/no-this-in-async-data.md | 35 +++++++++++++++++++ lib/rules/no-this-in-async-data.js | 44 ++++++++++++++++++++++++ tests/lib/rules/no-this-in-async-data.js | 37 ++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 docs/rules/no-this-in-async-data.md create mode 100644 lib/rules/no-this-in-async-data.js create mode 100644 tests/lib/rules/no-this-in-async-data.js diff --git a/docs/rules/no-this-in-async-data.md b/docs/rules/no-this-in-async-data.md new file mode 100644 index 0000000..106420b --- /dev/null +++ b/docs/rules/no-this-in-async-data.md @@ -0,0 +1,35 @@ +# Preventing using this in asyncData (no-this-in-async-data) + +Please describe the origin of the rule here. + +## Rule Details + +This rule aims to... + +Examples of **incorrect** code for this rule: + +```js + +// fill me in + +``` + +Examples of **correct** code for this rule: + +```js + +// fill me in + +``` + +### Options + +If there are any options, describe them here. Otherwise, delete this section. + +## When Not To Use It + +Give a short description of when it would be appropriate to turn off this rule. + +## Further Reading + +If there are other links that describe the issue this rule addresses, please include them here in a bulleted list. diff --git a/lib/rules/no-this-in-async-data.js b/lib/rules/no-this-in-async-data.js new file mode 100644 index 0000000..d1620cd --- /dev/null +++ b/lib/rules/no-this-in-async-data.js @@ -0,0 +1,44 @@ +/** + * @fileoverview Preventing using this in asyncData + * @author Clark Du + */ +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + meta: { + docs: { + description: "Preventing using this in asyncData", + category: "Fill me in", + recommended: false + }, + fixable: null, // or "code" or "whitespace" + schema: [ + // fill in your schema + ] + }, + + create: function(context) { + + // variables should be defined here + + //---------------------------------------------------------------------- + // Helpers + //---------------------------------------------------------------------- + + // any helper functions should go here or else delete this section + + //---------------------------------------------------------------------- + // Public + //---------------------------------------------------------------------- + + return { + + // give me methods + + }; + } +}; diff --git a/tests/lib/rules/no-this-in-async-data.js b/tests/lib/rules/no-this-in-async-data.js new file mode 100644 index 0000000..d59bbc7 --- /dev/null +++ b/tests/lib/rules/no-this-in-async-data.js @@ -0,0 +1,37 @@ +/** + * @fileoverview Preventing using this in asyncData + * @author Clark Du + */ +"use strict"; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +var rule = require("../../../lib/rules/no-this-in-async-data"), + + RuleTester = require("eslint").RuleTester; + + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +var ruleTester = new RuleTester(); +ruleTester.run("no-this-in-async-data", rule, { + + valid: [ + + // give me some code that won't trigger a warning + ], + + invalid: [ + { + code: "this.await fetch(`/api${this.$route.path}`)", + errors: [{ + message: "Fill me in.", + type: "Me too" + }] + } + ] +});