1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-07-12 23:50:27 +02:00

Cleanup some eslint issues.

This commit is contained in:
Chen-I Lim
2020-10-20 13:26:06 -07:00
parent 9255bd4ded
commit c95ab685e4
11 changed files with 159 additions and 153 deletions

2
.gitignore vendored
View File

@ -37,3 +37,5 @@ __debug_bin
files files
octo*.db octo*.db
.eslintcache .eslintcache
.vscode/settings.json
.prettierrc.json

View File

@ -1,5 +0,0 @@
{
"tabWidth": 4,
"useTabs": true,
"semi": false
}

View File

@ -4,15 +4,15 @@ import {MenuOption} from './menu'
class Constants { class Constants {
static menuColors: MenuOption[] = [ static menuColors: MenuOption[] = [
{id: 'propColorDefault', name: 'Default', type: 'color'}, {id: 'propColorDefault', name: 'Default', type: 'color'},
{id: 'propColorGray', name: 'Gray', type: 'color'}, {id: 'propColorGray', name: 'Gray', type: 'color'},
{id: 'propColorBrown', name: 'Brown', type: 'color'}, {id: 'propColorBrown', name: 'Brown', type: 'color'},
{id: 'propColorOrange', name: 'Orange', type: 'color'}, {id: 'propColorOrange', name: 'Orange', type: 'color'},
{id: 'propColorYellow', name: 'Yellow', type: 'color'}, {id: 'propColorYellow', name: 'Yellow', type: 'color'},
{id: 'propColorGreen', name: 'Green', type: 'color'}, {id: 'propColorGreen', name: 'Green', type: 'color'},
{id: 'propColorBlue', name: 'Blue', type: 'color'}, {id: 'propColorBlue', name: 'Blue', type: 'color'},
{id: 'propColorPurple', name: 'Purple', type: 'color'}, {id: 'propColorPurple', name: 'Purple', type: 'color'},
{id: 'propColorPink', name: 'Pink', type: 'color'}, {id: 'propColorPink', name: 'Pink', type: 'color'},
{id: 'propColorRed', name: 'Red', type: 'color'}, {id: 'propColorRed', name: 'Red', type: 'color'},
] ]
} }

View File

