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:
commit
4fed499c99
8 changed files with 79 additions and 39 deletions
38
.eslintrc.js
38
.eslintrc.js
|
@ -273,6 +273,44 @@ module.exports = {
|
||||||
__WEBPACK_SERVE__: 'readonly'
|
__WEBPACK_SERVE__: 'readonly'
|
||||||
},
|
},
|
||||||
rules: {
|
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']
|
'@typescript-eslint/prefer-string-starts-ends-with': ['error']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,7 +12,7 @@ import AccessContainer from '../../../../components/dashboard/users/AccessContai
|
||||||
import CheckBoxElement from '../../../../elements/CheckBoxElement';
|
import CheckBoxElement from '../../../../elements/CheckBoxElement';
|
||||||
import Page from '../../../../components/Page';
|
import Page from '../../../../components/Page';
|
||||||
|
|
||||||
type userInput = {
|
type UserInput = {
|
||||||
Name?: string;
|
Name?: string;
|
||||||
Password?: string;
|
Password?: string;
|
||||||
};
|
};
|
||||||
|
@ -110,7 +110,7 @@ const UserNew = () => {
|
||||||
loadUser();
|
loadUser();
|
||||||
|
|
||||||
const saveUser = () => {
|
const saveUser = () => {
|
||||||
const userInput: userInput = {};
|
const userInput: UserInput = {};
|
||||||
userInput.Name = (page.querySelector('#txtUsername') as HTMLInputElement).value;
|
userInput.Name = (page.querySelector('#txtUsername') as HTMLInputElement).value;
|
||||||
userInput.Password = (page.querySelector('#txtPassword') as HTMLInputElement).value;
|
userInput.Password = (page.querySelector('#txtPassword') as HTMLInputElement).value;
|
||||||
window.ApiClient.createUser(userInput).then(function (user) {
|
window.ApiClient.createUser(userInput).then(function (user) {
|
||||||
|
|
|
@ -1948,47 +1948,47 @@ export default function (view) {
|
||||||
|
|
||||||
// Register to SyncPlay playback events and show big animated icon
|
// Register to SyncPlay playback events and show big animated icon
|
||||||
const showIcon = (action) => {
|
const showIcon = (action) => {
|
||||||
let primary_icon_name = '';
|
let primaryIconName = '';
|
||||||
let secondary_icon_name = '';
|
let secondaryIconName = '';
|
||||||
let animation_class = 'oneShotPulse';
|
let animationClass = 'oneShotPulse';
|
||||||
let iconVisibilityTime = 1500;
|
let iconVisibilityTime = 1500;
|
||||||
const syncPlayIcon = view.querySelector('#syncPlayIcon');
|
const syncPlayIcon = view.querySelector('#syncPlayIcon');
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'schedule-play':
|
case 'schedule-play':
|
||||||
primary_icon_name = 'sync spin';
|
primaryIconName = 'sync spin';
|
||||||
secondary_icon_name = 'play_arrow centered';
|
secondaryIconName = 'play_arrow centered';
|
||||||
animation_class = 'infinitePulse';
|
animationClass = 'infinitePulse';
|
||||||
iconVisibilityTime = -1;
|
iconVisibilityTime = -1;
|
||||||
hideOsd();
|
hideOsd();
|
||||||
break;
|
break;
|
||||||
case 'unpause':
|
case 'unpause':
|
||||||
primary_icon_name = 'play_circle_outline';
|
primaryIconName = 'play_circle_outline';
|
||||||
break;
|
break;
|
||||||
case 'pause':
|
case 'pause':
|
||||||
primary_icon_name = 'pause_circle_outline';
|
primaryIconName = 'pause_circle_outline';
|
||||||
showOsd();
|
showOsd();
|
||||||
break;
|
break;
|
||||||
case 'seek':
|
case 'seek':
|
||||||
primary_icon_name = 'update';
|
primaryIconName = 'update';
|
||||||
animation_class = 'infinitePulse';
|
animationClass = 'infinitePulse';
|
||||||
iconVisibilityTime = -1;
|
iconVisibilityTime = -1;
|
||||||
break;
|
break;
|
||||||
case 'buffering':
|
case 'buffering':
|
||||||
primary_icon_name = 'schedule';
|
primaryIconName = 'schedule';
|
||||||
animation_class = 'infinitePulse';
|
animationClass = 'infinitePulse';
|
||||||
iconVisibilityTime = -1;
|
iconVisibilityTime = -1;
|
||||||
break;
|
break;
|
||||||
case 'wait-pause':
|
case 'wait-pause':
|
||||||
primary_icon_name = 'schedule';
|
primaryIconName = 'schedule';
|
||||||
secondary_icon_name = 'pause shifted';
|
secondaryIconName = 'pause shifted';
|
||||||
animation_class = 'infinitePulse';
|
animationClass = 'infinitePulse';
|
||||||
iconVisibilityTime = -1;
|
iconVisibilityTime = -1;
|
||||||
break;
|
break;
|
||||||
case 'wait-unpause':
|
case 'wait-unpause':
|
||||||
primary_icon_name = 'schedule';
|
primaryIconName = 'schedule';
|
||||||
secondary_icon_name = 'play_arrow shifted';
|
secondaryIconName = 'play_arrow shifted';
|
||||||
animation_class = 'infinitePulse';
|
animationClass = 'infinitePulse';
|
||||||
iconVisibilityTime = -1;
|
iconVisibilityTime = -1;
|
||||||
break;
|
break;
|
||||||
default: {
|
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');
|
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');
|
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);
|
const clone = syncPlayIcon.cloneNode(true);
|
||||||
clone.style.visibility = 'visible';
|
clone.style.visibility = 'visible';
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
(function (DOMParser) {
|
(function (DOMParser) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const DOMParser_proto = DOMParser.prototype;
|
const DOMParserPrototype = DOMParser.prototype;
|
||||||
const real_parseFromString = DOMParser_proto.parseFromString;
|
const realParseFromString = DOMParserPrototype.parseFromString;
|
||||||
|
|
||||||
// Firefox/Opera/IE throw errors on unsupported types
|
// Firefox/Opera/IE throw errors on unsupported types
|
||||||
try {
|
try {
|
||||||
|
@ -24,13 +24,13 @@
|
||||||
}
|
}
|
||||||
} catch (ex) { /* noop */ }
|
} catch (ex) { /* noop */ }
|
||||||
|
|
||||||
DOMParser_proto.parseFromString = function (markup, type) {
|
DOMParserPrototype.parseFromString = function (markup, type) {
|
||||||
if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
|
if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
|
||||||
const doc = document.implementation.createHTMLDocument('');
|
const doc = document.implementation.createHTMLDocument('');
|
||||||
doc.documentElement.innerHTML = markup;
|
doc.documentElement.innerHTML = markup;
|
||||||
return doc;
|
return doc;
|
||||||
} else {
|
} else {
|
||||||
return real_parseFromString.apply(this, arguments);
|
return realParseFromString.apply(this, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}(DOMParser));
|
}(DOMParser));
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
(function (HTMLMediaElement) {
|
(function (HTMLMediaElement) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const HTMLMediaElement_proto = HTMLMediaElement.prototype;
|
const HTMLMediaElementPrototype = HTMLMediaElement.prototype;
|
||||||
const real_play = HTMLMediaElement_proto.play;
|
const realPlay = HTMLMediaElementPrototype.play;
|
||||||
|
|
||||||
HTMLMediaElement_proto.play = function () {
|
HTMLMediaElementPrototype.play = function () {
|
||||||
try {
|
try {
|
||||||
const promise = real_play.apply(this, arguments);
|
const promise = realPlay.apply(this, arguments);
|
||||||
|
|
||||||
if (typeof promise?.then === 'function') {
|
if (typeof promise?.then === 'function') {
|
||||||
return promise;
|
return promise;
|
||||||
|
|
|
@ -204,7 +204,7 @@ const uaMatch = function (ua) {
|
||||||
|
|
||||||
const versionMatch = /(version)[ /]([\w.]+)/.exec(ua);
|
const versionMatch = /(version)[ /]([\w.]+)/.exec(ua);
|
||||||
|
|
||||||
let platform_match = /(ipad)/.exec(ua)
|
let platformMatch = /(ipad)/.exec(ua)
|
||||||
|| /(iphone)/.exec(ua)
|
|| /(iphone)/.exec(ua)
|
||||||
|| /(windows)/.exec(ua)
|
|| /(windows)/.exec(ua)
|
||||||
|| /(android)/.exec(ua)
|
|| /(android)/.exec(ua)
|
||||||
|
@ -213,7 +213,7 @@ const uaMatch = function (ua) {
|
||||||
let browser = match[1] || '';
|
let browser = match[1] || '';
|
||||||
|
|
||||||
if (browser === 'edge') {
|
if (browser === 'edge') {
|
||||||
platform_match = [''];
|
platformMatch = [''];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browser === 'opr') {
|
if (browser === 'opr') {
|
||||||
|
@ -236,7 +236,7 @@ const uaMatch = function (ua) {
|
||||||
return {
|
return {
|
||||||
browser: browser,
|
browser: browser,
|
||||||
version: version,
|
version: version,
|
||||||
platform: platform_match[0] || '',
|
platform: platformMatch[0] || '',
|
||||||
versionMajor: versionMajor
|
versionMajor: versionMajor
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,8 @@ import globalize from 'lib/globalize';
|
||||||
import Dashboard from 'utils/dashboard';
|
import Dashboard from 'utils/dashboard';
|
||||||
import { getParameterByName } from 'utils/url';
|
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) {
|
function getNode(item, folderState, selected) {
|
||||||
const htmlName = getNodeInnerHtml(item);
|
const htmlName = getNodeInnerHtml(item);
|
||||||
const node = {
|
const node = {
|
||||||
|
@ -336,4 +338,4 @@ window.MetadataEditor = {
|
||||||
getCurrentItemId: getCurrentItemId,
|
getCurrentItemId: getCurrentItemId,
|
||||||
setCurrentItemId: setCurrentItemId
|
setCurrentItemId: setCurrentItemId
|
||||||
};
|
};
|
||||||
|
/* eslint-enable @typescript-eslint/naming-convention */
|
||||||
|
|
|
@ -3,9 +3,9 @@ export interface Event {
|
||||||
type: string;
|
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) {
|
if (!obj) {
|
||||||
throw new Error('obj cannot be null!');
|
throw new Error('obj cannot be null!');
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,13 @@ function getCallbacks(obj: any, type: string): callback[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
on(obj: any, type: string, fn: callback): void {
|
on(obj: any, type: string, fn: Callback): void {
|
||||||
const callbacks = getCallbacks(obj, type);
|
const callbacks = getCallbacks(obj, type);
|
||||||
|
|
||||||
callbacks.push(fn);
|
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 callbacks = getCallbacks(obj, type);
|
||||||
|
|
||||||
const i = callbacks.indexOf(fn);
|
const i = callbacks.indexOf(fn);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue