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" + }] + } + ] +});