diff --git a/README.md b/README.md index d2cb2bc..3c2b8c6 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ This plugin provides four predefined configs: | | Rule ID | Description | |:---|:--------|:------------| | | [nuxt/no-env-in-context](./docs/rules/no-env-in-context.md) | Disallow `context.isServer/context.isClient` in `asyncData/fetch/nuxtServerInit` | -| | [nuxt/no-env-in-mounted](./docs/rules/no-env-in-mounted.md) | Disallow `process.server/process.client` in `mounted/beforeMount` | +| | [nuxt/no-env-in-hooks](./docs/rules/no-env-in-hooks.md) | Disallow `process.server/process.client` in client only Vue lifecycle hooks like: `mounted, beforeMount, updated...` | | | [nuxt/no-globals-in-created](./docs/rules/no-globals-in-created.md) | Disallow `window/document` in `created/beforeCreate` | | | [nuxt/no-this-in-fetch-data](./docs/rules/no-this-in-fetch-data.md) | Disallow `this` in `asyncData/fetch` | diff --git a/docs/rules/no-env-in-mounted.md b/docs/rules/no-env-in-hooks.md similarity index 82% rename from docs/rules/no-env-in-mounted.md rename to docs/rules/no-env-in-hooks.md index 8def594..3d800c7 100644 --- a/docs/rules/no-env-in-mounted.md +++ b/docs/rules/no-env-in-hooks.md @@ -1,4 +1,4 @@ -# nuxt/no-env-in-mounted +# nuxt/no-env-in-hooks > Disallow `process.server` and `process.client` in the following lifecycle hooks: `beforeMount`, `mounted`, `beforeUpdate`, `updated`, `activated`, `deactivated`, `beforeDestroy` and `destroyed`. @@ -6,7 +6,7 @@ ## Rule Details -This rule is for preventing using `process.server/process.client` in `mounted/beforeMount` since they're only executed in client side. +This rule is for preventing using `process.server/process.client` in client only Vue lifecycle hooks since they're only executed in client side. Examples of **incorrect** code for this rule: @@ -45,5 +45,5 @@ export default { ## :mag: Implementation -- [Rule source](https://github.com/nuxt/eslint-plugin-nuxt/blob/master/lib/rules/no-env-in-mounted.js) -- [Test source](https://github.com/nuxt/eslint-plugin-nuxt/blob/master/lib/rules/__test__/no-env-in-mounted.test.js) +- [Rule source](https://github.com/nuxt/eslint-plugin-nuxt/blob/master/lib/rules/no-env-in-hooks.js) +- [Test source](https://github.com/nuxt/eslint-plugin-nuxt/blob/master/lib/rules/__test__/no-env-in-hooks.test.js) diff --git a/lib/configs/base.js b/lib/configs/base.js index 7a6e057..536b164 100644 --- a/lib/configs/base.js +++ b/lib/configs/base.js @@ -16,7 +16,7 @@ module.exports = { ], rules: { 'nuxt/no-env-in-context': 'error', - 'nuxt/no-env-in-mounted': 'error', + 'nuxt/no-env-in-hooks': 'error', 'nuxt/no-globals-in-created': 'error', 'nuxt/no-this-in-fetch-data': 'error' } diff --git a/lib/index.js b/lib/index.js index 3901d84..dcbcefa 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,7 @@ module.exports = { rules: { 'no-env-in-context': require('./rules/no-env-in-context'), - 'no-env-in-mounted': require('./rules/no-env-in-mounted'), + 'no-env-in-hooks': require('./rules/no-env-in-hooks'), 'no-globals-in-created': require('./rules/no-globals-in-created'), 'no-this-in-fetch-data': require('./rules/no-this-in-fetch-data'), 'no-timing-in-fetch-data': require('./rules/no-timing-in-fetch-data') diff --git a/lib/rules/__test__/no-env-in-mounted.test.js b/lib/rules/__test__/no-env-in-hooks.test.js similarity index 92% rename from lib/rules/__test__/no-env-in-mounted.test.js rename to lib/rules/__test__/no-env-in-hooks.test.js index f43c8d1..d7e794f 100644 --- a/lib/rules/__test__/no-env-in-mounted.test.js +++ b/lib/rules/__test__/no-env-in-hooks.test.js @@ -1,5 +1,5 @@ /** - * @fileoverview disallow `process.server/process.client` in `mounted/beforeMount` + * @fileoverview disallow `process.server/process.client` in `Vue Lifecycle Hooks` * @author Xin Du */ 'use strict' @@ -8,7 +8,7 @@ // Requirements // ------------------------------------------------------------------------------ -var rule = require('../no-env-in-mounted') +var rule = require('../no-env-in-hooks') var RuleTester = require('eslint').RuleTester @@ -22,7 +22,7 @@ const parserOptions = { // ------------------------------------------------------------------------------ var ruleTester = new RuleTester() -ruleTester.run('no-env-in-mounted', rule, { +ruleTester.run('no-env-in-hooks', rule, { valid: [ { diff --git a/lib/rules/no-env-in-mounted.js b/lib/rules/no-env-in-hooks.js similarity index 100% rename from lib/rules/no-env-in-mounted.js rename to lib/rules/no-env-in-hooks.js