Skip to content

Commit

Permalink
feat: update to eslint 9 + flat config (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezcasas authored Aug 30, 2024
1 parent 2f5f2f1 commit e59aadc
Show file tree
Hide file tree
Showing 11 changed files with 2,830 additions and 4,005 deletions.
86 changes: 0 additions & 86 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
on:
push:
branches:
branches:
- 'main'

jobs:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* https://eslint.org/docs/latest/extend/shareable-configs
102 changes: 57 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<p align="center">
<a href="https://codely.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codely.com/logo/codely_logo-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codely.com/logo/codely_logo-light.svg">
<img alt="Codely logo" src="https://codely.com/logo/codely_logo.svg">
</picture>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codely.com/logo/codely_logo-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codely.com/logo/codely_logo-light.svg">
<img alt="Codely logo" src="https://codely.com/logo/codely_logo.svg">
</picture>
</a>
</p>

Expand All @@ -13,8 +13,8 @@
</h1>

<p align="center">
<a href="https://github.com/CodelyTV"><img src="https://img.shields.io/badge/CodelyTV-OS-green.svg?style=flat-square" alt="Codely Open Source"/></a>
<a href="https://pro.codely.com"><img src="https://img.shields.io/badge/CodelyTV-PRO-black.svg?style=flat-square" alt="CodelyTV Courses"/></a>
<a href="https://github.com/CodelyTV"><img src="https://img.shields.io/badge/CodelyTV-OS-green.svg?style=flat-square" alt="Codely Open Source"/></a>
<a href="https://pro.codely.com"><img src="https://img.shields.io/badge/CodelyTV-PRO-black.svg?style=flat-square" alt="CodelyTV Courses"/></a>
</p>

<p align="center">
Expand All @@ -27,58 +27,70 @@

## 👀 How to use

1. Install the dependency
```bash
npm install --save-dev eslint-config-codely
```
2. Add it to your `.eslintrc.js` file:
```js
{
extends: [ "eslint-config-codely" ]
}
```
3. If you are using TypeScript, extend the TypeScript configuration instead, and point to your `tsconfig.json` in `parserOptions`:
```js
{
extends: [ "eslint-config-codely/typescript" ],
overrides: [
{
files: ["*.ts", "*.tsx"],
parserOptions: {
project: ["./tsconfig.json"],
},
},
]
}
```
1. Install the dependency.
```bash
npm install --save-dev eslint-config-codely
```
2. Add it to your `eslint.config.js` file.

For JavaScript:
```js
import eslintConfigCodely from "eslint-config-codely";

export default [
...eslintConfigCodely.js,
{
// Your config here
}
]
```

For TypeScript:
```js
import eslintConfigCodely from "eslint-config-codely";

export default [
...eslintConfigCodely.ts,
{
// You should add the path to your tsconfig
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.json"],
},
}
// Your config here
}
]
```

ℹ️ Please note that some of the rules enabled by default require that you have `strict: true` in your `tsconfig.json`.

## 🤔 What it does

- Lints JavaScript using [`eslint:recommended`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files#using-eslintrecommended) and [Prettier](https://prettier.io/)
- Additionally, lints TypeScript using [`@typescript-eslint/recommended` and `@typescript-eslint/recommended-requiring-type-checking`](https://typescript-eslint.io/docs/linting/configs)
- Lints JavaScript using [`eslint:recommended`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files#using-eslintrecommended) and [Prettier](https://prettier.io/).
- Additionally, lints TypeScript using [`@typescript-eslint/recommended` and `@typescript-eslint/recommended-requiring-type-checking`](https://typescript-eslint.io/docs/linting/configs).
- Uses the following plugins:
- [`import`](https://github.com/import-js/eslint-plugin-import/): helps validate proper imports
- [`simple-import-sort`](https://github.com/lydell/eslint-plugin-simple-import-sort/): sorts imports
- [`unused-imports`](https://github.com/sweepline/eslint-plugin-unused-imports): finds and removes unused ES6 module imports
- Uses the following [JavaScript rules](https://github.com/CodelyTV/eslint-config-codely/blob/main/.eslintrc.js#L13) and [TypeScript rules](https://github.com/CodelyTV/eslint-config-codely/blob/main/typescript.js#L17)
- [`import`](https://github.com/import-js/eslint-plugin-import/): helps validate proper imports.
- [`simple-import-sort`](https://github.com/lydell/eslint-plugin-simple-import-sort/): sorts imports.
- [`unused-imports`](https://github.com/sweepline/eslint-plugin-unused-imports): finds and removes unused ES6 module imports.
- Uses rules inside the [configs](configs) folder.

## 👌 Codely Code Quality Standards

Publishing this package we are committing ourselves to the following code quality standards:

- 🤝 Respect **Semantic Versioning**: No breaking changes in patch or minor versions
- 🤏 No surprises in transitive dependencies: Use the **bare minimum dependencies** needed to meet the purpose
- 🎯 **One specific purpose** to meet without having to carry a bunch of unnecessary other utilities
- ✅ **Tests** as documentation and usage examples
- 📖 **Well documented ReadMe** showing how to install and use
- ⚖️ **License favoring Open Source** and collaboration
- 🤝 Respect **Semantic Versioning**: No breaking changes in patch or minor versions.
- 🤏 No surprises in transitive dependencies: Use the **bare minimum dependencies** needed to meet the purpose.
- 🎯 **One specific purpose** to meet without having to carry a bunch of unnecessary other utilities.
- ✅ **Tests** as documentation and usage examples.
- 📖 **Well documented ReadMe** showing how to install and use.
- ⚖️ **License favoring Open Source** and collaboration.

## 🔀 Related resources

- [🔦 Linting en JavaScript y TypeScript](https://pro.codely.com/library/linting-en-javascript-y-typescript-188432/446893/about/): Used as a template to bootstrap this plugin
- [🎯 Codely's ESLint Hexagonal Architecture plugin](https://github.com/CodelyTV/eslint-plugin-hexagonal-architecture): A plugin that helps you to enforce hexagonal architecture best practises. Valid for your JavaScript or TypeScript projects
- [🔦 Linting en JavaScript y TypeScript](https://pro.codely.com/library/linting-en-javascript-y-typescript-188432/446893/about/): Used as a template to bootstrap this plugin.
- [🎯 Codely's ESLint Hexagonal Architecture plugin](https://github.com/CodelyTV/eslint-plugin-hexagonal-architecture): A plugin that helps you to enforce hexagonal architecture best practises. Valid for your JavaScript or TypeScript projects.

Opinionated skeletons ready for different purposes:

Expand Down
104 changes: 104 additions & 0 deletions configs/codely-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import babelParser from "@babel/eslint-parser";
import js from "@eslint/js";
import eslintPluginImportX from "eslint-plugin-import-x";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort";
import eslintPluginUnusedImports from "eslint-plugin-unused-imports";
import globals from "globals";

export default [
js.configs.recommended,
eslintPluginPrettierRecommended,
{
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parser: babelParser,
parserOptions: {
requireConfigFile: false,
},
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
"simple-import-sort": eslintPluginSimpleImportSort,
import: eslintPluginImportX,
"unused-imports": eslintPluginUnusedImports,
},
rules: {
// error prevention
"array-callback-return": ["error", { checkForEach: true }],
"no-await-in-loop": "error",
"no-constant-binary-expression": "error",
"no-constructor-return": "error",
"no-promise-executor-return": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-unmodified-loop-condition": "error",
"no-unreachable-loop": "error",
"no-unused-private-class-members": "error",
"no-use-before-define": [
"error",
{
functions: false,
classes: true,
variables: true,
allowNamedExports: false,
},
],
"require-atomic-updates": "error",

// good practises
camelcase: ["error", { properties: "never" }],
eqeqeq: "error",
"new-cap": ["error", { capIsNew: false }],
"no-array-constructor": "error",
"no-console": ["error", { allow: ["error"] }],
"no-else-return": ["error", { allowElseIf: false }],
"no-extend-native": "error",
"no-lonely-if": "error",
"no-param-reassign": "error",
"no-return-assign": "error",
"no-throw-literal": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
radix: "error",
yoda: "error",

// style
curly: "error",
"lines-between-class-members": ["error", "always", { exceptAfterSingleLine: true }],
"padding-line-between-statements": [
"error",
{ blankLine: "always", prev: "*", next: "return" },
],

// plugins
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"import/no-unresolved": "error",
"import/no-webpack-loader-syntax": "error",
"prettier/prettier": ["error", { printWidth: 100, useTabs: true }],
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
"unused-imports/no-unused-imports": "error",
"no-unused-vars": "off",
"unused-imports/no-unused-vars": [
"warn",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
},
},
];
Loading

0 comments on commit e59aadc

Please sign in to comment.