Vercel's engineering style guide

Overview

The Vercel Style Guide

This repository is the home of Vercel's style guide, which includes configs for popular linting and styling tools.

The following configs are available, and are designed to be used together.

Contributing

Please read our contributing guide before creating a pull request.

Prettier

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

See: https://prettier.io/docs/en/install.html

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

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

ESLint

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

See: https://eslint.org/docs/user-guide/getting-started#installation-and-usage

This ESLint config is designed to be composable. The base configs, @vercel/style-guide/eslint/node or @vercel/style-guide/eslint/browser, set up a project for JavaScript and should always be first in extends.

The following optional configs are available:

  • @vercel/style-guide/eslint/jest
  • @vercel/style-guide/eslint/next (requires @vercel/style-guide/eslint/react)
  • @vercel/style-guide/eslint/react
  • @vercel/style-guide/eslint/typescript (requires additional configuration)

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 shared ESLint config(s) in a Next.js project, set the following in .eslintrc.js.

module.exports = {
  extends: [
    require.resolve('@vercel/style-guide/eslint/browser'),
    require.resolve('@vercel/style-guide/eslint/react'),
    require.resolve('@vercel/style-guide/eslint/next'),
  ],
};

Configuring ESLint 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/docs/linting/type-linting

module.exports = {
  extends: [
    require.resolve('@vercel/style-guide/eslint/node'),
    require.resolve('@vercel/style-guide/eslint/typescript'),
  ],
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
};

Scoped configuration with overrides

ESLint configs can be scoped to include/exclude specific paths. This ensures that rules don't "leak" to places where those rules don't apply.

In this example, Jest rules are only being applied to files matching Jest's default test match pattern.

module.exports = {
  extends: [require.resolve('@vercel/style-guide/eslint/node')],
  overrides: [
    {
      files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
      extends: [require.resolve('@vercel/style-guide/eslint/jest')],
    },
  ],
};

A note on file extensions

By default, all TypeScript rules are scoped to files ending with .ts and .tsx.

However, when using overrides, file extensions must be included or ESLint will only include .js files.

module.exports = {
  overrides: [
    { files: [`directory/**/*.[jt]s?(x)`], rules: { 'my-rule': 'off' } },
  ],
};

TypeScript

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

