Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 76 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,59 @@ npm install --save-dev eslint-plugin-fp-ts
yarn add --dev eslint-plugin-fp-ts
```

Then enable the plugin in your `.eslintrc` config
Then enable the plugin in your `eslint.config.mjs` file

```json
{
"plugins": ["fp-ts"]
}
```js
import {defineConfig} from 'eslint/config'
import fptsPlugin from 'eslint-plugin-fp-ts'

export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}
}
)
```

and enable the rules you want, for example

```json
{
"plugins": ["fp-ts"],
"rules": {
"fp-ts/no-lib-imports": "error"
```js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
},

rules: {
"fp-ts/no-lib-imports": "error"
}
}
}
)
```

If you want to enable rules that require type information (see the table below),
then you will also need to add some extra info:

```js
module.exports = {
plugins: ["fp-ts"],
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
},
rules: {
"fp-ts/no-discarded-pure-expression": "error",
},
};
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
},

languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},

rules: {
"fp-ts/no-discarded-pure-expression": "error",
}
}
)
```

If your project is a multi-package monorepo, you can follow the instructions
Expand Down Expand Up @@ -87,12 +107,18 @@ If your project is a multi-package monorepo, you can follow the instructions

The plugin defines a `recommended` configuration with some reasonable defaults.

To use it, add it to the `extends` clause of your `.eslintrc` file:
To use it, add it to the `extends` clause of your `eslint.config.mjs` file:

```json
{
"extends": ["plugin:fp-ts/recommended"]
}
```js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
},

extends: ["plugin:fp-ts/recommended"]
}
)
```

The rules included in this configuration are:
Expand All @@ -107,13 +133,19 @@ recommended rules which require type information.

This configuration needs to be included _in addition_ to the `recommended` one:

```
{
"extends": [
"plugin:fp-ts/recommended",
"plugin:fp-ts/recommended-requiring-type-checking"
]
}
```js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
},

extends: [
"fp-ts/recommended",
"fp-ts/recommended-requiring-type-checking"
]
}
)
```

> 👉 You can read more about linting with type information, including
Expand All @@ -125,10 +157,16 @@ This configuration needs to be included _in addition_ to the `recommended` one:
The plugin also defines an `all` configuration which includes every available
rule.

To use it, add it to the `extends` clause of your `.eslintrc` file:
To use it, add it to the `extends` clause of your `eslint.config.mjs` file:

```json
{
"extends": ["plugin:fp-ts/all"]
}
```js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
},

extends: ["fp-ts/all",]
}
)
```
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-fp-ts",
"version": "0.4.0",
"version": "0.5.0",
"description": "fp-ts ESLint rules",
"keywords": [
"eslint",
Expand All @@ -10,14 +10,17 @@
],
"author": "buildo",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/buildo/eslint-plugin-fp-ts"
},
"scripts": {
"prepare": "npm run build",
"preversion": "yarn lint && yarn test && yarn build",
"declarations": "tsc -p ./tsconfig.declaration.json",
"build": "rimraf lib && yarn tsc",
"postbuild": "yarn declarations",
"pretest": "yarn --cwd tests/fixtures/fp-ts-project install",
"test": "jest",
"lint": "eslint src/**/*.ts"
Expand Down
49 changes: 46 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { array, record, semigroup } from "fp-ts";
import { pipe } from "fp-ts/function";
import {ESLint} from 'eslint'

const potentialErrors = {
"no-lib-imports": require("./rules/no-lib-imports").default,
Expand All @@ -16,12 +17,52 @@ const suggestions = {
"prefer-bimap": require("./rules/prefer-bimap").default,
};

export const rules = {
const pkg = require('../package.json');

export const meta: ESLint.Plugin["meta"] & {namespace?: string} = {
name: pkg.name,
version: pkg.version,
namespace: 'fp-ts'
}

export const rules: ESLint.Plugin["rules"] = {
...potentialErrors,
...suggestions,
};

export const configs = {
export const configs: ESLint.Plugin["configs"] = {};

const plugin: ESLint.Plugin = {
meta,
rules,
configs
}

// assign configs here so we can reference `plugin`
Object.assign(configs, {
// flat config format
"flat/recommended": {
plugins: {"fp-ts": plugin},
rules: {
"fp-ts/no-lib-imports": "error",
"fp-ts/no-pipeable": "error",
},
},
"flat/recommended-requiring-type-checking": {
plugins: {"fp-ts": plugin},
rules: {
"fp-ts/no-discarded-pure-expression": "error",
},
},
"flat/all": {
plugins: {"fp-ts": plugin},
rules: {
...configuredRules(potentialErrors, "error"),
...configuredRules(suggestions, "warn"),
},
},

// eslintrc format
recommended: {
plugins: ["fp-ts"],
rules: {
Expand All @@ -42,7 +83,9 @@ export const configs = {
...configuredRules(suggestions, "warn"),
},
},
};
});

export default plugin

function configuredRules(
rules: Record<string, unknown>,
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true
},
"include": ["src/index.ts"]
}
Loading