From 8f017695375894c0e81c736463cd1a7225b60ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ctalatkuyuk=E2=80=9D?= <“talatkuyuk@gmail.com”> Date: Fri, 10 Jan 2025 00:28:55 +0300 Subject: [PATCH] updated the eslint config inline with eslint 9 --- .eslintignore | 7 ---- .eslintrc.json | 30 --------------- eslint.config.js | 61 +++++++++++++++++++++++++++++++ src/csr/idle-callback-polyfill.js | 2 - src/csr/types.ts | 1 - src/lib/prepare.ts | 2 +- src/lib/util.ts | 9 +++-- src/rsc/types.ts | 1 - tests/ErrorBoundary.jsx | 5 ++- tests/ErrorBoundarySimple.jsx | 4 +- 10 files changed, 75 insertions(+), 47 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 8c8305d..0000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -.DS_Store -.vscode -dist -node_modules -package-lock.json -archive -coverage \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 9a4f932..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "root": true, - "extends": ["eslint:recommended", "prettier", "plugin:prettier/recommended"], - "plugins": ["@typescript-eslint", "prettier"], - "parser": "@babel/eslint-parser", - "parserOptions": { - "requireConfigFile": false - }, - "rules": { - "no-prototype-builtins": "off" - }, - "overrides": [ - { - "files": ["**/*.ts", "**/*.tsx"], - "parser": "@typescript-eslint/parser", - "extends": [ - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-explicit-any": "off" - } - } - ], - "env": { - "node": true - } -} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..afe7c08 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,61 @@ +import eslint from "@eslint/js"; +import tseslint from "typescript-eslint"; +import globals from "globals"; +import react from "eslint-plugin-react"; +import eslintPluginPrettier from "eslint-plugin-prettier"; +import eslintConfigPrettier from "eslint-config-prettier"; + +export default tseslint.config( + { + ignores: [ + "**/archive/**", + "**/coverage/**", + "**/dist/**", + "**/node_modules/**", + "**/package-lock.json", + "**/.DS_Store", + "**/.vscode", + ], + }, + eslint.configs.recommended, + { + files: ["**/*.{ts,tsx}"], + extends: [eslint.configs.recommended, tseslint.configs.recommended], + plugins: { + react, + prettier: eslintPluginPrettier, + }, + rules: { + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-explicit-any": "off", + }, + }, + { + files: ["**/*.{js,jsx}"], + extends: [tseslint.configs.disableTypeChecked], + }, + { + files: ["**/*.jsx"], + plugins: { + react, + prettier: eslintPluginPrettier, + }, + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + globals: globals.browser, + }, + }, + { + files: ["src/csr/idle-callback-polyfill.js"], + languageOptions: { + sourceType: "script", + globals: globals.browser, + }, + }, + eslintConfigPrettier, +); diff --git a/src/csr/idle-callback-polyfill.js b/src/csr/idle-callback-polyfill.js index 715bec5..6511d60 100644 --- a/src/csr/idle-callback-polyfill.js +++ b/src/csr/idle-callback-polyfill.js @@ -6,7 +6,6 @@ */ if (typeof window !== "undefined") { - // eslint-disable-next-line no-undef window.requestIdleCallback ||= function (cb) { var start = Date.now(); return setTimeout(function () { @@ -19,7 +18,6 @@ if (typeof window !== "undefined") { }, 1); }; - // eslint-disable-next-line no-undef window.cancelIdleCallback ||= function (id) { clearTimeout(id); }; diff --git a/src/csr/types.ts b/src/csr/types.ts index a6d3f6f..9ceedd6 100644 --- a/src/csr/types.ts +++ b/src/csr/types.ts @@ -12,7 +12,6 @@ import { type Compatible } from "vfile"; import { type VfileDataIntoScope } from "../lib/util.js"; -// eslint-disable-next-line @typescript-eslint/ban-types export type Prettify = { [K in keyof T]: T[K] } & {}; export type SerializeProps = Record> = { diff --git a/src/lib/prepare.ts b/src/lib/prepare.ts index 017172c..fc5e374 100644 --- a/src/lib/prepare.ts +++ b/src/lib/prepare.ts @@ -22,7 +22,7 @@ export function prepare = Record { if (typeof field === "string") { scope[field] = data[field]; - } else if (field.hasOwnProperty("name") && field.hasOwnProperty("as")) { + } else if ( + Object.prototype.hasOwnProperty.call(field, "name") && + Object.prototype.hasOwnProperty.call(field, "as") + ) { scope[field.as] = data[field.name]; } }); } else if ( - vfileDataIntoScope.hasOwnProperty("name") && - vfileDataIntoScope.hasOwnProperty("as") + Object.prototype.hasOwnProperty.call(vfileDataIntoScope, "name") && + Object.prototype.hasOwnProperty.call(vfileDataIntoScope, "as") ) { scope[vfileDataIntoScope.as] = data[vfileDataIntoScope.name]; } diff --git a/src/rsc/types.ts b/src/rsc/types.ts index dd34a98..3f2ab4f 100644 --- a/src/rsc/types.ts +++ b/src/rsc/types.ts @@ -9,7 +9,6 @@ import { type Compatible } from "vfile"; import { VfileDataIntoScope } from "../lib/util.js"; -// eslint-disable-next-line @typescript-eslint/ban-types export type Prettify = { [K in keyof T]: T[K] } & {}; export type EvaluateProps = Record> = { diff --git a/tests/ErrorBoundary.jsx b/tests/ErrorBoundary.jsx index 9fff007..6f64cb0 100644 --- a/tests/ErrorBoundary.jsx +++ b/tests/ErrorBoundary.jsx @@ -7,15 +7,18 @@ class ErrorBoundary extends React.Component { // Define a state variable to track whether is an error or not this.state = { hasError: false }; } + + // eslint-disable-next-line no-unused-vars static getDerivedStateFromError(error) { // Update state so the next render will show the fallback UI return { hasError: true }; } + componentDidCatch(error, errorInfo) { - // You can use your own error logging service here console.log({ error, errorInfo }); } + render() { // Check if the error is thrown if (this.state.hasError) { diff --git a/tests/ErrorBoundarySimple.jsx b/tests/ErrorBoundarySimple.jsx index b59556e..a5f22a4 100644 --- a/tests/ErrorBoundarySimple.jsx +++ b/tests/ErrorBoundarySimple.jsx @@ -7,12 +7,14 @@ export default class ErrorBoundary extends React.Component { } static getDerivedStateFromError(error) { + console.log(error); + // Update state so the next render will show the fallback UI. return { hasError: true }; } componentDidCatch(error, info) { - // log the error + console.log({ error, info }); } render() {