0.3.0 • Published 2 years ago

@marcozac/eslint-config v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@marcozac/eslint-config

License Package version Eslint peer dependency

A collection of type definitions for ESLint with some useful plugins, rules and configurations.

Introduction

The package includes a main and a monorepo configurations and resolves the plugins using the Rush Stack patch. Thus is not necessary to reinstall them and they are not listed as peer dependencies.

Moreover, exports the configuration object and, although slightly out of the package scope, a basic Prettier configuration.

It also supports by default Typescript and json files parsing with @typescript-eslint/parser and jsonc-eslint-parser. See parsers section for more details.

The rule set is a mix of Airbnb-styled rules for Javascript and Typescript including the recommendend settings for Prettier and Jest.

Installation

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

Environments

The node, es2018 and jest (with settings.jest.version = 27) environments are enabled by default.

Parsers

The package uses Babel as default parser instead of Espree.

Additional per-file extension parsers are described in the table below.

ParserFile extensions
Babeldefault
Typescript eslint parser.ts, .tsx, .d.ts, .cts, .mts
Jsonc parser.json, .jsonc, .json5

Extensions

Main

// <projectFolder>/.eslintrc.js
module.exports = {
  extends: ['@marcozac/eslint-config'],
};

Monorepo

The monorepo configuration is basically the main one with the rootMode of Babel options set to upward.

It is available for extension from @marcozac/eslint-config/monorepo.

// <projectFolder>/.eslintrc.js
module.exports = {
  extends: ['@marcozac/eslint-config/monorepo'],
};

Rush Stack ESLint patch

The package exports also the ESLint configuration patched by @rushstack/eslint-patch under @marcozac/eslint-config/rushstack-patch to work in monorepos built on top of Rush Stack.

Typescript

Many of the rules included in the configuration require to define parserOptions.project property. By default, the program use includes/tsconfig.base.json, which extends the project tsconfig.json including all javascript and typescript files.

Exports

Configuration object

In some cases you may need to import the package types or the configuration object instead of using extends property. They are available to be imported from @marcozac/eslint-config/eslint-config.

❌ WARNING
Do not try to import the configuration object from the main path since its resolution will fail by @rushstack/eslint-patch.

import { config, Config } from '@marcozac/eslint-config/eslint-config';

const foo: Config = config;
type Bar = Config.Environments;

Prettier configuration

Since has prettier/prettier = error in its rule set, it also exports the basic Prettier configuration below under @marcozac/eslint-config/prettier-config path.

module.exports = {
  printWidth: 80,
  semi: true,
  singleQuote: true,
  trailingComma: 'all',
  tabWidth: 2,
  arrowParens: 'avoid',
  endOfLine: 'auto',
};

Since Prettier has not an extends property, so it must be imported into a configuration object as in the example below.

// <projectFolder>/.prettierrc.js
const configBase = require('@marcozac/eslint-config/prettier-config');

module.exports = {
  ...configBase, // or skipping the constant declaration: ...require('@marcozac/eslint-config/prettier-config')
  // ...
};

// Export without any changes
// module.exports = require('@marcozac/eslint-config/prettier-config');

Internal

The configurations in the internal directory are intended to be used in this monorepo.

If you wish, you can use them. On your own risk 😈

For more detailed info click here.

Export path
@marcozac/eslint-config/internalInternal ESLint configuration
@marcozac/eslint-config/internal/eslint-configThe same of @marcozac/eslint-config/internal
@marcozac/eslint-config/internal/prettier-configInternal Prettier configuration

ESLint example

// @ts-check

/** @type {import('@marcozac/eslint-config/eslint-config').Config} */
const config = {
  root: true,
  extends: ['@marcozac/eslint-config/internal'],
};
module.exports = config;

Prettier example

module.exports = require('@marcozac/eslint-config/internal/prettier-config');