Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
feat: add no-env-in-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Dec 19, 2018
1 parent ee73e8b commit 016f609
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 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`.
- :gear: This rule is included in `"plugin:nuxt/base"`.

## 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:

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion lib/configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
'use strict'
Expand All @@ -8,7 +8,7 @@
// Requirements
// ------------------------------------------------------------------------------

var rule = require('../no-env-in-mounted')
var rule = require('../no-env-in-hooks')

var RuleTester = require('eslint').RuleTester

Expand All @@ -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: [
{
Expand Down
File renamed without changes.

0 comments on commit 016f609

Please sign in to comment.