Skip to content

Commit

Permalink
🔥 chore: goodbye prettier
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <[email protected]>
  • Loading branch information
SimonShiki committed Oct 29, 2023
1 parent 803ccee commit 0d1401b
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 103 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@
"no-var": "error",
"comma-spacing": "error",
"func-call-spacing": "error",
"space-before-function-paren": "error",
"dot-location": ["error", "property"],
"no-whitespace-before-property": "error",
"space-unary-ops": ["error", {
"words": true,
"nonwords": false
}],
"quotes": [2, "single", {
"allowTemplateLiterals": true,
"avoidEscape": true
}],
"no-unneeded-ternary": [2],
"eol-last": [2, "always"],
"key-spacing": [2, {
"beforeColon": false,
"afterColon": true,
"mode": "strict"
}],
"keyword-spacing": [2, {
"before": true,
"after": true
}]
}
}
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"scripts": {
"build": "NODE_ENV=production webpack --color --bail",
"lint": "eslint ./src/ --ext .js,.ts,tsx,jsx",
"format": "prettier -w --config .prettierrc.json ./src",
"typecheck": "tsc --watch --noEmit"
},
"devDependencies": {
Expand All @@ -24,7 +23,6 @@
"eslint": "^8.49.0",
"html-webpack-plugin": "^5.5.3",
"mini-svg-data-uri": "^1.4.4",
"prettier": "^3.0.3",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type MothDispatched = MothDispatchedAllocate | MothDispatchedLoad;
* Get all extensions.
* @returns Extensions.
*/
function getExtensionInfo() {
function getExtensionInfo () {
const processedExtInfo: MothExtensionInfo[] = [];
for (const [extId, ext] of window.chibi.loader.loadedScratchExtension.entries()) {
processedExtInfo.push({
Expand All @@ -37,7 +37,7 @@ function getExtensionInfo() {
* Handle messages from the frontend (popup window).
* @param event Event from the frontend.
*/
async function messageHandler(event: MessageEvent) {
async function messageHandler (event: MessageEvent) {
if (event.origin !== 'https://chibi.codingclip.cc') return;
if (!('type' in event.data)) return;
switch ((event.data as MothDispatched).type) {
Expand Down Expand Up @@ -86,7 +86,7 @@ window.addEventListener('message', messageHandler);
* Open the popup (?) window.
* @param open window.open function (compatible with ccw).
*/
function openFrontend(open: typeof window.open) {
function openFrontend (open: typeof window.open) {
dashboardWindow = open(
'https://chibi.codingclip.cc/#manage',
'Chibi',
Expand Down
48 changes: 24 additions & 24 deletions src/injector/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const MAX_LISTENING_MS = 30 * 1000;
* @param vm Virtual machine instance. For some reasons we cannot use VM here.
* @returns Blockly instance.
*/
function getBlocklyInstance(vm: any): any | undefined {
// hijack Function.prototype.apply to get React element instance.
function hijack(fn: (...args: unknown[]) => void): any {
function getBlocklyInstance (vm: any): any | undefined {
// Hijack Function.prototype.apply to get React element instance.
function hijack (fn: (...args: unknown[]) => void): any {
const _orig = Function.prototype.apply;
Function.prototype.apply = function (thisArg: any) {
return thisArg;
Expand All @@ -46,11 +46,11 @@ function getBlocklyInstance(vm: any): any | undefined {
const events = vm._events?.EXTENSION_ADDED;
if (events) {
if (events instanceof Function) {
// it is a function, just hijack it.
// It is a function, just hijack it.
const result = hijack(events);
if (result && result.ScratchBlocks) return result.ScratchBlocks;
} else {
// it is an array, hijack every listeners.
// It is an array, hijack every listeners.
for (const value of events) {
const result = hijack(value);
if (result && result.ScratchBlocks) return result.ScratchBlocks;
Expand All @@ -65,7 +65,7 @@ function getBlocklyInstance(vm: any): any | undefined {
* @param open window.open function (compatible with ccw).
* @return Callback promise. After that you could use window.chibi.vm to get the virtual machine.
*/
export function trap(open: typeof window.open): Promise<void> {
export function trap (open: typeof window.open): Promise<void> {
window.chibi = {
// @ts-expect-error defined in webpack define plugin
version: __CHIBI_VERSION__,
Expand Down Expand Up @@ -106,11 +106,11 @@ export function trap(open: typeof window.open): Promise<void> {
* Inject into the original virtual machine.
* @param vm {ChibiCompatibleVM} Original virtual machine instance.
*/
export function inject(vm: ChibiCompatibleVM) {
export function inject (vm: ChibiCompatibleVM) {
const loader = (window.chibi.loader = new ChibiLoader(vm));
const originalLoadFunc = vm.extensionManager.loadExtensionURL;
const getLocale = vm.getLocale;
let format = formatMessage.namespace();
const format = formatMessage.namespace();
format.setup({
locale: getLocale ? getLocale.call(vm) : 'en',
missingTranslation: 'ignore',
Expand All @@ -126,26 +126,26 @@ export function inject(vm: ChibiCompatibleVM) {
try {
const res = env
? confirm(
format('chibi.tryLoadInEnv', {
extensionURL,
url,
env
})
)
format('chibi.tryLoadInEnv', {
extensionURL,
url,
env
})
)
: confirm(
format('chibi.tryLoadInEnv', {
extensionURL,
url
})
);
format('chibi.tryLoadInEnv', {
extensionURL,
url
})
);
if (res) {
await loader.load(
url,
(env
? env
: confirm(format('chibi.loadInSandbox'))
? 'sandboxed'
: 'unsandboxed') as 'unsandboxed' | 'sandboxed'
? 'sandboxed'
: 'unsandboxed') as 'unsandboxed' | 'sandboxed'
);
const extensionId = loader.getIdByUrl(url);
// @ts-expect-error internal hack
Expand Down Expand Up @@ -214,8 +214,8 @@ export function inject(vm: ChibiCompatibleVM) {
return result;
};
// TODO: compiler support
const originalArgReporterBooleanFunc = vm.runtime._primitives['argument_reporter_boolean'];
vm.runtime._primitives['argument_reporter_boolean'] = function (
const originalArgReporterBooleanFunc = vm.runtime._primitives.argument_reporter_boolean;
vm.runtime._primitives.argument_reporter_boolean = function (
args: Record<string, unknown>,
...otherArgs: unknown[]
) {
Expand Down Expand Up @@ -256,7 +256,7 @@ export function inject(vm: ChibiCompatibleVM) {
// Blockly stuffs
setTimeout(() => {
const blockly = (window.chibi.blockly = getBlocklyInstance(vm));
// deprecated: this method will be removed in the future.
// Deprecated: this method will be removed in the future.
if (!blockly) {
warn('Cannot find real blockly instance, try alternative method...');
const originalProcedureCallback =
Expand Down
14 changes: 7 additions & 7 deletions src/loader/dispatch/central-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _CentralDispatch extends SharedDispatch {
*/
workers: Worker[] = [];
_onMessage!: (worker: Worker, event: MessageEvent) => void;
constructor() {
constructor () {
super();
/**
* Map of channel name to worker or local service provider.
Expand All @@ -38,7 +38,7 @@ class _CentralDispatch extends SharedDispatch {
* @param {*} [args] - the arguments to be copied to the method, if any.
* @returns {*} - the return value of the service method.
*/
callSync(service: string, method: string, ...args: unknown[]) {
callSync (service: string, method: string, ...args: unknown[]) {
const { provider, isRemote } = this._getServiceProvider(service);
if (provider) {
if (isRemote) {
Expand All @@ -54,7 +54,7 @@ class _CentralDispatch extends SharedDispatch {
* @param {string} service - a globally unique string identifying this service. Examples: 'vm', 'gui', 'extension9'.
* @param {object} provider - a local object which provides this service.
*/
setServiceSync(service: string, provider: any) {
setServiceSync (service: string, provider: any) {
if (this.services.hasOwnProperty(service)) {
console.warn(`Central dispatch replacing existing service provider for ${service}`);
}
Expand All @@ -67,7 +67,7 @@ class _CentralDispatch extends SharedDispatch {
* @param {object} provider - a local object which provides this service.
* @returns {Promise} - a promise which will resolve once the service is registered.
*/
setService(service: string, provider: any) {
setService (service: string, provider: any) {
/** Return a promise for consistency with {@link WorkerDispatch#setService} */
try {
this.setServiceSync(service, provider);
Expand All @@ -81,7 +81,7 @@ class _CentralDispatch extends SharedDispatch {
* The dispatcher will immediately attempt to "handshake" with the worker.
* @param {Worker} worker - the worker to add into the dispatch system.
*/
addWorker(worker: Worker) {
addWorker (worker: Worker) {
if (this.workers.indexOf(worker) === -1) {
this.workers.push(worker);
worker.onmessage = this._onMessage.bind(this, worker);
Expand All @@ -99,7 +99,7 @@ class _CentralDispatch extends SharedDispatch {
* @returns {{provider:(object|Worker), isRemote:boolean}} - the means to contact the service, if found
* @protected
*/
_getServiceProvider(service: string) {
_getServiceProvider (service: string) {
const provider = this.services[service];
return (
provider && {
Expand All @@ -118,7 +118,7 @@ class _CentralDispatch extends SharedDispatch {
* @returns {Promise|undefined} - a promise for the results of this operation, if appropriate
* @protected
*/
_onDispatchMessage(worker: Worker, message: DispatchCallMessage) {
_onDispatchMessage (worker: Worker, message: DispatchCallMessage) {
let promise;
switch (message.method) {
case 'setService':
Expand Down
22 changes: 11 additions & 11 deletions src/loader/dispatch/shared-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SharedDispatch {
* @param {*} [args] - the arguments to be copied to the method, if any.
* @returns {Promise} - a promise for the return value of the service method.
*/
call(service: string, method: string, ...args: unknown[]) {
call (service: string, method: string, ...args: unknown[]) {
return this.transferCall(service, method, null, ...args);
}
/**
Expand All @@ -91,7 +91,7 @@ class SharedDispatch {
* @param {*} [args] - the arguments to be copied to the method, if any.
* @returns {Promise} - a promise for the return value of the service method.
*/
transferCall(service: string, method: string, transfer: unknown, ...args: unknown[]) {
transferCall (service: string, method: string, transfer: unknown, ...args: unknown[]) {
try {
// @ts-expect-error TS(2339): It's not implemented.
const { provider, isRemote } = this._getServiceProvider(service);
Expand All @@ -113,7 +113,7 @@ class SharedDispatch {
* @returns {boolean} - true if the service is remote (calls must cross a Worker boundary), false otherwise.
* @private
*/
_isRemoteService(service: string): boolean {
_isRemoteService (service: string): boolean {
// @ts-expect-error TS(2339): It's not implemented.
return this._getServiceProvider(service).isRemote;
}
Expand All @@ -125,7 +125,7 @@ class SharedDispatch {
* @param {*} [args] - the arguments to be copied to the method, if any.
* @returns {Promise} - a promise for the return value of the service method.
*/
_remoteCall(
_remoteCall (
provider: any,
service: string,
method: string,
Expand All @@ -142,7 +142,7 @@ class SharedDispatch {
* @param {*} [args] - the arguments to be copied to the method, if any.
* @returns {Promise} - a promise for the return value of the service method.
*/
_remoteTransferCall(
_remoteTransferCall (
provider: Worker,
service: string,
method: string,
Expand All @@ -168,7 +168,7 @@ class SharedDispatch {
* @returns {*} - a unique response ID for this set of callbacks. See {@link _deliverResponse}.
* @protected
*/
_storeCallbacks(resolve: (value: unknown) => void, reject: (value: unknown) => void) {
_storeCallbacks (resolve: (value: unknown) => void, reject: (value: unknown) => void) {
const responseId = this.nextResponseId++;
this.callbacks[responseId] = [resolve, reject];
return responseId;
Expand All @@ -179,7 +179,7 @@ class SharedDispatch {
* @param {DispatchResponseMessage} message - the message containing the response value(s).
* @protected
*/
_deliverResponse(responseId: number, message: DispatchResponseMessage) {
_deliverResponse (responseId: number, message: DispatchResponseMessage) {
try {
const [resolve, reject] = this.callbacks[responseId];
delete this.callbacks[responseId];
Expand All @@ -198,7 +198,7 @@ class SharedDispatch {
* @param {MessageEvent} event - the message event to be handled.
* @protected
*/
_onMessage(worker: Worker, event: MessageEvent) {
_onMessage (worker: Worker, event: MessageEvent) {
/** @type {DispatchMessage} */
const message = event.data;
message.args = message.args || [];
Expand Down Expand Up @@ -244,7 +244,7 @@ class SharedDispatch {
* @returns {{provider:(object|Worker), isRemote:boolean}} - the means to contact the service, if found
* @protected
*/
_getServiceProvider(service: string) {
_getServiceProvider (service: string) {
throw new Error(
`Could not get provider for ${service}: _getServiceProvider not implemented`
);
Expand All @@ -257,7 +257,7 @@ class SharedDispatch {
* @returns {Promise|undefined} - a promise for the results of this operation, if appropriate
* @private
*/
_onDispatchMessage(worker: Worker, message: DispatchCallMessage) {
_onDispatchMessage (worker: Worker, message: DispatchCallMessage) {
throw new Error(
`Unimplemented dispatch message handler cannot handle ${message.method} method`
);
Expand All @@ -268,7 +268,7 @@ class SharedDispatch {
* @param {obj} object - The Object that need to be purified.
* @returns {object} - purified object.
*/
_purifyObject(obj: unknown, visited = new Set(), depth = 1): unknown {
_purifyObject (obj: unknown, visited = new Set(), depth = 1): unknown {
if (typeof obj === 'function' || typeof obj === 'symbol') {
return undefined;
}
Expand Down
10 changes: 5 additions & 5 deletions src/loader/dispatch/worker-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _WorkerDispatch extends SharedDispatch {
_onConnect!: (value?: unknown) => void;
// @ts-expect-error
_onMessage!: (worker: window & globalThis, event: MessageEvent) => void;
constructor() {
constructor () {
super();

this._connectionPromise = new Promise((resolve) => {
Expand All @@ -48,7 +48,7 @@ class _WorkerDispatch extends SharedDispatch {
* dispatch.call('myService', 'hello');
* })
*/
get waitForConnection() {
get waitForConnection () {
return this._connectionPromise;
}

Expand All @@ -59,7 +59,7 @@ class _WorkerDispatch extends SharedDispatch {
* @param {object} provider - a local object which provides this service.
* @returns {Promise} - a promise which will resolve once the service is registered.
*/
setService(service: string, provider: unknown) {
setService (service: string, provider: unknown) {
if (this.services.hasOwnProperty(service)) {
console.warn(`Worker dispatch replacing existing service provider for ${service}`);
}
Expand All @@ -76,7 +76,7 @@ class _WorkerDispatch extends SharedDispatch {
* @returns {{provider:(object|Worker), isRemote:boolean}} - the means to contact the service, if found
* @protected
*/
_getServiceProvider(service: string) {
_getServiceProvider (service: string) {
// If we don't have a local service by this name, contact central dispatch by calling `postMessage` on self
const provider = this.services[service];
return {
Expand All @@ -93,7 +93,7 @@ class _WorkerDispatch extends SharedDispatch {
* @returns {Promise|undefined} - a promise for the results of this operation, if appropriate
* @protected
*/
_onDispatchMessage(worker: Worker, message: DispatchCallMessage) {
_onDispatchMessage (worker: Worker, message: DispatchCallMessage) {
let promise;
switch (message.method) {
case 'handshake':
Expand Down
Loading

0 comments on commit 0d1401b

Please sign in to comment.