Skip to content

Commit

Permalink
fix: prettier code style
Browse files Browse the repository at this point in the history
  • Loading branch information
BroKun committed Nov 21, 2023
1 parent 1dcfd6f commit b0d26e5
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 102 deletions.
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,31 @@
"clean": "git clean -fX ."
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.23.2",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@babel/plugin-transform-flow-strip-types": "^7.22.5",
"@babel/plugin-transform-private-methods": "^7.22.5",
"@babel/plugin-transform-private-property-in-object": "^7.22.11",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@babel/plugin-proposal-decorators": "^7.23.3",
"@babel/plugin-transform-class-properties": "^7.23.3",
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
"@babel/plugin-transform-private-methods": "^7.23.3",
"@babel/plugin-transform-private-property-in-object": "^7.23.4",
"@babel/preset-env": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@changesets/cli": "^2.26.2",
"@commitlint/cli": "^17.8.0",
"@commitlint/config-conventional": "^17.8.0",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.6",
"@types/react-test-renderer": "^18.0.3",
"@commitlint/cli": "^17.8.1",
"@commitlint/config-conventional": "^17.8.1",
"@swc/core": "^1.3.99",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.5.9",
"@types/node": "^20.9.3",
"@types/react-test-renderer": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@umijs/lint": "^4.0.86",
"@umijs/lint": "^4.0.88",
"babel-jest": "^29.7.0",
"babel-plugin-parameter-decorator": "^1.0.16",
"dotenv-cli": "^7.3.0",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-mdx": "^2.2.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.33.2",
Expand All @@ -60,12 +62,10 @@
"lint-staged": "^13.3.0",
"nx": "^16.10.0",
"postcss-less": "^6.0.0",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"react-test-renderer": "^18.2.0",
"stylelint": "^14.16.1",
"typescript": "^4.9.5",
"@swc/core": "^1.3.99",
"@swc/jest": "^0.2.29"
"typescript": "^4.9.5"
},
"engines": {
"node": ">=16.20.0"
Expand Down
27 changes: 14 additions & 13 deletions packages/libro-codemirror/src/auto-complete/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-unused-vars */
/* eslint-disable prefer-const */
/* eslint-disable @typescript-eslint/no-parameter-properties */
/* eslint-disable @typescript-eslint/parameter-properties */
import { codePointAt, codePointSize, fromCodePoint } from '@codemirror/state';

// Scores are counted from 0 (great match) down to negative numbers,
Expand Down Expand Up @@ -64,11 +63,13 @@ export class FuzzyMatcher {
// at the start
if (chars.length === 1) {
const first = codePointAt(word, 0);
return first === chars[0]
? [0, 0, codePointSize(first)]
: first === folded[0]
? [Penalty.CaseFold, 0, codePointSize(first)]
: null;
if (first === chars[0]) {
return [0, 0, codePointSize(first)];
}
if (first === folded[0]) {
return [Penalty.CaseFold, 0, codePointSize(first)];
}
return null;
}
const direct = word.indexOf(this.pattern);
if (direct === 0) {
Expand Down Expand Up @@ -134,13 +135,13 @@ export class FuzzyMatcher {
? (next >= 48 && next <= 57) || (next >= 97 && next <= 122)
? Tp.Lower
: next >= 65 && next <= 90
? Tp.Upper
: Tp.NonWord
? Tp.Upper
: Tp.NonWord
: (ch = fromCodePoint(next)) !== ch.toLowerCase()
? Tp.Upper
: ch !== ch.toUpperCase()
? Tp.Lower
: Tp.NonWord;
? Tp.Upper
: ch !== ch.toUpperCase()
? Tp.Lower
: Tp.NonWord;
if (
!i ||
(type === Tp.Upper && hasLower) ||
Expand Down
13 changes: 7 additions & 6 deletions packages/libro-codemirror/src/auto-complete/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import type { Extension, EditorState, StateEffect } from '@codemirror/state';
import { Prec } from '@codemirror/state';
import type { KeyBinding } from '@codemirror/view';
Expand Down Expand Up @@ -66,11 +65,13 @@ const completionKeymapExt = Prec.highest(
/// returns `null`.
export function completionStatus(state: EditorState): null | 'active' | 'pending' {
const cState = state.field(completionState, false);
return cState && cState.active.some((a) => a.state === State.Pending)
? 'pending'
: cState && cState.active.some((a) => a.state !== State.Inactive)
? 'active'
: null;
if (cState && cState.active.some((a) => a.state === State.Pending)) {
return 'pending';
}
if (cState && cState.active.some((a) => a.state !== State.Inactive)) {
return 'active';
}
return null;
}

const completionArrayCache: WeakMap<readonly Option[], readonly Completion[]> =
Expand Down
14 changes: 3 additions & 11 deletions packages/libro-codemirror/src/auto-complete/snippet.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-shadow */
/* eslint-disable prefer-const */
/* eslint-disable no-param-reassign */
/* eslint-disable @typescript-eslint/no-parameter-properties */
/* eslint-disable @typescript-eslint/parameter-properties */
import { indentUnit } from '@codemirror/language';
import type {
ChangeDesc,
Expand Down Expand Up @@ -96,13 +93,8 @@ class Snippet {
name = m[2] || m[3] || '',
found = -1;
for (let i = 0; i < fields.length; i++) {
if (
seq !== null
? fields[i].seq === seq
: name
? fields[i].name === name
: false
) {
const sameName = name ? fields[i].name === name : false;
if (seq !== null ? fields[i].seq === seq : sameName) {
found = i;
}
}
Expand Down
53 changes: 26 additions & 27 deletions packages/libro-codemirror/src/auto-complete/state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* eslint-disable @typescript-eslint/no-this-alias */
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-parameter-properties */
/* eslint-disable @typescript-eslint/parameter-properties */
/* eslint-disable prefer-const */
import type { Transaction, EditorState, ChangeDesc } from '@codemirror/state';
import { StateField, StateEffect } from '@codemirror/state';
import type { Tooltip } from '@codemirror/view';
Expand Down Expand Up @@ -33,8 +29,8 @@ function score(option: Completion) {
}

function sortOptions(active: readonly ActiveSource[], state: EditorState) {
let options = [],
i = 0;
const options = [];
let i = 0;
for (const a of active) {
if (a.hasResult()) {
if (a.result.filter === false) {
Expand All @@ -49,8 +45,8 @@ function sortOptions(active: readonly ActiveSource[], state: EditorState) {
options.push(new Option(option, a, match));
}
} else {
let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to)),
match;
const matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to));
let match;
for (const option of a.result.options) {
if ((match = matcher.match(option.label))) {
if (option.boost !== undefined) {
Expand All @@ -62,8 +58,8 @@ function sortOptions(active: readonly ActiveSource[], state: EditorState) {
}
}
}
let result = [],
prev = null;
const result = [];
let prev = null;
const compare = state.facet(completionConfig).compareCompletions;
for (const opt of options.sort(
(a, b) => b.match[0] - a.match[0] || compare(a.completion, b.completion),
Expand Down Expand Up @@ -168,8 +164,8 @@ export class CompletionState {
}

update(tr: Transaction) {
let { state } = tr,
conf = state.facet(completionConfig);
const { state } = tr;
const conf = state.facet(completionConfig);
const sources =
conf.override ||
state
Expand All @@ -195,15 +191,16 @@ export class CompletionState {
) {
active = this.active;
}

let open =
let open;
if (
tr.selection ||
active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
!sameResults(active, this.active)
? CompletionDialog.build(active, state, this.id, this.open, conf)
: this.open && tr.docChanged
? this.open.map(tr.changes)
: this.open;
) {
open = CompletionDialog.build(active, state, this.id, this.open, conf);
} else {
open = this.open && tr.docChanged ? this.open.map(tr.changes) : this.open;
}
if (
!open &&
active.every((a) => a.state !== State.Pending) &&
Expand Down Expand Up @@ -280,11 +277,13 @@ export const enum State {
}

export function getUserEvent(tr: Transaction): 'input' | 'delete' | null {
return tr.isUserEvent('input.type')
? 'input'
: tr.isUserEvent('delete.backward')
? 'delete'
: null;
if (tr.isUserEvent('input.type')) {
return 'input';
}
if (tr.isUserEvent('delete.backward')) {
return 'delete';
}
return null;
}

export class ActiveSource {
Expand All @@ -299,8 +298,8 @@ export class ActiveSource {
}

update(tr: Transaction, conf: Required<CompletionConfig>): ActiveSource {
let event = getUserEvent(tr),
value: ActiveSource = this;
const event = getUserEvent(tr);
let value: ActiveSource = this;
if (event) {
value = value.handleUserEvent(tr, event, conf);
} else if (tr.docChanged) {
Expand Down Expand Up @@ -385,8 +384,8 @@ export class ActiveResult extends ActiveSource {
type === 'input' && conf.activateOnTyping ? State.Pending : State.Inactive,
);
}
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos),
updated;
const explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
let updated;
if (checkValid(this.result.validFor, tr.state, from, to)) {
return new ActiveResult(this.source, explicitPos, this.result, from, to);
}
Expand Down
18 changes: 10 additions & 8 deletions packages/libro-codemirror/src/auto-complete/view.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-parameter-properties */
/* eslint-disable @typescript-eslint/parameter-properties */
import type { Transaction } from '@codemirror/state';
import type {
EditorView,
Expand Down Expand Up @@ -53,12 +51,16 @@ export function moveCompletionSelection(
);
}
const { length } = cState.open.options;
let selected =
cState.open.selected > -1
? cState.open.selected + step * (forward ? 1 : -1)
: forward
? 0
: length - 1;
let selected;
if (cState.open.selected > -1) {
selected = cState.open.selected + step * (forward ? 1 : -1);
} else {
if (forward) {
selected = 0;
} else {
selected = length - 1;
}
}
if (selected < 0) {
selected = by === 'page' ? 0 : length - 1;
} else if (selected >= length) {
Expand Down
21 changes: 11 additions & 10 deletions packages/libro-common/src/polling/poll.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-param-reassign */
/* eslint-disable @typescript-eslint/no-namespace */

/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Event } from '@difizen/mana-common';
import { Emitter, Deferred } from '@difizen/mana-common';

Expand Down Expand Up @@ -294,12 +291,16 @@ export class Poll<T = any, U = any, V extends string = 'standby'>
*/
protected _execute(): void {
let standby = typeof this.standby === 'function' ? this.standby() : this.standby;
standby =
standby === 'never'
? false
: standby === 'when-hidden'
? !!(typeof document !== 'undefined' && document && document.hidden)
: standby;
switch (standby) {
case 'never':
standby = false;
break;
case 'when-hidden':
standby = !!(typeof document !== 'undefined' && document && document.hidden);
break;
default:
break;
}

// If in standby mode schedule next tick without calling the factory.
if (standby) {
Expand Down
16 changes: 11 additions & 5 deletions packages/libro-shared-model/src/ymodels.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-explicit-any */
import type {
IAttachments,
IBaseCellMetadata,
Expand Down Expand Up @@ -744,11 +746,15 @@ export class YBaseCell<Metadata extends IBaseCellMetadata>
*/
transact(f: () => void, undoable = true): void {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.notebook && undoable
? this.notebook.transact(f)
: this.ymodel.doc === null
? f()
: this.ymodel.doc.transact(f, this);
if (this.notebook && undoable) {
this.notebook.transact(f);
} else {
if (this.ymodel.doc === null) {
f();
} else {
this.ymodel.doc.transact(f, this);
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/libro-terminal/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const terminalIntegratedFontFamily: ConfigurationNode<any> = {
defaultValue: isOSX
? "Menlo, Monaco, 'Courier New', monospace"
: isWindows
? "Consolas, 'Courier New', monospace"
: "'Droid Sans Mono', 'monospace', monospace",
? "Consolas, 'Courier New', monospace"
: "'Droid Sans Mono', 'monospace', monospace",
};
export const terminalIntegratedFontSize: ConfigurationNode<any> = {
id: 'terminal.integrated.fontSize',
Expand Down

0 comments on commit b0d26e5

Please sign in to comment.