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

@the1812/eslint-config

v1.2.1

Published

按照个人喜好 ([@the1812](https://github.com/the1812/)) 配置的 ESLint Config. 可用于 JavaScript, TypeScript 和 Vue 3 项目.

Downloads

79

Readme

@the1812/eslint-config

按照个人喜好 (@the1812) 配置的 ESLint Config. 可用于 JavaScript, TypeScript 和 Vue 3 项目.

主要特性

集成 prettier

一个命令搞定代码风格和格式化, 无需担心互相冲突.

# ✔️
eslint . --ext .ts,.vue

# ❌
eslint . --ext .ts,.vue
prettier . --write

内置 prettier 的配置为:

{
  semi: false,
  singleQuote: true,
  trailingComma: 'all',
  arrowParens: 'avoid',
  endOfLine: 'auto',
  printWidth: 100,
}

禁止先使用再声明

除纯类型引用以外, 所有定义必须先声明再使用.

// ✔️
function name() { }
const a = name()

// ❌
const a = name()
function name() { }

禁止 C 风格命名

跟丑陋的全大写和下划线说再见.

// ✔️
const SomeConstant = 1
function someFunction (param) {
  const clonedParam = clone(param)
}
let someVar = 2

// ❌
const SOME_CONSTANT = 1
function someFunction (param) {
  const _param = clone(param)
}
let some_var = 2

减少重复代码

同名属性优先解构, 同名参数省略冒号.

// ✔️
const { prop } = obj
const param = {
  prop,
}

// ❌
const prop = obj.prop
const param = {
  prop: prop,
}

禁止默认导出

有意义的名字才是好名字.

// ✔️
export const createApp = () => { }

// ❌
const createApp = () => { }
export default createApp

[!NOTE] 其他常见第三方库的配置文件仍然允许默认导出. 例如 webpack.config.ts, vite.config.ts 等.

禁止省略大括号

控制流语句内容必须有大括号.

// ✔️
if (foo) {
  doSomething()
}
while (bar) {
  doSomething()
}
for (let i = 0; i < items.length; i+=1) {
  doSomething()
}

// ❌
if (foo) doSomething()
while (bar) doSomething()
for (let i = 0; i < items.length; i+=1)
  doSomething()

使用方式

安装

需要安装包本身和所有的 peerDependencies.

pnpm install -D eslint @the1812/eslint-config @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-airbnb-base eslint-config-prettier eslint-plugin-import eslint-plugin-prettier eslint-plugin-vue

也可以使用 install-peerdeps 来简化命令.

pnpx install-peerdeps @the1812/eslint-config -D -P

配置

在 ESLint 配置文件中添加任意一种配置.

适用于 JavaScript 或 TypeScript 项目

// .eslintrc.cjs
module.exports = {
  extends: ['@the1812/eslint-config'],
  // ...
}

适用于 Vue 3 项目

// .eslintrc.cjs
module.exports = {
  extends: ['@the1812/eslint-config/vue'],
  // ...
}