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 node_modules
.cache .cache
dist dist
.vscode

View File

@ -1,4 +1,4 @@
"use strict" 'use strict'
const logger = { const logger = {
log: (s) => console.log('[peertube-plugin-livechat] ' + s), log: (s) => console.log('[peertube-plugin-livechat] ' + s),
@ -53,7 +53,7 @@ function displayButton (buttons, name, label, callback) {
function displayChatButtons (peertubeHelpers, uuid) { function displayChatButtons (peertubeHelpers, uuid) {
logger.log('Adding buttons in the DOM...') logger.log('Adding buttons in the DOM...')
const p = new Promise((resolve, reject) => { const p = new Promise((resolve) => {
Promise.all([ Promise.all([
peertubeHelpers.translate('Open chat'), peertubeHelpers.translate('Open chat'),
peertubeHelpers.translate('Open chat in a new window'), peertubeHelpers.translate('Open chat in a new window'),
@ -79,12 +79,12 @@ function displayChatButtons (peertubeHelpers, uuid) {
} }
function toggleShowHideButtons (chatOpened) { function toggleShowHideButtons (chatOpened) {
// showing/hiding buttons... // showing/hiding buttons...
document.querySelectorAll('.peertube-plugin-livechat-button-open') 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') 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 () { function openChat () {
@ -92,14 +92,14 @@ function openChat () {
const uuid = lastUUID const uuid = lastUUID
if (!uuid) { if (!uuid) {
logger.log('No current 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 + '.') logger.info('Trying to load the chat for video ' + uuid + '.')
const iframeUri = getIframeUri(uuid) const iframeUri = getIframeUri(uuid)
if (!iframeUri) { if (!iframeUri) {
logger.error('Incorrect iframe uri') logger.error('Incorrect iframe uri')
return reject() return reject(new Error('Incorrect iframe uri'))
} }
const additionalStyles = settings['chat-style'] || '' const additionalStyles = settings['chat-style'] || ''
@ -127,6 +127,7 @@ function openChat () {
resolve() resolve()
}) })
return p
} }
function closeChat () { function closeChat () {
@ -157,7 +158,7 @@ function register ({ registerHook, peertubeHelpers }) {
const nonLiveOn = !!settings['chat-all-non-lives'] const nonLiveOn = !!settings['chat-all-non-lives']
const uuids = parseUUIDs(settings['chat-videos-list']) const uuids = parseUUIDs(settings['chat-videos-list'])
const iframeUri = settings['chat-uri'] || '' const iframeUri = settings['chat-uri'] || ''
if ( iframeUri === '' ) { if (iframeUri === '') {
logger.log('no uri, can\'t add chat.') logger.log('no uri, can\'t add chat.')
return return
} }

13
main.js
View File

@ -1,11 +1,11 @@
async function register ({ async function register ({
registerHook, _registerHook,
registerSetting, registerSetting,
settingsManager, _settingsManager,
storageManager, _storageManager,
videoCategoryManager, _videoCategoryManager,
videoLicenceManager, _videoLicenceManager,
videoLanguageManager _videoLanguageManager
}) { }) {
registerSetting({ registerSetting({
name: 'chat-auto-display', name: 'chat-auto-display',
@ -63,7 +63,6 @@ async function register ({
} }
async function unregister () { async function unregister () {
return
} }
module.exports = { module.exports = {

1370
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,11 @@
], ],
"devDependencies": { "devDependencies": {
"@purtuga/esm-webpack-plugin": "^1.1.1", "@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": "^4.41.2",
"webpack-cli": "^3.3.10" "webpack-cli": "^3.3.10"
}, },
@ -31,7 +36,8 @@
"library": "./main.js", "library": "./main.js",
"scripts": { "scripts": {
"prepare": "npm run build", "prepare": "npm run build",
"build": "webpack --mode=production" "build": "webpack --mode=production",
"lint": "npx eslint --ext .js ."
}, },
"staticDirs": {}, "staticDirs": {},
"translations": { "translations": {