2023-11-29 01:09:21 +11:00
|
|
|
// @ts-check
|
|
|
|
const { defineConfig } = require('eslint-define-config');
|
|
|
|
|
|
|
|
module.exports = defineConfig({
|
2019-01-04 21:28:38 +11:00
|
|
|
root: true,
|
|
|
|
|
2022-12-19 02:51:37 +11:00
|
|
|
extends: [
|
|
|
|
'eslint:recommended',
|
2023-01-30 13:08:37 +11:00
|
|
|
'plugin:react/recommended',
|
2023-05-09 11:09:11 +10:00
|
|
|
'plugin:react-hooks/recommended',
|
2023-01-30 16:18:12 +11:00
|
|
|
'plugin:jsx-a11y/recommended',
|
2023-02-14 01:12:31 +11:00
|
|
|
'plugin:import/recommended',
|
2023-02-16 17:30:56 +11:00
|
|
|
'plugin:promise/recommended',
|
2023-04-30 10:29:54 +10:00
|
|
|
'plugin:jsdoc/recommended',
|
2022-12-19 02:51:37 +11:00
|
|
|
],
|
|
|
|
|
2019-01-04 21:28:38 +11:00
|
|
|
env: {
|
|
|
|
browser: true,
|
|
|
|
node: true,
|
|
|
|
es6: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
globals: {
|
|
|
|
ATTACHMENT_HOST: false,
|
|
|
|
},
|
|
|
|
|
2023-04-03 11:31:39 +10:00
|
|
|
parser: '@typescript-eslint/parser',
|
2019-01-04 21:28:38 +11:00
|
|
|
|
|
|
|
plugins: [
|
|
|
|
'react',
|
|
|
|
'jsx-a11y',
|
|
|
|
'import',
|
|
|
|
'promise',
|
2023-04-03 11:31:39 +10:00
|
|
|
'@typescript-eslint',
|
2023-04-24 06:46:13 +10:00
|
|
|
'formatjs',
|
2019-01-04 21:28:38 +11:00
|
|
|
],
|
|
|
|
|
|
|
|
parserOptions: {
|
|
|
|
sourceType: 'module',
|
|
|
|
ecmaFeatures: {
|
|
|
|
jsx: true,
|
|
|
|
},
|
2022-06-02 03:22:35 +10:00
|
|
|
ecmaVersion: 2021,
|
2023-03-24 13:17:53 +11:00
|
|
|
requireConfigFile: false,
|
|
|
|
babelOptions: {
|
|
|
|
configFile: false,
|
|
|
|
presets: ['@babel/react', '@babel/env'],
|
|
|
|
},
|
2019-01-04 21:28:38 +11:00
|
|
|
},
|
2023-04-03 20:41:10 +10:00
|
|
|
|
2019-01-04 21:28:38 +11:00
|
|
|
settings: {
|
|
|
|
react: {
|
|
|
|
version: 'detect',
|
|
|
|
},
|
|
|
|
'import/ignore': [
|
|
|
|
'node_modules',
|
|
|
|
'\\.(css|scss|json)$',
|
|
|
|
],
|
2019-02-01 10:14:05 +11:00
|
|
|
'import/resolver': {
|
2023-05-10 20:59:29 +10:00
|
|
|
typescript: {},
|
2019-02-01 10:14:05 +11:00
|
|
|
},
|
2019-01-04 21:28:38 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
'consistent-return': 'error',
|
|
|
|
'dot-notation': 'error',
|
2023-04-20 01:46:46 +10:00
|
|
|
eqeqeq: ['error', 'always', { 'null': 'ignore' }],
|
2023-10-09 22:38:29 +11:00
|
|
|
'indent': ['error', 2],
|
2019-01-04 21:28:38 +11:00
|
|
|
'jsx-quotes': ['error', 'prefer-single'],
|
2023-10-09 22:38:29 +11:00
|
|
|
'semi': ['error', 'always'],
|
2022-12-19 02:51:37 +11:00
|
|
|
'no-case-declarations': 'off',
|
2019-01-04 21:28:38 +11:00
|
|
|
'no-catch-shadow': 'error',
|
|
|
|
'no-console': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
allow: [
|
|
|
|
'error',
|
|
|
|
'warn',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2022-12-19 02:51:37 +11:00
|
|
|
'no-empty': 'off',
|
2022-04-05 02:19:45 +10:00
|
|
|
'no-restricted-properties': [
|
|
|
|
'error',
|
|
|
|
{ property: 'substring', message: 'Use .slice instead of .substring.' },
|
|
|
|
{ property: 'substr', message: 'Use .slice instead of .substr.' },
|
|
|
|
],
|
2023-06-03 03:58:18 +10:00
|
|
|
'no-restricted-syntax': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
selector: 'Literal[value=/•/], JSXText[value=/•/]',
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
message: "Use '·' (middle dot) instead of '•' (bullet)",
|
|
|
|
},
|
|
|
|
],
|
2022-12-19 02:51:37 +11:00
|
|
|
'no-self-assign': 'off',
|
2019-01-04 21:28:38 +11:00
|
|
|
'no-unused-expressions': 'error',
|
2023-04-03 11:31:39 +10:00
|
|
|
'no-unused-vars': 'off',
|
|
|
|
'@typescript-eslint/no-unused-vars': [
|
2019-01-04 21:28:38 +11:00
|
|
|
'error',
|
|
|
|
{
|
|
|
|
vars: 'all',
|
|
|
|
args: 'after-used',
|
2023-05-09 11:08:47 +10:00
|
|
|
destructuredArrayIgnorePattern: '^_',
|
2019-01-04 21:28:38 +11:00
|
|
|
ignoreRestSiblings: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'valid-typeof': 'error',
|
|
|
|
|
2023-04-03 11:31:39 +10:00
|
|
|
'react/jsx-filename-extension': ['error', { extensions: ['.jsx', 'tsx'] }],
|
2019-01-04 21:28:38 +11:00
|
|
|
'react/jsx-boolean-value': 'error',
|
2023-01-30 13:08:37 +11:00
|
|
|
'react/display-name': 'off',
|
2023-05-23 19:47:36 +10:00
|
|
|
'react/jsx-fragments': ['error', 'syntax'],
|
2019-01-04 21:28:38 +11:00
|
|
|
'react/jsx-equals-spacing': 'error',
|
|
|
|
'react/jsx-no-bind': 'error',
|
2023-05-23 19:47:36 +10:00
|
|
|
'react/jsx-no-useless-fragment': 'error',
|
2023-01-30 13:08:37 +11:00
|
|
|
'react/jsx-no-target-blank': 'off',
|
2023-05-23 18:52:27 +10:00
|
|
|
'react/jsx-tag-spacing': 'error',
|
|
|
|
'react/jsx-uses-react': 'off', // not needed with new JSX transform
|
|
|
|
'react/jsx-wrap-multilines': 'error',
|
|
|
|
'react/no-deprecated': 'off',
|
|
|
|
'react/react-in-jsx-scope': 'off', // not needed with new JSX transform
|
2019-01-04 21:28:38 +11:00
|
|
|
'react/self-closing-comp': 'error',
|
|
|
|
|
2023-01-30 16:18:12 +11:00
|
|
|
// recommended values found in https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/index.js
|
2019-01-04 21:28:38 +11:00
|
|
|
'jsx-a11y/accessible-emoji': 'warn',
|
2023-01-30 16:18:12 +11:00
|
|
|
'jsx-a11y/click-events-have-key-events': 'off',
|
|
|
|
'jsx-a11y/label-has-associated-control': 'off',
|
|
|
|
'jsx-a11y/media-has-caption': 'off',
|
|
|
|
'jsx-a11y/no-autofocus': 'off',
|
|
|
|
// recommended rule is:
|
|
|
|
// 'jsx-a11y/no-interactive-element-to-noninteractive-role': [
|
|
|
|
// 'error',
|
|
|
|
// {
|
|
|
|
// tr: ['none', 'presentation'],
|
|
|
|
// canvas: ['img'],
|
|
|
|
// },
|
|
|
|
// ],
|
|
|
|
'jsx-a11y/no-interactive-element-to-noninteractive-role': 'off',
|
|
|
|
// recommended rule is:
|
|
|
|
// 'jsx-a11y/no-noninteractive-element-interactions': [
|
|
|
|
// 'error',
|
|
|
|
// {
|
|
|
|
// body: ['onError', 'onLoad'],
|
|
|
|
// iframe: ['onError', 'onLoad'],
|
|
|
|
// img: ['onError', 'onLoad'],
|
|
|
|
// },
|
|
|
|
// ],
|
2019-01-04 21:28:38 +11:00
|
|
|
'jsx-a11y/no-noninteractive-element-interactions': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
handlers: [
|
|
|
|
'onClick',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-01-30 16:18:12 +11:00
|
|
|
// recommended rule is:
|
|
|
|
// 'jsx-a11y/no-noninteractive-tabindex': [
|
|
|
|
// 'error',
|
|
|
|
// {
|
|
|
|
// tags: [],
|
|
|
|
// roles: ['tabpanel'],
|
|
|
|
// allowExpressionValues: true,
|
|
|
|
// },
|
|
|
|
// ],
|
|
|
|
'jsx-a11y/no-noninteractive-tabindex': 'off',
|
2019-01-04 21:28:38 +11:00
|
|
|
'jsx-a11y/no-onchange': 'warn',
|
2023-01-30 16:18:12 +11:00
|
|
|
// recommended is full 'error'
|
2019-01-04 21:28:38 +11:00
|
|
|
'jsx-a11y/no-static-element-interactions': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
handlers: [
|
|
|
|
'onClick',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2023-02-14 01:12:31 +11:00
|
|
|
// See https://github.com/import-js/eslint-plugin-import/blob/main/config/recommended.js
|
2019-01-04 21:28:38 +11:00
|
|
|
'import/extensions': [
|
|
|
|
'error',
|
|
|
|
'always',
|
|
|
|
{
|
|
|
|
js: 'never',
|
2023-02-20 13:20:59 +11:00
|
|
|
jsx: 'never',
|
2023-05-10 20:59:29 +10:00
|
|
|
mjs: 'never',
|
2023-04-03 11:31:39 +10:00
|
|
|
ts: 'never',
|
|
|
|
tsx: 'never',
|
2019-01-04 21:28:38 +11:00
|
|
|
},
|
|
|
|
],
|
2023-05-10 20:59:29 +10:00
|
|
|
'import/first': 'error',
|
2019-01-04 21:28:38 +11:00
|
|
|
'import/newline-after-import': 'error',
|
2023-05-10 20:59:29 +10:00
|
|
|
'import/no-anonymous-default-export': 'error',
|
2019-01-04 21:28:38 +11:00
|
|
|
'import/no-extraneous-dependencies': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
devDependencies: [
|
2023-11-29 01:09:21 +11:00
|
|
|
'.eslintrc.js',
|
2019-01-04 21:28:38 +11:00
|
|
|
'config/webpack/**',
|
2023-04-03 20:41:10 +10:00
|
|
|
'app/javascript/mastodon/performance.js',
|
2019-01-04 21:28:38 +11:00
|
|
|
'app/javascript/mastodon/test_setup.js',
|
|
|
|
'app/javascript/**/__tests__/**',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-05-09 11:08:47 +10:00
|
|
|
'import/no-amd': 'error',
|
|
|
|
'import/no-commonjs': 'error',
|
|
|
|
'import/no-import-module-exports': 'error',
|
2023-05-10 20:59:29 +10:00
|
|
|
'import/no-relative-packages': 'error',
|
|
|
|
'import/no-self-import': 'error',
|
|
|
|
'import/no-useless-path-segments': 'error',
|
2019-01-04 21:28:38 +11:00
|
|
|
'import/no-webpack-loader-syntax': 'error',
|
|
|
|
|
2023-05-24 01:15:17 +10:00
|
|
|
'import/order': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
alphabetize: { order: 'asc' },
|
|
|
|
'newlines-between': 'always',
|
|
|
|
groups: [
|
|
|
|
'builtin',
|
|
|
|
'external',
|
|
|
|
'internal',
|
|
|
|
'parent',
|
|
|
|
['index', 'sibling'],
|
|
|
|
'object',
|
|
|
|
],
|
|
|
|
pathGroups: [
|
|
|
|
// React core packages
|
|
|
|
{
|
|
|
|
pattern: '{react,react-dom,react-dom/client,prop-types}',
|
|
|
|
group: 'builtin',
|
|
|
|
position: 'after',
|
|
|
|
},
|
|
|
|
// I18n
|
|
|
|
{
|
|
|
|
pattern: '{react-intl,intl-messageformat}',
|
|
|
|
group: 'builtin',
|
|
|
|
position: 'after',
|
|
|
|
},
|
|
|
|
// Common React utilities
|
|
|
|
{
|
2023-10-20 04:44:55 +11:00
|
|
|
pattern: '{classnames,react-helmet,react-router,react-router-dom}',
|
2023-05-24 01:15:17 +10:00
|
|
|
group: 'external',
|
|
|
|
position: 'before',
|
|
|
|
},
|
|
|
|
// Immutable / Redux / data store
|
|
|
|
{
|
2024-01-08 21:57:40 +11:00
|
|
|
pattern: '{immutable,@reduxjs/toolkit,react-redux,react-immutable-proptypes,react-immutable-pure-component}',
|
2023-05-24 01:15:17 +10:00
|
|
|
group: 'external',
|
|
|
|
position: 'before',
|
|
|
|
},
|
|
|
|
// Internal packages
|
|
|
|
{
|
|
|
|
pattern: '{mastodon/**}',
|
|
|
|
group: 'internal',
|
|
|
|
position: 'after',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
pathGroupsExcludedImportTypes: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2023-02-16 17:30:56 +11:00
|
|
|
'promise/always-return': 'off',
|
2020-07-12 07:51:22 +10:00
|
|
|
'promise/catch-or-return': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
allowFinally: true,
|
|
|
|
},
|
|
|
|
],
|
2023-02-16 17:30:56 +11:00
|
|
|
'promise/no-callback-in-promise': 'off',
|
|
|
|
'promise/no-nesting': 'off',
|
|
|
|
'promise/no-promise-in-callback': 'off',
|
2023-04-24 06:46:13 +10:00
|
|
|
|
|
|
|
'formatjs/blocklist-elements': 'error',
|
|
|
|
'formatjs/enforce-default-message': ['error', 'literal'],
|
|
|
|
'formatjs/enforce-description': 'off', // description values not currently used
|
|
|
|
'formatjs/enforce-id': 'off', // Explicit IDs are used in the project
|
|
|
|
'formatjs/enforce-placeholders': 'off', // Issues in short_number.jsx
|
|
|
|
'formatjs/enforce-plural-rules': 'error',
|
|
|
|
'formatjs/no-camel-case': 'off', // disabledAccount is only non-conforming
|
|
|
|
'formatjs/no-complex-selectors': 'error',
|
|
|
|
'formatjs/no-emoji': 'error',
|
|
|
|
'formatjs/no-id': 'off', // IDs are used for translation keys
|
|
|
|
'formatjs/no-invalid-icu': 'error',
|
|
|
|
'formatjs/no-literal-string-in-jsx': 'off', // Should be looked at, but mainly flagging punctuation outside of strings
|
|
|
|
'formatjs/no-multiple-whitespaces': 'error',
|
|
|
|
'formatjs/no-offset': 'error',
|
|
|
|
'formatjs/no-useless-message': 'error',
|
|
|
|
'formatjs/prefer-formatted-message': 'error',
|
2023-04-24 16:07:19 +10:00
|
|
|
'formatjs/prefer-pound-in-plural': 'error',
|
2023-04-30 10:29:54 +10:00
|
|
|
|
|
|
|
'jsdoc/check-types': 'off',
|
|
|
|
'jsdoc/no-undefined-types': 'off',
|
|
|
|
'jsdoc/require-jsdoc': 'off',
|
|
|
|
'jsdoc/require-param-description': 'off',
|
|
|
|
'jsdoc/require-property-description': 'off',
|
|
|
|
'jsdoc/require-returns-description': 'off',
|
|
|
|
'jsdoc/require-returns': 'off',
|
2019-01-04 21:28:38 +11:00
|
|
|
},
|
2023-03-24 13:17:53 +11:00
|
|
|
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
files: [
|
2023-11-29 01:09:21 +11:00
|
|
|
'.eslintrc.js',
|
2023-03-24 13:17:53 +11:00
|
|
|
'*.config.js',
|
|
|
|
'.*rc.js',
|
|
|
|
'ide-helper.js',
|
2023-05-09 11:08:47 +10:00
|
|
|
'config/webpack/**/*',
|
2023-06-01 07:43:39 +10:00
|
|
|
'config/formatjs-formatter.js',
|
2023-03-24 13:17:53 +11:00
|
|
|
],
|
|
|
|
|
|
|
|
env: {
|
|
|
|
commonjs: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
parserOptions: {
|
|
|
|
sourceType: 'script',
|
|
|
|
},
|
2023-05-09 11:08:47 +10:00
|
|
|
|
|
|
|
rules: {
|
|
|
|
'import/no-commonjs': 'off',
|
|
|
|
},
|
2023-03-24 13:17:53 +11:00
|
|
|
},
|
2023-04-03 20:41:10 +10:00
|
|
|
{
|
|
|
|
files: [
|
|
|
|
'**/*.ts',
|
|
|
|
'**/*.tsx',
|
|
|
|
],
|
|
|
|
|
|
|
|
extends: [
|
|
|
|
'eslint:recommended',
|
2023-07-13 19:49:16 +10:00
|
|
|
'plugin:@typescript-eslint/strict-type-checked',
|
|
|
|
'plugin:@typescript-eslint/stylistic-type-checked',
|
2023-04-03 20:41:10 +10:00
|
|
|
'plugin:react/recommended',
|
2023-05-09 11:09:11 +10:00
|
|
|
'plugin:react-hooks/recommended',
|
2023-04-03 20:41:10 +10:00
|
|
|
'plugin:jsx-a11y/recommended',
|
|
|
|
'plugin:import/recommended',
|
|
|
|
'plugin:import/typescript',
|
|
|
|
'plugin:promise/recommended',
|
2023-05-31 17:27:21 +10:00
|
|
|
'plugin:jsdoc/recommended-typescript',
|
2023-05-10 03:02:12 +10:00
|
|
|
'plugin:prettier/recommended',
|
2023-04-03 20:41:10 +10:00
|
|
|
],
|
|
|
|
|
2023-05-10 20:59:29 +10:00
|
|
|
parserOptions: {
|
2023-07-13 19:49:16 +10:00
|
|
|
project: true,
|
2023-05-10 20:59:29 +10:00
|
|
|
tsconfigRootDir: __dirname,
|
|
|
|
},
|
|
|
|
|
2023-04-03 20:41:10 +10:00
|
|
|
rules: {
|
2023-05-10 20:59:29 +10:00
|
|
|
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
|
|
|
|
|
|
|
|
'@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
|
|
|
|
'@typescript-eslint/consistent-type-exports': 'error',
|
|
|
|
'@typescript-eslint/consistent-type-imports': 'error',
|
2023-11-29 05:20:10 +11:00
|
|
|
"@typescript-eslint/prefer-nullish-coalescing": ['error', { ignorePrimitives: { boolean: true } }],
|
2024-01-08 21:57:40 +11:00
|
|
|
"@typescript-eslint/no-restricted-imports": [
|
|
|
|
"warn",
|
|
|
|
{
|
|
|
|
"name": "react-redux",
|
|
|
|
"importNames": ["useSelector", "useDispatch"],
|
|
|
|
"message": "Use typed hooks `useAppDispatch` and `useAppSelector` instead."
|
|
|
|
}
|
|
|
|
],
|
2023-04-30 10:29:54 +10:00
|
|
|
'jsdoc/require-jsdoc': 'off',
|
2023-05-09 11:11:56 +10:00
|
|
|
|
|
|
|
// Those rules set stricter rules for TS files
|
|
|
|
// to enforce better practices when converting from JS
|
|
|
|
'import/no-default-export': 'warn',
|
|
|
|
'react/prefer-stateless-function': 'warn',
|
|
|
|
'react/function-component-definition': ['error', { namedComponents: 'arrow-function' }],
|
2023-05-23 18:52:27 +10:00
|
|
|
'react/jsx-uses-react': 'off', // not needed with new JSX transform
|
|
|
|
'react/react-in-jsx-scope': 'off', // not needed with new JSX transform
|
|
|
|
'react/prop-types': 'off',
|
2023-04-03 20:41:10 +10:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: [
|
|
|
|
'**/__tests__/*.js',
|
|
|
|
'**/__tests__/*.jsx',
|
|
|
|
],
|
|
|
|
|
|
|
|
env: {
|
|
|
|
jest: true,
|
|
|
|
},
|
2023-11-29 01:09:21 +11:00
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
],
|
2023-11-29 01:09:21 +11:00
|
|
|
});
|