Skip to content

Commit

Permalink
chore: fix all biome warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Jun 20, 2024
1 parent c3dc8c2 commit 1503dcd
Show file tree
Hide file tree
Showing 105 changed files with 1,083 additions and 1,084 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"*.{js,cjs}": ["biome format --write", "git add"],
"*.{js,cjs}": ["biome check --write", "git add"],
"*.css": ["stylelint --fix", "prettier --write --parser css", "git add"],
"*.json": ["prettier --write --parser json", "git add"],
"*.md": ["prettier --write --parser markdown", "git add"]
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

### Features

- added `collectionValidators` and `fileValidators`: Custom validators are now supported for collections and files. This enhancement allows for the addition of necessary checks for uploaded files and collections, providing flexibility and control over compliance with requirements ([#667](https://github.com/uploadcare/blocks/issues/667)) ([d3260b0](https://github.com/uploadcare/blocks/commit/d3260b0cce5ac6ca7cfd0aeb8aff0c9fc35036ed)). See docs [here](https://uploadcare.com/docs/file-uploader/validators).

- added `collectionValidators` and `fileValidators`: Custom validators are now supported for collections and files. This enhancement allows for the addition of necessary checks for uploaded files and collections, providing flexibility and control over compliance with requirements ([#667](https://github.com/uploadcare/blocks/issues/667)) ([d3260b0](https://github.com/uploadcare/blocks/commit/d3260b0cce5ac6ca7cfd0aeb8aff0c9fc35036ed)). See docs [here](https://uploadcare.com/docs/file-uploader/validators).

## [0.42.1](https://github.com/uploadcare/blocks/compare/v0.42.0...v0.42.1) (2024-05-30)

Expand Down
12 changes: 6 additions & 6 deletions abstract/ActivityBlock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventType } from '../blocks/UploadCtxProvider/EventEmitter.js';
// @ts-check
import { debounce } from '../blocks/utils/debounce.js';
import { EventType } from '../blocks/UploadCtxProvider/EventEmitter.js';
import { Block } from './Block.js';
import { activityBlockCtx } from './CTX.js';

Expand All @@ -15,15 +15,15 @@ export class ActivityBlock extends Block {

/** @private */
_deactivate() {
let actDesc = ActivityBlock._activityCallbacks.get(this);
const actDesc = ActivityBlock._activityCallbacks.get(this);
this[ACTIVE_PROP] = false;
this.removeAttribute(ACTIVE_ATTR);
actDesc?.deactivateCallback?.();
}

/** @private */
_activate() {
let actDesc = ActivityBlock._activityCallbacks.get(this);
const actDesc = ActivityBlock._activityCallbacks.get(this);
this.$['*historyBack'] = this.historyBack.bind(this);
/** @private */
this[ACTIVE_PROP] = true;
Expand Down Expand Up @@ -139,7 +139,7 @@ export class ActivityBlock extends Block {
const currentActivity = this.$['*currentActivity'];

/** @type {Set<import('./Block').Block>} */
let blocksRegistry = this.$['*blocksRegistry'];
const blocksRegistry = this.$['*blocksRegistry'];
const hasCurrentActivityInCtx = !![...blocksRegistry].find(
(block) => block instanceof ActivityBlock && block.activityType === currentActivity,
);
Expand Down Expand Up @@ -169,7 +169,7 @@ export class ActivityBlock extends Block {

historyBack() {
/** @type {String[]} */
let history = this.$['*history'];
const history = this.$['*history'];
if (history) {
let nextActivity = history.pop();
while (nextActivity === this.activityType) {
Expand All @@ -178,7 +178,7 @@ export class ActivityBlock extends Block {
let couldOpenActivity = !!nextActivity;
if (nextActivity) {
/** @type {Set<ActivityBlock>} */
let blocksRegistry = this.$['*blocksRegistry'];
const blocksRegistry = this.$['*blocksRegistry'];
const nextActivityBlock = [...blocksRegistry].find((block) => block.activityType === nextActivity);
couldOpenActivity = nextActivityBlock?.couldOpenActivity ?? false;
}
Expand Down
36 changes: 18 additions & 18 deletions abstract/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseComponent, Data } from '@symbiotejs/symbiote';
import { initialConfig } from '../blocks/Config/initialConfig.js';
import { EventEmitter } from '../blocks/UploadCtxProvider/EventEmitter.js';
import { WindowHeightTracker } from '../utils/WindowHeightTracker.js';
import { extractFilename, extractCdnUrlModifiers, extractUuid } from '../utils/cdn-utils.js';
import { extractCdnUrlModifiers, extractFilename, extractUuid } from '../utils/cdn-utils.js';
import { getLocaleDirection } from '../utils/getLocaleDirection.js';
import { getPluralForm } from '../utils/getPluralForm.js';
import { applyTemplateData, getPluralObjects } from '../utils/template-utils.js';
Expand Down Expand Up @@ -36,15 +36,15 @@ export class Block extends BaseComponent {
if (!str) {
return '';
}
let template = this.$[localeStateKey(str)] || str;
let pluralObjects = getPluralObjects(template);
for (let pluralObject of pluralObjects) {
const template = this.$[localeStateKey(str)] || str;
const pluralObjects = getPluralObjects(template);
for (const pluralObject of pluralObjects) {
variables[pluralObject.variable] = this.pluralize(
pluralObject.pluralKey,
Number(variables[pluralObject.countVariable]),
);
}
let result = applyTemplateData(template, variables);
const result = applyTemplateData(template, variables);
return result;
}

Expand Down Expand Up @@ -96,8 +96,8 @@ export class Block extends BaseComponent {
hasBlockInCtx(callback) {
// @ts-ignore TODO: fix this
/** @type {Set} */
let blocksRegistry = this.$['*blocksRegistry'];
for (let block of blocksRegistry) {
const blocksRegistry = this.$['*blocksRegistry'];
for (const block of blocksRegistry) {
if (callback(block)) {
return true;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ export class Block extends BaseComponent {

if (this.hasAttribute('retpl')) {
// @ts-ignore TODO: fix this
this.constructor['template'] = null;
this.constructor.template = null;
this.processInnerHtml = true;
}
if (this.requireCtxName) {
Expand Down Expand Up @@ -168,7 +168,7 @@ export class Block extends BaseComponent {
this.add('*blocksRegistry', new Set());
}

let blocksRegistry = this.$['*blocksRegistry'];
const blocksRegistry = this.$['*blocksRegistry'];
blocksRegistry.add(this);

if (!this.has('*eventEmitter')) {
Expand All @@ -190,7 +190,7 @@ export class Block extends BaseComponent {

destroyCallback() {
/** @type {Set<Block>} */
let blocksRegistry = this.$['*blocksRegistry'];
const blocksRegistry = this.$['*blocksRegistry'];
blocksRegistry.delete(this);

this.localeManager?.destroyL10nBindings(this);
Expand Down Expand Up @@ -224,18 +224,18 @@ export class Block extends BaseComponent {
* @param {Number} [decimals]
*/
fileSizeFmt(bytes, decimals = 2) {
let units = ['B', 'KB', 'MB', 'GB', 'TB'];
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
/**
* @param {String} str
* @returns {String}
*/
if (bytes === 0) {
return `0 ${units[0]}`;
}
let k = 1024;
let dm = decimals < 0 ? 0 : decimals;
let i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / k ** i).toFixed(dm)) + ' ' + units[i];
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${Number.parseFloat((bytes / k ** i).toFixed(dm))} ${units[i]}`;
}

/**
Expand Down Expand Up @@ -268,7 +268,7 @@ export class Block extends BaseComponent {
/** @returns {import('../types').ConfigType} } */
get cfg() {
if (!this.__cfgProxy) {
let o = Object.create(null);
const o = Object.create(null);
/** @private */
this.__cfgProxy = new Proxy(o, {
set: (obj, key, value) => {
Expand Down Expand Up @@ -327,10 +327,10 @@ export class Block extends BaseComponent {
/** @param {String} [name] */
static reg(name) {
if (!name) {
super.reg();
Block.reg();
return;
}
super.reg(name.startsWith(TAG_PREFIX) ? name : TAG_PREFIX + name);
Block.reg(name.startsWith(TAG_PREFIX) ? name : TAG_PREFIX + name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions abstract/LocaleManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { debounce } from '../blocks/utils/debounce.js';
import { resolveLocaleDefinition } from './localeRegistry.js';
import { default as en } from '../locales/file-uploader/en.js';
import { resolveLocaleDefinition } from './localeRegistry.js';

/** @param {string} key */
export const localeStateKey = (key) => `*l10n/${key}`;
Expand Down Expand Up @@ -33,7 +33,7 @@ export class LocaleManager {
constructor(blockInstance) {
this._blockInstance = blockInstance;

for (let [key, value] of Object.entries(en)) {
for (const [key, value] of Object.entries(en)) {
this._blockInstance.add(localeStateKey(key), value, false);
}

Expand Down
6 changes: 3 additions & 3 deletions abstract/SolutionBlock.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { uploaderBlockCtx } from './CTX.js';
import svgIconsSprite from '../blocks/themes/lr-basic/svg-sprite.js';
import { Block } from './Block.js';
import { uploaderBlockCtx } from './CTX.js';

export class SolutionBlock extends Block {
requireCtxName = true;
init$ = uploaderBlockCtx(this);
_template = null;

static set template(value) {
this._template = svgIconsSprite + value + /** HTML */ `<slot></slot>`;
SolutionBlock._template = `${svgIconsSprite + value}<slot></slot>`;
}

static get template() {
return this._template;
return SolutionBlock._template;
}
}
38 changes: 19 additions & 19 deletions abstract/TypedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class TypedCollection {
if (Object.keys(changeMap).length === 0) {
return;
}
this.__propertyObservers.forEach((handler) => {
for (const handler of this.__propertyObservers) {
handler({ ...changeMap });
});
}
changeMap = Object.create(null);
});
};
Expand All @@ -95,8 +95,8 @@ export class TypedCollection {
}
/** @private */
this.__notifyTimeout = window.setTimeout(() => {
let added = new Set(this.__added);
let removed = new Set(this.__removed);
const added = new Set(this.__added);
const removed = new Set(this.__removed);
this.__added.clear();
this.__removed.clear();
for (const handler of this.__collectionObservers) {
Expand Down Expand Up @@ -128,16 +128,16 @@ export class TypedCollection {
* @returns {string}
*/
add(init) {
let item = new TypedData(this.__typedSchema);
for (let prop in init) {
const item = new TypedData(this.__typedSchema);
for (const prop in init) {
item.setValue(prop, init[prop]);
}
this.__items.add(item.uid);
this.notify();

this.__data.add(item.uid, item);
this.__added.add(item);
this.__watchList.forEach((propName) => {
for (const propName of this.__watchList) {
if (!this.__subsMap[item.uid]) {
this.__subsMap[item.uid] = [];
}
Expand All @@ -146,7 +146,7 @@ export class TypedCollection {
this.__notifyObservers(propName, item.uid);
}),
);
});
}
return item.uid;
}

Expand All @@ -164,7 +164,7 @@ export class TypedCollection {
* @returns {any}
*/
readProp(id, propName) {
let item = this.read(id);
const item = this.read(id);
return item.getValue(propName);
}

Expand All @@ -175,7 +175,7 @@ export class TypedCollection {
* @param {T} value
*/
publishProp(id, propName, value) {
let item = this.read(id);
const item = this.read(id);
item.setValue(propName, value);
}

Expand All @@ -189,9 +189,9 @@ export class TypedCollection {
}

clearAll() {
this.__items.forEach((id) => {
for (const id of this.__items) {
this.remove(id);
});
}
}

/** @param {Function} handler */
Expand All @@ -213,13 +213,13 @@ export class TypedCollection {
* @returns {String[]}
*/
findItems(checkFn) {
let result = [];
this.__items.forEach((id) => {
let item = this.read(id);
const result = [];
for (const id of this.__items) {
const item = this.read(id);
if (checkFn(item)) {
result.push(id);
}
});
}
return result;
}

Expand All @@ -235,10 +235,10 @@ export class TypedCollection {
Data.deleteCtx(this.__ctxId);
this.__propertyObservers = null;
this.__collectionObservers = null;
for (let id in this.__subsMap) {
this.__subsMap[id].forEach((sub) => {
for (const id in this.__subsMap) {
for (const sub of this.__subsMap[id]) {
sub.remove();
});
}
delete this.__subsMap[id];
}
}
Expand Down
8 changes: 4 additions & 4 deletions abstract/TypedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export class TypedData {
* @param {any} value
*/
setValue(prop, value) {
if (!this.__typedSchema.hasOwnProperty(prop)) {
if (!Object.hasOwn(this.__typedSchema, prop)) {
console.warn(MSG_NAME + prop);
return;
}
let pDesc = this.__typedSchema[prop];
const pDesc = this.__typedSchema[prop];
if (value?.constructor === pDesc.type || value instanceof pDesc.type || (pDesc.nullable && value === null)) {
this.__data.pub(prop, value);
return;
Expand All @@ -49,14 +49,14 @@ export class TypedData {

/** @param {Object<string, any>} updObj */
setMultipleValues(updObj) {
for (let prop in updObj) {
for (const prop in updObj) {
this.setValue(prop, updObj[prop]);
}
}

/** @param {String} prop */
getValue(prop) {
if (!this.__typedSchema.hasOwnProperty(prop)) {
if (!Object.hasOwn(this.__typedSchema, prop)) {
console.warn(MSG_NAME + prop);
return undefined;
}
Expand Down
Loading

0 comments on commit 1503dcd

Please sign in to comment.