1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #6213 from thornbill/eslint-naming

Add eslint rules for consistent naming
This commit is contained in:
Bill Thornton 2024-11-21 15:26:54 -05:00 committed by GitHub
commit 4fed499c99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 79 additions and 39 deletions

View file

@ -273,6 +273,44 @@ module.exports = {
__WEBPACK_SERVE__: 'readonly'
},
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: [ 'camelCase', 'PascalCase' ],
leadingUnderscore: 'allow'
},
{
selector: 'variable',
format: [ 'camelCase', 'PascalCase', 'UPPER_CASE' ],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allowSingleOrDouble'
},
{
selector: 'typeLike',
format: [ 'PascalCase' ]
},
{
selector: 'enumMember',
format: [ 'PascalCase', 'UPPER_CASE' ]
},
{
selector: [ 'objectLiteralProperty', 'typeProperty' ],
format: [ 'camelCase', 'PascalCase' ],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allowSingleOrDouble'
},
// Ignore numbers, locale strings (en-us), aria/data attributes, CSS selectors,
// and api_key parameter
{
selector: [ 'objectLiteralProperty', 'typeProperty' ],
format: null,
filter: {
regex: '[ &\\-]|^([0-9]+)$|^api_key$',
match: true
}
}
],
'@typescript-eslint/prefer-string-starts-ends-with': ['error']
}
},

View file

