jellyfin-web/.eslintrc.js

303 lines
10 KiB
JavaScript
Raw Normal View History

2020-08-24 18:12:35 -07:00
const restrictedGlobals = require('confusing-browser-globals');
2020-04-25 05:06:56 -07:00
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
2020-04-25 05:06:56 -07:00
plugins: [
2024-08-20 23:52:39 -07:00
'@stylistic',
'@typescript-eslint',
2021-05-28 09:31:31 -07:00
'react',
2020-04-25 05:06:56 -07:00
'import',
2022-09-30 14:57:47 -07:00
'eslint-comments',
'sonarjs'
2020-04-25 05:06:56 -07:00
],
env: {
node: true,
es6: true,
es2017: true,
es2020: true
},
extends: [
'eslint:recommended',
2021-05-28 09:31:31 -07:00
'plugin:react/recommended',
2020-04-25 05:06:56 -07:00
'plugin:import/errors',
'plugin:eslint-comments/recommended',
2022-09-30 14:57:47 -07:00
'plugin:compat/recommended',
'plugin:sonarjs/recommended'
2020-04-25 05:06:56 -07:00
],
rules: {
'array-callback-return': ['error', { 'checkForEach': true }],
'curly': ['error', 'multi-line', 'consistent'],
'default-case-last': ['error'],
'max-params': ['error', 7],
2023-07-06 08:49:55 -07:00
'new-cap': [
'error',
{
'capIsNewExceptions': ['jQuery.Deferred'],
'newIsCapExceptionPattern': '\\.default$'
}
],
'no-duplicate-imports': ['error'],
2021-11-22 08:36:49 -07:00
'no-empty-function': ['error'],
2023-07-06 11:46:14 -07:00
'no-extend-native': ['error'],
'no-lonely-if': ['error'],
'no-nested-ternary': ['error'],
'no-redeclare': ['off'],
'@typescript-eslint/no-redeclare': ['error', { builtinGlobals: false }],
2020-08-24 18:12:35 -07:00
'no-restricted-globals': ['error'].concat(restrictedGlobals),
'no-return-assign': ['error'],
2022-08-09 04:51:43 -07:00
'no-return-await': ['error'],
2022-09-30 14:57:47 -07:00
'no-sequences': ['error', { 'allowInParentheses': false }],
'no-shadow': ['off'],
'@typescript-eslint/no-shadow': ['error'],
2023-07-06 08:49:55 -07:00
'no-throw-literal': ['error'],
2023-10-05 11:00:38 -07:00
'no-undef-init': ['error'],
'no-unneeded-ternary': ['error'],
'no-unused-expressions': ['off'],
'@typescript-eslint/no-unused-expressions': ['error', { 'allowShortCircuit': true, 'allowTernary': true, 'allowTaggedTemplates': true }],
'no-unused-private-class-members': ['error'],
'no-useless-rename': ['error'],
'no-useless-constructor': ['off'],
'@typescript-eslint/no-useless-constructor': ['error'],
'no-var': ['error'],
2022-04-13 07:33:06 -07:00
'no-void': ['error', { 'allowAsStatement': true }],
'no-warning-comments': ['warn', { 'terms': ['fixme', 'hack', 'xxx'] }],
2020-05-30 14:15:06 -07:00
'one-var': ['error', 'never'],
'prefer-const': ['error', { 'destructuring': 'all' }],
'prefer-promise-reject-errors': ['warn', { 'allowEmptyReject': true }],
2023-05-04 08:00:48 -07:00
'@typescript-eslint/prefer-for-of': ['error'],
2023-07-06 10:39:48 -07:00
'@typescript-eslint/prefer-optional-chain': ['error'],
2023-03-08 22:01:05 -07:00
'radix': ['error'],
2022-04-21 10:40:17 -07:00
'yoda': 'error',
2022-09-29 09:50:25 -07:00
2022-09-30 14:57:47 -07:00
'react/jsx-filename-extension': ['error', { 'extensions': ['.jsx', '.tsx'] }],
2022-12-16 14:02:11 -07:00
'react/jsx-no-bind': ['error'],
'react/jsx-no-useless-fragment': ['error'],
2022-12-16 14:02:11 -07:00
'react/jsx-no-constructed-context-values': ['error'],
'react/no-array-index-key': ['error'],
2022-09-30 14:57:47 -07:00
2022-12-16 14:02:11 -07:00
'sonarjs/no-inverted-boolean-check': ['error'],
2022-09-30 14:57:47 -07:00
// TODO: Enable the following rules and fix issues
2022-12-16 14:02:11 -07:00
'sonarjs/cognitive-complexity': ['off'],
2024-08-20 23:52:39 -07:00
'sonarjs/no-duplicate-string': ['off'],
'@stylistic/block-spacing': ['error'],
'@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
'@stylistic/comma-dangle': ['error', 'never'],
'@stylistic/comma-spacing': ['error'],
'@stylistic/eol-last': ['error'],
'@stylistic/indent': ['error', 4, { 'SwitchCase': 1 }],
'@stylistic/jsx-quotes': ['error', 'prefer-single'],
'@stylistic/keyword-spacing': ['error'],
'@stylistic/max-statements-per-line': ['error'],
'@stylistic/no-floating-decimal': ['error'],
'@stylistic/no-multi-spaces': ['error'],
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1 }],
'@stylistic/no-trailing-spaces': ['error'],
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/operator-linebreak': ['error', 'before', { overrides: { '?': 'after', ':': 'after', '=': 'after' } }],
'@stylistic/padded-blocks': ['error', 'never'],
'@stylistic/quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }],
'@stylistic/semi': ['error'],
'@stylistic/space-before-blocks': ['error'],
'@stylistic/space-infix-ops': ['error']
2020-04-25 05:06:56 -07:00
},
2021-05-28 09:31:31 -07:00
settings: {
react: {
version: 'detect'
},
'import/parsers': {
'@typescript-eslint/parser': [ '.ts', '.tsx' ]
},
2023-05-02 06:52:08 -07:00
'import/resolver': {
node: {
extensions: [
'.js',
'.ts',
'.jsx',
'.tsx'
],
moduleDirectory: [
'node_modules',
'src'
]
}
},
polyfills: [
// Native Promises Only
'Promise',
// whatwg-fetch
'fetch',
// document-register-element
'document.registerElement',
// resize-observer-polyfill
'ResizeObserver',
// fast-text-encoding
'TextEncoder',
// intersection-observer
'IntersectionObserver',
// Core-js
'Object.assign',
'Object.is',
'Object.setPrototypeOf',
'Object.toString',
'Object.freeze',
'Object.seal',
'Object.preventExtensions',
'Object.isFrozen',
'Object.isSealed',
'Object.isExtensible',
'Object.getOwnPropertyDescriptor',
'Object.getPrototypeOf',
'Object.keys',
'Object.entries',
'Object.getOwnPropertyNames',
'Function.name',
'Function.hasInstance',
'Array.from',
'Array.arrayOf',
'Array.copyWithin',
'Array.fill',
'Array.find',
'Array.findIndex',
'Array.iterator',
'String.fromCodePoint',
'String.raw',
'String.iterator',
'String.codePointAt',
'String.endsWith',
'String.includes',
'String.repeat',
'String.startsWith',
'String.trim',
'String.anchor',
'String.big',
'String.blink',
'String.bold',
'String.fixed',
'String.fontcolor',
'String.fontsize',
'String.italics',
'String.link',
'String.small',
'String.strike',
'String.sub',
'String.sup',
'RegExp',
'Number',
'Math',
'Date',
'async',
'Symbol',
'Map',
'Set',
'WeakMap',
'WeakSet',
'ArrayBuffer',
'DataView',
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'Reflect',
// Temporary while eslint-compat-plugin is buggy
'document.querySelector'
]
2021-05-28 09:31:31 -07:00
},
2020-04-25 05:06:56 -07:00
overrides: [
// Config files and development scripts
{
files: [
'./babel.config.js',
'./.eslintrc.js',
'./postcss.config.js',
'./webpack.*.js',
'./scripts/**/*.js'
]
},
// JavaScript source files
2020-04-25 05:06:56 -07:00
{
files: [
2023-07-06 07:39:44 -07:00
'./src/**/*.{js,jsx,ts,tsx}'
2020-04-25 05:06:56 -07:00
],
2023-05-02 08:24:36 -07:00
parserOptions: {
project: ['./tsconfig.json']
},
2020-04-25 05:06:56 -07:00
env: {
node: false,
amd: true,
browser: true,
es6: true,
es2017: true,
es2020: true
},
globals: {
// Browser globals
'MediaMetadata': 'readonly',
// Tizen globals
'tizen': 'readonly',
'webapis': 'readonly',
// WebOS globals
'webOS': 'readonly',
// Dependency globals
'$': 'readonly',
'jQuery': 'readonly',
// Jellyfin globals
'ApiClient': 'writable',
2021-09-07 16:46:43 -07:00
'Events': 'writable',
2020-04-25 05:06:56 -07:00
'chrome': 'writable',
'DlnaProfilePage': 'writable',
'DashboardPage': 'writable',
'Emby': 'readonly',
'Globalize': 'writable',
'Hls': 'writable',
'LibraryMenu': 'writable',
'LinkParser': 'writable',
'LiveTvHelpers': 'writable',
2021-05-22 04:38:20 -07:00
'Loading': 'writable',
2020-04-25 05:06:56 -07:00
'MetadataEditor': 'writable',
2021-06-11 10:16:11 -07:00
'ServerNotifications': 'writable',
'TaskButton': 'writable',
2020-04-25 05:06:56 -07:00
'UserParentalControlPage': 'writable',
'Windows': 'readonly',
// Build time definitions
2024-05-17 14:22:55 -07:00
__COMMIT_SHA__: 'readonly',
__JF_BUILD_VERSION__: 'readonly',
__PACKAGE_JSON_NAME__: 'readonly',
2024-03-23 07:31:14 -07:00
__PACKAGE_JSON_VERSION__: 'readonly',
__USE_SYSTEM_FONTS__: 'readonly',
__WEBPACK_SERVE__: 'readonly'
2023-05-02 08:24:36 -07:00
},
rules: {
'@typescript-eslint/prefer-string-starts-ends-with': ['error']
2020-04-25 05:06:56 -07:00
}
},
// TypeScript source files
{
files: [
2023-07-06 07:39:44 -07:00
'./src/**/*.{ts,tsx}'
],
extends: [
'eslint:recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:eslint-comments/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended'
],
rules: {
'@typescript-eslint/no-floating-promises': ['error'],
2023-07-13 08:57:47 -07:00
'@typescript-eslint/no-unused-vars': ['error'],
'sonarjs/cognitive-complexity': ['error']
}
2020-04-25 05:06:56 -07:00
}
]
2020-06-28 00:38:06 -07:00
};