Skip to content

Commit

Permalink
feat!: Update to flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed Oct 23, 2024
1 parent ad0b353 commit bdc2193
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 220 deletions.
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ISC License

Copyright (c) 2022, Mark Skelton
Copyright (c) 2024, Mark Skelton

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
62 changes: 18 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,35 @@
[![package version](https://img.shields.io/npm/v/@mskelton/eslint-config)](https://www.npmjs.com/package/@mskelton/eslint-config)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

> Simple and sensible ESLint config.
Simple and sensible ESLint config.

## Description

This package contains a simple and sensible ESLint config that you can use to
get up and running with a TypeScript. It uses the
[TypeScript ESLint parser](https://github.com/typescript-eslint/typescript-eslint)
and [Prettier](https://prettier.io).
get up and running. It uses the
[TypeScript ESLint](https://github.com/typescript-eslint/typescript-eslint) and
[Prettier](https://prettier.io).

## Installation

```sh
npm install -D @mskelton/eslint-config eslint eslint-plugin-sort @typescript-eslint/eslint-plugin @typescript-eslint/parser
```

### React

If using React, install the following peer dependencies in addition to the list
above.

```sh
npm install -D eslint-plugin-react eslint-plugin-react-hooks
```

### Vitest

If using Vitest, install the following peer dependencies in addition to the list
above.

```sh
npm install -D eslint-plugin-vitest
```

### Jest

If using Jest, install the following peer dependencies in addition to the list
above.

```sh
npm install -D eslint-plugin-jest
npm install -D @mskelton/eslint-config eslint
```

## Usage

In your `.eslintrc` file, add the following content including the configs you
want for your project.
In your `eslint.config.mjs` file, add the following content including the
configs you want for your project.

```js
import mskelton from "@mskelton/eslint-config"

```json
{
"extends": [
"@mskelton",
"@mskelton/eslint-config/react",
"@mskelton/eslint-config/vitest",
"@mskelton/eslint-config/jest",
"@mskelton/eslint-config/playwright"
]
}
/** @type {import('eslint').Linter.Config[]} */
export default [
...mskelton.recommended,
...mskelton.react,
...mskelton.playwright,
...mskelton.vitest,
...mskelton.jest,
]
```
Binary file modified bun.lockb
Binary file not shown.
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import mskelton from "./lib/index.js"

/** @type {import('eslint').Linter.Config[]} */
export default [
// ...mskelton.recommended,
// ...mskelton.react,
// ...mskelton.playwright,
// ...mskelton.vitest,
...mskelton.jest,
]
57 changes: 0 additions & 57 deletions index.js

This file was deleted.

14 changes: 0 additions & 14 deletions jest.js

This file was deleted.

24 changes: 24 additions & 0 deletions lib/configs/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-check

import jest from "eslint-plugin-jest"
import globals from "globals"

/** @type {import("eslint").Linter.Config[]} */
export default [
{
...jest.configs["flat/recommended"],
files: ["**/__tests__/**", "**/*.{spec,test}.{js,jsx,ts,tsx}"],
rules: {
...jest.configs["flat/recommended"].rules,
...jest.configs["flat/style"].rules,
},
},
{
files: ["**/__mocks__/**"],
languageOptions: {
globals: {
...globals.jest,
},
},
},
]
24 changes: 24 additions & 0 deletions lib/configs/playwright.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-check

import playwright from "eslint-plugin-playwright"

/** @type {import("eslint").Linter.Config[]} */
export default [
playwright.configs["flat/recommended"],
{
rules: {
"playwright/missing-playwright-await": [
"error",
{ customMatchers: ["toPassAxe"] },
],
"playwright/prefer-lowercase-title": [
"error",
{ ignoreTopLevelDescribe: true },
],
"playwright/prefer-strict-equal": "error",
"playwright/prefer-to-be": "error",
"playwright/prefer-to-have-length": "error",
"playwright/require-top-level-describe": "error",
},
},
]
49 changes: 49 additions & 0 deletions lib/configs/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import react from "eslint-plugin-react"
import globals from "globals"
import reactHooks from "eslint-plugin-react-hooks"

/** @type {import("eslint").Linter.Config[]} */
export default [
react.configs.flat.recommended,
{
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
react,
"react-hooks": reactHooks,
},
settings: {
react: {
version: "detect",
},
},
rules: {
"react/button-has-type": "error",
"react/destructuring-assignment": "error",
"react/function-component-definition": [
"error",
{
namedComponents: "function-declaration",
unnamedComponents: "function-expression",
},
],
"react/jsx-boolean-value": "error",
"react/jsx-curly-brace-presence": ["error", "never"],
"react/jsx-no-useless-fragment": "error",
"react/jsx-sort-props": ["error", { reservedFirst: true }],
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/self-closing-comp": "warn",
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error",
},
},
]
61 changes: 61 additions & 0 deletions lib/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @ts-check

import eslint from "@eslint/js"
import prettier from "eslint-config-prettier"
import sort from "eslint-plugin-sort"
import globals from "globals"
import tseslint from "typescript-eslint"

/** @type {import("eslint").Linter.Config[]} */
export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
sort.configs["flat/recommended"],
prettier,
{
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-useless-constructor": "error",
"no-template-curly-in-string": "error",
"no-unused-vars": "off",
"no-useless-constructor": "off",
"no-useless-rename": "warn",
"no-var": "error",
"object-shorthand": "warn",
"prefer-template": "error",
"sort/exports": "off",
"sort/imports": [
"warn",
{
groups: [
{ order: 10, type: "side-effect" },
{ order: 40, regex: "^\\.+\\/" },
{ order: 20, type: "dependency" },
{ order: 30, type: "other" },
],
typeOrder: "last",
},
],
"sort/string-enums": "warn",
"sort/string-unions": "warn",
"sort/type-properties": "warn",
},
},
]
15 changes: 15 additions & 0 deletions lib/configs/vitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check

import vitest from "eslint-plugin-vitest"

/** @type {import("eslint").Linter.Config[]} */
export default [
{
files: ["**/*.{spec,test}.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"],
plugins: { vitest },
rules: {
...vitest.configs.all.rules,
"vitest/no-hooks": "off",
},
},
]
11 changes: 11 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Linter } from "eslint"

declare const config: {
jest: Linter.Config[]
playwright: Linter.Config[]
react: Linter.Config[]
recommended: Linter.Config[]
vitest: Linter.Config[]
}

export default config
15 changes: 15 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import jest from "./configs/jest.js"
import playwright from "./configs/playwright.js"
import react from "./configs/react.js"
import recommended from "./configs/recommended.js"
import vitest from "./configs/vitest.js"

const config = {
jest,
playwright,
react,
recommended,
vitest,
}

export default config
Loading

0 comments on commit bdc2193

Please sign in to comment.