{
  "extends": "@vercel/style-guide/typescript"
}
Comments
  • `it.only()` or `describe.only()` should fail lint

    `it.only()` or `describe.only()` should fail lint

    Sometimes developers will use it.only() or describe.only() to run a single jest test locally but accidentally commit it to a PR and thus skip all tests except the one they're working on.

    We should probably disable it.skip() as well for the same reason.

    eslint 
    opened by styfle 7
  • Enable `no-constant-binary-expression`

    Enable `no-constant-binary-expression`

    When we upgrade ESLint to 8.14.0 we should enable this rule: https://eslint.org/docs/rules/no-constant-binary-expression

    I tried enabling it and found two instances of easy to fix bugs.

    Saw this recommended in this tweet

    eslint released on @canary released 
    opened by codybrouwers 3
  • Adjust options for `@typescript-eslint/no-misused-promises` to allow promises as JSX attributes

    Adjust options for `@typescript-eslint/no-misused-promises` to allow promises as JSX attributes

    We are currently using the default options of this recommended rule @typescript-eslint/no-misused-promises, but it results in errors trying to pass functions that return promises as React props to components that are only expecting a () => void type, including built in React event handlers like onClick.

    image

    This fix for this is to update the options for the rule disable checking void returns for attributes like this:

      "@typescript-eslint/no-misused-promises": [
        "error",
        {
          "checksVoidReturn": {
            "arguments": false,
            "attributes": true
          }
        }
      ]
    
    eslint 
    opened by codybrouwers 3
  • Prefer inline type imports

    Prefer inline type imports

    https://github.com/import-js/eslint-plugin-import/issues/2469

    Would much prefer

    import { type Foo } from 'some/package` 
    

    over

    import type { Foo } from 'some/package`
    

    as it keeps the single import line, and all related entries together.

    https://github.com/import-js/eslint-plugin-import/pull/2475 looks like it may block this though.

    opened by dglsparsons 2
  • Enable `import/no-extraneous-dependencies`

    Enable `import/no-extraneous-dependencies`

    https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md

    We should also enable the options includeInternal and includeTypes.

    eslint released on @canary released 
    opened by mrmckeb 2
  • Add rule for `node:` protocol prefix

    Add rule for `node:` protocol prefix

    As this is now widely supported, we can probably enable this. It's auto-fixable too.

    https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md

    eslint released on @canary released 
    opened by mrmckeb 2
  • Enforce consistent enum usage

    Enforce consistent enum usage

    We see people setting enum keys in const-style sometimes, but would prefer to standardise around the approach used in docs.

    This can be set via: https://typescript-eslint.io/rules/naming-convention

    Incorrect

    enum Colors {
      RED = 'rgb(255, 0, 0)',
      NOT_RED = 'rgb(0, 255, 255)',
    }
    
    enum COLORS { /* ... */ }
    

    Correct

    enum Colors {
      Red = 'rgb(255, 0, 0)',
      NotRed = 'rgb(0, 255, 255)',
    }
    

    See:

    • https://www.typescriptlang.org/docs/handbook/enums.html
    • https://basarat.gitbook.io/typescript/type-system/enums
    eslint released on @canary released 
    opened by mrmckeb 2
  • Improve custom component definitions

    Improve custom component definitions

    We currently hardcode some custom components here, including this copy-paste mistake. https://github.com/vercel/style-guide/blob/canary/eslint/rules/next/jsx-a11y.js#L14

    We need to find a more flexible approach to this.

    One solution might be to generate an ESLint config via a function.

    bug eslint released on @canary released 
    opened by mrmckeb 2
  • Enable additional Jest rules

    Enable additional Jest rules

    For consistency in test files, we can consider enabling these rules:

    • jest/no-duplicate-hooks
    • jest/prefer-lowercase-title
    • jest/require-top-level-describe
    eslint released on @canary released 
    opened by mrmckeb 2
  • Support some items from `strict` TypeScript ESLint config

    Support some items from `strict` TypeScript ESLint config

    This has recently been added, and will have some crossover with our current rules: https://github.com/typescript-eslint/typescript-eslint/pull/4706

    We could consider exposing this through our own strict config.

    eslint released on @canary released 
    opened by mrmckeb 2
  • Enable allowExpressions for the react/jsx-no-useless-fragment rule

    Enable allowExpressions for the react/jsx-no-useless-fragment rule

    The react/jsx-no-useless-fragment has a allowExpressions configuration option that allows fragments that have a single expression in them like:

    const arrayOfElements = array.map((item) => {
      return <span key={item}>{item}</span>
    })
    <>
      {arrayOfElements}
    </>
    

    This is useful for TypeScript when in an component you want to return a single array of elements but if you return just the arrayOfElements then the return type of the component becomes JSX.Element[] which when you use the component produces an error:

    'Component' cannot be used as a JSX component.
      Its return type 'Element[]' is not a valid JSX element.
        Type 'Element[]' is missing the following properties from type 'ReactElement<any, any>': type, props, keyts(2786)
    

    So wrapping the array with the fragment fixes the type error but causes the ESLint error, so enabling the allowExpressions option allows for this specific use case.

    eslint released on @canary released 
    opened by codybrouwers 2
  • Adding a new preset for Testing Library

    Adding a new preset for Testing Library

    Hi there 👋. I'd like to propose a new preset for Testing Library: @vercel/style-guide/eslint/testing-library

    This preset would enable the following plugins:

    These plugins would be enabled only on testing files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],

    Thoughts? I'd be happy to create a PR to add this new preset.

    eslint 
    opened by Belco90 2
  • Considering enabling `react/no-unknown-property`

    Considering enabling `react/no-unknown-property`

    Today, when copying SVG elements from Figma to React, many of the properties will be in snake case (stroke-width) but in React we need them to be camel case (strokeWidth)

    Right now, there's no way to autofix those errors so a lot of time is spent on manually find and replacing on each SVG copied over. I've previously enabled react/no-unknown-property which will auto-fix the SVG errors:

    CleanShot 2022-10-18 at 15 49 32

    Thanks!

    enhancement eslint 
    opened by raunofreiberg 5
  • Consider enabling the `allowExpressions` option for `@typescript-eslint/explicit-function-return-type`

    Consider enabling the `allowExpressions` option for `@typescript-eslint/explicit-function-return-type`

    After enabling the @typescript-eslint/explicit-function-return-type rule, we saw lot's of return types added within expressions that already have a required return type, for example:

    <btn
      onClick={(): void => onClick()}
    >
    

    Typescript will catch this usually which makes the void return type redundant. The rule has this allowExpressions option that allows for not requiring return types in this example that we should look into enabling since it is false by default.

    The downside to this rule is it will allow you to skip specifying the return type in functions like map that you might want to only return a single type from.

    eslint 
    opened by codybrouwers 0
  • Inline recommended configs

    Inline recommended configs

    As of the latest release, we've unpinned version dependencies.

    This gives users more flexibility, and makes it easier to bump dependencies of this package (like @typescript-eslint) to support new TypeScript versions, etc.

    This also introduces the risk of a plugin releasing a change to a recommended config in a minor release, which would be breaking as code that previously passed may now fail. Worse, a rule could be broken/removed in a minor release, breaking the config. We feel these risks are very low, which is why we opted to shelve this work for future.

    eslint 
    opened by mrmckeb 0
