Adding eslint.

This commit is contained in:
John Livingston 2021-02-20 11:55:00 +01:00
parent 31d3d96590
commit fba0422adb
6 changed files with 1418 additions and 22 deletions

23
.eslintrc.json Normal file
View File

@ -0,0 +1,23 @@
{
"root": true,
"env": {
"browser": true,
"es6": true
},
"extends": [
"standard"
],
"globals": {},
"plugins": [],
"ignorePatterns": ["node_modules/", "dist/", "webpack.config.js"],
"rules": {
"max-len": [
"error",
{
"code": 120,
"comments": 120
}
],
"no-unused-vars": [2, {"argsIgnorePattern": "^_"}]
}
}

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
.cache
dist
.vscode

View File

@ -1,4 +1,4 @@
"use strict"
'use strict'
const logger = {
log: (s) => console.log('[peertube-plugin-livechat] ' + s),
@ -53,7 +53,7 @@ function displayButton (buttons, name, label, callback) {
function displayChatButtons (peertubeHelpers, uuid) {
logger.log('Adding buttons in the DOM...')
const p = new Promise((resolve, reject) => {
const p = new Promise((resolve) => {
Promise.all([
peertubeHelpers.translate('Open chat'),
peertubeHelpers.translate('Open chat in a new window'),
@ -79,12 +79,12 @@ function displayChatButtons (peertubeHelpers, uuid) {
}
function toggleShowHideButtons (chatOpened) {
// showing/hiding buttons...
// showing/hiding buttons...
document.querySelectorAll('.peertube-plugin-livechat-button-open')
.forEach(button => button.style.display = (chatOpened === true || chatOpened === null ? 'none' : ''))
.forEach(button => (button.style.display = (chatOpened === true || chatOpened === null ? 'none' : '')))
document.querySelectorAll('.peertube-plugin-livechat-button-close')
.forEach(button => button.style.display = (chatOpened === false || chatOpened === null ? 'none' : ''))
.forEach(button => (button.style.display = (chatOpened === false || chatOpened === null ? 'none' : '')))
}
function openChat () {
@ -92,17 +92,17 @@ function openChat () {
const uuid = lastUUID
if (!uuid) {
logger.log('No current uuid.')
return reject()
return reject(new Error('No current uuid.'))
}
logger.info('Trying to load the chat for video ' + uuid + '.')
const iframeUri = getIframeUri(uuid)
if (!iframeUri) {
logger.error('Incorrect iframe uri')
return reject()
return reject(new Error('Incorrect iframe uri'))
}
const additionalStyles = settings['chat-style'] || ''
logger.info('Opening the chat...')
const videoWrapper = document.querySelector('#video-wrapper')
@ -127,6 +127,7 @@ function openChat () {
resolve()
})
return p
}
function closeChat () {
@ -157,7 +158,7 @@ function register ({ registerHook, peertubeHelpers }) {
const nonLiveOn = !!settings['chat-all-non-lives']
const uuids = parseUUIDs(settings['chat-videos-list'])
const iframeUri = settings['chat-uri'] || ''
if ( iframeUri === '' ) {
if (iframeUri === '') {
logger.log('no uri, can\'t add chat.')
return
}
@ -165,7 +166,7 @@ function register ({ registerHook, peertubeHelpers }) {
logger.log('not activated.')
return
}
logger.log('Checking if this video should have a chat...')
const uuid = lastUUID
const video = videoCache[uuid]
@ -183,7 +184,7 @@ function register ({ registerHook, peertubeHelpers }) {
logger.log('This video will not have a chat.')
return
}
displayChatButtons(peertubeHelpers, uuid).then(() => {
if (settings['chat-auto-display']) {
openChat()

15
main.js
View File

@ -1,11 +1,11 @@
async function register ({
registerHook,
_registerHook,
registerSetting,
settingsManager,
storageManager,
videoCategoryManager,
videoLicenceManager,
videoLanguageManager
_settingsManager,
_storageManager,
_videoCategoryManager,
_videoLicenceManager,
_videoLanguageManager
}) {
registerSetting({
name: 'chat-auto-display',
@ -36,7 +36,7 @@ async function register ({
type: 'input-textarea',
default: '',
descriptionHTML: 'Videos UUIDs for which we want a chat. ' +
'Can be non-live videos. One per line. <br />' +
'Can be non-live videos. One per line. <br />' +
'You can add comments: everything after the # character will be stripped off, and empty lines ignored.<br />' +
'Don\'t add private videos, the UUIDs will be send to frontend.',
private: false
@ -63,7 +63,6 @@ async function register ({
}
async function unregister () {
return
}
module.exports = {

1370
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,11 @@
],
"devDependencies": {
"@purtuga/esm-webpack-plugin": "^1.1.1",
"eslint": "^7.20.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
},
@ -31,7 +36,8 @@
"library": "./main.js",
"scripts": {
"prepare": "npm run build",
"build": "webpack --mode=production"
"build": "webpack --mode=production",
"lint": "npx eslint --ext .js ."
},
"staticDirs": {},
"translations": {