mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier * chore: remove clang-format * chore: remove clang-format config * chore: lint additional ts files * chore: fix lint errors in blocks * chore: add prettier-ignore where needed * chore: ignore js blocks when formatting * chore: fix playground html syntax * chore: fix yaml spacing from merge * chore: convert text blocks to use arrow functions * chore: format everything with prettier * chore: fix lint unused imports in blocks
This commit is contained in:
committed by
GitHub
parent
af991f5e1b
commit
88ff901a72
@@ -9,59 +9,58 @@
|
||||
* constructor input type than the type that is stored.
|
||||
*/
|
||||
|
||||
|
||||
import {Field, FieldValidator, fieldRegistry} from 'blockly-test/core';
|
||||
|
||||
interface Cell {
|
||||
cellId: string;
|
||||
cellId: string;
|
||||
}
|
||||
|
||||
interface CellGroup {
|
||||
cells: Cell[];
|
||||
cells: Cell[];
|
||||
}
|
||||
|
||||
type FieldMitosisValidator = FieldValidator<CellGroup>;
|
||||
|
||||
class FieldMitosis extends Field<CellGroup> {
|
||||
constructor(cell: Cell, validator: FieldMitosisValidator) {
|
||||
super(Field.SKIP_SETUP);
|
||||
constructor(cell: Cell, validator: FieldMitosisValidator) {
|
||||
super(Field.SKIP_SETUP);
|
||||
|
||||
this.setValue(cell);
|
||||
this.setValidator(validator);
|
||||
}
|
||||
this.setValue(cell);
|
||||
this.setValidator(validator);
|
||||
}
|
||||
|
||||
// Overwritten Field methods.
|
||||
// Overwritten Field methods.
|
||||
|
||||
protected doClassValidation_(newCell?: unknown): CellGroup | null {
|
||||
if (!this.isCell(newCell)) return null;
|
||||
protected doClassValidation_(newCell?: unknown): CellGroup | null {
|
||||
if (!this.isCell(newCell)) return null;
|
||||
|
||||
const cellGroup = this.getValue() ?? {cells: []};
|
||||
cellGroup.cells.push(newCell);
|
||||
return cellGroup;
|
||||
}
|
||||
const cellGroup = this.getValue() ?? {cells: []};
|
||||
cellGroup.cells.push(newCell);
|
||||
return cellGroup;
|
||||
}
|
||||
|
||||
// Example-specific methods.
|
||||
// Example-specific methods.
|
||||
|
||||
private isCell(maybeCell: unknown): maybeCell is Cell {
|
||||
if (!maybeCell) return false;
|
||||
const couldBeCell = maybeCell as { [key: string]: unknown };
|
||||
return 'cellId' in couldBeCell && typeof couldBeCell.cellId === 'string';
|
||||
}
|
||||
private isCell(maybeCell: unknown): maybeCell is Cell {
|
||||
if (!maybeCell) return false;
|
||||
const couldBeCell = maybeCell as {[key: string]: unknown};
|
||||
return 'cellId' in couldBeCell && typeof couldBeCell.cellId === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* The cell divides, creating two new cells!
|
||||
*/
|
||||
doMitosis(): void {
|
||||
const cellGroup = this.getValue();
|
||||
if (!cellGroup) return;
|
||||
/**
|
||||
* The cell divides, creating two new cells!
|
||||
*/
|
||||
doMitosis(): void {
|
||||
const cellGroup = this.getValue();
|
||||
if (!cellGroup) return;
|
||||
|
||||
const cells = cellGroup.cells.flatMap((cell) => {
|
||||
const leftCell: Cell = {cellId: `${cell.cellId}-left`};
|
||||
const rightCell: Cell = {cellId: `${cell.cellId}-right`};
|
||||
return [leftCell, rightCell];
|
||||
});
|
||||
this.value_ = {cells};
|
||||
}
|
||||
const cells = cellGroup.cells.flatMap((cell) => {
|
||||
const leftCell: Cell = {cellId: `${cell.cellId}-left`};
|
||||
const rightCell: Cell = {cellId: `${cell.cellId}-right`};
|
||||
return [leftCell, rightCell];
|
||||
});
|
||||
this.value_ = {cells};
|
||||
}
|
||||
}
|
||||
|
||||
fieldRegistry.register('field_mitosis', FieldMitosis);
|
||||
@@ -69,12 +68,12 @@ fieldRegistry.register('field_mitosis', FieldMitosis);
|
||||
// Example use of the class.
|
||||
|
||||
function cellValidator(cellGroup: CellGroup): CellGroup | undefined {
|
||||
// The cell group is good! Use it as is.
|
||||
if (cellGroup.cells.length > 0) return undefined;
|
||||
// The cell group is good! Use it as is.
|
||||
if (cellGroup.cells.length > 0) return undefined;
|
||||
|
||||
// Uh oh! No cells.
|
||||
const emergencyCell: Cell = {cellId: 'emergency-cell'};
|
||||
return {cells: [emergencyCell]};
|
||||
// Uh oh! No cells.
|
||||
const emergencyCell: Cell = {cellId: 'emergency-cell'};
|
||||
return {cells: [emergencyCell]};
|
||||
}
|
||||
|
||||
const cellField = new FieldMitosis({cellId: 'cell-A'}, cellValidator);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
{
|
||||
"include": [
|
||||
"src/**/*",
|
||||
],
|
||||
"include": ["src/**/*"],
|
||||
"compilerOptions": {
|
||||
"allowJs": false,
|
||||
"outDir": "dist",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"blockly-test/*": ["../../dist/*"],
|
||||
"blockly-test/*": ["../../dist/*"]
|
||||
},
|
||||
|
||||
"declaration": false,
|
||||
@@ -17,6 +15,6 @@
|
||||
"module": "ES2015",
|
||||
"moduleResolution": "node",
|
||||
"target": "ES2020",
|
||||
"strict": true,
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user