Releases(v4.0.2)
  • v4.0.2(Sep 30, 2022)

  • v4.0.2-canary.1(Sep 30, 2022)

  • v4.0.1(Sep 29, 2022)

  • v4.0.1-canary.1(Sep 29, 2022)

  • v4.0.0(Sep 29, 2022)

    4.0.0 (2022-09-29)

    Bug Fixes

    • eslint: move to optional peer dependencies (2f4ef76), closes #16

    Features

    • eslint: disable @typescript-eslint/prefer-nullish-coalescing (0b2dcea)
    • eslint: add @typescript-eslint/strict (65f2cc9), closes #28
    • eslint: add playwright config (0180600), closes #22
    • eslint: base next on next/recommended (b1cf7b3)
    • eslint: disable react/no-unknown-property (41e2fad)
    • eslint: enable @typescript-eslint/explicit-function-return-type (19e8188)
    • eslint: enable @typescript-eslint/no-redundant-type-constituents (6109def), closes #2
    • eslint: enable import/no-extraneous-dependencies (fb5a84e), closes #37
    • eslint: enable no-constant-binary-expression (911ec00), closes #23
    • eslint: enable react/hook-use-state (b8ce4a0), closes #1
    • eslint: enable react/jsx-no-leaked-render (f2cfc32)
    • eslint: enable react/no-unstable-nested-components (4f8c60f), closes #20
    • eslint: enable unicorn/prefer-node-protocol (eb8deb2), closes #36
    • eslint: enable additional Jest style rules (db9e8ab), closes #29
    • eslint: enforce consistent enum casing (21cc24a), closes #34
    • eslint: prefer jest/unbound-method over @typescript-eslint/unbound-method (b7b3cbc)
    • eslint: remove pre-defined custom jsx-a11y components (82808ab), closes #30
    • eslint: update import/order configuration (e4d92d3), closes #13
    • eslint: update configuration for react/jsx-no-useless-fragment (d1f08d3), closes #24
    • prettier: add prettier-plugin-packagejson (1b41033), closes #4

    BREAKING CHANGES

    • eslint: Custom components for jsx-a11y must now be defined in settings.
    • eslint: Explicit function return types are now required in TypeScript files.
    • eslint: The typescript config now extends strict from @typescript-eslint.
    • eslint: Multiple new rules have been enabled (please see above).
    • eslint: You must now define custom components for eslint-plugin-jsx-a11y. For instructions, see: https://github.com/vercel/style-guide#configuring-custom-components-for-jsx-a11y
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-canary.7(Sep 29, 2022)

  • v4.0.0-canary.6(Sep 28, 2022)

  • v4.0.0-canary.5(Sep 22, 2022)

  • v4.0.0-canary.4(Sep 22, 2022)

  • v4.0.0-canary.3(Sep 22, 2022)

  • v4.0.0-canary.2(Sep 22, 2022)

  • v4.0.0-canary.1(Sep 21, 2022)

    4.0.0-canary.1 (2022-09-21)

    Bug Fixes

    • eslint: move to optional peer dependencies (2f4ef76), closes #16

    Features

    • eslint: add @typescript-eslint/strict (65f2cc9), closes #28
    • eslint: add playwright config (0180600), closes #22
    • eslint: base next on next/recommended (b1cf7b3)
    • eslint: enable @typescript-eslint/explicit-function-return-type (19e8188)
    • eslint: enable @typescript-eslint/no-redundant-type-constituents (6109def), closes #2
    • eslint: enable import/no-extraneous-dependencies (fb5a84e), closes #37
    • eslint: enable no-constant-binary-expression (911ec00), closes #23
    • eslint: enable react/hook-use-state (b8ce4a0), closes #1
    • eslint: enable react/jsx-no-leaked-render (f2cfc32)
    • eslint: enable react/no-unstable-nested-components (4f8c60f), closes #20
    • eslint: enable unicorn/prefer-node-protocol (eb8deb2), closes #36
    • eslint: enable additional Jest style rules (db9e8ab), closes #29
    • eslint: enforce consistent enum casing (21cc24a), closes #34
    • eslint: prefer jest/unbound-method over @typescript-eslint/unbound-method (b7b3cbc)
    • eslint: remove pre-defined custom jsx-a11y components (82808ab), closes #30
    • eslint: update import/order configuration (e4d92d3), closes #13
    • eslint: update configuration for react/jsx-no-useless-fragment (d1f08d3), closes #24
    • prettier: add prettier-plugin-packagejson (1b41033), closes #4

    BREAKING CHANGES

    • eslint: Custom components for jsx-a11y must now be defined in settings.
    • eslint: Explicit function return types are now required in TypeScript files.
    • eslint: Multiple new rules were added/enabled (see above feature changes).
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Mar 29, 2022)

    3.0.0 (2022-03-29)

    Features

    • deps: upgrade all dependencies
    • eslint: add no-implicit-coercion
    • eslint: create separate browser and Node entry points
    • eslint: disable capIsNew for new-cap rule
    • eslint: enable reportUnusedDisableDirectives

    BREAKING CHANGES

    • deps: eslint@^8.8.0 and prettier@^2.5.1 are now required.
    • eslint: Two new root configs have replaced the previous root config. ESLint configs that extended @vercel/style-guide/eslint should now extend @vercel/style-guide/eslint/browser or @vercel/style-guide/eslint/node.
    Source code(tar.gz)
    Source code(zip)
