From 1b7523398a7e020cbaf4c9a7fc07795992199a8e Mon Sep 17 00:00:00 2001 From: Matias Pequeno Date: Sat, 2 Mar 2024 09:36:02 -0300 Subject: [PATCH] Fixed some eslint issues when linting examples --- .eslintignore | 1 + .eslintrc.json | 68 +++++++++++++++++++++++++++++ .eslintrc.yaml | 53 ---------------------- .github/workflows/ci.yaml | 5 ++- babel.config.js | 3 ++ examples/nextjs/.eslintignore | 11 +++++ examples/nextjs/.eslintrc.json | 4 +- examples/react-17/.eslintignore | 11 +++++ examples/react-17/.eslintrc.json | 4 ++ examples/react-17/package-lock.json | 26 +++++++++-- examples/react-17/package.json | 7 --- examples/typescript/.eslintignore | 11 +++++ package-lock.json | 24 +++++----- package.json | 4 +- 14 files changed, 154 insertions(+), 78 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 .eslintrc.yaml create mode 100644 examples/nextjs/.eslintignore create mode 100644 examples/react-17/.eslintignore create mode 100644 examples/react-17/.eslintrc.json create mode 100644 examples/typescript/.eslintignore diff --git a/.eslintignore b/.eslintignore index d7d56a9..acca00a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,6 +5,7 @@ build bundles coverage dist +examples lib node_modules out diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..c647193 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,68 @@ +{ + "env": { + "browser": true, + "es2022": true, + "jest": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "prettier", + "plugin:react-hooks/recommended", + "plugin:jest/recommended", + "plugin:jest-dom/recommended" + ], + "parser": "@babel/eslint-parser", + "plugins": ["@babel", "jest", "react", "react-hooks", "testing-library"], + "settings": { + "react": { + "version": "detect" + } + }, + "overrides": [ + { + "files": ["**/*.mjs"], + "parserOptions": { + "babelOptions": { + "parserOpts": { + "plugins": ["importAssertions"] + } + } + } + }, + { + "files": [ + "**/__tests__/**/*.[jt]s?(x)", + "**/?(*.)+(spec|test).[jt]s?(x)" + ], + "extends": ["plugin:testing-library/react"] + }, + { + "files": ["**/*.ts?(x)"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "tsconfigRootDir": ".", + "project": ["./tsconfig.json"] + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "rules": { + "@typescript-eslint/no-unused-vars": [ + "error", + { + "varsIgnorePattern": "^_", + "argsIgnorePattern": "^_" + } + ], + "@typescript-eslint/unbound-method": "off", + "jest/unbound-method": "error", + "react/react-in-jsx-scope": "off" + } + } + ] +} diff --git a/.eslintrc.yaml b/.eslintrc.yaml deleted file mode 100644 index e8eaa2e..0000000 --- a/.eslintrc.yaml +++ /dev/null @@ -1,53 +0,0 @@ -env: - browser: true - es2022: true - jest: true - node: true -extends: - - eslint:recommended - - plugin:react/recommended - - prettier - - plugin:react-hooks/recommended - - plugin:jest/recommended - - plugin:jest-dom/recommended -parser: '@babel/eslint-parser' -plugins: - - '@babel' - - jest - - react - - react-hooks - - testing-library -settings: - react: - version: detect -overrides: - - files: - - '**/*.mjs' - parserOptions: - babelOptions: - parserOpts: - plugins: ['importAssertions'] - - files: - - '**/__tests__/**/*.[jt]s?(x)' - - '**/?(*.)+(spec|test).[jt]s?(x)' - extends: - - 'plugin:testing-library/react' - - files: - - '**/*.ts?(x)' - parser: '@typescript-eslint/parser' - parserOptions: - tsconfigRootDir: . - project: ['./tsconfig.json'] - extends: - - eslint:recommended - - plugin:@typescript-eslint/eslint-recommended - - plugin:@typescript-eslint/recommended - - plugin:@typescript-eslint/recommended-requiring-type-checking - rules: - '@typescript-eslint/no-unused-vars': - - error - - varsIgnorePattern: '^_' - argsIgnorePattern: '^_' - # For compat with jest: https://typescript-eslint.io/rules/unbound-method/ - '@typescript-eslint/unbound-method': 'off' - 'jest/unbound-method': 'error' diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 55302dc..0033ed7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -56,7 +56,10 @@ jobs: prettier: true eslint: true eslint_args: '--max-warnings 0' - eslint_extensions: js,jsx,ts,tsx + eslint_extensions: js,jsx,mjs,cjs,ts,tsx + + - name: Lint examples + run: npm run lint:examples - name: Build run: npm run build:all diff --git a/babel.config.js b/babel.config.js index 024b2e4..2db5888 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,6 @@ +/** + * @type {import('@babel/core').TransformOptions} + */ module.exports = { presets: ['@babel/preset-env', '@babel/preset-react'], plugins: [ diff --git a/examples/nextjs/.eslintignore b/examples/nextjs/.eslintignore new file mode 100644 index 0000000..d7d56a9 --- /dev/null +++ b/examples/nextjs/.eslintignore @@ -0,0 +1,11 @@ +.github +.next +.yalc +build +bundles +coverage +dist +lib +node_modules +out +public diff --git a/examples/nextjs/.eslintrc.json b/examples/nextjs/.eslintrc.json index cdffcd6..aee2189 100644 --- a/examples/nextjs/.eslintrc.json +++ b/examples/nextjs/.eslintrc.json @@ -1,5 +1,7 @@ { "root": true, "extends": ["next/core-web-vitals"], - "ignorePatterns": ["node_modules", ".next"] + "rules": { + "react/react-in-jsx-scope": "off" + } } diff --git a/examples/react-17/.eslintignore b/examples/react-17/.eslintignore new file mode 100644 index 0000000..d7d56a9 --- /dev/null +++ b/examples/react-17/.eslintignore @@ -0,0 +1,11 @@ +.github +.next +.yalc +build +bundles +coverage +dist +lib +node_modules +out +public diff --git a/examples/react-17/.eslintrc.json b/examples/react-17/.eslintrc.json new file mode 100644 index 0000000..b878577 --- /dev/null +++ b/examples/react-17/.eslintrc.json @@ -0,0 +1,4 @@ +{ + "root": true, + "extends": ["react-app", "react-app/jest"] +} diff --git a/examples/react-17/package-lock.json b/examples/react-17/package-lock.json index 5da28a8..acbd5b7 100644 --- a/examples/react-17/package-lock.json +++ b/examples/react-17/package-lock.json @@ -17,6 +17,7 @@ "web-vitals": "^2.1.4" }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^12.1.3", "@testing-library/user-event": "^13.5.0", @@ -850,9 +851,17 @@ } }, "node_modules/@babel/plugin-proposal-private-property-in-object": { - "version": "7.21.0-placeholder-for-preset-env.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", - "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "version": "7.21.11", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", + "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.", + "dev": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-create-class-features-plugin": "^7.21.0", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + }, "engines": { "node": ">=6.9.0" }, @@ -2095,6 +2104,17 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.0-placeholder-for-preset-env.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", + "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/preset-env/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", diff --git a/examples/react-17/package.json b/examples/react-17/package.json index 4e05c00..bcc276e 100644 --- a/examples/react-17/package.json +++ b/examples/react-17/package.json @@ -24,13 +24,6 @@ "test": "react-scripts test", "eject": "react-scripts eject" }, - "eslintConfig": { - "root": true, - "extends": [ - "react-app", - "react-app/jest" - ] - }, "browserslist": { "production": [ ">0.2%", diff --git a/examples/typescript/.eslintignore b/examples/typescript/.eslintignore new file mode 100644 index 0000000..d7d56a9 --- /dev/null +++ b/examples/typescript/.eslintignore @@ -0,0 +1,11 @@ +.github +.next +.yalc +build +bundles +coverage +dist +lib +node_modules +out +public diff --git a/package-lock.json b/package-lock.json index 462fb8b..37bf3d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -696,18 +696,6 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/plugin-proposal-private-property-in-object": { - "version": "7.21.0-placeholder-for-preset-env.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", - "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", - "dev": true, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-syntax-async-generators": { "version": "7.8.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.8.4.tgz", @@ -1916,6 +1904,18 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.0-placeholder-for-preset-env.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", + "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "dev": true, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/preset-modules": { "version": "0.1.6-no-external-plugins", "resolved": "https://registry.npmjs.org/@babel/preset-modules/-/preset-modules-0.1.6-no-external-plugins.tgz", diff --git a/package.json b/package.json index a814312..34a1f44 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ ], "scripts": { "test": "jest", - "lint": "eslint src babel.config.js index.d.ts", + "lint": "eslint . --ext .js,.jsx,.mjs,.cjs,.ts,.tsx", + "lint:examples": "ts-node scripts/foreach-example.ts npx eslint . --ext .js,.jsx,.mjs,.cjs,.ts,.tsx", + "lint:all": "npm run lint && npm run lint:examples", "install:all": "node scripts/install-all.js", "clean:build": "rimraf dist lib bundles", "clean:all": "ts-node scripts/clean.ts",