Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Prettier with Biome #7441

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
node-version-file: ".nvmrc"
- run: npm install -g yarn@^1.19.0 && yarn install

- name: Check formatting with prettier
run: yarn prettier-check
- name: Check formatting
run: yarn format-check

- name: Build TerriaJS tests
run: yarn gulp lint release --continue
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Update .prettierignore whenever this file changes
docs/
node_modules/
.idea/
Expand Down
43 changes: 0 additions & 43 deletions .prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

49 changes: 49 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "main"
},
"files": { "ignoreUnknown": false, "ignore": [] },
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": [
"./wwwroot/data/regionids/*",
"**/yarn.lock",
"**/*.scss.d.ts",
"./wwwroot/third_party/*",
"doc/acknowledgements/attributions.md",
"./wwwroot/test/init/sdmx-abs.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a 1.7 MB file that hasn't been updated since 2017, so put it in the ignore list to not slow down the formatting that is done.

]
},
"organizeImports": { "enabled": false },
"linter": { "enabled": false, "rules": { "recommended": true } },
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSameLine": false,
"attributePosition": "auto",
"bracketSpacing": true
}
},
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
}
}
}
28 changes: 14 additions & 14 deletions lib/Core/TypeConditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ export type Or<
> = [A] extends [true]
? true
: [B] extends [true]
? true
: [C] extends [true]
? true
: [D] extends [true]
? true
: [E] extends [true]
? true
: [F] extends [true]
? true
: [G] extends [true]
? true
: [H] extends [true]
? true
: false;
? true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting of ?: is consistent with Prettier version 3.4.2.

: [C] extends [true]
? true
: [D] extends [true]
? true
: [E] extends [true]
? true
: [F] extends [true]
? true
: [G] extends [true]
? true
: [H] extends [true]
? true
: false;

/**
* Inverts a conditional, changing `true` to `false` and `false` to `true`.
Expand Down
10 changes: 5 additions & 5 deletions lib/Core/loadBlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export function parseZipJsonBlob(blob: Blob): Promise<JsonValue> {
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
if (isJson(entry.filename)) {
return entry
.getData(new ZipData64URIWriter())
.then(function (uri: string) {
return loadJson(uri);
});
return entry.getData(new ZipData64URIWriter()).then(function (
uri: string
) {
return loadJson(uri);
});
}
}
return undefined;
Expand Down
12 changes: 6 additions & 6 deletions lib/Map/DragPoints/LeafletDragPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ LeafletDragPoints.prototype._onMouseDownOnPoint = function (entity) {
return;
}

var dragEntity = this._draggableObjects.entities.values.filter(function (
dragObjEntity
) {
// Not necessarily same entity, but will have same id.
return dragObjEntity.id === entity.id;
})[0];
var dragEntity = this._draggableObjects.entities.values.filter(
function (dragObjEntity) {
// Not necessarily same entity, but will have same id.
return dragObjEntity.id === entity.id;
}
)[0];
if (defined(dragEntity)) {
// The touch events below don't actually work because Leaflet doesn't
// expose these events. See here for a possible workaround:
Expand Down
5 changes: 2 additions & 3 deletions lib/ModelMixins/ExportWebCoverageServiceMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,8 @@ function ExportWebCoverageServiceMixin<
}

private async loadWcsCapabilities() {
const capabilities = await WebCoverageServiceCapabilitiesStratum.load(
this
);
const capabilities =
await WebCoverageServiceCapabilitiesStratum.load(this);

runInAction(() =>
this.strata.set(
Expand Down
4 changes: 2 additions & 2 deletions lib/ModelMixins/TileErrorHandlerMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ function TileErrorHandlerMixin<T extends AbstractConstructor<ModelType>>(
return this === (baseMap as any)
? true
: baseMap instanceof CompositeCatalogItem
? baseMap.memberModels.includes(this)
: false;
? baseMap.memberModels.includes(this)
: false;
};
/** End helper methods **/

