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

@cs-magic/prettier-config

v0.2.0

Published

Shared Prettier configurations for CS Magic projects

Downloads

122

Readme

@cs-magic/prettier-config

CS Magic 项目的共享 Prettier 配置。

安装

npm install --save-dev @cs-magic/prettier-config

使用

基础配置

package.json 中:

{
  "prettier": "@cs-magic/prettier-config"
}

或者在 .prettierrc 中:

module.exports = require('@cs-magic/prettier-config/src')

TypeScript 项目

// .prettierrc
module.exports = require('@cs-magic/prettier-config/src/typescript')

Tailwind CSS 项目

// .prettierrc
module.exports = require('@cs-magic/prettier-config/src/tailwind')

与 ESLint 集成

如果你使用 @cs-magic/eslint-config,已经包含了 Prettier 配置。只需在 .eslintrc.js 中:

module.exports = {
  extends: [
    '@cs-magic/eslint-config/react', // 或其他配置
    '@cs-magic/eslint-config/prettier',
  ],
}

如果你想单独集成:

  1. 安装依赖:
npm install --save-dev eslint-config-prettier eslint-plugin-prettier
  1. 配置 ESLint:
// .eslintrc.js
module.exports = {
  extends: [
    // 其他配置...
    'plugin:prettier/recommended',
  ],
}

自定义配置

创建 .prettierrc 文件来覆盖默认配置:

module.exports = {
  ...require('@cs-magic/prettier-config/src'),
  // 你的自定义配置
  semi: true,
  tabWidth: 4,
}

配置说明

基础配置特点

  • 行宽限制:100 字符
  • 使用空格而非 Tab
  • 无分号
  • 单引号
  • ES5 尾逗号
  • 箭头函数参数自动括号

TypeScript 配置特点

  • 自动组织导入语句
  • 预设的导入顺序规则
  • 分组之间自动添加空行

Tailwind 配置特点

  • 类名自动排序
  • 支持多种类名属性
  • 支持常用的工具函数

常见问题

1. 格式化特定文件

prettier --write "src/**/*.{js,jsx,ts,tsx}"

2. 检查格式是否正确

prettier --check "src/**/*.{js,jsx,ts,tsx}"

3. 在 VS Code 中使用

  1. 安装 Prettier 插件
  2. 设置为默认格式化工具:
{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true
}