Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Convert to ESLint Flat Config #207

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7a3dca1
converting base files
bsokol-wl May 1, 2024
2cb766b
more updates
bsokol-wl May 2, 2024
28fba7e
fixing workleap plugin
bsokol-wl May 2, 2024
c7d8573
cleanup
bsokol-wl May 2, 2024
6c84195
documentation and bug fixes
bsokol-wl May 3, 2024
3d72e34
Refactor to consistent arrays
bsokol-wl May 6, 2024
8d2bcff
Removing unnecessary config values
bsokol-wl May 6, 2024
8464507
fixing node globals issues
bsokol-wl May 6, 2024
b6a5e1d
fixing failing tests
bsokol-wl May 6, 2024
c44f94a
fix import build error
bsokol-wl May 6, 2024
9ccb3c3
convert remaining eslint configs
bsokol-wl May 6, 2024
b6ed33c
let knip analyze eslint plugin
bsokol-wl May 6, 2024
217327a
Updating sample app
bsokol-wl May 6, 2024
10accd0
fix typo in ignore
bsokol-wl May 6, 2024
fce525a
update docs
bsokol-wl May 7, 2024
cc54e44
add limited scope helper
bsokol-wl May 7, 2024
cb81189
update config for single file
bsokol-wl May 7, 2024
67151c2
update to use antfu helpers
bsokol-wl May 8, 2024
ec737d1
remove unused leftovers
bsokol-wl May 8, 2024
a5d8188
update lockfile
bsokol-wl May 8, 2024
b8c6646
clean up samples
bsokol-wl May 8, 2024
565bb69
add react global
bsokol-wl May 8, 2024
9c5b87b
move configs back to individual packages
bsokol-wl May 9, 2024
ae5a507
remove useless test
bsokol-wl May 9, 2024
4aea643
Merge branch 'main' into feat/eslint-flat-config
bsokol-wl May 9, 2024
1647bae
update ci to use pnpm 9
bsokol-wl May 9, 2024
c5df596
clean up unused scripts
bsokol-wl May 9, 2024
538d663
re-add removed self-dependencies
bsokol-wl May 9, 2024
ae489a9
PR updates
bsokol-wl May 10, 2024
cf980fa
fix more PR comments
bsokol-wl May 10, 2024
8e46c5c
Fix knip
patricklafrance May 10, 2024
2dab2ae
fix config naming
bsokol-wl May 10, 2024
fd7f027
update all documentation
bsokol-wl May 10, 2024
f7e3f98
add knip issue info
bsokol-wl May 10, 2024
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
5 changes: 5 additions & 0 deletions .changeset/tidy-mangos-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workleap/eslint-plugin": major
---

Convert all configs to flat config. Update documentation.
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
name: Install pnpm
id: pnpm-install
with:
version: 8
version: 9
run_install: false

- name: Get pnpm store directory
Expand Down
77 changes: 44 additions & 33 deletions docs/eslint/advanced-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,61 @@ Each configuration piece can be extended individually, or in combination with ot

To extend the configuration with a single piece:

```json !#4 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": "plugin:@workleap/typescript",
"rules": {
...
}
}
```javascript !#4 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";

const config = [
...workleapPlugin.configs.typescript
];

export default config;
```

### Multiple pieces

To extend the configuration with multiple pieces:

```json !#4 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": ["plugin:@workleap/core", "plugin:@workleap/typescript"],
"rules": {
...
}
}
```javascript !#4-5 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";

const config = [
...workleapPlugin.configs.core,
...workleapPlugin.configs.typescript,
];

export default config;
```

## Lint additional files
The `concat` helper from [eslint-flat-config-utils](https://github.com/antfu/eslint-flat-config-utils) is useful to avoid having to spread arrays.

```javascript !#1,4-7 eslint.config.js
import { concat } from "eslint-flat-config-utils";
import workleapPlugin from "@workleap/eslint-config";

const config = concat(
workleapPlugin.configs.core,
workleapPlugin.configs.typescript,
);

The configuration pieces already targets which file extensions their linting rules will be applied to. If you wish to lint additional file extensions for a given piece you can add an ESLint [override block](https://eslint.org/docs/latest/use/configure/configuration-files#how-do-overrides-work):

```json !#5-10 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": ["plugin:@workleap/react"],
"overrides": [
{
"files": ["*.js", "*.jsx"],
"extends": "plugin:@workleap/react"
}
]
}
export default config;
```

## Lint additional files

The configuration pieces already target which file extensions their linting rules will be applied to. If you wish to lint additional file extensions for a given piece you can override the `files` key as you would with any JavaScript object. Since Workleap shared configs are arrays, you will need to use a `map` function.

```javascript !#4-7 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";

const config = [
...workleapPlugin.configs.react.map(conf => ({
...conf,
files: ["*.js", "*.jsx"],
}))
];

export default config;
```



Expand Down
109 changes: 76 additions & 33 deletions docs/eslint/custom-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,57 @@ For a list of the rules included with the default shared configurations, refer t

You can disable a default rule by defining the rule locally with the `"off"` value:

```json !#5-7 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": "plugin:@workleap/web-application",
"rules": {
"no-var": "off"
```javascript !#5-9 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";

const config = [
...workleapPlugin.configs.webApplication,
{
rules: {
"no-var": "off"
}
}
}
];

export default config;
```

## Change a default rule severity

You can update the severity of a rule by defining the rule locally with either the `"warn"` or `"error"` severity:

```json !#5-7 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": "plugin:@workleap/web-application",
"rules": {
"jsx-a11y/alt-text": "error"
```javascript !#5-9 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";

const config = [
...workleapPlugin.configs.webApplication,
{
rules: {
"jsx-a11y/alt-text": "error"
}
}
}
];

export default config;
```

## Change a default rule value

You can update a default rule value by defining the rule locally with its new value:

```json !#5-7 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": "plugin:@workleap/web-application",
"rules": {
"quotes": ["warn", "single"]
```javascript !#5-9 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";

const config = [
...workleapPlugin.configs.webApplication,
{
rules: {
"quotes": ["warn", "single"]
}
}
}
];

export default config;
```

!!!light
Expand All @@ -65,16 +77,47 @@ Please, don't update your project configuration to use single quotes :sweat_smil

You can add configure additional rules from a third party [ESLint plugin](https://eslint.org/docs/latest/use/configure/plugins):

```json !#4,6-8 .eslintrc.json
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"plugins": ["unicorn"],
"extends": "plugin:@workleap/web-application",
"rules": {
"unicorn/better-regex": "error"
```javascript !#2,6-13 eslint.config.js
import workleapPlugin from "@workleap/eslint-config";
import eslintPluginUnicorn from 'eslint-plugin-unicorn';

const config = [
...workleapPlugin.configs.webApplication,
{
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: {
"unicorn/better-regex": "error"
}
}
}
];

export default config;
```

## `concat` helper

If you are combining many configuration objects, it can be helpful to use the `concat` helper from [eslint-flat-config-utils](https://github.com/antfu/eslint-flat-config-utils) to avoid having to spread arrays.

```javascript !#1,5,15 eslint.config.js
import { concat } from "eslint-flat-config-utils";
import workleapPlugin from "@workleap/eslint-config";
import eslintPluginUnicorn from 'eslint-plugin-unicorn';

const config = concat(
workleapPlugin.configs.webApplication,
{
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: {
"unicorn/better-regex": "error"
}
}
);

export default config;
```

## Start from scratch
Expand Down
Loading