diff --git a/.eslintrc.json b/.eslintrc.json index 203ae2e..5975d4a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,10 +18,10 @@ "ecmaVersion": 2020 }, "rules": { - "valid-jsdoc": "off", + // H5P Group rules "semi": ["error", "always"], "indent": ["error", 2, { "SwitchCase": 1 }], - // "brace-style": ["error", "stroustrup"], + "brace-style": ["error", "stroustrup"], "keyword-spacing": ["error", { "after": true }], "comma-spacing": ["error", { "before": false, "after": true }], "space-infix-ops": ["error", { "int32Hint": false }], @@ -33,11 +33,23 @@ "asyncArrow": "always" }], "no-extra-boolean-cast": "off", - "no-console": ["error", { "allow": ["warn", "error", "log"] }], - "quotes": ["error", "double"], - "arrow-parens": ["error", "always"], - "object-curly-spacing": ["error", "always"], - "no-alert": ["error"] + "no-console": ["error", { "allow": ["warn", "error"] }], + "quotes": ["error", "single"], + // SNORDIAN specific rules + "arrow-parens": ["error", "always"], + "object-curly-spacing": ["error", "always"], + "prefer-template": ["error"], + "no-await-in-loop": ["error"], + "no-self-compare": ["error"], + "dot-notation": ["error"], + "no-eval": ["error"], + "no-implied-eval": ["error"], + "no-magic-numbers": ["warn", { + "ignoreArrayIndexes": true, + "ignoreDefaultValues": true, + "enforceConst": true, + "ignore": [-1, 0, 1] + }] }, "plugins": ["jsdoc"], "parser": "@babel/eslint-parser", diff --git a/scripts/app.js b/scripts/app.js index 6d8477a..8dce2b8 100644 --- a/scripts/app.js +++ b/scripts/app.js @@ -1,7 +1,5 @@ -import React from 'react'; import { createRoot } from 'react-dom/client'; -import Main from './components/Main'; -import { H5PContext } from './context/H5PContext'; + import { sanitizeContentTypeParameters } from './utils/sanitization'; export default class Wrapper extends H5P.EventDispatcher { @@ -102,7 +100,8 @@ export default class Wrapper extends H5P.EventDispatcher { const wrapperSize = this.wrapper.getBoundingClientRect(); if (wrapperSize.width < mobileThreshold) { this.wrapper.classList.add('mobile'); - } else { + } + else { this.wrapper.classList.remove('mobile'); } } diff --git a/scripts/components/Dialog/Dialog.js b/scripts/components/Dialog/Dialog.js index 33ab3a5..8d7441e 100644 --- a/scripts/components/Dialog/Dialog.js +++ b/scripts/components/Dialog/Dialog.js @@ -18,18 +18,12 @@ export default class Dialog extends React.Component { } } - handleResize(isNarrow) { + handleResize() { if (this.el) { // Reset to allow size growth this.el.style.width = ''; this.el.style.height = ''; - this.el.style.height = this.el.getBoundingClientRect().height + 'px'; - //if (isNarrow) { - // This make IE11 not show the image. It seems to be the combination of - // flexbox and width:auto that is causing this - // Shrink dialog width for narrow images - // this.el.style.width = 'auto'; - //} + this.el.style.height = `${this.el.getBoundingClientRect().height }px`; } } @@ -43,10 +37,10 @@ export default class Dialog extends React.Component { this.props.children.type === 'div' ? this.props.children : React.Children.map(this.props.children, (child) => - React.cloneElement(child, { - onResize: this.handleResize, - }) - ); + React.cloneElement(child, { + onResize: this.handleResize, + }) + ); return (
diff --git a/scripts/components/Dialog/InteractionContent.js b/scripts/components/Dialog/InteractionContent.js index b0dfb8a..13faad7 100644 --- a/scripts/components/Dialog/InteractionContent.js +++ b/scripts/components/Dialog/InteractionContent.js @@ -51,7 +51,7 @@ export default class InteractionContent extends React.Component { if (library.library.split(' ')[0] === 'H5P.Video') { this.instance.on('stateChange', (e) => { if (e.data === H5P.Video.PLAYING) { - this.props.onAudioIsPlaying('video-' + this.props.hotspot); + this.props.onAudioIsPlaying(`video-${ this.props.hotspot}`); } }); } diff --git a/scripts/components/HUD/Buttons/AudioButton.js b/scripts/components/HUD/Buttons/AudioButton.js index 8fbec47..c19e734 100644 --- a/scripts/components/HUD/Buttons/AudioButton.js +++ b/scripts/components/HUD/Buttons/AudioButton.js @@ -1,7 +1,6 @@ import React from 'react'; import { H5PContext } from '../../../context/H5PContext'; -import Button from './Button/Button'; export default class AudioButton extends React.Component { constructor(props) { @@ -13,13 +12,12 @@ export default class AudioButton extends React.Component { /** * Determine player ID from given props - * - * @param {Object} props - * @return {string} + * @param {object} props React props. + * @returns {string|undefined} Player ID. */ getPlayerId(props) { if (props.sceneId !== undefined && props.sceneAudioTrack && props.sceneAudioTrack.length) { - return 'scene-' + props.sceneId; + return `scene-${ props.sceneId}`; } if (this.context.behavior.audio && this.context.behavior.audio.length) { return 'global'; @@ -28,9 +26,8 @@ export default class AudioButton extends React.Component { /** * Get track from given player ID - * - * @param {string} props - * @return {Array} + * @param {string} id Player ID. + * @returns {object} Audio track. */ getTrack(id) { return id === 'global' ? this.context.behavior.audio : this.props.sceneAudioTrack; @@ -38,9 +35,8 @@ export default class AudioButton extends React.Component { /** * Get the audio player for the current track. - * - * @param {string} id - * @return {AudioElement} or 'null' if track isn't playable. + * @param {string} id Audio player id. + * @returns {HTMLAudioElement} or 'null' if track isn't playable. */ getPlayer(id) { if (!id) { @@ -76,7 +72,8 @@ export default class AudioButton extends React.Component { if (id === this.props.isPlaying) { // Pause and reset the player player.pause(); - } else { + } + else { // Start the playback! player.play(); } @@ -103,6 +100,7 @@ export default class AudioButton extends React.Component { /** * React - runs after render. + * @param {object} prevProps Previous props. */ componentDidUpdate(prevProps) { if (this.props.isPlaying && this.props.isPlaying !== prevProps.isPlaying) { @@ -143,6 +141,7 @@ export default class AudioButton extends React.Component { /** * React - adds dom elements. + * @returns {HTMLElement} React element */ render() { const id = this.getPlayerId(this.props); @@ -150,7 +149,7 @@ export default class AudioButton extends React.Component { return null; } - const type = 'audio-track' + (this.props.isPlaying === id ? ' active' : ''); + const type = `audio-track${ this.props.isPlaying === id ? ' active' : ''}`; return (