npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magic-lint

v2.3.0

Published

configless lint tool all in one

Downloads

75

Readme

magic-lint

提供代码规范,同时支持代码美化,commit检查功能。

内部集成了 eslintstylelintprettierlint-stagedcommitlint等,简化项目初始化配置流程。

注意!!!需要自己在项目中配置.eslintrc.stylelintrc.prettierrccommitlint.config.js

安装

npm install magic-lint --save-dev

参数


Usage: magic-lint [options] file.js [file.js] [dir]

# 提交commit触发校验
magic-lint --commit --commit.config=./../commitlint.config.js

# 指定路径 lint
magic-lint --prettier --eslint --stylelint src/

# 只对提交的代码进行 lint
magic-lint --staged --prettier --eslint --stylelint

# 给eslint、prettier添加执行参数
magic-lint --eslint.debug  -s.formatter=json -p.no-semi

Options:
--commit, -C              check commit msg                                    [boolean] [default: false]
--staged, -S              only lint git staged files                          [boolean] [default: false]
--prettier, -p            format code with prettier                           [boolean] [default: false]
--eslint, -e              enable lint javascript                              [boolean] [default: false]
--stylelint, --style, -s  enable lint style                                   [boolean] [default: false]
--fix, -f                 fix all eslint and stylelint auto-fixable problems  [boolean] [default: false]
--quiet, -q               report errors only                                  [boolean] [default: false]
--cwd                     current working directory                           [default: process.cwd()]
--harmony                 work as prettier-eslint                             [boolean] [default: true]

参数说明

harmony

和谐模式,目的是处理prettiereslint的冲突问题,会和prettier-eslint一样,先用prettier处理,再用eslint处理。

默认开启。

使用教程

husky最新版(v7及以上)为例:

1. 初始化husky

npx husky-init && npm install       # npm
npx husky-init && yarn              # Yarn 1
yarn dlx husky-init --yarn2 && yarn # Yarn 2

脚本执行会在package.json添加一个示例pre-commit钩子,默认会执行npm test命令。

如果要修改的话打开.husky/pre-commit移除npm test

2. 新增钩子

// 比如在commit-msg时执行命令
npx husky add .husky/commit-msg '你要执行的命令'

注意:如果是Windows用户使用npx husky add ...可能会遇到注意,请使用node node_modules/.bin/husky add ...命令替代。

husky现在采用了Shell脚本的方式,实现是更自由了,但是也没法和之前无缝使用了,请仔细阅读。

  • $(dirname "$0")指代的是hook所在的目录

检查commit

编辑.husky/commit-msg文件,添加:

npx --no-install magic-lint --commit --commit.config "$(dirname "$0")/../commitlint.config.js" --commit.edit "$1"

eslint格式化

编辑.husky/pre-msg文件,添加:

npx --no-install magic-lint --staged --eslint --stylelint --prettier --fix"

husky 旧版本

搭配husky食用,在 package.json 添加

"husky": {
  "hooks": {
    "pre-commit": "magic-lint --staged --eslint --stylelint --prettier --fix",
    "commit-msg": "magic-lint --commit"
  }
}

另外迁移指南请看Migrate from v4 to v7