Skip to content

Commit

Permalink
updated the eslint config inline with eslint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
“talatkuyuk” committed Jan 9, 2025
1 parent 864c3cd commit 8f01769
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 47 deletions.
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.json

This file was deleted.

61 changes: 61 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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,
);
2 changes: 0 additions & 2 deletions src/csr/idle-callback-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -19,7 +18,6 @@ if (typeof window !== "undefined") {
}, 1);
};

// eslint-disable-next-line no-undef
window.cancelIdleCallback ||= function (id) {
clearTimeout(id);
};
Expand Down
1 change: 0 additions & 1 deletion src/csr/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = { [K in keyof T]: T[K] } & {};

export type SerializeProps<TScope extends Record<string, unknown> = Record<string, unknown>> = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function prepare<TFrontmatter extends Record<string, unknown> = Record<st
const vfile = looksLikeAVFile(source) ? source : new VFile(source);

// makes frontmatter available via vfile.data.matter
parseFrontmatter && matter(vfile, { strip: true });
if (parseFrontmatter) matter(vfile, { strip: true });

const frontmatter = (vfile.data.matter ?? {}) as TFrontmatter;

Expand Down
9 changes: 6 additions & 3 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,16 @@ export function passVfileDataIntoScope(
vfileDataIntoScope.forEach((field) => {
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];
}
Expand Down
1 change: 0 additions & 1 deletion src/rsc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = { [K in keyof T]: T[K] } & {};

export type EvaluateProps<TScope extends Record<string, unknown> = Record<string, unknown>> = {
Expand Down
5 changes: 4 additions & 1 deletion tests/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion tests/ErrorBoundarySimple.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8f01769

Please sign in to comment.