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

Create ESLint flat config setup #258

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a6bd899
Create ESLint flat config setup
leroykorterink May 28, 2024
1154d0e
Remove Lerna configuration
leroykorterink Nov 6, 2024
b358348
Update Node.js version matrix in GitHub Actions
leroykorterink Nov 6, 2024
6005d11
Update GitHub Actions workflow for flat config package
leroykorterink Nov 6, 2024
f3b759a
Refactor ESLint scripts to run on the current directory instead of wo…
leroykorterink Nov 6, 2024
2f49290
Add exports and update README.md
leroykorterink Nov 6, 2024
48fca88
Fix export path
leroykorterink Nov 6, 2024
b067c3e
Add eslint-plugin-storybook
leroykorterink Nov 7, 2024
5ef951c
Ensure @typescript-eslint/parser is installed correctly
leroykorterink Nov 7, 2024
3fa1e21
Disable react/react-in-jsx-scope because it's often available globally
leroykorterink Nov 7, 2024
be43f84
Allow literals in story files
leroykorterink Nov 7, 2024
93dbc5e
Allow React component name convention in style files
leroykorterink Nov 7, 2024
1aff390
Allow implicit return type in IFFEs and expressions
leroykorterink Nov 7, 2024
b66651b
Add eslint-plugin-react-hooks
leroykorterink Nov 7, 2024
e0c9e2c
Add security, markdown and prettier configuration
leroykorterink Nov 8, 2024
fa2abd0
Move security plugin to dedicated node preset
leroykorterink Nov 8, 2024
f4c940a
Update readme
leroykorterink Nov 8, 2024
340baa2
Reorder typescriptReact configuration to include typescriptReact afte…
leroykorterink Nov 8, 2024
dd88142
Fix casing typo in README.md
leroykorterink Nov 19, 2024
77617e2
Remove typescript-eslint reference from javascript example
leroykorterink Nov 19, 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
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

25 changes: 9 additions & 16 deletions .github/workflows/bump-version-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ concurrency:
on:
workflow_dispatch:
inputs:
config:
description: 'The config for which to create a new version'
required: true
type: choice
options:
- eslint-config
- eslint-config-typescript
- eslint-config-react
- eslint-config-typescript-react
version:
description: 'Semver type of new version (major / minor / patch / prerelease)'
required: true
Expand Down Expand Up @@ -58,19 +49,21 @@ jobs:
run: npm ci

- name: Setup Git
run: |
run: |-
git config user.name github-actions
git config user.email [email protected]

- name: bump version
run: |
npm version ${{ github.event.inputs.version }} -w packages/${{ github.event.inputs.config }} --no-git-tag-version --preid ${{ github.event.inputs.prereleaseid }}
run: |-
npm version ${{ github.event.inputs.version }} --no-git-tag-version --preid ${{ github.event.inputs.prereleaseid }}
git add .
git commit -m "${{ github.event.inputs.config }} v$(npm pkg get version --prefix packages/${{ github.event.inputs.config }} | tr -d '"')" --no-verify
git tag @mediamonks/${{ github.event.inputs.config }}@$(npm pkg get version --prefix packages/${{ github.event.inputs.config }} | tr -d '"') -m "${{ github.event.inputs.config }} v$(npm pkg get version --prefix packages/${{ github.event.inputs.config }} | tr -d '"')"
git commit -m "v$(npm pkg get version | tr -d '"')" --no-verify
git tag @mediamonks/eslint-config@$(npm pkg get version | tr -d '"') -m "v$(npm pkg get version | tr -d '"')"

- name: publish
run: |
run: |-
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
npm publish -w packages/${{ github.event.inputs.config }} --provenance
npm publish --provenance
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh

npx lint-staged
npm run eslint
npm run build
npx eslint
12 changes: 0 additions & 12 deletions .vscode/settings.json

This file was deleted.

209 changes: 67 additions & 142 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,168 +1,93 @@
# Media.Monks - eslint Configuration
# Monks - eslint Configuration

