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

@stsiarzhanau/eslint-config-nextjs-typescript

v1.2.0

Published

ESLint config for Next.js apps with additional rules for TypeScript, TailwindCSS, Vitest, React Testing Library and more

Downloads

16

Readme

eslint-config-nextjs-typescript

Custom ESLint configuration for Next.js (and not only) apps.

Examples of usage

Do I need this?

If you don't use TypeScript with Next.js or have a mixed TS/JS codebase, you definitely don't need this config.

If you don't use Prettier, TailwindCSS, Vitest and React Testing Library (at least a couple of them) when building Next.js applications and don't want to use additional TypeScript specific rules, then you probably don't need this config as well.

Otherwise, this config may be handy. As it allows not to bother with extending from eslint-config-next or eslint-plugin-next, dealing with potential conflicts / unintended overrides and installing additional dependencies.

The best combo is to use this config alongside with Prettier and prettier-plugin-tailwindcss. See examples above.

What's included?

  • recommended config from core ESLint
  • recommended-type-checked and stylistic-type-checked configs from @typescript-eslint/eslint-plugin
  • recommended and typescript configs from eslint-plugin-import
  • recommended and jsx-runtime configs from eslint-plugin-react
  • recommended config from eslint-plugin-jsx-a11y
  • recommended config from eslint-plugin-react-hooks
  • recommended config from eslint-plugin-tailwind-css
  • core-web-vitals config from @next/eslint-plugin-next
  • recommended config from eslint-plugin-vitest
  • react config from eslint-plugin-testing-library
  • recommended config from jest-dom
  • eslint-config-prettier
  • configured rules from eslint-plugin-simple-import sort
  • configured parser options and plugin settings

Installation in a new create-next-app project

First, run interactive Next.js installation.

npx create-next-app@latest

Select "No" when prompted "Would you like to use ESLint"?

Install this package and ESLint.

npm install --save-dev eslint @stsiarzhanau/eslint-config-nextjs-typescript

Then create a .eslintrc.json file with the following contents in the root folder of your Next.js project.

{
  "extends": "@stsiarzhanau/nextjs-typescript",
  "parserOptions": {
    "project": ["./tsconfig.json"]
  }
}

Modify scripts entry of your package.json.

"scripts": {
	"dev": "next dev",
	"build": "next build",
	"start": "next start",
  - "lint": "next lint"
  + "lint": "eslint [your options] [directories to lint]"
},

Replacing built-in ESLint configuration in an existing create-next-app project

Uninstall built-in ESLint config.

npm uninstall eslint-config-next

Install this package.

npm install --save-dev @stsiarzhanau/eslint-config-nextjs-typescript

Modify existing .eslintrc.json.

{
  - "extends": "next/core-web-vitals"
  + "extends": "@stsiarzhanau/nextjs-typescript",
  + "parserOptions": {
  +   "project": ["./tsconfig.json"]
  + }
}

Modify scripts entry of your package.json.

"scripts": {
	"dev": "next dev",
	"build": "next build",
	"start": "next start",
  - "lint": "next lint"
  + "lint": "eslint [your options] [directories to lint]"
},

Usage with React projects not based on Next.js

If you are using this config in a React project not based on Next.js, you can extend from @stsiarzhanau/nextjs-typescript/core instead of the default @stsiarzhanau/nextjs-typescript export. This will exclude Next.js specific rules:

{
  "extends": "@stsiarzhanau/nextjs-typescript/core",
  "parserOptions": {
    "project": ["./tsconfig.json"]
  }
}

Additional configuration

This config uses type aware rules from @typescript-eslint/eslint-plugin. That means the plugin uses your tsconfig.json to understand project structure. If you have a single tsconfig.json in the root directory, you are good to go. If you have more complex custom project structure you'll need to override parserOptions.project and/or parserOptions.tsconfigRootDir config options. This may also require changing ESLint configuration file format to .eslintrc.js.