• Stars
    star
    2,614
  • Rank 16,807 (Top 0.4 %)
  • Language
    JavaScript
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Progressive ESLint config for your React/Vue/TypeScript projects

eslint-config-alloy

Build Status Build Status npm package npm downloads

English / 简体中文

NEWS: eslint-config-alloy now support TypeScript 5.0
If you are using TypeScript 4.0, please npm install --save-dev eslint-config-alloy@4

NEWS: eslint-config-alloy now support Vue 3.0
If you are using Vue 2.0, please npm install --save-dev eslint-config-alloy@3


The AlloyTeam ESLint config is not only a progressive ESLint config for your React/Vue/TypeScript projects but also the best reference for configuring your personalized ESLint rules.

Quick start

Please choose the following configuration based on the technology stack used by your project:

Philosophy

  • Let Prettier handle style-related rules
  • Inherit ESLint's philosophy and help everyone build their own rules
  • High degree of automation: advanced rules management, test as a document, as a website
  • Keep up with the times, follow up the latest rules as soon as possible
Details

Let Prettier handle style-related rules

Prettier is a code formatting tool that offers fewer options but is more professional than the style-related rules in ESLint.

Now that Prettier has become a necessary tool in front-end projects, eslint-config-alloy does not need to maintain the style-related rules in ESLint anymore, so we completely removed all Prettier related rules in the v3 version, and use ESLint to check logical errors which it's good at.

As for whether two spaces or four spaces are used for indentation and whether there is a semicolon at the end, you can configure it in the project's .prettierrc.js. Of course, we also provide a recommended Prettier configuration for your reference.

Inherit ESLint's philosophy and help everyone build their own rules

Don't you remember how ESLint defeated JSHint and became the most popular JS code inspection tool? It is because of the plugin and configuration that ESLint advocates, which meets the individual needs of different technology stacks of different teams.

Therefore, eslint-config-alloy also inherits the philosophy of ESLint. It will not emphasize the need to use our config. Instead, we help you to make your config by reference our completed documents, examples, tests, websites, etc.

High degree of automation: advanced rules management, test as a document, as a website

Relentless push automation

eslint-config-alloy uses a high degree of automation to hand over all processes that can be managed automatically, including:

  • Through GitHub Actions, automatically weekly check whether ESLint and related plugins have new versions and if there are new rules in the new version which we need to add
  • Automatically check if our rules include Prettier rules
  • Automatically check if our rules include deprecated rules

Also, through automated scripts, we can even divide and conquer thousands of ESLint configuration files, and each rule is managed in a separate directory:

  • Integrate single configurations into a final configuration through a script
  • The description and reason in single configurations are built into a website by a script for everyone to view
  • The bad.js and good.js in a single configuration are output to website by script, and you can even see the error message (which are run in a real ESLint script) in the bad.js of website

The benefits of this are very obvious — test as a document, as a website. We can maintain the rules and tests in one place. Other tasks are handed over to an automated script, which greatly reduces the maintenance cost. In short, when we have a new rule to add, we only need to write three files test/index/another-rule/.eslintrc.js, test/index/another-rule/bad.js, test/index/another-rule/good.js.

Keep up with the times, follow up the latest rules as soon as possible

ESLint is updated very quickly, there is a new version almost every week, sometimes there are new rules, sometimes existing rules are deprecated, and related plug-ins (React/Vue/TypeScript) will be updated from time to time. Without automation tools, it is difficult to follow up.

And eslint-config-alloy, through the above-mentioned automated tools, can receive notifications from GitHub Actions at the first time, telling us which rules need to be added:

In this way, we can follow the latest rules in a time when the front-end community is changing rapidly, and always keep the vitality and advanced of eslint-config-alloy.

Usage

Built-in

npm install --save-dev eslint @babel/core @babel/eslint-parser eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

React

