1. eslint-plugin-eggache
custom eslint rule for egg RTFM issues
eslint-plugin-eggache
Package: eslint-plugin-eggache
Created by: eggjs
Last modified: Thu, 29 Sep 2022 14:38:54 GMT
Version: 2.0.0
License: MIT
Downloads: 84,129
Repository: https://github.com/eggjs/eslint-plugin-eggache

Install

npm install eslint-plugin-eggache
yarn add eslint-plugin-eggache

eslint-plugin-eggache

custom eslint rule for egg RTFM questions

NPM version
build status
Test coverage
David deps
Known Vulnerabilities
NPM download

Usage

 npm i eslint-plugin-eggache --save

Add eggache to the plugins section of your .eslintrc configuration file.

 // ${app_root}/.eslintrc
{
  "extends": [
    "plugin:eggache/recommended"
  ]
}

By default it enable all the recommended rules, if you want to custom, just configure the rules section.

 // ${app_root}/.eslintrc
{
  "extends": [
    "plugin:eggache/recommended"
  ],
  "rules": {
    'eggache/no-override-exports': [ 'error' ],
    'eggache/no-unexpected-plugin-keys': 'error',
  }
}

Rules

no-override-exports

A common mistake that newbie will make - override module.exports and exports.

 /* eslint eggache/no-override-exports: [ 'error' ] */

// config/config.default.js
exports.view = {};

module.exports = appInfo => {
  const config = exports = {};
  config.keys = '123456';
  return config;
}

Options:

The first options is a boolean, default to false, means only check:

  • config/config.*.js
  • config/plugin.*.js

set it to true means to check all files.

 /* eslint eggache/no-override-exports: [ 'error', true ] */

// due to options `true`, this will pass the lint
// ${app_root}/app.js
module.exports = exports = {};
exports.keys = '123456';

no-unexpected-plugin-keys

Sometimes, developer will confuse plugin.js and config.default.js.

plugin.js only allow [ 'enable', 'package', 'path', 'env' ] and it control whether to load a plugin.

The plugin's config should write to config/config.{env}.js.

 /* eslint eggache/no-unexpected-plugin-keys: [ 'error' ] */

// config/plugin.js
module.exports = {
  test: {
    enable: true,
    package: 'egg-test',
    someConfig: 'should not place here',
  },
}

no-only-tests

A common mistake that developer will make - forget to remove .only in tests before committing.

 /* eslint eggache/no-only-tests: [ 'error' ] */
describe.only('desc something', function() {
  it.only('assert somnething', function() {
    // do nothing
  });
})

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code