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

Eslint shared config environments #11

Merged
merged 17 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 2 additions & 27 deletions .eslintrc.js
JulienMartel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import'],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts']
},
'import/resolver': {
typescript: {
alwaysTryTypes: true
}
}
},
extends: [
'airbnb-base',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier'
],
extends: ['./node'],
rules: {
indent: 'off',
'no-use-before-define': 'off',
'no-else-return': [
'error',
{
allowElseIf: true
}
],
'import/extensions': 'off'
'no-console': 'off'
leoortizz marked this conversation as resolved.
Show resolved Hide resolved
}
}
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install pnpm
run: curl -L https://unpkg.com/@pnpm/self-installer | node
- name: Install dependencies
run: pnpm install

- name: Build step
run: pnpm build

lint-and-format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install pnpm
run: curl -L https://unpkg.com/@pnpm/self-installer | node
- name: Install dependencies
run: pnpm install

- name: Lint step
run: pnpm lint
- name: Format step
run: pnpm dlx prettier --check "**/*.{js,ts}"
6 changes: 3 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm commitlint --edit $1
npx --no -- commitlint --edit ${1}
2 changes: 1 addition & 1 deletion .versionrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
{ "type": "chore", "section": "Chore" },
{ "type": "revert", "section": "Reverts" }
]
}
}
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
# eslint-config

ESLint config used at Monogram.
ESLint config used at [Monogram](https://monogram.io/).

## Usage

Run the configuration with the following command:
### Automatic

Run the following command and follow the prompts.

```sh
npx @monogram/eslint-config
```

### Manual

Install dependencies

```sh
pnpm add -D eslint @monogram/eslint-config
```

Depending on your project, add the following to a `.eslintrc.js` file:

#### Node.js rules

```js
module.exports = {
extends: '@monogram/eslint-config/node'
}
```

_[See the rules](./node.js)_

#### Next.js rules

```js
module.exports = {
extends: '@monogram/eslint-config/next'
}
```

_[See the rules](./next.js)_

#### Svelte

_coming soon_

#### Astro

_coming soon_
14 changes: 5 additions & 9 deletions src/configs/nextjs.ts → next.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = {
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import'],
settings: {
Expand All @@ -11,15 +11,12 @@ const config = {
}
}
},

extends: [
'next/core-web-vitals',
'airbnb',
'airbnb/hooks',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'next', // = eslint-plugin-react / eslint-plugin-react-hooks / eslint-plugin-next
'next/core-web-vitals',
'prettier'
'eslint-config-prettier'
],
rules: {
indent: 'off',
Expand All @@ -39,8 +36,7 @@ const config = {
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
'react/prop-types': 'off', // Since we do not use prop-types
'react/require-default-props': 'off', // Since we do not use prop-types
'no-plusplus': [2, { allowForLoopAfterthoughts: true }] // allow ++ only in for loops
'no-plusplus': [2, { allowForLoopAfterthoughts: true }], // allow ++ only in for loops
'react/react-in-jsx-scope': 'off' // not needed in next.js
}
}

export default config
9 changes: 5 additions & 4 deletions src/configs/node.ts → node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = {
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import'],
settings: {
Expand All @@ -18,16 +18,17 @@ const config = {
'prettier'
],
rules: {
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
indent: 'off',
'@typescript-eslint/consistent-type-imports': 'error',
'no-use-before-define': 'off',
'no-else-return': [
'error',
{
allowElseIf: true
}
],
'import/extensions': 'off'
'import/extensions': 'off',
'import/prefer-default-export': 'off'
}
}

export default config
75 changes: 36 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,58 @@
"version": "0.1.2",
"description": "ESLint configs used at Monogram",
"keywords": [
"eslint",
"eslint-config-airbnb",
"eslint-config-next"
"eslint-config",
"nodejs",
"nextjs"
],
"license": "MIT",
"scripts": {
"update-local": "pnpm build && pnpm install-locally",
"install-locally": "npm install -g",
"postinstall": "pnpm build",
"build": "tsc",
"lint": "eslint",
"prepublish": "pnpm build && pnpm release",
"build": "tsc --project tsconfig.json",
"prestart": "pnpm build",
"start": "ts-node src/index.ts",
"release": "standard-version",
"postinstall": "pnpm build"
},
"main": "dist/index.js",
"bin": {
"eslint-config": "dist/index.js"
"prepare": "husky install"
},
"main": "./dist/index.js",
"bin": "./dist/index.js",
"files": [
"dist"
"dist",
"next.js",
"node.js"
],
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.3.0",
"eslint-plugin-import": "^2.26.0"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@commitlint/types": "^16.2.1",
"@monogram/prettier-config": "^0.0.8",
"@types/node": "^17.0.18",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",
"@commitlint/cli": "^17.6.7",
"@commitlint/config-conventional": "^17.6.7",
"@commitlint/types": "^17.4.4",
"@monogram/prettier-config": "^0.2.0",
"@types/inquirer": "^9.0.3",
"@types/node": "^20.4.5",
"eslint": "^8.46.0",
"husky": "^8.0.3",
"standard-version": "^9.5.0",
"typescript": "^5.1.6"
},
"dependencies": {
"@inquirer/prompts": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "6.1.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.3.0",
"eslint-plugin-import": "^2.26.0",
"husky": "^7.0.4",
"standard-version": "^9.3.2",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
"eslint-config-next": "^13.4.11",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5"
},
"prettier": "@monogram/prettier-config",
"repository": {
"type": "git",
"url": "git+https://github.com/monogramdesign/eslint-config.git"
},
"author": "Leonardo Ortiz",
"contributors": [
"Leonardo Ortiz",
"Julien Martel"
],
"bugs": {
"url": "https://github.com/monogramdesign/eslint-config/issues"
},
Expand Down
Loading
Loading