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
223 changes: 184 additions & 39 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,127 @@
import { fixupConfigRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import tsParser from '@typescript-eslint/parser';
import prettier from 'eslint-plugin-prettier';
import { fixupPluginRules } from '@eslint/compat';
import eslintComments from '@eslint-community/eslint-plugin-eslint-comments';
import reactNativeCommunity from '@react-native/eslint-plugin';
import { defineConfig } from 'eslint/config';
import prettierConfig from 'eslint-config-prettier';
import jest from 'eslint-plugin-jest';
import prettier from 'eslint-plugin-prettier';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactNative from 'eslint-plugin-react-native';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import tseslint from 'typescript-eslint';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

/**
* Rules ported from @react-native/eslint-config (shared.js, 0.84.1).
* That package still peers on ESLint ^8 || ^9 and crashes under ESLint 10
* (`scopeManager.addGlobals is not a function`), so the preset is inlined here.
* Rules removed from ESLint core (valid-jsdoc, no-catch-shadow, no-native-reassign,
* no-negated-in-lhs, Node.js rules, no-new-object) and the Flow-only rules are dropped.
*/
const reactNativeGlobals = {
__DEV__: 'writable',
__fbBatchedBridgeConfig: 'readonly',
ErrorUtils: 'readonly',
};

const reactNativeRules = {
'no-cond-assign': 'warn',
'no-console': 'off',
'no-const-assign': 'error',
'no-constant-condition': 'off',
'no-control-regex': 'warn',
'no-debugger': 'warn',
'no-dupe-class-members': 'error',
'no-dupe-keys': 'error',
'no-empty': 'off',
'no-ex-assign': 'warn',
'no-extra-boolean-cast': 'warn',
'no-func-assign': 'warn',
'no-inner-declarations': 'off',
'no-invalid-regexp': 'warn',
'no-obj-calls': 'warn',
'no-regex-spaces': 'warn',
'no-sparse-arrays': 'warn',
'no-unreachable': 'error',
'use-isnan': 'warn',
'valid-typeof': 'warn',
'dot-notation': 'warn',
'no-alert': 'warn',
'no-caller': 'warn',
'no-div-regex': 'warn',
'no-eval': 'error',
'no-extend-native': 'warn',
'no-extra-bind': 'warn',
'no-fallthrough': 'warn',
'no-implied-eval': 'warn',
'no-labels': 'warn',
'no-iterator': 'warn',
'no-lone-blocks': 'warn',
'no-new': 'warn',
'no-new-func': 'error',
'no-new-wrappers': 'warn',
'no-octal': 'warn',
'no-octal-escape': 'warn',
'no-proto': 'warn',
'no-redeclare': 'off',
'no-return-assign': 'warn',
'no-script-url': 'warn',
'no-self-compare': 'warn',
'no-sequences': 'warn',
'no-unused-expressions': 'off',
'no-useless-escape': 'warn',
'no-void': 'warn',
'no-with': 'warn',
'radix': 'warn',
'yoda': 'warn',
'no-delete-var': 'warn',
'no-global-assign': 'error',
'no-label-var': 'warn',
'no-shadow': 'warn',
'no-shadow-restricted-names': 'warn',
'no-undef': 'error',
'no-undef-init': 'warn',
'no-unused-vars': [
'warn',
{ vars: 'all', args: 'none', ignoreRestSiblings: true },
],
'no-use-before-define': 'off',
'consistent-this': 'warn',
'no-array-constructor': 'warn',
'no-empty-character-class': 'warn',
'no-object-constructor': 'warn',
'no-bitwise': 'warn',

'@eslint-community/eslint-comments/no-aggregating-enable': 'warn',
'@eslint-community/eslint-comments/no-unlimited-disable': 'warn',
'@eslint-community/eslint-comments/no-unused-disable': 'warn',
'@eslint-community/eslint-comments/no-unused-enable': 'warn',

'react/jsx-no-comment-textnodes': 'error',
'react/jsx-no-duplicate-props': 'error',
'react/jsx-no-undef': 'error',
'react/jsx-uses-react': 'warn',
'react/jsx-uses-vars': 'warn',
'react/no-did-mount-set-state': 'warn',
'react/no-did-update-set-state': 'warn',
'react/no-string-refs': 'error',
'react/no-unstable-nested-components': 'warn',
'react/self-closing-comp': 'warn',

'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',

'react-native/no-inline-styles': 'warn',
'@react-native/no-deep-imports': 'warn',
};

/**
* PHPStan level-10 equivalent for TypeScript.
* Rules attach to the FlatCompat object that already registers @typescript-eslint
* (from @react-native/eslint-config) so the plugin is not redefined.
*/
const typescriptStrictRules = {
'@typescript-eslint/no-explicit-any': 'error',
Expand Down Expand Up @@ -67,52 +170,94 @@ const typescriptStrictRules = {
],
};

const baseConfigs = fixupConfigRules(
compat.extends('@react-native', 'prettier')
).map((config) => {
if (config.plugins?.['@typescript-eslint'] == null) {
return config;
}

return {
...config,
export default defineConfig([
{
ignores: [
'node_modules/',
'lib/',
'plugin/build/',
'.github/scripts/',
'example/',
'coverage/',
],
},
{
files: ['**/*.{js,jsx,ts,tsx}'],
plugins: {
'@eslint-community/eslint-comments': eslintComments,
'react': fixupPluginRules(react),
'react-hooks': reactHooks,
'react-native': fixupPluginRules(reactNative),
'@react-native': fixupPluginRules(reactNativeCommunity),
prettier,
},
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: { ecmaFeatures: { jsx: true } },
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
...reactNativeGlobals,
},
},
settings: { react: { version: 'detect' } },
rules: reactNativeRules,
},
{
// CommonJS entry points and build configs.
files: ['**/*.js'],
languageOptions: { sourceType: 'commonjs' },
},
{
files: ['**/*.{ts,tsx}'],
extends: [tseslint.configs.base],
languageOptions: {
...config.languageOptions,
parser: tsParser,
parserOptions: {
...config.languageOptions?.parserOptions,
projectService: true,
tsconfigRootDir: __dirname,
},
},
rules: {
...config.rules,
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
'no-unused-vars': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'warn',
'no-undef': 'off',
...typescriptStrictRules,
},
};
});

export default defineConfig([
},
{
ignores: [
'node_modules/',
'lib/',
'plugin/build/',
'.github/scripts/',
'example/',
'coverage/',
files: [
'**/*.{spec,test}.{js,ts,tsx}',
'**/__{mocks,tests}__/**/*.{js,ts,tsx}',
],
plugins: { jest },
languageOptions: { globals: globals.jest },
rules: {
'react-native/no-inline-styles': 'off',
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'warn',
'jest/no-identical-title': 'warn',
'jest/valid-expect': 'warn',
},
},
...baseConfigs,
prettierConfig,
{
files: ['**/*.{js,jsx,ts,tsx}'],
plugins: { prettier },
rules: {
'react/react-in-jsx-scope': 'off',
'prettier/prettier': 'error',
'no-var': 'error',
'prefer-const': 'error',
eqeqeq: ['error', 'always'],
'eqeqeq': ['error', 'always'],
'no-throw-literal': 'error',
},
},
Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,25 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^21.2.4",
"@eslint/compat": "^1.3.2",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.35.0",
"@eslint-community/eslint-plugin-eslint-comments": "^4.8.1",
"@eslint/compat": "^2.1.1",
"@expo/config-plugins": ">=8.0.0",
"@react-native/babel-preset": "0.84.1",
"@react-native/eslint-config": "0.84.1",
"@react-native/eslint-plugin": "0.84.1",
"@release-it/conventional-changelog": "^12.0.2",
"@types/jest": "^29.5.14",
"@types/react": "^19.2.0",
"@types/react-test-renderer": "^19",
"commitlint": "^21.2.4",
"del-cli": "^6.0.0",
"eslint": "^9.35.0",
"eslint": "^10.15.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-jest": "^29.17.1",
"eslint-plugin-prettier": "^5.5.7",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-native": "^5.0.0",
"globals": "^17.14.0",
"jest": "^29.7.0",
"lefthook": "^2.0.3",
"prettier": "^2.8.8",
Expand All @@ -116,7 +120,8 @@
"react-test-renderer": "19.2.3",
"release-it": "^21.1.2",
"turbo": "^2.9.14",
"typescript": "^5.9.2"
"typescript": "^5.9.2",
"typescript-eslint": "^8.74.0"
},
"peerDependencies": {
"expo": ">=50.0.0",
Expand Down
Loading
Loading