Skip to content

Commit

Permalink
Update to ESLint 9 (#3)
Browse files Browse the repository at this point in the history
* Remove `comma-dangle`

* Begin ESLint v9 rewrite, remove unused React config

* Switch to flat config

* Change `no-console` to `warn`

* Update package versions

* Update peer dependencies versions, move import to dependencies

* Mark as RC

* Disable `import/no-named-as-default`

See import-js/eslint-plugin-import#2995 and import-js/eslint-plugin-import#2556#issuecomment-2121423498

* Remove `plugins`

* Update `eslint-plugin-import`

In hindsight, I should have read the release notes and saw that the
PR wasn't released yet even though it was merged.

* Add typings

* Release version 2.0.0

* Add the types to `package.json`

* Add the ESLint configuration to the README
  • Loading branch information
hkamran80 authored Oct 3, 2024
1 parent aab7574 commit c6fca60
Show file tree
Hide file tree
Showing 9 changed files with 1,816 additions and 1,716 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ A collection of tools and configurations I use for development.
- Prettier configuration ([`@hkamran/prettier-config`](https://www.npmjs.com/package/@hkamran/prettier-config))
- Trailing commas: all
- Tab width: 4
- ESLint configuration ([`@hkamran/eslint-config`](https://www.npmjs.com/package/@hkamran/eslint-config))
- Vite scaffold utility (vue-ts only) ([`@hkamran/vite-scaffold-vue-ts`](https://www.npmjs.com/package/@hkamran/vite-scaffold-vue-ts))
- Image conversion utility ([`@hkamran/image-convert`](https://www.npmjs.com/package/@hkamran/image-convert))
- Convert images to the AVIF and WebP file formats
- Utility creator ([`@hkamran/create-utility`](https://www.npmjs.com/package/@hkamran/create-utility))
- Create a utility
- Create a utility
74 changes: 0 additions & 74 deletions packages/eslint-config/.eslintrc.js

This file was deleted.

54 changes: 43 additions & 11 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
# `@hkamran/prettier-config`
# `@hkamran/eslint-config`

[![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL3.0-green.svg)](../../LICENSE.md)
[![npm version](https://badge.fury.io/js/%40hkamran%2Fprettier-config.svg)](https://badge.fury.io/js/%40hkamran%2Fprettier-config.svg)
[![npm version](https://badge.fury.io/js/%40hkamran%2Feslint-config.svg)](https://badge.fury.io/js/%40hkamran%2Feslint-config.svg)

My personal Prettier configuration
My personal ESLint configuration

## Installation

```bash
npm i -D @hkamran/prettier-config
npm i -D @hkamran/eslint-config
```

> [!NOTE]
> For `.eslintrc.*` (not flat config), use version 1.0.1.
## Usage

Add the following key-value pair to your `package.json` file.
Import the module, then use the spread operator to insert it into your ESLint configuration.

```js
import hkamranConfig from "@hkamran/eslint-config";

```json
"prettier": "@hkamran/prettier-config"
export default [
// ... other configuration ...
...hkamranConfig,
]
```

## Settings

| Rule | Setting |
| --------------- | ------- |
| Trailing Commas | all |
| Tab Width | 4 |
This configuration also includes the [recommended ESLint configuration](https://eslint.org/docs/latest/rules), [Prettier ESLint configuration](https://github.com/prettier/eslint-config-prettier), and the [import plugin](https://github.com/import-js/eslint-plugin-import).

It runs on all JavaScript files (`.js`, `.mjs`, and `.cjs`) and TypeScript files (`.ts`).

| Rule | Severity | Options |
|-------------------------------|----------|------------------------------------------------------------------|
| `no-alert` | Error | |
| `no-await-in-loop` | Error | |
| `no-return-assign` | Error | |
| `no-restricted-syntax` | Error | `FunctionExpression`, `LabeledStatement`, `WithStatement` |
| `no-var` | Error | |
| `no-use-before-define` | Error | |
| `no-unused-expressions` | Error | `enforceForJSX: true` |
| `no-param-reassign` | Error | `props: false` |
| `no-console` | Warn | |
| `no-underscore-dangle` | Error | |
| `prefer-const` | Error | `destructuring: all` |
| `arrow-body-style` | Error | `as-needed`, `requireReturnForObjectLiteral: false` |
| `space-before-function-paren` | Off | |
| `import/first` | Error | |
| `import/newline-after-import` | Error | |
| `import/no-duplicates` | Error | |
| `import/no-unassigned-import` | Error | `allow: [x@/styles/*.css"]` |
| `import/no-unresolved` | Error | `allow: ["@/styles/*.css"]` |
| `import/extensions` | Error | `never`, `css: always` |
| `import/no-dynamic-require` | ERror | |
| `import/no-cycle` | Error | |
| `import/order` | Error | `groups: [builtin, external, internal, [parent, sibling], type]` |
2 changes: 2 additions & 0 deletions packages/eslint-config/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _default: import("@typescript-eslint/utils").TSESLint.FlatConfig.ConfigFile;
export default _default;
80 changes: 78 additions & 2 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
const eslintrc = require("./.eslintrc.js");
import eslint from "@eslint/js";
import prettierConfig from "eslint-config-prettier";
import importPlugin from "eslint-plugin-import";

module.exports = eslintrc;
/** @type{import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile} */
export default [
eslint.configs.recommended,
prettierConfig,
importPlugin.flatConfigs.recommended,
{
files: ["**/*.{js,mjs,cjs,ts}"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {
"no-alert": "error",
"no-await-in-loop": "error",
"no-return-assign": "error",
"no-restricted-syntax": [
"error",
"FunctionExpression",
"LabeledStatement",
"WithStatement",
],
"no-var": "error",
"no-use-before-define": "error",
"no-unused-expressions": ["error", { enforceForJSX: true }],
"no-param-reassign": [
"error",
{
props: false,
},
],
"no-console": "warn",
"no-underscore-dangle": "error",

"prefer-const": [
"error",
{
destructuring: "all",
},
],
"arrow-body-style": [
"error",
"as-needed",
{ requireReturnForObjectLiteral: false },
],
"space-before-function-paren": "off",

"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"import/no-unassigned-import": [
"error",
{ allow: ["@/styles/*.css"] },
],
"import/no-unresolved": [
"error",
{ ignore: ["@/styles/(.*).css"] },
],
"import/extensions": ["error", "never", { css: "always" }],
"import/no-dynamic-require": "error",
"import/no-cycle": "error",
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
["parent", "sibling"],
"type",
],
},
],
},
},
];
43 changes: 23 additions & 20 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"name": "@hkamran/eslint-config",
"version": "1.0.0",
"license": "AGPL-3.0-or-later",
"version": "2.0.0",
"license": "AGPL-3.0",
"description": "My personal ESLint configuration",
"main": "index.js",
"types": "index.d.ts",
"type": "module",
"scripts": {
"prepare": "rimraf index.d.ts && tsc"
},
"author": {
"name": "H. Kamran",
"email": "[email protected]",
Expand All @@ -12,36 +17,34 @@
"repository": {
"type": "git",
"url": "git+https://github.com/hkamran80/devtools.git",
"directory": "packages/prettier-config"
"directory": "packages/eslint-config"
},
"bugs": {
"url": "https://github.com/hkamran80/devtools/issues"
},
"homepage": "https://github.com/hkamran80/devtools/blob/main/packages/prettier-config/README.md",
"homepage": "https://github.com/hkamran80/devtools/blob/main/packages/eslint-config/README.md",
"keywords": [
"eslint",
"eslint-config"
],
"dependencies": {
"eslint-plugin-import": "^2.31.0"
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"@hkamran/prettier-config": "link:../prettier-config",
"@typescript-eslint/parser": "^5.60.1",
"eslint": "^8.43.0",
"eslint-config-next": "^13.4.7",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "npm:[email protected]",
"prettier": "^2.8.8",
"typescript": "^5.1.6"
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__js": "^8.42.3",
"@typescript-eslint/utils": "^8.8.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"typescript": "^5.6.2"
},
"peerDependencies": {
"eslint": "^8.0.0",
"eslint-plugin-import": "npm:[email protected]",
"prettier": "^2.7.1",
"typescript": "^4.8.4"
},
"eslintConfig": {
"extends": [
"./.eslintrc.js"
]
"eslint": ">= 9",
"prettier": ">= 2"
},
"prettier": "@hkamran/prettier-config",
"publishConfig": {
Expand Down
Loading

0 comments on commit c6fca60

Please sign in to comment.