GithubHelp home page GithubHelp logo

sunny-117 / eslint-plugin-reviewget Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 701 KB

🚀当用户使用 getXXX get开头的函数的时候 如果不返回值的话 那么就会报错 🐛可以 fix 🎉用户可以自行配置是否 fix

License: MIT License

JavaScript 100.00%

eslint-plugin-reviewget's Introduction

eslint-plugin-reviewget

开发思路参考:git commit

Feature

  • 当用户使用 getXXX get开头的函数的时候 如果不返回值的话 那么就会报错
  • 可以 fix
  • 用户可以自行配置是否 fix

Base Environment

eslint-plugin-xxx: 插件命名规范

测试插件:

1. demo测试

pnpm init -y
pnpm i eslint -D
pnpx eslint --init

配置 .eslintrc.js

module.exports = {
    "root": true,
    "env": {
        "browser": true,
        "commonjs": true,
        "es2021": true
    },
    "overrides": [
    ],
    "parserOptions": {
        "ecmaVersion": "latest"
    },
    "plugins": [
        "reviewget"
    ],
    "rules": {
        "reviewget/get": ["warn"]
    }
}

eslint-plugin-reviewget/example下安装本地写好的插件

pnpm i ../

2. 单元测试环境

创建reviewget.spec.js文件

const { RuleTester } = require("eslint")
const { rules } = require('./index')

const ruleTester = new RuleTester()
ruleTester.run('get', rules.get, {
    valid: [
        {
            name: 'success',
            code: `function getName(){ return ''}`
        }
    ],
    invalid: [


    ]
})

watch 模式, 利用 mocha 测试库

pnpm test -- --watch

Finish

对于一个eslint来说,对 ast 分析 ,从信息里面提取出需要的东西,检测是否符合要求

开发完成插件后,在example中进行使用之前,需要进行如下操作:

Publish

先打包,发包的时候使用打包结果

// package.json 
"files": [
    "index.js",
    "package.json"
],
// 表示发布上去的文件
npm login --registry https://registry.npmjs.org 
npm publish --registry https://registry.npmjs.org 

在example里面直接install

// 删除
 "dependencies": {
    "eslint-plugin-reviewget": "link:.."
  }

Problem

vscode保存时候自动完成eslint补全

Reference

eslint-plugin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.