Expand Down
8 changes: 4 additions & 4 deletions lib/Models/BoxDrawing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,8 @@ export default class BoxDrawing {
const normalAxis = planeLocal.normal.x
? Axis.X
: planeLocal.normal.y
? Axis.Y
: Axis.Z;
? Axis.Y
: Axis.Z;
const style: Readonly<SideStyle> = {
fillColor: Color.WHITE.withAlpha(0.1),
outlineColor: Color.WHITE,
Expand Down Expand Up @@ -891,8 +891,8 @@ export default class BoxDrawing {
const axis = planeLocal.normal.x
? Axis.X
: planeLocal.normal.y
? Axis.Y
: Axis.Z;
? Axis.Y
: Axis.Z;

const scratchDirection = new Cartesian3();
const scratchMoveVector = new Cartesian3();
Expand Down
4 changes: 2 additions & 2 deletions lib/Models/Catalog/CatalogItems/ApiTableCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ function getResponseDataPath(data: JsonValue, jsonPath: string) {
path === ""
? data
: Array.isArray(data)
? _map(data, path)
: _get(data, path);
? _map(data, path)
: _get(data, path);
return pathSegments.reduce(
(nextData, segment) => getPath(nextData, segment),
data
Expand Down
11 changes: 7 additions & 4 deletions lib/Models/Catalog/CatalogItems/CogCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ class CogLoadableStratum extends LoadableStratum(CogCatalogItemTraits) {
? // Warn for 2D mode
i18next.t("models.commonModelErrors.3dTypeIn2dMode", this)
: this.model._imageryProvider?.tilingScheme &&
// Show warning for experimental reprojection freature if not using EPSG 3857 or 4326
isCustomTilingScheme(this.model._imageryProvider?.tilingScheme)
? i18next.t("models.cogCatalogItem.experimentalReprojectionWarning", this)
: undefined;
// Show warning for experimental reprojection freature if not using EPSG 3857 or 4326
isCustomTilingScheme(this.model._imageryProvider?.tilingScheme)
? i18next.t(
"models.cogCatalogItem.experimentalReprojectionWarning",
this
)
: undefined;
}

@computed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ class MapboxVectorTileCatalogItem extends MappableMixin(
}
}

@computed
/** Convert traits into paint rules:
@computed /** Convert traits into paint rules:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier 3.4.2 also has this problem. Split out the change that moves the JSDoc to #7440 so that can get merged now without having to update the formatter.

* - `layer` and `fillColor`/`lineColor` into simple rules
* - `parsedJsonStyle`
*/
Expand Down
15 changes: 6 additions & 9 deletions lib/Models/Catalog/Ckan/CkanItemReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ export class CkanDatasetStratum extends LoadableStratum(
ckanItemReference.datasetId !== undefined &&
ckanItemReference.resourceId !== undefined
) {
ckanItemReference._ckanDataset = await loadCkanDataset(
ckanItemReference
);
ckanItemReference._ckanDataset =
await loadCkanDataset(ckanItemReference);
ckanItemReference._ckanResource = findResourceInDataset(
ckanItemReference._ckanDataset,
ckanItemReference.resourceId
Expand All @@ -81,9 +80,8 @@ export class CkanDatasetStratum extends LoadableStratum(
ckanItemReference.datasetId !== undefined &&
ckanItemReference.resourceId === undefined
) {
ckanItemReference._ckanDataset = await loadCkanDataset(
ckanItemReference
);
ckanItemReference._ckanDataset =
await loadCkanDataset(ckanItemReference);
const matched = getSupportedFormats(
ckanItemReference._ckanDataset,
ckanItemReference.preparedSupportedFormats
Expand All @@ -95,9 +93,8 @@ export class CkanDatasetStratum extends LoadableStratum(
ckanItemReference.datasetId === undefined &&
ckanItemReference.resourceId !== undefined
) {
ckanItemReference._ckanResource = await loadCkanResource(
ckanItemReference
);
ckanItemReference._ckanResource =
await loadCkanResource(ckanItemReference);
ckanItemReference._supportedFormat = isResourceInSupportedFormats(
ckanItemReference._ckanResource,
ckanItemReference.preparedSupportedFormats
Expand Down
8 changes: 4 additions & 4 deletions lib/Models/Catalog/Ows/OwsInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function parseOwsKeywordList(json: any): OwsKeywordList | undefined {
const Keyword = isJsonString(json.Keyword)
? json.Keyword
: Array.isArray(json.Keyword)
? filterOutUndefined(
json.Keyword.map((s) => (isJsonString(s) ? s : undefined))
)
: [];
? filterOutUndefined(
json.Keyword.map((s) => (isJsonString(s) ? s : undefined))
)
: [];
return {
type,
Keyword
Expand Down
4 changes: 2 additions & 2 deletions lib/Models/Catalog/Ows/WebFeatureServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ export class GetCapabilitiesStratum extends LoadableStratum(

return supportsGeojson
? "JSON"
: this.capabilities.outputTypes?.find((outputFormat) =>
: (this.capabilities.outputTypes?.find((outputFormat) =>
searchValue.test(outputFormat)
) ?? "gml3";
) ?? "gml3");
}

/** Finds the best srsName to use.
Expand Down
5 changes: 4 additions & 1 deletion lib/Models/Catalog/Ows/WebMapServiceCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ export default class WebMapServiceCapabilities {
readonly [name: string]: CapabilitiesLayer;
};

private constructor(readonly xml: XMLDocument, readonly json: any) {
private constructor(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't appreciate that constructors with readonly parameters are split over multiple lines even when they fit with room to spare in a single line, but this formatting is also consistent with Prettier 3.4.2.

readonly xml: XMLDocument,
readonly json: any
) {
this.allLayers = [];
this.rootLayers = [];
this.topLevelNamedLayers = [];
Expand Down
4 changes: 2 additions & 2 deletions lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ export default class WebMapServiceCapabilitiesStratum extends LoadableStratum(
const formatsArray = isJsonArray(formats)
? formats
: isJsonString(formats)
? [formats]
: [];
? [formats]
: [];

if (this.catalogItem.supportsGetTimeseries) {
return { format: "text/csv", type: "text" };
Expand Down
12 changes: 6 additions & 6 deletions lib/Models/Catalog/Ows/WebProcessingServiceCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ function parseServiceIdentification(
const ServiceTypeVersion = isJsonString(json.ServiceTypeVersion)
? [json.ServiceTypeVersion]
: Array.isArray(json.ServiceTypeVersion)
? filterOutUndefined(
json.ServiceTypeVersion.map((s) => (isJsonString(s) ? s : undefined))
)
: undefined;
? filterOutUndefined(
json.ServiceTypeVersion.map((s) => (isJsonString(s) ? s : undefined))
)
: undefined;

if (
ServiceType === undefined ||
Expand Down Expand Up @@ -174,8 +174,8 @@ function parseProcessOfferings(json: any): Process[] | undefined {
const processes: any[] = Array.isArray(json.Process)
? json.Process
: isJsonObject(json.Process)
? [json.Process]
: [];
? [json.Process]
: [];
const ProcessOfferings = filterOutUndefined(processes.map(parseProcess));
return ProcessOfferings;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Models/Definition/FlattenedFromTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type FlattenedFromTraits<TDefinition extends ModelTraits> = Complete<{
? CopyNull<TDefinition[P], R> | undefined
: never
: SingleTrait<TDefinition[P]> extends infer R
? CopyNull<TDefinition[P], R> | undefined
: never;
? CopyNull<TDefinition[P], R> | undefined
: never;
}>;

export default FlattenedFromTraits;
Loading