The official Media.Monks eslint configuration, based on the
[Frontend Coding Standards](https://github.com/mediamonks/frontend-coding-standards).
The Monks ESLint Configuration is a set of linting rules and presets designed to enforce the
[Frontend Coding Standards](https://github.com/mediamonks/frontend-coding-standards) at Monks. This
configuration helps maintain code quality and consistency across different projects by providing
tailored presets for various project types, including JavaScript, TypeScript, and React.

| Package | Version | Downloads |
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `@mediamonks/eslint-config` | [![](https://img.shields.io/npm/v/@mediamonks/eslint-config)](https://npmjs.com/@mediamonks/eslint-config) | ![](https://img.shields.io/npm/dm/@mediamonks/eslint-config) |
| `@mediamonks/eslint-config-react` | [![](https://img.shields.io/npm/v/@mediamonks/eslint-config-react)](https://npmjs.com/@mediamonks/eslint-config-react) | ![](https://img.shields.io/npm/dm/@mediamonks/eslint-config-react) |
| `@mediamonks/eslint-config-typescript` | [![](https://img.shields.io/npm/v/@mediamonks/eslint-config-typescript)](https://npmjs.com/@mediamonks/eslint-config-typescript) | ![](https://img.shields.io/npm/dm/@mediamonks/eslint-config-typescript) |
| `@mediamonks/eslint-config-typescript-react` | [![](https://img.shields.io/npm/v/@mediamonks/eslint-config-typescript-react)](https://npmjs.com/@mediamonks/eslint-config-typescript-react) | ![](https://img.shields.io/npm/dm/@mediamonks/eslint-config-typescript-react) |
| `@mediamonks/eslint-plugin-react` | [![](https://img.shields.io/npm/v/@mediamonks/eslint-plugin-react)](https://npmjs.com/@mediamonks/eslint-plugin-react) | ![](https://img.shields.io/npm/dm/@mediamonks/eslint-plugin-react) |
## Quickstart

## Installation

Installation and configuration in a project is super easy, follow the instructions for one of the
following project types.

- [For JavaScript projects](#for-javascript-projects)
- [For JavaScript projects using React](#for-javascript-projects-using-react)
- [For TypeScript projects](#for-typescript-projects)
- [For TypeScript projects using React](#for-typescript-projects-using-react)

### For JavaScript projects

Install the following package(s):
1. Install `@mediamonks/eslint-config`

```sh
npm install --save-dev @mediamonks/eslint-config
```

Add the following configuration to your `package.json`

```json
"eslintConfig": {
"overrides": [
{
"files": ["*.js"],
"extends": [
"@mediamonks/eslint-config"
]
}
]
}
```

### For JavaScript projects using React
2. Create a `eslint.config.js` file in the root of your module

Install the following package(s):
3. Configure your project with one of the configuration presets

```sh
npm install --save-dev \
@mediamonks/eslint-config
@mediamonks/eslint-config-react
```
### Presets

Add the following configuration to your `package.json`

```json
"eslintConfig": {
"overrides": [
{
"files": ["*.js"],
"extends": [
"@mediamonks/eslint-config"
]
}
{
"files": ["*.jsx"],
"extends": [
"@mediamonks/eslint-config",
"@mediamonks/eslint-config-react"
]
}
]
}
```
| Project Type | Preset Name | Description |
| -------------------- | --------------- | -------------------------------------------- |
| JavaScript | javascript | Preset for standard JavaScript projects |
| JavaScript and React | react | Preset for React projects using JavaScript |
| TypeScript | typescript | Preset for TypeScript projects |
| TypeScript and React | typescriptReact | Preset for React projects using TypeScript |
| JavaScript (Node.js) | javascriptNode | Preset for Node.js projects using JavaScript |
| TypeScript (Node.js) | typescriptNode | Preset for Node.js projects using TypeScript |

### For TypeScript projects
## Examples

Install the following package(s):
The package provides presets tailored for different project types. These presets ensure that your
project adheres to the coding standards and best practices. Below are examples of how to configure
your project using these presets.

```sh
npm install --save-dev \
@mediamonks/eslint-config \
@mediamonks/eslint-config-typescript
```
### For projects with JavaScript

Add the following configuration to your `package.json`
```js
import { configs } from '@mediamonks/eslint-config';

```json
"eslintConfig": {
"overrides": [
{
"files": ["*.js"],
"extends": [
"@mediamonks/eslint-config"
]
export default [
{
ignores: ['build/*'],
},
...configs.JavaScript,
{
leroykorterink marked this conversation as resolved.
Show resolved Hide resolved
languageOptions: {
// Your project language options...
// Please see the eslint/typescript-eslint documentation for more details
},
leroykorterink marked this conversation as resolved.
Show resolved Hide resolved
{
"files": ["*.ts"],
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@mediamonks/eslint-config",
"@mediamonks/eslint-config-typescript"
]
}
]
}
},
];
```

### For TypeScript projects using React
### For projects with TypeScript

Install the following package(s):
```js
import { configs } from '@mediamonks/eslint-config';

```sh
npm install --save-dev \
@mediamonks/eslint-config \
@mediamonks/eslint-config-react \
@mediamonks/eslint-config-typescript \
@mediamonks/eslint-config-typescript-react
export default [
{
ignores: ['build/*'],
},
...configs.typescript,
{
languageOptions: {
parserOptions: {
project: true,
},
},
},
];
```

Add the following configuration to your `package.json`
### For projects with TypeScript and React

```json
"eslintConfig": {
"overrides": [
{
"files": ["*.js"],
"extends": [
"@mediamonks/eslint-config"
]
},
{
"files": ["*.jsx"],
"extends": [
"@mediamonks/eslint-config",
"@mediamonks/eslint-config-react"
]
},
{
"files": ["*.ts"],
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@mediamonks/eslint-config",
"@mediamonks/eslint-config-typescript"
]
```js
import { configs } from '@mediamonks/eslint-config';

export default [
{
ignores: ['build/*'],
},
...configs.typescriptReact,
{
languageOptions: {
// Your project language options...
// Please see the eslint/typescript-eslint documentation for more details
},
{
"files": ["*.tsx"],
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@mediamonks/eslint-config",
"@mediamonks/eslint-config-react",
"@mediamonks/eslint-config-typescript",
"@mediamonks/eslint-config-typescript-react"
]
}
]
}
},
];
```
16 changes: 16 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { configs } from './src/index.js';

/**
* @type {import('eslint').Linter.Config}
*/
export default [
...configs.javascript,
{
name: 'local configuration',
languageOptions: {
parserOptions: {
projectService: true,
},
},
},
];
6 changes: 0 additions & 6 deletions lerna.json

This file was deleted.

Loading
Loading