npm install --save-dev eslint @babel/core @babel/eslint-parser @babel/preset-react@latest eslint-plugin-react eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/react',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

Vue

npm install --save-dev eslint @babel/core @babel/eslint-parser vue-eslint-parser eslint-plugin-vue eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/vue',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

TypeScript

npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/typescript',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

TypeScript React

npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/react',
    'alloy/typescript',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

TypeScript Vue

It is recommended to use npm init vue@3 to create a project with Vue, TypeScript and ESLint integrated, and then refer to this example to adjust its ESLint configuration.

The conventional way is as follows:

npm install --save-dev @babel/core @babel/eslint-parser @typescript-eslint/eslint-plugin @typescript-eslint/parser @vue/eslint-config-typescript eslint eslint-config-alloy eslint-plugin-vue vue-eslint-parser

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: ['alloy', 'alloy/vue', 'alloy/typescript'],
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: {
      js: '@babel/eslint-parser',
      jsx: '@babel/eslint-parser',

      ts: '@typescript-eslint/parser',
      tsx: '@typescript-eslint/parser',

      // Leave the template parser unspecified, so that it could be determined by `<script lang="...">`
    },
  },
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

Troubleshooting

With VSCode

Just install the ESLint extension in VSCode.

Refer to here to configure the extension.

Autofix ESLint errors on save

If you want to enable auto-fix-on-save, you need to set your .vscode/settings.json like this:

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
}

With Prettier

eslint-config-alloy does not include any style-related rules in v3, so there is no need to install eslint-config-prettier. Just install prettier and related VSCode plugins.

AlloyTeam provides a set of Prettier configuration, you can create a .prettierrc to reuse it:

"eslint-config-alloy/.prettierrc.js"

A best practice for VSCode is to auto format code with Prettier and autofix errors with ESLint by setting .vscode/settings.json to this:

