定制 automattic/eslint-changed 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

automattic/eslint-changed

Composer 安装命令:

composer require automattic/eslint-changed

包简介

description

README 文档

README

Run ESLint on files and only report new warnings and errors.

Installation

Install via your favorite JS package manager. Note the peer dependency on eslint.

For example,

npm install @automattic/eslint-changed eslint

Usage

To identify the changes, eslint-changed needs the ESLint output for both the old and new versions of the file, as well as the diff between them. If you use git, it can determine this automatically. Otherwise, you can supply the necessary information manually.

Options used in both modes are:

  • --debug: Enable debug output.
  • --ext <list>: Comma-separated list of JavaScript file extensions. Ignored if files are listed. (default: ".js")
  • --format <name>: ESLint format to use for output. (default: "stylish")
  • --in-diff-only: Only include messages on lines changed in the diff. This may miss things like deleting a var that leads to a new no-undef elsewhere.

Manual diff

The following options are used with manual mode:

  • --diff <file>: A file containing the unified diff of the changes.
  • --diff-base <dir>: Base directory the diff is relative to. Defaults to the current directory.
  • --eslint-orig <file>: A file containing the JSON output of eslint on the unchanged files.
  • --eslint-new <file>: A file containing the JSON output of eslint on the changed files.

With git

In git mode, eslint-changed needs to be able to run git. If this is not available by that name in the shell path, set environment variable GIT as appropriate.

The following options are used with git mode:

  • --git: Signify that you're using git mode.
  • --git-staged: Compare the staged version to the HEAD version (this is the default).
  • --git-unstaged: Compare the working copy version to the staged (or HEAD) version.
  • --git-base <ref>: Compare the HEAD version to the HEAD of a different base (e.g. branch).
  • --eslint-options <name=value...>: Pass additional options for ESLint. Value is interpreted as JSON if possible, otherwise it's treated as a literal string. See https://eslint.org/docs/latest/integrate/nodejs-api#-new-eslintoptions (or the equivalent for the version of eslint in use) for details on available options.

Examples

This will compare the staged changes with HEAD.

npx @automattic/eslint-changed --git

This will compare HEAD with origin/trunk.

npx @automattic/eslint-changed --git --git-base origin/trunk

This does much the same as the previous example, but manually. If you're using something other than git, you might do something like this.

# Produce a diff.
git diff origin/trunk...HEAD > /tmp/diff

# Check out the merge-base of origin/trunk and HEAD.
git checkout origin/trunk...HEAD

# Run ESLint.
npx eslint --format=json . > /tmp/eslint.orig.json

# Go back to HEAD.
git checkout -

# Run ESLint again.
npx eslint --format=json . > /tmp/eslint.new.json

# Run eslint-changed.
npx @automattic/eslint-changed --diff /tmp/diff --eslint-orig /tmp/eslint.orig.json --eslint=new /tmp/eslint.new.json

Note that, to be exactly the same as the above, you'd want to extract the list of files from the diff instead of linting everything. But this will work.

This will compare file.js in HEAD with origin/trunk, with the equivalent of passing --flag v10_config_lookup_from_file to eslint.

npx @automattic/eslint-changed --git --git-base origin/trunk --eslint-options flags='["v10_config_lookup_from_file"]' -- file.js

Inspiration

We had been using phpcs-changed for a while, and wanted the same thing for ESLint.

automattic/eslint-changed 适用场景与选型建议

automattic/eslint-changed 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 2.37k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 automattic/eslint-changed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 automattic/eslint-changed 我们能提供哪些服务?
定制开发 / 二次开发

基于 automattic/eslint-changed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 1
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2021-08-13