@glasshouse/style-guide

中文文档
1.1.2发布于 2025/03/21MITTypeScriptCommonJS近 30 天下载 4490

Glasshouse's engineering style guide

原始使用文档
文档目录9 节
  1. Installation
  2. Prettier
  3. ESLint
  4. Configuration (new: eslint.config.js)
  5. Configuration (legacy: .eslintrc*)
  6. Configuring ESLint (new: eslint.config.js) for TypeScript
  7. Configuring ESLint (legacy: .eslintrc*) for TypeScript
  8. TypeScript
  9. Stylelint

GVSStack

This repository includes configs for popular linting and styling tools, extended from @vercel/style-guide. See Vercel's style guide.

The following configs are available:

Installation

All configs are contained in one package, @glasshouse/style-guide. To install:

# If you use npm
npm i --save-dev @glasshouse/style-guide

# If you use pnpm
pnpm i --save-dev @glasshouse/style-guide

# If you use Yarn
yarn add --dev @glasshouse/style-guide

Prettier

Note: Prettier is a peer-dependency of this package, and should be installed at the root of your project. See: Install · Prettier

To use the shared Prettier config, set the following in package.json:

{
  "prettier": "@glasshouse/style-guide/prettier"
}

ESLint

:information_source: ESLint is a peer-dependency of this package, and should be installed at the root of your project.

See: Getting Started with ESLint - ESLint - Pluggable JavaScript Linter

Configuration (new: eslint.config.js)

:warning: BREAKING CHANGE:

  • ESLint minimum version is now 9.0.0.
  • Refactored configs using new flat config format.
  • Moved all configs into a single object default export. You can now import new flat configs by the example below.
import gvseslint from '@glasshouse/style-guide/eslint

export default [
  ...gvseslint.configs.flat.node,
]

:information_source: These ESLint configs are based from @vercel/style-guide/eslint

The following configs are available:

  • browser
  • node
  • next (requires @next/eslint-plugin-next to be installed at the same version as next)
  • react
  • typescript (requires typescript to be installed and additional configuration)

For example, use the shared ESLint config(s) in a Next.js project, set the following in eslint.config.js (or any other ESLint configuration file format):

import gvseslint from '@glasshouse/style-guide/eslint';

/** @type {import('eslint').Linter.Config[]} */
export default [
    ...gvseslint.configs.flat.browser,
    ...gvseslint.configs.flat.react,
    ...gvseslint.configs.flat.typescript,
    ...gvseslint.configs.flat.next,
    // ...
];

Configuration (legacy: .eslintrc*)

:warning: This is compatible only with version 0.3.1 or earlier of the package. The latest version (1.0.0) introduces breaking changes, which are not supported.

All configs require typescript to be installed and additional configuration.

The following configs are available:

  • @glasshouse/style-guide/eslint/base
  • @glasshouse/style-guide/eslint/library
  • @glasshouse/style-guide/eslint/react
  • @glasshouse/style-guide/eslint/next (requires @next/eslint-plugin-next to be installed at the same version as next)

:information_source: You'll need to use require.resolve to provide ESLint with absolute paths, due to an issue around ESLint config resolution (see eslint/eslint#9188).

For example, use the @glasshouse/style-guide/eslint/next in a Next.js project, set the following in .eslintrc.js (or any other ESLint config file format):

/** @type {import('eslint').Linter.Config} */
module.exports = {
    extends: [require.resolve('@glasshouse/style-guide/eslint/next')],
};

Configuring ESLint (new: eslint.config.js) for TypeScript

Some of the rules enabled in the TypeScript config require additional type information, you'll need to provide the path to your tsconfig.json.

For more information, see: https://typescript-eslint.io/getting-started/typed-linting

export default [
    //...,
    ...gvseslint.configs.flat.typescript,
    {
        languageOptions: {
            parserOptions: {
                projectService: true,
                tsconfigRootDir: import.meta.dirname,
            },
        },
    },
];

Configuring ESLint (legacy: .eslintrc*) for TypeScript

const { resolve } = require('node:path');

const project = resolve(__dirname, 'tsconfig.json');

module.exports = {
    root: true,
    extends: [require.resolve('glasshouse/style-guide/eslint/next')],
    parserOptions: {
        project,
    },
    settings: {
        'import/resolver': {
            typescript: {
                project,
            },
        },
    },
};

TypeScript

This style guide provides multiple TypeScript configs for different project types.

To use the shared TypeScript config, set the following in tsconfig.json.

{
    "extends": "@glasshouse/style-guide/typescript/react-library"
}

The base TypeScript config is also available as @glasshouse/style-guide/typescript which only specifies a set of general rules:

{
    "extends": "@glasshouse/style-guide/typescript"
}

Stylelint

:information_source: Stylelint is a peer-dependency of this package, and should be installed at the root of your project.

See: Stylelint

This style guide provides a shared Stylelint config with extended SCSS/SASS linting rules support.

To use this config, set the following in stylelint.config.mjs (or any other Stylelint config file format):

/** @type {import('stylelint').Config} */
export default {
    extends: ['@glasshouse/style-guide/stylelint'],
};

版本与发布记录

@glasshouse/style-guide 共发布 21 个版本,首次发布于 2024/07/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.2latest2025/03/211.7 年前
1.1.12025/03/091.7 年前
1.1.02025/03/091.7 年前
1.0.82025/03/091.7 年前
1.0.52025/03/061.7 年前
1.0.42024/12/201.9 年前

关于 @glasshouse/style-guide 的常见问题

@glasshouse/style-guide 是什么?

Glasshouse's engineering style guide

如何安装 @glasshouse/style-guide?

在项目目录运行 npm install @glasshouse/style-guide,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typescript(>=5.8.2)、eslint-config-prettier(>=10.1.1)、@typescript-eslint/parser(>=8.26.0)、prettier-plugin-sort-json(>=4.1.1)、stylelint-config-standard(>=37.0.0)、prettier-plugin-packagejson(>=2.5.10)、prettier-plugin-tailwindcss(>=0.6.11)、eslint-plugin-react-compiler(>=19.0.0-beta-37ed2a7-20241206)、stylelint-config-css-modules(>=4.4.0)、stylelint-config-recess-order(>=6.0.0)、@typescript-eslint/eslint-plugin(>=8.26.0)、eslint-plugin-simple-import-sort(>=12.1.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@glasshouse/style-guide 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@glasshouse/style-guide 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@glasshouse/style-guide 可以商用吗?

@glasshouse/style-guide 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@glasshouse/style-guide 的下载量有多少?

根据 npm 官方下载统计,@glasshouse/style-guide 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,490 次,日均约 150 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@glasshouse/style-guide 还在维护吗?

最新版本 1.1.2 发布于 2025/03/21(1.7 年前);至今共发布 21 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/07/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。