Skip to content

Commit

Permalink
feat: add support for flat configs
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Mar 13, 2024
1 parent 3a7f95f commit 12f45f8
Show file tree
Hide file tree
Showing 45 changed files with 672 additions and 491 deletions.
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,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
20 changes: 19 additions & 1 deletion eslint-doc-generator.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ import { format } from "prettier";

export default {
configEmoji: [["lite", "☑️"]],
ignoreConfig: ["all", "off", "disable-type-checked"],
ignoreConfig: [
"all",
"off",
"disable-type-checked",
"flat/all",
"flat/currying",
"flat/disable-type-checked",
"flat/external-typescript-recommended",
"flat/external-vanilla-recommended",
"flat/lite",
"flat/no-exceptions",
"flat/no-mutations",
"flat/no-other-paradigms",
"flat/no-statements",
"flat/off",
"flat/recommended",
"flat/strict",
"flat/stylistic",
],
ruleDocSectionInclude: ["Rule Details"],
ruleListSplit: "meta.docs.category",
postprocess: (doc) => format(doc, { parser: "markdown" }),
Expand Down
56 changes: 13 additions & 43 deletions src/configs/all.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
import { type Linter } from "@typescript-eslint/utils/ts-eslint";
import { type FlatConfig } from "@typescript-eslint/utils/ts-eslint";

import * as functionalParameters from "#eslint-plugin-functional/rules/functional-parameters";
import * as immutableData from "#eslint-plugin-functional/rules/immutable-data";
import * as noClasses from "#eslint-plugin-functional/rules/no-classes";
import * as noConditionalStatements from "#eslint-plugin-functional/rules/no-conditional-statements";
import * as noExpressionStatements from "#eslint-plugin-functional/rules/no-expression-statements";
import * as noLet from "#eslint-plugin-functional/rules/no-let";
import * as noLoopStatements from "#eslint-plugin-functional/rules/no-loop-statements";
import * as noMixedTypes from "#eslint-plugin-functional/rules/no-mixed-types";
import * as noPromiseReject from "#eslint-plugin-functional/rules/no-promise-reject";
import * as noReturnVoid from "#eslint-plugin-functional/rules/no-return-void";
import * as noThisExpressions from "#eslint-plugin-functional/rules/no-this-expressions";
import * as noThrowStatements from "#eslint-plugin-functional/rules/no-throw-statements";
import * as noTryStatements from "#eslint-plugin-functional/rules/no-try-statements";
import * as preferImmutableTypes from "#eslint-plugin-functional/rules/prefer-immutable-types";
import * as preferPropertySignatures from "#eslint-plugin-functional/rules/prefer-property-signatures";
import * as preferTacit from "#eslint-plugin-functional/rules/prefer-tacit";
import * as readonlyType from "#eslint-plugin-functional/rules/readonly-type";
import * as typeDeclarationImmutability from "#eslint-plugin-functional/rules/type-declaration-immutability";
import { rules } from "#eslint-plugin-functional/rules";
import { ruleNameScope } from "#eslint-plugin-functional/utils/misc";

const config: Linter.Config = {
rules: {
[`functional/${functionalParameters.name}`]: "error",
[`functional/${immutableData.name}`]: "error",
[`functional/${noClasses.name}`]: "error",
[`functional/${noConditionalStatements.name}`]: "error",
[`functional/${noExpressionStatements.name}`]: "error",
[`functional/${noLet.name}`]: "error",
[`functional/${noLoopStatements.name}`]: "error",
[`functional/${noMixedTypes.name}`]: "error",
[`functional/${noPromiseReject.name}`]: "error",
[`functional/${noReturnVoid.name}`]: "error",
[`functional/${noThisExpressions.name}`]: "error",
[`functional/${noThrowStatements.name}`]: "error",
[`functional/${noTryStatements.name}`]: "error",
[`functional/${preferImmutableTypes.name}`]: "error",
[`functional/${preferPropertySignatures.name}`]: "error",
[`functional/${preferTacit.name}`]: "warn",
[`functional/${readonlyType.name}`]: "error",
[`functional/${typeDeclarationImmutability.name}`]: "error",
},
};

export default config;
export default {
...Object.fromEntries(
Object.entries(rules)
.filter(([, rule]) => rule.meta.deprecated !== true)
.map(([name, rule]) => [
`${ruleNameScope}/${name}`,
rule.meta.docs.recommendedSeverity,
]),
),
} satisfies FlatConfig.Config["rules"];
25 changes: 16 additions & 9 deletions src/configs/currying.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { type Linter } from "@typescript-eslint/utils/ts-eslint";
import { type FlatConfig } from "@typescript-eslint/utils/ts-eslint";

import * as functionalParameters from "#eslint-plugin-functional/rules/functional-parameters";
import { rules } from "#eslint-plugin-functional/rules";
import { ruleNameScope } from "#eslint-plugin-functional/utils/misc";

const config: Linter.Config = {
rules: {
[`functional/${functionalParameters.name}`]: "error",
},
};

export default config;
export default Object.fromEntries(
Object.entries(rules)
.filter(
([, rule]) =>
rule.meta.deprecated !== true &&
rule.meta.docs.category === "Currying" &&
rule.meta.docs.recommended !== false,
)
.map(([name, rule]) => [
`${ruleNameScope}/${name}`,
rule.meta.docs.recommendedSeverity,
]),
) satisfies FlatConfig.Config["rules"];
11 changes: 0 additions & 11 deletions src/configs/deprecated.ts

This file was deleted.

17 changes: 7 additions & 10 deletions src/configs/disable-type-checked.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { type Linter } from "@typescript-eslint/utils/ts-eslint";
import { type FlatConfig } from "@typescript-eslint/utils/ts-eslint";

import { rules } from "#eslint-plugin-functional/rules";
import { ruleNameScope } from "#eslint-plugin-functional/utils/misc";

const config: Linter.Config = {
rules: Object.fromEntries(
Object.entries(rules)
.filter(([, rule]) => rule.meta.docs?.requiresTypeChecking === true)
.map(([name]) => [`functional/${name}`, "off"]),
),
};

export default config;
export default Object.fromEntries(
Object.entries(rules)
.filter(([, rule]) => rule.meta.docs?.requiresTypeChecking === true)
.map(([name]) => [`${ruleNameScope}/${name}`, "off"]),
) satisfies FlatConfig.Config["rules"];
23 changes: 9 additions & 14 deletions src/configs/external-typescript-recommended.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { type Linter } from "@typescript-eslint/utils/ts-eslint";
import { type FlatConfig } from "@typescript-eslint/utils/ts-eslint";

import externalVanillaRecommended from "#eslint-plugin-functional/configs/external-vanilla-recommended";
import { mergeConfigs } from "#eslint-plugin-functional/utils/merge-configs";

const tsConfig: Linter.Config = {
rules: {
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
},
};
const tsConfig = {
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
} satisfies FlatConfig.Config["rules"];

const fullConfig: Linter.Config = mergeConfigs(
externalVanillaRecommended,
tsConfig,
);

export default fullConfig;
export default {
...externalVanillaRecommended,
...tsConfig,
} satisfies FlatConfig.Config["rules"];
Loading

0 comments on commit 12f45f8

Please sign in to comment.