@ -4,7 +4,7 @@ class FlashMessage {
// //
// Show a temporary status message // Show a temporary status message
// //
static show(text: string, delay = 800) { static show(text: string, delay = 800): void {
const flashPanel = document.createElement('div') const flashPanel = document.createElement('div')
flashPanel.innerText = text flashPanel.innerText = text
flashPanel.classList.add('flashPanel') flashPanel.classList.add('flashPanel')

View File

@ -14,84 +14,88 @@ class PropertyMenu extends Menu {
constructor() { constructor() {
super() super()
const typeMenuOptions = [ const typeMenuOptions = [
{id: 'text', name: 'Text'}, {id: 'text', name: 'Text'},
{id: 'number', name: 'Number'}, {id: 'number', name: 'Number'},
{id: 'select', name: 'Select'}, {id: 'select', name: 'Select'},
{id: 'createdTime', name: 'Created Time'}, {id: 'createdTime', name: 'Created Time'},
{id: 'updatedTime', name: 'Updated Time'}, {id: 'updatedTime', name: 'Updated Time'},
] ]
this.subMenuOptions.set('type', typeMenuOptions) this.subMenuOptions.set('type', typeMenuOptions)
} }
createMenuElement() { createMenuElement(): HTMLElement {
const menu = Utils.htmlToElement('<div class="menu noselect" style="min-width: 200px;"></div>') const menu = Utils.htmlToElement('<div class="menu noselect" style="min-width: 200px;"></div>')
const ul = menu.appendChild(Utils.htmlToElement('<ul class="menu-options"></ul>')) const ul = menu.appendChild(Utils.htmlToElement('<ul class="menu-options"></ul>'))
const nameTextbox = ul.appendChild(Utils.htmlToElement('<li class="menu-textbox"></li>')) const nameTextbox = ul.appendChild(Utils.htmlToElement('<li class="menu-textbox"></li>'))
this.nameTextbox = nameTextbox this.nameTextbox = nameTextbox
let propertyValue = this.property ? this.property.name : '' let propertyValue = this.property ? this.property.name : ''
nameTextbox.innerText = propertyValue nameTextbox.innerText = propertyValue
nameTextbox.contentEditable = 'true' nameTextbox.contentEditable = 'true'
nameTextbox.onclick = (e) => { nameTextbox.onclick = (e) => {
e.stopPropagation() e.stopPropagation()
} }
nameTextbox.onblur = () => { nameTextbox.onblur = () => {
if (nameTextbox.innerText !== propertyValue) { if (nameTextbox.innerText !== propertyValue) {
propertyValue = nameTextbox.innerText propertyValue = nameTextbox.innerText
if (this.onNameChanged) { if (this.onNameChanged) {
this.onNameChanged(nameTextbox.innerText) this.onNameChanged(nameTextbox.innerText)
} }
} }
} }
nameTextbox.onmouseenter = () => { nameTextbox.onmouseenter = () => {
this.hideSubMenu() this.hideSubMenu()
} }
nameTextbox.onkeydown = (e) => { nameTextbox.onkeydown = (e) => {
if (e.keyCode === 13 || e.keyCode === 27) { if (e.keyCode === 13 || e.keyCode === 27) {
nameTextbox.blur(); e.stopPropagation() nameTextbox.blur()
e.stopPropagation()
} }
} }
ul.appendChild(Utils.htmlToElement('<li class="menu-separator"></li>')) ul.appendChild(Utils.htmlToElement('<li class="menu-separator"></li>'))
this.appendMenuOptions(ul) this.appendMenuOptions(ul)
return menu return menu
} }
showAt(left: number, top: number) { showAt(left: number, top: number): void {
this.options = [ this.options = [
{id: 'type', name: this.typeDisplayName(this.property.type), type: 'submenu'}, {id: 'type', name: this.typeDisplayName(this.property.type), type: 'submenu'},
{id: 'delete', name: 'Delete'}, {id: 'delete', name: 'Delete'},
] ]
super.showAt(left, top) super.showAt(left, top)
setTimeout(() => { setTimeout(() => {
this.nameTextbox.focus() this.nameTextbox.focus()
document.execCommand('selectAll', false, null) document.execCommand('selectAll', false, null)
}, 20) }, 20)
} }
private typeDisplayName(type: PropertyType): string { private typeDisplayName(type: PropertyType): string {
switch (type) { switch (type) {
case 'text': return 'Text' case 'text': return 'Text'
case 'number': return 'Number' case 'number': return 'Number'
case 'select': return 'Select' case 'select': return 'Select'
case 'multiSelect': return 'Multi Select' case 'multiSelect': return 'Multi Select'
case 'person': return 'Person' case 'person': return 'Person'
case 'file': return 'File or Media' case 'file': return 'File or Media'
case 'checkbox': return 'Checkbox' case 'checkbox': return 'Checkbox'
case 'url': return 'URL' case 'url': return 'URL'
case 'email': return 'Email' case 'email': return 'Email'
case 'phone': return 'Phone' case 'phone': return 'Phone'
case 'createdTime': return 'Created Time' case 'createdTime': return 'Created Time'
case 'createdBy': return 'Created By' case 'createdBy': return 'Created By'
case 'updatedTime': return 'Updated Time' case 'updatedTime': return 'Updated Time'
case 'updatedBy': return 'Updated By' case 'updatedBy': return 'Updated By'
default: {
Utils.assertFailure(`typeDisplayName, unhandled type: ${type}`)
return type
}
} }
Utils.assertFailure(`typeDisplayName, unhandled type: ${type}`)
} }
} }

View File

@ -83,9 +83,7 @@ class UndoManager {
let checkpoint: number let checkpoint: number
if (isDiscardable) { if (isDiscardable) {
checkpoint = checkpoint =
this.commands.length > 1 ? this.commands.length > 1 ? this.commands[this.commands.length - 1].checkpoint : 0
this.commands[this.commands.length - 1].checkpoint :
0
} else { } else {
checkpoint = Date.now() checkpoint = Date.now()
} }

View File

@ -9,7 +9,7 @@ declare global {
} }
class Utils { class Utils {
static createGuid() { static createGuid(): string {
const crypto = window.crypto || window.msCrypto const crypto = window.crypto || window.msCrypto
function randomDigit() { function randomDigit() {
if (crypto && crypto.getRandomValues) { if (crypto && crypto.getRandomValues) {
@ -25,8 +25,7 @@ class Utils {
static htmlToElement(html: string): HTMLElement { static htmlToElement(html: string): HTMLElement {
const template = document.createElement('template') const template = document.createElement('template')
html = html.trim() template.innerHTML = html.trim()
template.innerHTML = html
return template.content.firstChild as HTMLElement return template.content.firstChild as HTMLElement
} }
@ -36,11 +35,11 @@ class Utils {
return element! return element!
} }
static htmlEncode(text: string) { static htmlEncode(text: string): string {
return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
} }
static htmlDecode(text: string) { static htmlDecode(text: string): string {
return String(text).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"') return String(text).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"')
} }
@ -77,7 +76,7 @@ class Utils {
// Errors // Errors
static assertValue(valueObject: any) { static assertValue(valueObject: any): void {
const name = Object.keys(valueObject)[0] const name = Object.keys(valueObject)[0]
const value = valueObject[name] const value = valueObject[name]
if (!value) { if (!value) {
@ -85,7 +84,7 @@ class Utils {
} }
} }
static assert(condition: any, tag = '') { static assert(condition: any, tag = ''): void {
/// #!if ENV !== "production" /// #!if ENV !== "production"
if (!condition) { if (!condition) {
Utils.logError(`ASSERT [${tag ?? new Error().stack}]`) Utils.logError(`ASSERT [${tag ?? new Error().stack}]`)
@ -94,24 +93,26 @@ class Utils {
/// #!endif /// #!endif
} }
static assertFailure(tag = '') { static assertFailure(tag = ''): void {
/// #!if ENV !== "production" /// #!if ENV !== "production"
Utils.assert(false, tag) Utils.assert(false, tag)
/// #!endif /// #!endif
} }
static log(message: string) { static log(message: string): void {
/// #!if ENV !== "production" /// #!if ENV !== "production"
const timestamp = (Date.now() / 1000).toFixed(2) const timestamp = (Date.now() / 1000).toFixed(2)
// eslint-disable-next-line no-console
console.log(`[${timestamp}] ${message}`) console.log(`[${timestamp}] ${message}`)
/// #!endif /// #!endif
} }
static logError(message: any) { static logError(message: string): void {
/// #!if ENV !== "production" /// #!if ENV !== "production"
const timestamp = (Date.now() / 1000).toFixed(2) const timestamp = (Date.now() / 1000).toFixed(2)
// eslint-disable-next-line no-console
console.error(`[${timestamp}] ${message}`) console.error(`[${timestamp}] ${message}`)
/// #!endif /// #!endif
@ -119,7 +120,7 @@ class Utils {
// favicon // favicon
static setFavicon(icon?: string) { static setFavicon(icon?: string): void {
const href = icon ? const href = icon ?
`data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>` : `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>` :
'' ''
@ -132,7 +133,7 @@ class Utils {
// File names // File names
static sanitizeFilename(filename: string) { static sanitizeFilename(filename: string): string {
// TODO: Use an industrial-strength sanitizer // TODO: Use an industrial-strength sanitizer
let sanitizedFilename = filename let sanitizedFilename = filename
const illegalCharacters = ['\\', '/', '?', ':', '<', '>', '*', '|', '"', '.'] const illegalCharacters = ['\\', '/', '?', ':', '<', '>', '*', '|', '"', '.']
@ -162,7 +163,7 @@ class Utils {
// Arrays // Arrays
static arraysEqual(a: any[], b: any[]) { static arraysEqual(a: any[], b: any[]): boolean {
if (a === b) { if (a === b) {
return true return true
} }

View File

@ -8,12 +8,12 @@ import {OctoUtils} from './octoUtils'
class WorkspaceTree { class WorkspaceTree {
boards: Board[] = [] boards: Board[] = []
async sync() { async sync(): Promise<void> {
const blocks = await octoClient.getBlocks(undefined, 'board') const blocks = await octoClient.getBlocks(undefined, 'board')
this.rebuild(OctoUtils.hydrateBlocks(blocks)) this.rebuild(OctoUtils.hydrateBlocks(blocks))
} }
private rebuild(blocks: Block[]) { private rebuild(blocks: Block[]): void {
this.boards = blocks.filter((block) => block.type === 'board') as Board[] this.boards = blocks.filter((block) => block.type === 'board') as Board[]
} }
} }

View File

@ -1,79 +1,79 @@
const webpack = require("webpack") // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
const path = require("path") // See LICENSE.txt for license information.
const CopyPlugin = require("copy-webpack-plugin") const path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin') const CopyPlugin = require('copy-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const outpath = path.resolve(__dirname, "pack") const outpath = path.resolve(__dirname, 'pack');
function makeCommonConfig() { function makeCommonConfig() {
const commonConfig = { const commonConfig = {
target: "web", target: 'web',
mode: "development", mode: 'development',
entry: "./index.js", node: {
node: { __dirname: false,
__dirname: false, __filename: false,
__filename: false },
}, module: {
module: { rules: [
rules: [ {
{ test: /\.tsx?$/,
test: /\.tsx?$/, use: 'ts-loader',
use: "ts-loader", exclude: [/node_modules/],
exclude: [/node_modules/], },
}, {
{ test: /\.html$/,
test: /\.html$/, loader: 'file-loader',
loader: "file-loader", },
}, {
{ test: /\.s[ac]ss$/i,
test: /\.s[ac]ss$/i, use: [
use: [ 'style-loader',
'style-loader', 'css-loader',
'css-loader', 'sass-loader',
'sass-loader', ],
], },
}, {
{ test: /\.(tsx?|js|jsx|html)$/,
test: /\.(tsx?|js|jsx|html)$/, use: [
use: [ ],
], exclude: [/node_modules/],
exclude: [/node_modules/], },
} ],
] },
}, resolve: {
resolve: { modules: [
modules: [ 'node_modules',
'node_modules', path.resolve(__dirname),
path.resolve(__dirname), ],
], extensions: ['.js', '.jsx', '.ts', '.tsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'], },
}, plugins: [
plugins: [ new CopyPlugin({
new CopyPlugin({ patterns: [
patterns: [ {from: path.resolve(__dirname, 'static'), to: 'static'},
{ from: path.resolve(__dirname, "static"), to: "static" }, {from: path.resolve(__dirname, 'node_modules/easymde/dist/easymde.min.css'), to: 'static'},
{ from: path.resolve(__dirname, "node_modules/easymde/dist/easymde.min.css"), to: "static" }, ],
], }),
}), new HtmlWebpackPlugin({
new HtmlWebpackPlugin({ inject: true,
inject: true, title: 'OCTO',
title: "OCTO", chunks: ['main'],
chunks: ["main"], template: 'html-templates/page.ejs',
template: "html-templates/page.ejs", filename: 'index.html',
filename: 'index.html', publicPath: '/',
publicPath: '/' }),
}), ],
], entry: {
entry: { main: './src/main.tsx',
main: "./src/main.tsx", },
}, output: {
output: { filename: 'static/[name].js',
filename: "static/[name].js", path: outpath,
path: outpath },
} };
}
return commonConfig return commonConfig;
} }
module.exports = makeCommonConfig module.exports = makeCommonConfig;

View File

@ -1,17 +1,20 @@
const merge = require("webpack-merge"); // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
const makeCommonConfig = require("./webpack.common.js"); // See LICENSE.txt for license information.
const merge = require('webpack-merge');
const makeCommonConfig = require('./webpack.common.js');
const commonConfig = makeCommonConfig(); const commonConfig = makeCommonConfig();
const config = merge.merge(commonConfig, { const config = merge.merge(commonConfig, {
mode: "development", mode: 'development',
devtool: "inline-source-map", devtool: 'inline-source-map',
optimization: { optimization: {
minimize: false minimize: false,
} },
}); });
module.exports = [ module.exports = [
merge.merge(config, { merge.merge(config, {
}), }),
]; ];

View File

@ -1,18 +1,21 @@
const merge = require("webpack-merge"); // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
const TerserPlugin = require("terser-webpack-plugin"); // See LICENSE.txt for license information.
const makeCommonConfig = require("./webpack.common.js"); const merge = require('webpack-merge');
const TerserPlugin = require('terser-webpack-plugin');
const makeCommonConfig = require('./webpack.common.js');
const commonConfig = makeCommonConfig(); const commonConfig = makeCommonConfig();
const config = merge.merge(commonConfig, { const config = merge.merge(commonConfig, {
mode: "production", mode: 'production',
optimization: { optimization: {
minimize: true, minimize: true,
minimizer: [new TerserPlugin({})] minimizer: [new TerserPlugin({})],
} },
}); });
module.exports = [ module.exports = [
merge.merge(config, { merge.merge(config, {
}), }),
]; ];