Owner
Vercel
Develop. Preview. Ship. Creators of Next.js.
Vercel
AirBnb Javascript Style Guide'ının Türkçe diline çevrildiği repository

Airbnb JavaScript Stil Kılavuzu() { JavaScript'e büyük ölçüde mantıklı/makul bir yaklaşım Not: Bu kılavuz sizin Babel kullandığınızı varsayar ve babel

Gökhan Kandemir 71 Dec 29, 2022
ToolJet an open-source low-code framework to build and deploy internal tools quickly without much effort from the engineering teams

ToolJet is an open-source low-code framework to build and deploy internal tools quickly without much effort from the engineering teams. You can connect to your data sources, such as databases (like PostgreSQL, MongoDB, Elasticsearch, etc), API endpoints (ToolJet supports importing OpenAPI spec & OAuth2 authorization), and external services (like Stripe, Slack, Google Sheets, Airtable) and use our pre-built UI widgets to build internal tools.

ToolJet 15.6k Jan 3, 2023
BI, API and Automation layer for your Engineering Operations data

Faros Community Edition Faros Community Edition (CE) is an open-source engineering operations platform that connects the dots between all your operati

Faros AI 272 Dec 23, 2022
This is project for 1-st course of "Software Engineering"

Сar-Racing Управління: Гравець № 1: W, A, S, D Гравець № 2: ArrowUp, ArrowLeft, ArrowDown, ArrowRight Це гонки на виживання для двох гравців. Виграє т

Volodymyr Vikulin 11 Dec 18, 2022
Incredible resources (with links) to help up-skill yourselves on various fields. Resources like programming, designing, engineering and much more and completely Open Source.

Shiryoku Incredible resources (with links) to help up-skill yourselves on various fields. Resources like programming, designing, engineering and much

Kunal Keshan 22 Dec 15, 2022
Project of "Web Development" course for the Bachelor's degree in Computer Engineering, taken at the University of Pisa. Final evaluation: 30/30.

La battaglia della Meloria Welcome! This is the ???? version of the README file. Click here for ???? version. Introduction Historical reinterpretation

Daniel Namaki 3 Oct 6, 2022
Base62-token.js - Generate & Verify GitHub-style & npm-style Base62 Tokens

base62-token.js Generate & Verify GitHub-style & npm-style Secure Base62 Tokens Works in Vanilla JS (Browsers), Node.js, and Webpack. Online Demo See

Root 4 Jun 11, 2022
Mostly adequate guide to FP (in javascript)

About this book This is a book on the functional paradigm in general. We'll use the world's most popular functional programming language: JavaScript.

null 22.3k Jan 3, 2023
📚 Study guide and introduction to the modern front end stack.

Grab Front End Guide Credits: Illustration by @yangheng This guide has been cross-posted on Free Code Camp. Grab is Southeast Asia (SEA)'s leading tra

Grab 14.7k Jan 3, 2023
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹

TypeScript Deep Dive I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack

Basarat Ali Syed 18.7k Jan 4, 2023
Frontend tech guide and collection of highly recommended materials

Frontend Learning Kit Frontend tech guide and collection of highly recommended materials Show your support by giving a ⭐ to this repo 2022 Frontend De

Sadanand Akshay Pai 2.9k Jan 7, 2023
Dev Guide for Archival Node & Indexer Setup

Algorand - The Undocumented Docs Dev Notes for Archival Node, Indexer Setup (and more) Archival Node FAQ [ ? ] How much space will I need? See -> http

null 5 May 23, 2022
A simple guide to HTML elements

?? HEAD A simple guide to HTML <head> elements Table of Contents Recommended Minimum Elements Meta Link Icons Social Facebook Open Graph Twitter Card

Josh Buchea 29.5k Jan 1, 2023
A learning guide for JavaScript programmers.

Table of Contents Awesome JavaScript 专题列表 基础 开发准备 推荐的书 源代码阅读 敏捷方法与工具 JavaScript ES6 Node.js 图书 最佳实践 风格指南 常用的Node Web框架 常用NPM工具模块 开发工具和库 Future Awesome

Sun 785 Dec 26, 2022
A kickstarter guide to writing ES6

ES6 for Humans ?? The complete guide is now available on Amazon Table of Contents let, const and block scoping Arrow Functions Default Function Parame

Deepak Grover 6.3k Jan 4, 2023
A website that acts as a guide about the universities to potential students whole throughout the globe.

A website that acts as a guide about the universities to potential students whole throughout the globe.

null 1 Apr 15, 2022
Solidity Quickstart is an extensive solidity guide for the solidity newbies out there.

?? Solidity Quickstart Solidity Quickstart is an extensive solidity guide for the solidity newbies out there. ?? How does it work? All the guides rela

Kira 8 Aug 6, 2022
A guide that teach you build a custom version of chromium on macOS/Windows/Linux that supporting hardware/software HEVC decoding.

enable-chromium-hevc-hardware-decoding A guide that teach you build a custom version of chromium on macOS/Windows/Linux that supports hardware/softwar

Sta Zhu 778 Jan 1, 2023
A complete guide for learning Object Oriented Programming Pillars, SOLID Principles and Design Patterns with TypeScript!

Object Oriented Programming Expert With TypeScript This repository is a complete guide and tutorial for the principles and techniques of object-orient

Ahmad Jafari 44 Dec 29, 2022