eslint-plugin-lodashs

Overview

eslint-plugin-lodashs

npm badge gitHub release badge gitHub tag badge gitHub repo size badge jest badge badge


简介

关于lodash工具函数的lint。

如:get函数,取默认值。

官方解释:Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.(在获取的值是undefined时,则返回默认值)

import _ from 'lodash'

let a = {
  b: "值"
}

let c = _.get(a, 'b', '默认值')

if (c.length) {
  // TODO
}

上面的写法看似没问题。但是有种情况,当 b 的值为:null 时,上面的写法就取不到默认值。

import _ from 'lodash'

let a = {
  b: null
}

let c = _.get(a, 'b', '默认值')

if (c.length) {  // Error: Uncaught TypeError: Cannot read properties of null (reading 'length')
  // TODO
}

在常规的业务里很经常用到get函数,但是写法不注意,可能会导致代码不够健壮,会有隐患存在。这时项目如果有eslint,我们就可以让工具帮我们检测修复有问题的代码。

健壮的代码如:

import _ from 'lodash'

let a = {
  b: null
}

let c = _.get(a, 'b') || '默认值'

if (c.length) {
  // TODO
}

Installation

先安装 ESLint:

$ npm i eslint --save-dev

接下来安装 eslint-plugin-lodashs:

$ npm install eslint-plugin-lodashs --save-dev

Usage

添加 lodashs 在你的配置文件里: .eslintrc

可以省略前缀: eslint-plugin-

{
  "plugins": [
    "lodashs"
  ]
}

配置对应的规则:lodash-get

{
    "rules": {
        "lodashs/lodash-get": 2
    }
}

贡献规则

如果有感兴趣,在使用lodash的时候发现的问题可以用工具解决的,欢迎提 pr

问题

有问题的可以在这里提issue: issue

You might also like...

A template project for NRWL's NX, Ionic Framework, Stylelint, Eslint, and more from the OpenForge mobile app team.

OpenForge Ionic Monorepo Example This is a template project for all Ionic + Angular Monorepos. It was generated using a combination of Nx, Ionic Thank

Oct 26, 2022

Yet another eslint blame (might) with better adaptability

yet-another-eslint-blame Yet another eslint blame (might) with better adaptability. The input is eslint's output with json format (You can see it here

Mar 7, 2022

⚙ With a little preparation, the typescript eslint generic rules for vodyani may be readily integrated into projects.

Vodyani eslint-config ⚙ With a little preparation, the typescript eslint generic rules for vodyani may be readily integrated into projects. Installati

Sep 7, 2022

Express.js framework boilerplate with TypeScript, Prisma, ESLint, Husky and Jest

Express.js framework boilerplate with TypeScript, Prisma, ESLint, Husky and Jest

Setup a Node.js project with Typescript, Prisma ESLint, Prettier, Husky Node.js boilerplate with Express.js, TypeScript, Prisma, ESLint, Prettier, Hus

Dec 12, 2022

✨ An Eslint config to improve your code

eslint-config-descartes ✨ An Eslint config to improve your code by Descartes Team How to use? 1 - Install Eslint npm instal eslint-config-descartes es

Dec 21, 2022

📜 Sharable eslint configuration rimac technology uses in all of its projects.

Eslint Config Usage Install the library as a dev dependency alongside required dependencies using yarn add -D @rimac-technology/eslint-config

Nov 23, 2022

📦 Custom eslint rules for a better life.

Eslint Plugin Rimac Architecture When creating a new rule put it in the src/rules folder Name the file the same as the rule itself For example rimac/i

Nov 22, 2022

💅 A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, Prettier, GitHub Action releases and more.

💅 A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, Prettier, GitHub Action releases and more.

Electron App 💅  A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, P

Dec 29, 2022

An ESLint shareable configuration that used in our projects.

eslint-config An ESLint shareable configuration that used in our projects. Install npm install -D @clytage-pkg/eslint-config or with yarn yarn add -D

Nov 17, 2022
Releases(v0.0.1)
Owner
Gavin
Gavin
ESLint plugin about ECMAScript syntactic features.

eslint-plugin-es-x ESLint plugin which disallows each ECMAScript syntax. Forked from eslint-plugin-es. As the original repository seems no longer main

Yosuke Ota 69 Dec 6, 2022
ESLint plugin to disallow the optional-call operator

ESLint Plugin: no-optional-call Overview The no-optional-call ESLint plugin provides a single rule (non-configurable) that disallows any usage of the

Kyle Simpson 15 Sep 24, 2022
vite-react-typescript with eslint and prettier predefined settings

Vite + React + Typescript + Eslint + Prettier A starter for React with Typescript with the fast Vite and all static code testing with Eslint and forma

The Sword Breaker 315 Dec 30, 2022
Rollup + Babel + Prettier + Strict ESlint + VSCode - Enterprise grade boilerplate

Javascript package boilerplate by HackingBay Rollup + Babel + Prettier + Strict ESlint + VSCode - Enterprise grade boilerplate Minimalist js package b

HackingBay 1 Dec 28, 2021
Rollup + React + Babel + Prettier + Strict ESlint and Stylelint + Sass + VSCode + Playground app - Enterprise grade boilerplate

React package boilerplate by HackingBay Rollup + React 17 + Babel + Prettier + Strict ESlint and Stylelint + Sass + VSCode + Playground app - Enterpri

HackingBay 2 Jan 19, 2022
This package includes some opinionated configuration for ESLint.

eslint-config-float This package includes some opinionated configuration for ESLint, used at Float and friends. Installation You can install and use t

Float 2 Jan 7, 2022
🚀Starter project with Angular 13, Ngx-admin, NestJS, Nx Workspace, Jest, Cypress, ESLint & Prettier 🚀

Angular 13 + Ngx-admin + NestJs + NX Starter project with Angular 13, Ngx-admin, NestJs, Nx Workspace, Jest, Cypress, ESLint & Prettier Features ✅ Ang

Wilfried 49 Jan 4, 2023
This package includes the sensible ESLint configuration used by our team

TypeScript + Prettier ESLint configuration for CasterlyApp team (and others)

Casterly 2 Jan 26, 2022
Shared eslint configuration for Strapi v4 plugins & applications.

This package is currently under development and should be consider ALPHA in terms of state. I/We are currently accepting contributions and/or dedicated contributors to help develop and maintain this package.

Strapi Community 6 Oct 28, 2022
An ESLint shareable configuration that used in our projects.

eslint-config An ESLint shareable configuration that used in our projects. Install npm install -D @rahagia/eslint-config or with yarn yarn add -D @rah

Organisasi Bahagia 5 Apr 18, 2022