{
  "files.eol": "\n",
  "editor.tabSize": 2,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

Scripts

# install dependencies
pnpm i
# build eslintrc like index.js, react.js, etc.
pnpm build
# run tests
pnpm test
# autofix prettier errors
pnpm prettier:fix
# check if all rules are covered
pnpm rulesCoverage
# publish new version
npm version <major|minor|patch>
git push --follow-tags
npm publish

Q & A

Why another ESLint config

Our team initially used Airbnb rules, but because it was too strict, some rules still needed to be personalized, which led to more and more changes in the future and finally decided to maintain a new set. After more than four years of maintaining, eslint-config-alloy is now very mature and progressive and has been welcomed by many teams inside and outside the company.

Why not standard

The standard specification believes that everyone should not waste time in personalized specifications, but the entire community should unify a specification. This statement makes some sense, but it runs against the ESLint's design philosophy. Don't you remember how ESLint defeated JSHint and became the most popular JS code inspection tool? It is because of the plugin and configuration that ESLint advocates, which meets the individual needs of different technology stacks of different teams.

Therefore, eslint-config-alloy also inherits the philosophy of ESLint. It will not force you to use our config. Instead, we help you to make your config by referencing our examples, tests, websites and so on.

Why not airbnb

  1. eslint-config-alloy has officially maintained vue, typescript and react+typescript rules. In contrast, airbnb's vue and typescript are maintained by third parties.
  2. Progressive to ensure that we can keep up with the times, as mentioned earlier
  3. Convenient personalization, including explanations and website examples

Looks good, but I still choose airbnb

It's okay, eslint-config-alloy believes that different teams and projects can have different configurations from the design concept. Although you choose to use airbnb, you can still come to our website when you have personalized configuration needs.

Reference

More Repositories

1

Mars

腾讯移动 Web 前端知识库
9,586
star
2

AlloyFinger

Super tiny size multi-touch gestures library for the web.    You can touch this →
JavaScript
3,403
star
3

AlloyImage

基于HTML5的专业级图像处理开源引擎。An image processing lib based on html5.
JavaScript
3,002
star
4

PhyTouch

Smooth scrolling, rotation, pull to refresh, page transition and any motion for the web - 丝般顺滑的触摸运动方案
JavaScript
2,954
star
5

AlloyLever

1kb js library contains development debugging, error monitoring and reporting, user problem localization features - 1KB代码搞定开发调试发布,错误监控上报,用户问题定位
JavaScript
1,381
star
6

curvejs

Made curve a dancer in HTML5 canvas - 魔幻线条
JavaScript
1,300
star
7

CodeGuide

Alloyteam代码规范
HTML
1,275
star
8

JX

JX(Javascript eXtension tools) 是腾讯AlloyTeam推出的模块化、非侵入式Web前端框架,适合构建和组织工业级大规模、高效率的 Web App
JavaScript
1,156
star
9

AlloyCrop

The best and tiny size mobile cropping component - 做最好且最小的移动裁剪组件
JavaScript
940
star
10

Rythem

a fiddler-like project using Qt
C++
878
star
11

alloyteam.github.com

腾讯 AlloyTeam 开源项目官网 - 我们的愿景: 成为业界卓越的Web团队!
JavaScript
846
star
12

alloy-worker

面向事务的高可用 Web Worker 通信框架
TypeScript
635
star
13

AlloyStick

AlloyStick 骨骼动画引擎 - 腾讯 AlloyTeam
JavaScript
430
star
14

Rosin

A tool for web developers debug mobile page with fiddler. http://alloyteam.github.io/Rosin/
C#
310
star
15

StreetFighter

街霸StreetFighter
JavaScript
301
star
16

webtop

HTML5 本地App开发引擎
C++
290
star
17

AlloyPhoto

JavaScript
276
star
18

gopng

GoPng - a HTML5 css sprite generator with cool feature.
272
star
19

sodajs

Light weight but powerful template engine for JavaScript
JavaScript
256
star
20

tslint-config-alloy

AlloyTeam TSLint 规则
JavaScript
205
star
21

JXAnimate

基于CSS3的并行动画、声音引擎 - JX.Animate
CSS
192
star
22

AlloyTimer

AlloyTimer定时器 - 番茄工作法的时间管理应用
JavaScript
190
star
23

JMUI

移动Web开发UI组件库
JavaScript
178
star
24

AlloyViewer

H5图片查看器—Imageview component built with react
JavaScript
176
star
25

JM

面向Mobile的极致JavaScript库
JavaScript
141
star
26

AlloyDesigner

AlloyDesigner是一款致力于提高前端生产效率的浏览器内运行工具,AlloyDesigner + Chrome F12(Especially with WorkSpace) 打造前端新的开发和测试模式
138
star
27

omi-cli

Create website with no build configuration - 创建网站无需任何配置
JavaScript
126
star
28

AlloyPullRefresh

JavaScript
119
star
29

Spirit

腾讯移动Web整体解决方案
CSS
117
star
30

CodeTank

CodeTank(代码坦克)是全世界首款 Javascript 程序员的游戏, 由腾讯 AlloyTeam 用 HTML5、Javascript 等 Web 新技术来构建一个基于互联网的智能坦克机器人战斗仿真引擎
112
star
31

AlloyClip

A PC & Mobile Image Clip Kit based on AlloyImage
JavaScript
108
star
32

MLogger

一个浮在页面上的日志查看工具
JavaScript
100
star
33

Abstract.js

Abstract.js is a web framework for fast development
JavaScript
46
star
34

AlloyLint

apply eslint autofix but keep last author info in git blame。运行 eslint 的自动修复,但是保留最后修改人的信息
TypeScript
41
star
35

AlloyFlow

made workflow simple
JavaScript
39
star
36

AlloyTicker

The Master of Time          DEMO
JavaScript
25
star
37

netural

JavaScript前向神经网络(推理)和反向传播(训练)的实现
JavaScript
21
star