Skip to content

Commit

Permalink
Merge pull request #1256 from Arnei/eslint-quote
Browse files Browse the repository at this point in the history
Enforce eslint quotes
  • Loading branch information
Arnei authored Jan 18, 2024
2 parents b695e7b + 0259fa9 commit 53598c1
Show file tree
Hide file tree
Showing 54 changed files with 1,276 additions and 1,279 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ module.exports = {
"react-app/jest"
],
rules: {
// Both kinds of quotes are used a lot
"quotes": "off",

// "always" gives 319 warning, "never" gives 991.
"object-curly-spacing": "off",

Expand Down
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Body from './main/Body';
import Header from './main/Header';
import { GlobalStyle } from './cssStyles';
import Body from "./main/Body";
import Header from "./main/Header";
import { GlobalStyle } from "./cssStyles";

function App() {
return (
Expand Down
94 changes: 47 additions & 47 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
*
* Also does some global hotkey configuration
*/
import parseToml from '@iarna/toml/parse-string';
import deepmerge from 'deepmerge';
import { Flavor } from './types';
import parseToml from "@iarna/toml/parse-string";
import deepmerge from "deepmerge";
import { Flavor } from "./types";

/**
* Local constants
*/
const CONTEXT_SETTINGS_FILE = 'editor-settings.toml';
const CONTEXT_SETTINGS_FILE = "editor-settings.toml";

// Sources that values can come from.
const SRC_SERVER = 'src-server';
const SRC_URL = 'src-url';
const SRC_SERVER = "src-server";
const SRC_URL = "src-url";

/**
* Possible configuration values for a metadata catalog field
Expand All @@ -30,8 +30,8 @@ export interface configureFieldsAttributes {

export interface subtitleTags {
lang: string,
'auto-generated': string,
'auto-generator': string,
"auto-generated": string,
"auto-generator": string,
type: string,
}

Expand Down Expand Up @@ -138,19 +138,19 @@ export const init = async () => {

const rawUrlSettings = {};
urlParams.forEach((value, key) => {
// Create empty objects for full path (if the key contains '.') and set
// Create empty objects for full path (if the key contains ".") and set
// the value at the end.
let obj: { [k: string]: any; } = rawUrlSettings;
if (key.startsWith('opencast.') || key === 'allowedCallbackPrefixes') {
if (key.startsWith("opencast.") || key === "allowedCallbackPrefixes") {
return;
}

// Fallback for old parameter
if (key === 'mediaPackageId') {
key = 'id';
if (key === "mediaPackageId") {
key = "id";
}

const segments = key.split('.');
const segments = key.split(".");
segments.slice(0, -1).forEach(segment => {
if (!(segment in obj)) {
obj[segment] = {};
Expand All @@ -160,7 +160,7 @@ export const init = async () => {
obj[segments[segments.length - 1]] = value;
});

urlParameterSettings = validate(rawUrlSettings, true, SRC_URL, 'given as URL GET parameter');
urlParameterSettings = validate(rawUrlSettings, true, SRC_URL, "given as URL GET parameter");

// Combine results
settings = merge.all([defaultSettings, configFileSettings, urlParameterSettings]) as iSettings;
Expand All @@ -180,47 +180,47 @@ export const init = async () => {
const loadContextSettings = async () => {

// Try to retrieve the context settings.
let basepath = process.env.PUBLIC_URL || '/';
if (!basepath.endsWith('/')) {
basepath += '/';
let basepath = process.env.PUBLIC_URL || "/";
if (!basepath.endsWith("/")) {
basepath += "/";
}

// Construct path to settings file. If the `REACT_APP_SETTINGS_PATH` is
// given and starts with '/', it is interpreted as absolute path from the
// given and starts with "/", it is interpreted as absolute path from the
// server root.
const settingsPath = process.env.REACT_APP_SETTINGS_PATH || CONTEXT_SETTINGS_FILE;
const base = settingsPath.startsWith('/') ? '' : basepath;
const base = settingsPath.startsWith("/") ? "" : basepath;
const url = `${window.location.origin}${base}${settingsPath}`;
let response;
try {
response = await fetch(url);
} catch (e) {
console.warn(`Could not access '${settingsPath}' due to network error!`, e || "");
console.warn(`Could not access "${settingsPath}" due to network error!`, e || "");
return null;
}

if (response.status === 404) {
// If the settings file was not found, we silently ignore the error. We
// expect many installation to provide this file.
console.debug(`'${settingsPath}' returned 404: ignoring`);
console.debug(`"${settingsPath}" returned 404: ignoring`);
return null;
} else if (!response.ok) {
console.error(
`Fetching '${settingsPath}' failed: ${response.status} ${response.statusText}`
`Fetching "${settingsPath}" failed: ${response.status} ${response.statusText}`
);
return null;
}

if (response.headers.get('Content-Type')?.startsWith('text/html')) {
console.warn(`'${settingsPath}' request has 'Content-Type: text/html' -> ignoring...`);
if (response.headers.get("Content-Type")?.startsWith("text/html")) {
console.warn(`"${settingsPath}" request has "Content-Type: text/html" -> ignoring...`);
return null;
}

try {
return parseToml(await response.text());
} catch (e) {
console.error(`Could not parse '${settingsPath}' as TOML: `, e);
throw new SyntaxError(`Could not parse '${settingsPath}' as TOML: ${e}`);
console.error(`Could not parse "${settingsPath}" as TOML: `, e);
throw new SyntaxError(`Could not parse "${settingsPath}" as TOML: ${e}`);
}

};
Expand All @@ -236,7 +236,7 @@ const validate = (obj: Record<string, any> | null, allowParse: boolean, src: str
// Validates `obj` with `schema`. `path` is the current path used for error
// messages.
const validate = (schema: any, obj: Record<string, any> | null, path: string) => {
if (typeof schema === 'function') {
if (typeof schema === "function") {
return validateValue(schema, obj, path);
} else {
return validateObj(schema, obj, path);
Expand All @@ -255,7 +255,7 @@ const validate = (obj: Record<string, any> | null, allowParse: boolean, src: str
return newValue === undefined ? value : newValue;
} catch (e) {
console.warn(
`Validation of setting '${path}' (${sourceDescription}) with value '${value}' failed: `
`Validation of setting "${path}" (${sourceDescription}) with value "${value}" failed: `
+ `${e}. Ignoring.`
);
return null;
Expand All @@ -280,7 +280,7 @@ const validate = (obj: Record<string, any> | null, allowParse: boolean, src: str
}
} else {
console.warn(
`'${newPath}' (${sourceDescription}) is not a valid settings key. Ignoring.`
`"${newPath}" (${sourceDescription}) is not a valid settings key. Ignoring.`
);
}
}
Expand All @@ -294,65 +294,65 @@ const validate = (obj: Record<string, any> | null, allowParse: boolean, src: str

// Validation functions for different types.
const types = {
'string': (v: any, _allowParse: any) => {
if (typeof v !== 'string') {
"string": (v: any, _allowParse: any) => {
if (typeof v !== "string") {
throw new Error("is not a string, but should be");
}
},
'boolean': (v: string, allowParse: any) => {
if (typeof v === 'boolean') {
"boolean": (v: string, allowParse: any) => {
if (typeof v === "boolean") {
return;
}

if (allowParse) {
if (v === 'true') {
if (v === "true") {
return true;
}
if (v === 'false') {
if (v === "false") {
return false;
}
throw new Error("can't be parsed as boolean");
throw new Error("cant be parsed as boolean");
} else {
throw new Error("is not a boolean");
}
},
'array': (v: any, _allowParse: any) => {
"array": (v: any, _allowParse: any) => {
if (!Array.isArray(v)) {
throw new Error("is not an array, but should be");
}
for (const entry in v) {
if (typeof entry !== 'string') {
if (typeof entry !== "string") {
throw new Error("is not a string, but should be");
}
}
},
'map': (v: any, _allowParse: any) => {
"map": (v: any, _allowParse: any) => {
for (const key in v) {
if (typeof key !== 'string') {
if (typeof key !== "string") {
throw new Error("is not a string, but should be");
}
if (typeof v[key] !== 'string') {
if (typeof v[key] !== "string") {
throw new Error("is not a string, but should be");
}
}
},
'objectsWithinObjects': (v: any, _allowParse: any) => {
"objectsWithinObjects": (v: any, _allowParse: any) => {
for (const catalogName in v) {
if (typeof catalogName !== 'string') {
if (typeof catalogName !== "string") {
throw new Error("is not a string, but should be");
}
for (const fieldName in v[catalogName]) {
if (typeof fieldName !== 'string') {
if (typeof fieldName !== "string") {
throw new Error("is not a string, but should be");
}
for (const attributeName in v[catalogName][fieldName]) {
if (typeof attributeName !== 'string') {
if (typeof attributeName !== "string") {
throw new Error("is not a string, but should be");
}
if (attributeName === 'show' && typeof v[catalogName][fieldName][attributeName] !== 'boolean') {
if (attributeName === "show" && typeof v[catalogName][fieldName][attributeName] !== "boolean") {
throw new Error("is not a boolean");
}
if (attributeName === 'readonly' && typeof v[catalogName][fieldName][attributeName] !== 'boolean') {
if (attributeName === "readonly" && typeof v[catalogName][fieldName][attributeName] !== "boolean") {
throw new Error("is not a boolean");
}
}
Expand Down
Loading

0 comments on commit 53598c1

Please sign in to comment.