Skip to content

Commit

Permalink
feat: add support for flat configs (#789)
Browse files Browse the repository at this point in the history
* feat: add support for flat configs

* ci: fix release replacements

* chore(release): 6.2.0-next.1 [skip ci]

# [6.2.0-next.1](v6.1.1...v6.2.0-next.1) (2024-03-13)

### Features

* add support for flat configs ([901d52a](901d52a))

* fix: build types

* fix: improve types

* chore(release): 6.2.0-next.2 [skip ci]

# [6.2.0-next.2](v6.2.0-next.1...v6.2.0-next.2) (2024-03-14)

### Bug Fixes

* build types ([054a862](054a862))
* improve types ([2340489](2340489))

* feat: move flat configs to new "flat" subpackage

* ci: fix release

* chore(release): 6.2.0-next.3 [skip ci]

# [6.2.0-next.3](v6.2.0-next.2...v6.2.0-next.3) (2024-03-14)

### Features

* move flat configs to new "flat" subpackage ([1d3533f](1d3533f))

---------

Co-authored-by: semantic-release-bot <[email protected]>
  • Loading branch information
RebeccaStevens and semantic-release-bot authored Mar 20, 2024
1 parent 5fc52d1 commit 5fa7c2c
Show file tree
Hide file tree
Showing 57 changed files with 821 additions and 545 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/consistent-generic-constructors": "off",
"import/extensions": "off",
"import/no-unresolved": "off",
"init-declarations": "off",
"jsdoc/require-jsdoc": "off",
Expand Down
28 changes: 26 additions & 2 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,35 @@ plugins:
from: "\\$\\{__VERSION__\\}"
to: "${nextRelease.version}"
results:
- file: "./lib/index.js"
- file: "./lib/classic.cjs"
hasChanged: true
numMatches: 1
numReplacements: 1
- file: "./lib/index.mjs"
- file: "./lib/classic.d.cts"
hasChanged: false
numMatches: 0
numReplacements: 0
- file: "./lib/classic.d.mts"
hasChanged: false
numMatches: 0
numReplacements: 0
- file: "./lib/classic.mjs"
hasChanged: true
numMatches: 1
numReplacements: 1
- file: "./lib/flat.cjs"
hasChanged: true
numMatches: 1
numReplacements: 1
- file: "./lib/flat.d.cts"
hasChanged: false
numMatches: 0
numReplacements: 0
- file: "./lib/flat.d.mts"
hasChanged: false
numMatches: 0
numReplacements: 0
- file: "./lib/flat.mjs"
hasChanged: true
numMatches: 1
numReplacements: 1
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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";
```

### 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Tidelift is working with the maintainers of `eslint-plugin-functional` and a gro

## Rulesets

The following rulesets are made available by this plugin:
The following rulesets are made available by this plugin.

Presets:

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
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
21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,25 @@
"Jonas Kello"
],
"exports": {
"import": "./lib/index.mjs",
"require": "./lib/index.cjs"
".": {
"types": {
"import": "./lib/classic.d.mts",
"require": "./lib/classic.d.cts"
},
"import": "./lib/classic.mjs",
"require": "./lib/classic.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",
"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];
44 changes: 26 additions & 18 deletions src/index.ts → src/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@ 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";

const config: Linter.Plugin = {
export default {
rules,
configs: {
all,
lite,
recommended,
strict,
off,
"disable-type-checked": disableTypeChecked,
"external-vanilla-recommended": externalVanillaRecommended,
"external-typescript-recommended": externalTypeScriptRecommended,
currying,
"no-exceptions": noExceptions,
"no-mutations": noMutations,
"no-other-paradigms": noOtherParadigms,
"no-statements": noStatements,
stylistic,
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 },
},
};

export default config;
} as Linter.Plugin;
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.

Loading

0 comments on commit 5fa7c2c

Please sign in to comment.