nightgrey / eslint-config

A TypeScript ESLint configuration with opinionated defaults and modular addons.

Home Page:https://www.npmjs.com/package/@nightgrey/eslint-config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contributors Forks Stargazers Issues MIT License

@nightgrey/eslint-config [ALPHA]

All packages are in alpha and currently being tested and worked upon and are not stable.

This repository provides a modular ESLint configuration. It provides opinionated defaults for TypeScript projects with a few different (optional) flavours.

If you want to use this configuration or even just parts of it as a base for your own configuration, the configuration is modular, and you can install just parts of it to construct your own configuration, too.

Attention: This configuration is written in ESLint's flat configuration style. You can read more about it in the ESLint documentation.

Features

  • TypeScript configuration
  • Opinionated configuration
  • Modular configuration split in bases, addons and overrides.
    • Bases provide the core configuration.
    • Addons provide appropriate plugins and common-sense rules. For example, eslint-config-addon-jest provides the Jest plugin, automatically applies globals for Node.js, and makes sure dev dependency in *.test.[ext] files are allowed!
    • Overrides provide rules for specific files. For example, eslint-config-override-development-files allows imports of dev dependencies in the project root.

Packages

Configuration

Addons

Bases

Overrides

Table of Contents

Getting started

npm install --save-dev @nightgrey/eslint-config

eslint.config.js

import nightgreyEslintConfig from '@nightgrey/eslint-config';
import globals from 'globals';

/** @type {import('eslint').Linter.FlatConfig} */
const configuration = {
  // Your own configuration goes here, after the base configuration.

  // Important: You have to set your own language options depending on your project.
  // This code here assumes a Node.js project with ES2021 globals and TypeScript.
  // For more information, see https://eslint.org/docs/user-guide/configuring/language-options
  languageOptions: {
    parserOptions: {
      ecmaVersion: 'latest',
      project: './tsconfig.json',
    },
    globals: {
      ...globals.node,
      ...globals.es2021,
    },
  },
};

// Then, make sure to export the configuration array and to spread `nightgreyEslintConfig` first!

/** @type {Array<import('eslint').Linter.FlatConfig>} */
export default [...nightgreyEslintConfig, configuration];

Usage

To use addons or overrides, you have to install them as dependencies and add them to your configuration.

This is a configuration with all addons and overrides installed.

eslint.config.js

import eslintConfigGrey from '@nightgrey/eslint-config';
import { prettierAddon } from '@nightgrey/eslint-config-addon-prettier';
import { reactAddon } from '@nightgrey/eslint-config-addon-react';
import { nextAddon } from '@nightgrey/eslint-config-addon-next';
import { jestAddon } from '@nightgrey/eslint-config-addon-jest';
import { vitestAddon } from '@nightgrey/eslint-config-addon-vitest';
import { developmentFilesOverrides } from '@nightgrey/eslint-config-override-development-files';
import { indexFilesOverrides } from '@nightgrey/eslint-config-override-index-files';
import { testingLibraryReactAddon } from '@nightgrey/eslint-config-addon-testing-library-react';
import globals from 'globals';

/** @type {import('eslint').Linter.FlatConfig} */
const configuration = {
  // Your own configuration goes here.
  // See `Getting started` above for an example.
};

// Order:
// 1. Bases (or eslintConfigGrey)
// 2. Addons
// 3. Your configuration
// 4. Overrides
// Always last: Prettier addon

/** @type {Array<import('eslint').Linter.FlatConfig>} */
export default [
  // Bases
  ...eslintConfigGrey,
  // Addons
  reactAddon,
  nextAddon,
  jestAddon,
  testingLibraryReactAddon,
  // Your configuration
  configuration,
  // Overrides have to be added after addons and your own configuration.
  developmentFilesOverrides,
  indexFilesOverrides,
  // Important: It is recommended to add the prettier addon last.
  prettierAddon,
];

Roadmap

  • Add better tests
  • Add documentation for each package
  • Add presets

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

License

Distributed under the MIT License. See LICENSE.txt for more information.

About

A TypeScript ESLint configuration with opinionated defaults and modular addons.

https://www.npmjs.com/package/@nightgrey/eslint-config

License:MIT License


Languages

Language:JavaScript 82.2%Language:TypeScript 17.1%Language:Shell 0.8%