Skip to content

Latest commit

 

History

History
115 lines (90 loc) · 2.77 KB

GETTING_STARTED.md

File metadata and controls

115 lines (90 loc) · 2.77 KB

Getting Started

Installation

JavaScript

# Install with npm
npm install -D eslint eslint-plugin-functional

# Install with yarn
yarn add -D eslint eslint-plugin-functional

# Install with pnpm
pnpm add -D eslint eslint-plugin-functional

TypeScript

# Install with npm
npm install -D eslint @typescript-eslint/parser eslint-plugin-functional

# Install with yarn
yarn add -D eslint @typescript-eslint/parser eslint-plugin-functional

# Install with pnpm
pnpm add -D eslint @typescript-eslint/parser eslint-plugin-functional

Usage

Flat Config

If using the new flat config, import from eslint-plugin-functional/flat.

import functional from "eslint-plugin-functional/flat";

Classic Config

Add functional to the plugins section of your .eslintrc configuration file. Then configure the rules you want to use under the rules section.

{
  "plugins": ["functional"],
  "rules": {
    "functional/rule-name": "error"
  }
}

There are several rulesets provided by this plugin. See the README for what they are and what rules are included in each. Enable rulesets via the "extends" property of your .eslintrc configuration file.

Be sure to include the "plugin:functional/disable-type-checked" ruleset to disable rules that require TypeScript.

{
  // ...
  "extends": [
    "plugin:functional/external-vanilla-recommended",
    "plugin:functional/recommended",
    "plugin:functional/stylistic",
    "plugin:functional/disable-type-checked"
  ]
}

With TypeScript

Add @typescript-eslint/parser to the "parser" filed in your .eslintrc configuration file. To use type information, you will need to specify a path to your tsconfig.json file in the "project" property of "parserOptions". Alternatively, you can just set "project" to true to automatically use the nearest tsconfig.json files.

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": true
  }
}

See @typescript-eslint/parser's README.md for more information on the available parser options.

Example Config

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": true
  },
  "env": {
    "es6": true
  },
  "plugins": [
    "@typescript-eslint",
    "functional"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "plugin:functional/external-typescript-recommended",
    "plugin:functional/recommended",
    "plugin:functional/stylistic"
  ]
}