Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
nodejs: [18, 19, 20, 21, 22]
nodejs: [18, 19, 20, 21, 22.6,]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
with:
node-version-file: .nvmrc
cache: yarn
- uses: github/codeql-action/init@v2
- uses: github/codeql-action/init@v3
with:
languages: javascript-typescript
- uses: github/codeql-action/analyze@v2
- uses: github/codeql-action/analyze@v3
with:
category: /language:javascript-typescript
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.3.0
22.6.0
894 changes: 0 additions & 894 deletions .yarn/releases/yarn-4.3.1.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ plugins:
path: .yarn/plugins/@yarnpkg/plugin-engines.cjs
spec: "https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js"

yarnPath: .yarn/releases/yarn-4.3.1.cjs
yarnPath: .yarn/releases/yarn-4.6.0.cjs
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ But what if you don't want to use Jest as your testing framework? What if you do

## Table of contents

- [Features](#features)
- [Requirements](#requirements)
- [Install](#install)
- [Usage](#usage)
- [With Vitest](#with-vitest)
- [With Mocha](#with-mocha)
- [Mocking native methods](#mocking-native-methods)
- [Contributing](#contributing)
- [License](#license)
- [React Native Testing Mocks](#react-native-testing-mocks)
- [Motivation](#motivation)
- [Table of contents](#table-of-contents)
- [Features](#features)
- [Requirements](#requirements)
- [Install](#install)
- [Usage](#usage)
- [With Vitest](#with-vitest)
- [With Mocha](#with-mocha)
- [Mocking native methods](#mocking-native-methods)
- [Contributing](#contributing)
- [Something's missing?](#somethings-missing)
- [Contributions](#contributions)
- [License](#license)

### Features

Expand All @@ -45,10 +50,12 @@ But what if you don't want to use Jest as your testing framework? What if you do

## Requirements

- **Node.js:** >=18
- **Node.js:** >=18 <=22.6
- **react:** >=18.2.0
- **react-native:** ">=0.73.2

> **NOTE:** Node.js [enabled the `--experimental-detect-module` flag](https://github.com/nodejs/node/releases/tag/v22.7.0) on v22.7.0 by default. This raises an issue when transforming Flow code with Babel, so we're not supporting v22.7+ until the flag remains experimental and all issues are resolved.

## Install

With NPM:
Expand Down
88 changes: 38 additions & 50 deletions eslint.config.mjs → eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
// @ts-check
import path from "path";
import { fileURLToPath } from "url";

import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import eslintJs from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
import etc from "eslint-plugin-etc";
import * as importPlugin from "eslint-plugin-import";
import jsdoc from "eslint-plugin-jsdoc";
import reactJsxRuntime from "eslint-plugin-react/configs/jsx-runtime.js";
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
import perfectionist from "eslint-plugin-perfectionist";
import reactPlugin from "eslint-plugin-react";
import sonarjs from "eslint-plugin-sonarjs";
import globals from "globals";
import eslintTs from "typescript-eslint";

const project = "./tsconfig.json";
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const compat = new FlatCompat({
baseDirectory: dirname,
recommendedConfig: eslintJs.configs.recommended,
});

/**
* @param {string} name the pugin name
* @param {string} alias the plugin alias
* @returns {import("eslint").ESLint.Plugin}
* @param {object} config the plugin config
* @returns {import("typescript-eslint").ConfigWithExtends}
*/
function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias];

if (!plugin) {
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
}

return fixupPluginRules(plugin);
function fixConfigTypes(config) {
return config;
}

export default eslintTs.config(
eslintJs.configs.recommended,
...eslintTs.configs.recommendedTypeChecked,
...compat.extends("plugin:import/typescript"),
reactRecommended,
reactJsxRuntime,
fixConfigTypes(importPlugin.flatConfigs?.typescript),
fixConfigTypes(reactPlugin.configs.flat?.recommended),
fixConfigTypes(reactPlugin.configs.flat?.["jsx-runtime"]),
sonarjs.configs.recommended,
stylistic.configs.customize({
braceStyle: "1tbs",
Expand All @@ -63,7 +45,7 @@ export default eslintTs.config(
globals: { ...globals.browser, ...globals.node },
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2024,
ecmaVersion: 2023,
jsxPragma: null,
project,
tsconfigRootDir: import.meta.dirname,
Expand All @@ -74,13 +56,12 @@ export default eslintTs.config(
reportUnusedDisableDirectives: "error",
},
plugins: {
deprecation: legacyPlugin("eslint-plugin-deprecation", "deprecation"),
etc: fixupPluginRules(etc),
"extra-rules": legacyPlugin("eslint-plugin-extra-rules", "extra-rules"),
import: legacyPlugin("eslint-plugin-import", "import"),
import: importPlugin,
jsdoc,
perfectionist,
},
settings: {
"import/ignore": ["react-native"], // https://github.com/facebook/react-native/issues/28549
"import/resolver": {
typescript: {
alwaysTryTypes: true,
Expand All @@ -95,7 +76,6 @@ export default eslintTs.config(
{
rules: {
"@stylistic/arrow-parens": ["error", "as-needed"],
"@stylistic/indent": "off",
"@stylistic/indent-binary-ops": "off",
"@stylistic/jsx-curly-brace-presence": ["error", { children: "always" }],
"@stylistic/jsx-curly-newline": "off",
Expand All @@ -117,6 +97,7 @@ export default eslintTs.config(
"@stylistic/no-mixed-spaces-and-tabs": "error",
"@stylistic/no-multiple-empty-lines": ["error", { max: 1, maxBOF: 0, maxEOF: 0 }],
"@stylistic/object-curly-spacing": ["error", "always"],
"@stylistic/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
"@stylistic/padded-blocks": ["error", "never", { allowSingleLineBlocks: false }],
"@stylistic/quote-props": ["error", "as-needed"],
"@stylistic/quotes": ["error", "double", {
Expand All @@ -125,7 +106,6 @@ export default eslintTs.config(
}],
"@stylistic/space-before-function-paren": ["error", { anonymous: "never", named: "never" }],
"@stylistic/switch-colon-spacing": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "inline-type-imports" }],
Expand Down Expand Up @@ -187,14 +167,11 @@ export default eslintTs.config(
camelcase: "error",
"constructor-super": "error",
curly: "error",
"deprecation/deprecation": "error",
eqeqeq: "error",
"etc/no-assign-mutated-array": "error",
"etc/no-implicit-any-catch": "error",
"etc/no-internal": "error",
"etc/throw-error": "error",
"extra-rules/no-commented-out-code": "error",
"func-style": ["error", "declaration", { allowArrowFunctions: true }],
"import/default": "off",
"import/named": "off",
"import/namespace": "off",
"import/newline-after-import": "error",
"import/no-absolute-path": "error",
"import/no-cycle": ["error", {
Expand All @@ -204,7 +181,8 @@ export default eslintTs.config(
}],
"import/no-duplicates": ["error", { "prefer-inline": true }],
"import/no-import-module-exports": "error",
"import/no-namespace": "error",
"import/no-named-as-default-member": "off",
"import/no-namespace": ["error", { ignore: ["eslint-plugin-import"] }],
"import/no-relative-packages": "error",
"import/no-unresolved": "error",
"import/no-useless-path-segments": "error",
Expand Down Expand Up @@ -247,6 +225,11 @@ export default eslintTs.config(
"no-var": "error",
"object-shorthand": "error",
"one-var": ["error", "never"],
"perfectionist/sort-interfaces": ["error", { ignoreCase: false, type: "natural" }],
"perfectionist/sort-intersection-types": ["error", { ignoreCase: false, type: "natural" }],
"perfectionist/sort-object-types": ["error", { ignoreCase: false, type: "natural" }],
"perfectionist/sort-objects": ["error", { ignoreCase: false, type: "natural" }],
"perfectionist/sort-union-types": ["error", { ignoreCase: false, type: "natural" }],
"prefer-const": "error",
radix: "error",
"react/display-name": "off",
Expand All @@ -256,10 +239,17 @@ export default eslintTs.config(
"react/jsx-no-literals": "error",
"react/prop-types": "off",
"sonarjs/cognitive-complexity": "off",
"sonarjs/different-types-comparison": "off",
"sonarjs/function-return-type": "off",
"sonarjs/no-duplicate-string": "off",
"sonarjs/no-inverted-boolean-check": "error",
"sonarjs/no-empty-function": "off",
"sonarjs/no-extend-native": "off",
"sonarjs/no-nested-functions": "off",
"sonarjs/no-selector-parameter": "off",
"sonarjs/no-unused-expressions": "off",
"sonarjs/public-static-readonly": "off",
"sonarjs/sonar-prefer-read-only-props": "off",
"sort-imports": ["error", { ignoreDeclarationSort: true }],
"sort-keys": "error",
},
},
{
Expand All @@ -273,11 +263,6 @@ export default eslintTs.config(
rules: {
...eslintTs.configs.disableTypeChecked.rules,
"@typescript-eslint/explicit-function-return-type": "off",
"deprecation/deprecation": "off",
"etc/no-assign-mutated-array": "off",
"etc/no-implicit-any-catch": "off",
"etc/no-internal": "off",
"etc/throw-error": "off",
},
},
{
Expand All @@ -290,8 +275,11 @@ export default eslintTs.config(
files: ["**/*.test.ts?(x)"],
rules: {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/prefer-promise-reject-errors": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"etc/throw-error": "off",
"sonarjs/assertions-in-tests": "off",
"sonarjs/no-empty-test-file": "off",
"sonarjs/no-nested-functions": "off",
},
},
);
Loading
Loading