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

@lightbase/eslint-config

v1.0.2

Published

ESLint based linting and formatting configuration

Downloads

816

Readme

ESLint config

Opinionated but configurable ESLint config. Fully includes linting and formatting.

Install

npm install --save-dev --exact @lightbase/eslint-config

Some configurations require manually installed plugins. For example

npm install --save-dev --exact eslint-plugin-react eslint-plugin-react-hooks

This is documented below.

Usage

This package builds a config, compatible with ESLint Flat Config. To use the config, create the following eslint.config.js file:

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({});

Commands

Add the following scripts to your package.json:

{
	"scripts": {
		"lint": "eslint . --fix --cache --cache-location .cache/eslint/",
		"lint:ci": "eslint ."
	}
}

Make sure to add .cache to your .gitignore

[!NOTE]

In a CommonJS project, make sure to name your file eslint.config.mjs instead.

Default configuration and options

Prettier

Prettier is configured to run on all markdown, json, yaml, JavaScript and TypeScript files. We support the following configuration to override this:

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({
	prettier: {
		globalOverride: {
			// Override Prettier options for all supported files.
		},
		languageOverrides: {
			ts: {
				// Override Prettier options for a specific file
				// group.
			},
		},
	},
});

Typescript

Typescript ESLint is automatically enabled if a tsconfig.json is present.

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig(
	{},
	{
		// Apply custom rules
		files: ["**/*.ts"],
		rules: {
			"@typescript-eslint/no-unused-vars": "off",
		},
	},
);

Or explicitly disabling Typescript support can be done with:

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({
	typescript: false,
});

By default, we enable the recommended type checked rules from typescript-eslint. To disable these rules, use:

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({
	typescript: {
		disableTypeCheckedRules: true,
	},
});

Markdown

A Markdown processor is installed by default. Its purpose is to extract code-blocks and present them as virtual files. This means that markdown code-blocks can receive custom rules as follows:

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig(
	{},
	{
		files: ["**/*.md/*.js"],
		rules: {
			"no-unused-vars": "off",
		},
	},
);

React

The config optionally supports enabling React and Next.js specific rules. Add the following dependencies:

npm install --save-dev --exact eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-no-relative-import-paths

If you use Next.js, make sure to also add @next/eslint-plugin-next via:

npm install --save-dev --exact @next/eslint-plugin-next

React is only support in combination with Typescript (see above), and can be enabled as follows:

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({
	react: {
		withNextJs: true,
	},
});

This enables all Next.js rules and various recommended rules for React, hooks usage and JSX accessibility.

Globals

The config by default includes all globals for Node.js, Browser and ES2021. You can use other predefined presets via

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({
	// Make sure to include the full setup.
	globals: ["browser", "serviceworker"],
});

This enables environment-specific globals for all files. For a stricter setup, use custom configuration as explained below

import globals from "globals";
import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig(
	{},
	{
		files: ["**/*.js"],
		languageOptions: {
			globals: {
				...globals.es2015,
			},
		},
	},
);

Ignores

ESLint will by default ignore everything as defined in your .gitignore. You can add new directories like so.

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig(
	{
		// Define config options, explained above.
	},
	{
		// Ignore the packages/ directory.
		ignores: ["packages/**"],
	},
);

Make sure that nested directory ignores contain the proper wildcards for them to work.

# works
.cache
**/src/generated

# doesn't work
src/generated

Custom configuration

defineConfig accepts custom ESLint configuration as the 'rest' parameter. This allows you to configure rules for specific file patterns.

import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig(
	{
		// Define config options, explained above.
	},
	{
		// Ignore the packages/ directory.
		ignores: ["packages/**"],
	},
	{
		// Add rules for specific files.
		file: ["**/*.ts"],
		rules: {
			"no-console": "off",
		},
	},
);

IDE

WebStorm

Configuring Webstorm to use this config can be done as follows:

  • Go to Languages & Frameworks -> JavaScript -> Code Quality Tools -> ESLint
  • Select Automatic ESLint configuration
  • Set Run for files to **/*.*
  • Select Run eslint --fix on save
  • Click on Apply & OK

[!NOTE]

WebStorm sometimes doesn't pick up on an updated ESLint configuration. A restart of the background services fixes this.

  • In versions 2023.3 and below, go to the ESLint settings in your preferences according to the steps above. Select Disable ESLint configuration, click on Apply and select Automatic ESLint configuration again.
  • In versions 20241.1 and above use Help -> Find action -> Restart ESLint Service.

Credits

Inspired by Dirkdev98's initial design, solidified with @antfu/eslint-config.

License

MIT