Skip to content

Commit 441fc1d

Browse files
feat: move flat configs to new "flat" subpackage
1 parent 42a6299 commit 441fc1d

File tree

10 files changed

+246
-151
lines changed

10 files changed

+246
-151
lines changed

GETTING_STARTED.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ pnpm add -D eslint @typescript-eslint/parser eslint-plugin-functional
3030

3131
## Usage
3232

33+
### Flat Config
34+
35+
If using the new [flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new),
36+
import from `eslint-plugin-functional/flat`.
37+
38+
```ts
39+
import functional from "eslint-plugin-functional/flat";
40+
```
41+
42+
### Classic Config
43+
3344
Add `functional` to the plugins section of your `.eslintrc` configuration file. Then configure the rules you want to use under the rules section.
3445

3546
```jsonc

README.md

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ Tidelift is working with the maintainers of `eslint-plugin-functional` and a gro
3535

3636
The following rulesets are made available by this plugin.
3737

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

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

110107
### Currying
111108

112-
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
113-
| :----------------------------------------------------------- | :----------------------------- | :-------------------------- | :- | :- | :- | :- | :- | :- |
114-
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | ☑️ ✅ 🔒 ![badge-currying][] | | | | | | |
109+
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
110+
| :----------------------------------------------------------- | :----------------------------- | :------------------------ | :--- | :--- | :--- | :--- | :--- | :--- |
111+
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | ☑️ ✅ 🔒 ![badge-currying][] | | | | | | |
115112

116113
### No Exceptions
117114

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

124121
### No Mutations
125122

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

134131
### No Other Paradigms
135132

136-
| Name                | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
137-
| :------------------------------------------------------- | :------------------------------------------------------------------------ | :------------------------------------ | :- | :--- | :- | :- | :- | :- |
138-
| [no-classes](docs/rules/no-classes.md) | Disallow classes. | ☑️ ✅ 🔒 ![badge-no-other-paradigms][] | | | | | | |
139-
| [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][] | | | | | 💭 | |
140-
| [no-this-expressions](docs/rules/no-this-expressions.md) | Disallow this access. | 🔒 ![badge-no-other-paradigms][] | | ☑️ ✅ | | | | |
133+
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
134+
| :------------------------------------------------------- | :------------------------------------------------------------------------ | :---------------------------------- | :--- | :--- | :--- | :--- | :--- | :--- |
135+
| [no-classes](docs/rules/no-classes.md) | Disallow classes. | ☑️ ✅ 🔒 ![badge-no-other-paradigms][] | | | | | | |
136+
| [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][] | | | | | 💭 | |
137+
| [no-this-expressions](docs/rules/no-this-expressions.md) | Disallow this access. | 🔒 ![badge-no-other-paradigms][] | | ☑️ ✅ | | | | |
141138

142139
### No Statements
143140

144-
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
145-
| :------------------------------------------------------------------- | :--------------------------------------------- | :------------------------------- | :- | :- | :- | :- | :- | :- |
146-
| [no-conditional-statements](docs/rules/no-conditional-statements.md) | Disallow conditional statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
147-
| [no-expression-statements](docs/rules/no-expression-statements.md) | Disallow expression statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
148-
| [no-loop-statements](docs/rules/no-loop-statements.md) | Disallow imperative loops. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | | |
149-
| [no-return-void](docs/rules/no-return-void.md) | Disallow functions that don't return anything. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | 💭 | |
141+
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | |
142+
| :------------------------------------------------------------------- | :--------------------------------------------- | :----------------------------- | :--- | :--- | :--- | :--- | :--- | :--- |
143+
| [no-conditional-statements](docs/rules/no-conditional-statements.md) | Disallow conditional statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
144+
| [no-expression-statements](docs/rules/no-expression-statements.md) | Disallow expression statements. | ✅ 🔒 ![badge-no-statements][] | | ☑️ | | | 💭 | |
145+
| [no-loop-statements](docs/rules/no-loop-statements.md) | Disallow imperative loops. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | | |
146+
| [no-return-void](docs/rules/no-return-void.md) | Disallow functions that don't return anything. | ☑️ ✅ 🔒 ![badge-no-statements][] | | | | | 💭 | |
150147

151148
### Stylistic
152149

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

159156
<!-- end auto-generated rules list -->
160157
<!-- markdownlint-restore -->

knip.jsonc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"$schema": "node_modules/knip/schema-jsonc.json",
3-
"entry": ["src/index.ts!", "tests/**/*.test.ts", "cz-adapter/index.js"],
3+
"entry": [
4+
"src/flat.ts!",
5+
"src/classic.ts!",
6+
"tests/**/*.test.ts",
7+
"cz-adapter/index.js",
8+
],
49
"project": ["src/**/*.ts!", "tests/**/*.ts", "cz-adapter/**/*.{js,ts}"],
510
"ignore": ["tests/fixture/file.ts"],
611
"ignoreDependencies": ["@types/eslint", "@vitest/coverage-istanbul"],

package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,25 @@
3434
"Jonas Kello"
3535
],
3636
"exports": {
37-
"types": {
38-
"import": "./lib/index.d.mts",
39-
"require": "./lib/index.d.cts"
37+
".": {
38+
"types": {
39+
"import": "./lib/classic.d.mts",
40+
"require": "./lib/classic.d.cts"
41+
},
42+
"import": "./lib/classic.mjs",
43+
"require": "./lib/classic.cjs"
4044
},
41-
"import": "./lib/index.mjs",
42-
"require": "./lib/index.cjs"
45+
"./flat": {
46+
"types": {
47+
"import": "./lib/flat.d.mts",
48+
"require": "./lib/flat.d.cts"
49+
},
50+
"import": "./lib/flat.mjs",
51+
"require": "./lib/flat.cjs"
52+
}
4353
},
44-
"main": "lib/index.cjs",
45-
"types": "lib/index.d.cts",
54+
"main": "lib/classic.cjs",
55+
"types": "lib/classic.d.cts",
4656
"files": [
4757
"lib/",
4858
"package.json",

rollup.config.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ const treeshake = {
1212
unknownGlobalSideEffects: false,
1313
} satisfies RollupOptions["treeshake"];
1414

15-
const library = {
16-
input: "src/index.ts",
15+
const classic = {
16+
input: "src/classic.ts",
1717

1818
output: [
1919
{
20-
file: pkg.exports.import,
20+
file: pkg.exports["."].import,
2121
format: "esm",
2222
sourcemap: false,
2323
},
2424
{
25-
file: pkg.exports.require,
25+
file: pkg.exports["."].require,
2626
format: "cjs",
2727
sourcemap: false,
2828
},
@@ -42,4 +42,34 @@ const library = {
4242
treeshake,
4343
} satisfies RollupOptions;
4444

45-
export default [library];
45+
const flat = {
46+
input: "src/flat.ts",
47+
48+
output: [
49+
{
50+
file: pkg.exports["./flat"].import,
51+
format: "esm",
52+
sourcemap: false,
53+
},
54+
{
55+
file: pkg.exports["./flat"].require,
56+
format: "cjs",
57+
sourcemap: false,
58+
},
59+
],
60+
61+
plugins: [
62+
rollupPluginAutoExternal(),
63+
rollupPluginTs({
64+
transpileOnly: true,
65+
tsconfig: "tsconfig.build.json",
66+
}),
67+
rollupPluginDeassert({
68+
include: ["**/*.{js,ts}"],
69+
}),
70+
],
71+
72+
treeshake,
73+
} satisfies RollupOptions;
74+
75+
export default [classic, flat];

src/classic.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { type Linter } from "@typescript-eslint/utils/ts-eslint";
2+
3+
import all from "#eslint-plugin-functional/configs/all";
4+
import currying from "#eslint-plugin-functional/configs/currying";
5+
import disableTypeChecked from "#eslint-plugin-functional/configs/disable-type-checked";
6+
import externalTypeScriptRecommended from "#eslint-plugin-functional/configs/external-typescript-recommended";
7+
import externalVanillaRecommended from "#eslint-plugin-functional/configs/external-vanilla-recommended";
8+
import lite from "#eslint-plugin-functional/configs/lite";
9+
import noExceptions from "#eslint-plugin-functional/configs/no-exceptions";
10+
import noMutations from "#eslint-plugin-functional/configs/no-mutations";
11+
import noOtherParadigms from "#eslint-plugin-functional/configs/no-other-paradigms";
12+
import noStatements from "#eslint-plugin-functional/configs/no-statements";
13+
import off from "#eslint-plugin-functional/configs/off";
14+
import recommended from "#eslint-plugin-functional/configs/recommended";
15+
import strict from "#eslint-plugin-functional/configs/strict";
16+
import stylistic from "#eslint-plugin-functional/configs/stylistic";
17+
import { rules } from "#eslint-plugin-functional/rules";
18+
import { ruleNameScope } from "#eslint-plugin-functional/utils/misc";
19+
20+
export default {
21+
rules,
22+
configs: {
23+
all: { plugins: [ruleNameScope], rules: all },
24+
lite: { plugins: [ruleNameScope], rules: lite },
25+
recommended: { plugins: [ruleNameScope], rules: recommended },
26+
strict: { plugins: [ruleNameScope], rules: strict },
27+
off: { plugins: [ruleNameScope], rules: off },
28+
"disable-type-checked": {
29+
plugins: [ruleNameScope],
30+
rules: disableTypeChecked,
31+
},
32+
"external-vanilla-recommended": {
33+
plugins: [ruleNameScope],
34+
rules: externalVanillaRecommended,
35+
},
36+
"external-typescript-recommended": {
37+
plugins: [ruleNameScope],
38+
rules: externalTypeScriptRecommended,
39+
},
40+
currying: { plugins: [ruleNameScope], rules: currying },
41+
"no-exceptions": { plugins: [ruleNameScope], rules: noExceptions },
42+
"no-mutations": { plugins: [ruleNameScope], rules: noMutations },
43+
"no-other-paradigms": { plugins: [ruleNameScope], rules: noOtherParadigms },
44+
"no-statements": { plugins: [ruleNameScope], rules: noStatements },
45+
stylistic: { plugins: [ruleNameScope], rules: stylistic },
46+
},
47+
} as Linter.Plugin;

0 commit comments

Comments
 (0)