@ -12,7 +12,7 @@ import AccessContainer from '../../../../components/dashboard/users/AccessContai
import CheckBoxElement from '../../../../elements/CheckBoxElement';
import Page from '../../../../components/Page';
type userInput = {
type UserInput = {
Name?: string;
Password?: string;
};
@ -110,7 +110,7 @@ const UserNew = () => {
loadUser();
const saveUser = () => {
const userInput: userInput = {};
const userInput: UserInput = {};
userInput.Name = (page.querySelector('#txtUsername') as HTMLInputElement).value;
userInput.Password = (page.querySelector('#txtPassword') as HTMLInputElement).value;
window.ApiClient.createUser(userInput).then(function (user) {

View file

@ -1948,47 +1948,47 @@ export default function (view) {
// Register to SyncPlay playback events and show big animated icon
const showIcon = (action) => {
let primary_icon_name = '';
let secondary_icon_name = '';
let animation_class = 'oneShotPulse';
let primaryIconName = '';
let secondaryIconName = '';
let animationClass = 'oneShotPulse';
let iconVisibilityTime = 1500;
const syncPlayIcon = view.querySelector('#syncPlayIcon');
switch (action) {
case 'schedule-play':
primary_icon_name = 'sync spin';
secondary_icon_name = 'play_arrow centered';
animation_class = 'infinitePulse';
primaryIconName = 'sync spin';
secondaryIconName = 'play_arrow centered';
animationClass = 'infinitePulse';
iconVisibilityTime = -1;
hideOsd();
break;
case 'unpause':
primary_icon_name = 'play_circle_outline';
primaryIconName = 'play_circle_outline';
break;
case 'pause':
primary_icon_name = 'pause_circle_outline';
primaryIconName = 'pause_circle_outline';
showOsd();
break;
case 'seek':
primary_icon_name = 'update';
animation_class = 'infinitePulse';
primaryIconName = 'update';
animationClass = 'infinitePulse';
iconVisibilityTime = -1;
break;
case 'buffering':
primary_icon_name = 'schedule';
animation_class = 'infinitePulse';
primaryIconName = 'schedule';
animationClass = 'infinitePulse';
iconVisibilityTime = -1;
break;
case 'wait-pause':
primary_icon_name = 'schedule';
secondary_icon_name = 'pause shifted';
animation_class = 'infinitePulse';
primaryIconName = 'schedule';
secondaryIconName = 'pause shifted';
animationClass = 'infinitePulse';
iconVisibilityTime = -1;
break;
case 'wait-unpause':
primary_icon_name = 'schedule';
secondary_icon_name = 'play_arrow shifted';
animation_class = 'infinitePulse';
primaryIconName = 'schedule';
secondaryIconName = 'play_arrow shifted';
animationClass = 'infinitePulse';
iconVisibilityTime = -1;
break;
default: {
@ -1997,13 +1997,13 @@ export default function (view) {
}
}
syncPlayIcon.setAttribute('class', 'syncPlayIconCircle ' + animation_class);
syncPlayIcon.setAttribute('class', 'syncPlayIconCircle ' + animationClass);
const primaryIcon = syncPlayIcon.querySelector('.primary-icon');
primaryIcon.setAttribute('class', 'primary-icon material-icons ' + primary_icon_name);
primaryIcon.setAttribute('class', 'primary-icon material-icons ' + primaryIconName);
const secondaryIcon = syncPlayIcon.querySelector('.secondary-icon');
secondaryIcon.setAttribute('class', 'secondary-icon material-icons ' + secondary_icon_name);
secondaryIcon.setAttribute('class', 'secondary-icon material-icons ' + secondaryIconName);
const clone = syncPlayIcon.cloneNode(true);
clone.style.visibility = 'visible';

View file

@ -12,8 +12,8 @@
(function (DOMParser) {
'use strict';
const DOMParser_proto = DOMParser.prototype;
const real_parseFromString = DOMParser_proto.parseFromString;
const DOMParserPrototype = DOMParser.prototype;
const realParseFromString = DOMParserPrototype.parseFromString;
// Firefox/Opera/IE throw errors on unsupported types
try {
@ -24,13 +24,13 @@
}
} catch (ex) { /* noop */ }
DOMParser_proto.parseFromString = function (markup, type) {
DOMParserPrototype.parseFromString = function (markup, type) {
if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
const doc = document.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = markup;
return doc;
} else {
return real_parseFromString.apply(this, arguments);
return realParseFromString.apply(this, arguments);
}
};
}(DOMParser));

View file

@ -7,12 +7,12 @@
(function (HTMLMediaElement) {
'use strict';
const HTMLMediaElement_proto = HTMLMediaElement.prototype;
const real_play = HTMLMediaElement_proto.play;
const HTMLMediaElementPrototype = HTMLMediaElement.prototype;
const realPlay = HTMLMediaElementPrototype.play;
HTMLMediaElement_proto.play = function () {
HTMLMediaElementPrototype.play = function () {
try {
const promise = real_play.apply(this, arguments);
const promise = realPlay.apply(this, arguments);
if (typeof promise?.then === 'function') {
return promise;

View file

@ -204,7 +204,7 @@ const uaMatch = function (ua) {
const versionMatch = /(version)[ /]([\w.]+)/.exec(ua);
let platform_match = /(ipad)/.exec(ua)
let platformMatch = /(ipad)/.exec(ua)
|| /(iphone)/.exec(ua)
|| /(windows)/.exec(ua)
|| /(android)/.exec(ua)
@ -213,7 +213,7 @@ const uaMatch = function (ua) {
let browser = match[1] || '';
if (browser === 'edge') {
platform_match = [''];
platformMatch = [''];
}
if (browser === 'opr') {
@ -236,7 +236,7 @@ const uaMatch = function (ua) {
return {
browser: browser,
version: version,
platform: platform_match[0] || '',
platform: platformMatch[0] || '',
versionMajor: versionMajor
};
};

View file

@ -6,6 +6,8 @@ import globalize from 'lib/globalize';
import Dashboard from 'utils/dashboard';
import { getParameterByName } from 'utils/url';
// Disable the naming rules since jstree requires snake_case variables
/* eslint-disable @typescript-eslint/naming-convention */
function getNode(item, folderState, selected) {
const htmlName = getNodeInnerHtml(item);
const node = {
@ -336,4 +338,4 @@ window.MetadataEditor = {
getCurrentItemId: getCurrentItemId,
setCurrentItemId: setCurrentItemId
};
/* eslint-enable @typescript-eslint/naming-convention */

View file

@ -3,9 +3,9 @@ export interface Event {
type: string;
}
type callback = (e: Event, ...args: any[]) => void;
type Callback = (e: Event, ...args: any[]) => void;
function getCallbacks(obj: any, type: string): callback[] {
function getCallbacks(obj: any, type: string): Callback[] {
if (!obj) {
throw new Error('obj cannot be null!');
}
@ -23,13 +23,13 @@ function getCallbacks(obj: any, type: string): callback[] {
}
export default {
on(obj: any, type: string, fn: callback): void {
on(obj: any, type: string, fn: Callback): void {
const callbacks = getCallbacks(obj, type);
callbacks.push(fn);
},
off(obj: any, type: string, fn: callback): void {
off(obj: any, type: string, fn: Callback): void {
const callbacks = getCallbacks(obj, type);
const i = callbacks.indexOf(fn);