Skip to content

Commit

Permalink
feat: move flat configs to new "flat" subpackage
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Mar 14, 2024
1 parent 42a6299 commit 441fc1d
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 151 deletions.
11 changes: 11 additions & 0 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ pnpm add -D eslint @typescript-eslint/parser eslint-plugin-functional

## Usage

### Flat Config

If using the new [flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new),
import from `eslint-plugin-functional/flat`.

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

Check failure on line 39 in GETTING_STARTED.md

View workflow job for this annotation

GitHub Actions / lint_js / lint_js

Missing file extension "mts" for "eslint-plugin-functional/flat"

Check failure on line 39 in GETTING_STARTED.md

View workflow job for this annotation

GitHub Actions / lint_js

Missing file extension "mts" for "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.

```jsonc
Expand Down
65 changes: 31 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ Tidelift is working with the maintainers of `eslint-plugin-functional` and a gro

The following rulesets are made available by this plugin.

Note: if using a [flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new) add a `flat/` prefix to the preset name
(e.g. `functional.configs["flat/recommended"]`).

Presets:

- **Strict** (`plugin:functional/strict`)\
Expand Down Expand Up @@ -109,52 +106,52 @@ The [below section](#rules) gives details on which rules are enabled by each rul

### Currying

| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
| :----------------------------------------------------------- | :----------------------------- | :-------------------------- | :- | :- | :- | :- | :- | :- |
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | ☑️ ✅ 🔒 ![badge-currying][] | | | | | | |
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
| :----------------------------------------------------------- | :----------------------------- | :------------------------ | :--- | :--- | :--- | :--- | :--- | :--- |
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | ☑️ ✅ 🔒 ![badge-currying][] | | | | | | |

### No Exceptions

| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
| :------------------------------------------------------- | :----------------------------------------------------- | :------------------------------- | :- | :--- | :- | :- | :- | :- |
| [no-promise-reject](docs/rules/no-promise-reject.md) | Disallow rejecting promises. | | | | | | | |
| [no-throw-statements](docs/rules/no-throw-statements.md) | Disallow throwing exceptions. | ☑️ ✅ 🔒 ![badge-no-exceptions][] | | | | | | |
| [no-try-statements](docs/rules/no-try-statements.md) | Disallow try-catch[-finally] and try-finally patterns. | 🔒 ![badge-no-exceptions][] | | ☑️ ✅ | | | | |
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
| :------------------------------------------------------- | :----------------------------------------------------- | :----------------------------- | :--- | :--- | :--- | :--- | :--- | :--- |
| [no-promise-reject](docs/rules/no-promise-reject.md) | Disallow rejecting promises. | | | | | | | |
| [no-throw-statements](docs/rules/no-throw-statements.md) | Disallow throwing exceptions. | ☑️ ✅ 🔒 ![badge-no-exceptions][] | | | | | | |
| [no-try-statements](docs/rules/no-try-statements.md) | Disallow try-catch[-finally] and try-finally patterns. | 🔒 ![badge-no-exceptions][] | | ☑️ ✅ | | | | |

### No Mutations

| Name                          | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
| :--------------------------------------------------------------------------- | :-------------------------------------------------------------- | :------------------------------ | :- | :- | :- | :- | :- | :- |
| [immutable-data](docs/rules/immutable-data.md) | Enforce treating data as immutable. | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | | | 💭 | |
| [no-let](docs/rules/no-let.md) | Disallow mutable variables. | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | | | | |
| [prefer-immutable-types](docs/rules/prefer-immutable-types.md) | Require function parameters to be typed as certain immutability | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | 🔧 | 💡 | 💭 | |
| [prefer-readonly-type](docs/rules/prefer-readonly-type.md) | Prefer readonly types over mutable types. | | | | 🔧 | | 💭 ||
| [type-declaration-immutability](docs/rules/type-declaration-immutability.md) | Enforce the immutability of types based on patterns. | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | 🔧 | | 💭 | |
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
| :--------------------------------------------------------------------------- | :-------------------------------------------------------------- | :---------------------------- | :--- | :--- | :--- | :--- | :--- | :--- |
| [immutable-data](docs/rules/immutable-data.md) | Enforce treating data as immutable. | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | | | 💭 | |
| [no-let](docs/rules/no-let.md) | Disallow mutable variables. | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | | | | |
| [prefer-immutable-types](docs/rules/prefer-immutable-types.md) | Require function parameters to be typed as certain immutability | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | 🔧 | 💡 | 💭 | |
| [prefer-readonly-type](docs/rules/prefer-readonly-type.md) | Prefer readonly types over mutable types. | | | | 🔧 | | 💭 | |
| [type-declaration-immutability](docs/rules/type-declaration-immutability.md) | Enforce the immutability of types based on patterns. | ☑️ ✅ 🔒 ![badge-no-mutations][] | | | 🔧 | | 💭 | |

### No Other Paradigms

| Name                | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
| :------------------------------------------------------- | :------------------------------------------------------------------------ | :------------------------------------ | :- | :--- | :- | :- | :- | :- |
| [no-classes](docs/rules/no-classes.md) | Disallow classes. | ☑️ ✅ 🔒 ![badge-no-other-paradigms][] | | | | | | |
| [no-mixed-types](docs/rules/no-mixed-types.md) | Restrict types so that only members of the same kind are allowed in them. | ☑️ ✅ 🔒 ![badge-no-other-paradigms][] | | | | | 💭 | |
| [no-this-expressions](docs/rules/no-this-expressions.md) | Disallow this access. | 🔒 ![badge-no-other-paradigms][] | | ☑️ ✅ | | | | |
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
| :------------------------------------------------------- | :------------------------------------------------------------------------ | :---------------------------------- | :--- | :--- | :--- | :--- | :--- | :--- |
| [no-classes](docs/rules/no-classes.md) | Disallow classes. | ☑️ ✅ 🔒 ![badge-no-other-paradigms][] | | | | | | |
| [no-mixed-types](docs/rules/no-mixed-types.md) | Restrict types so that only members of the same kind are allowed in them. | ☑️ ✅ 🔒 ![badge-no-other-paradigms][] | | | | | 💭 | |
| [no-this-expressions](docs/rules/no-this-expressions.md) | Disallow this access. | 🔒 ![badge-no-other-paradigms][] | | ☑️ ✅ | | | | |

### No Statements

| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
| :------------------------------------------------------------------- | :--------------------------------------------- | :------------------------------- | :- | :- | :- | :- | :- | :- |
| [no-conditional-statements](docs/rules/no-conditional-statements.md) | Disallow conditional statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
| [no-expression-statements](docs/rules/no-expression-statements.md) | Disallow expression statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
| [no-loop-statements](docs/rules/no-loop-statements.md) | Disallow imperative loops. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | | |
| [no-return-void](docs/rules/no-return-void.md) | Disallow functions that don't return anything. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | 💭 | |
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
| :------------------------------------------------------------------- | :--------------------------------------------- | :----------------------------- | :--- | :--- | :--- | :--- | :--- | :--- |
| [no-conditional-statements](docs/rules/no-conditional-statements.md) | Disallow conditional statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
| [no-expression-statements](docs/rules/no-expression-statements.md) | Disallow expression statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
| [no-loop-statements](docs/rules/no-loop-statements.md) | Disallow imperative loops. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | | |
| [no-return-void](docs/rules/no-return-void.md) | Disallow functions that don't return anything. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | 💭 | |

### Stylistic

| Name                       | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
| :--------------------------------------------------------------------- | :--------------------------------------------------------------------- | :- | :- | :- | :- | :- | :- | :- |
| [prefer-property-signatures](docs/rules/prefer-property-signatures.md) | Prefer property signatures over method signatures. | 🎨 | | | | | 💭 | |
| [prefer-tacit](docs/rules/prefer-tacit.md) | Replaces `x => f(x)` with just `f`. | | 🎨 | | | 💡 | 💭 | |
| [readonly-type](docs/rules/readonly-type.md) | Require consistently using either `readonly` keywords or `Readonly<T>` | 🎨 | | | 🔧 | | 💭 | |
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
| :--------------------------------------------------------------------- | :--------------------------------------------------------------------- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| [prefer-property-signatures](docs/rules/prefer-property-signatures.md) | Prefer property signatures over method signatures. | 🎨 | | | | | 💭 | |
| [prefer-tacit](docs/rules/prefer-tacit.md) | Replaces `x => f(x)` with just `f`. | | 🎨 | | | 💡 | 💭 | |
| [readonly-type](docs/rules/readonly-type.md) | Require consistently using either `readonly` keywords or `Readonly<T>` | 🎨 | | | 🔧 | | 💭 | |

<!-- end auto-generated rules list -->
<!-- markdownlint-restore -->
Expand Down
7 changes: 6 additions & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"$schema": "node_modules/knip/schema-jsonc.json",
"entry": ["src/index.ts!", "tests/**/*.test.ts", "cz-adapter/index.js"],
"entry": [
"src/flat.ts!",
"src/classic.ts!",
"tests/**/*.test.ts",
"cz-adapter/index.js",
],
"project": ["src/**/*.ts!", "tests/**/*.ts", "cz-adapter/**/*.{js,ts}"],
"ignore": ["tests/fixture/file.ts"],
"ignoreDependencies": ["@types/eslint", "@vitest/coverage-istanbul"],
Expand Down
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@
"Jonas Kello"
],
"exports": {
"types": {
"import": "./lib/index.d.mts",
"require": "./lib/index.d.cts"
".": {
"types": {
"import": "./lib/classic.d.mts",
"require": "./lib/classic.d.cts"
},
"import": "./lib/classic.mjs",
"require": "./lib/classic.cjs"
},
"import": "./lib/index.mjs",
"require": "./lib/index.cjs"
"./flat": {
"types": {
"import": "./lib/flat.d.mts",
"require": "./lib/flat.d.cts"
},
"import": "./lib/flat.mjs",
"require": "./lib/flat.cjs"
}
},
"main": "lib/index.cjs",
"types": "lib/index.d.cts",
"main": "lib/classic.cjs",
"types": "lib/classic.d.cts",
"files": [
"lib/",
"package.json",
Expand Down
40 changes: 35 additions & 5 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const treeshake = {
unknownGlobalSideEffects: false,
} satisfies RollupOptions["treeshake"];

const library = {
input: "src/index.ts",
const classic = {
input: "src/classic.ts",

output: [
{
file: pkg.exports.import,
file: pkg.exports["."].import,
format: "esm",
sourcemap: false,
},
{
file: pkg.exports.require,
file: pkg.exports["."].require,
format: "cjs",
sourcemap: false,
},
Expand All @@ -42,4 +42,34 @@ const library = {
treeshake,
} satisfies RollupOptions;

export default [library];
const flat = {
input: "src/flat.ts",

output: [
{
file: pkg.exports["./flat"].import,
format: "esm",
sourcemap: false,
},
{
file: pkg.exports["./flat"].require,
format: "cjs",
sourcemap: false,
},
],

plugins: [
rollupPluginAutoExternal(),
rollupPluginTs({
transpileOnly: true,
tsconfig: "tsconfig.build.json",
}),
rollupPluginDeassert({
include: ["**/*.{js,ts}"],
}),
],

treeshake,
} satisfies RollupOptions;

export default [classic, flat];
47 changes: 47 additions & 0 deletions src/classic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { type Linter } from "@typescript-eslint/utils/ts-eslint";

import all from "#eslint-plugin-functional/configs/all";
import currying from "#eslint-plugin-functional/configs/currying";
import disableTypeChecked from "#eslint-plugin-functional/configs/disable-type-checked";
import externalTypeScriptRecommended from "#eslint-plugin-functional/configs/external-typescript-recommended";
import externalVanillaRecommended from "#eslint-plugin-functional/configs/external-vanilla-recommended";
import lite from "#eslint-plugin-functional/configs/lite";
import noExceptions from "#eslint-plugin-functional/configs/no-exceptions";
import noMutations from "#eslint-plugin-functional/configs/no-mutations";
import noOtherParadigms from "#eslint-plugin-functional/configs/no-other-paradigms";
import noStatements from "#eslint-plugin-functional/configs/no-statements";
import off from "#eslint-plugin-functional/configs/off";
import recommended from "#eslint-plugin-functional/configs/recommended";
import strict from "#eslint-plugin-functional/configs/strict";
import stylistic from "#eslint-plugin-functional/configs/stylistic";
import { rules } from "#eslint-plugin-functional/rules";
import { ruleNameScope } from "#eslint-plugin-functional/utils/misc";

export default {
rules,
configs: {
all: { plugins: [ruleNameScope], rules: all },
lite: { plugins: [ruleNameScope], rules: lite },
recommended: { plugins: [ruleNameScope], rules: recommended },
strict: { plugins: [ruleNameScope], rules: strict },
off: { plugins: [ruleNameScope], rules: off },
"disable-type-checked": {
plugins: [ruleNameScope],
rules: disableTypeChecked,
},
"external-vanilla-recommended": {
plugins: [ruleNameScope],
rules: externalVanillaRecommended,
},
"external-typescript-recommended": {
plugins: [ruleNameScope],
rules: externalTypeScriptRecommended,
},
currying: { plugins: [ruleNameScope], rules: currying },
"no-exceptions": { plugins: [ruleNameScope], rules: noExceptions },
"no-mutations": { plugins: [ruleNameScope], rules: noMutations },
"no-other-paradigms": { plugins: [ruleNameScope], rules: noOtherParadigms },
"no-statements": { plugins: [ruleNameScope], rules: noStatements },
stylistic: { plugins: [ruleNameScope], rules: stylistic },
},
} as Linter.Plugin;

0 comments on commit 441fc1d

Please sign in to comment.