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

chore: apply Biome unsafe changes #1941

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 13 additions & 6 deletions umap/static/umap/js/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class BaseAutocomplete {
onKeyDown(e) {
switch (e.key) {
case 'Tab':
if (this.current !== null) this.setChoice()
if (this.current !== null) {
this.setChoice()
}
DomEvent.stop(e)
break
case 'Enter':
Expand Down Expand Up @@ -195,8 +197,11 @@ export class BaseAutocomplete {

highlight() {
this.results.forEach((result, index) => {
if (index === this.current) DomUtil.addClass(result.el, 'on')
else DomUtil.removeClass(result.el, 'on')
if (index === this.current) {
DomUtil.addClass(result.el, 'on')
} else {
DomUtil.removeClass(result.el, 'on')
}
})
}

Expand Down Expand Up @@ -249,16 +254,18 @@ export class BaseAjax extends BaseAutocomplete {
this.clear()
return
}
if (val === this.cache) return
else this.cache = val
if (val === this.cache) {
return
}
this.cache = val
val = val.toLowerCase()
const url = Util.template(this.url, { q: encodeURIComponent(val) })
this.handleResults(await this._search(url))
}

async _search(url) {
const response = await this.request.get(url)
if (response && response.ok) {
if (response?.ok) {
return await response.json()
}
}
Expand Down
50 changes: 35 additions & 15 deletions umap/static/umap/js/modules/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export default class Browser {
}

addFeature(feature, parent) {
if (feature.isFiltered()) return
if (this.options.inBbox && !feature.isOnScreen(this.bounds)) return
if (feature.isFiltered()) {
return
}
if (this.options.inBbox && !feature.isOnScreen(this.bounds)) {
return
}
const row = DomUtil.create('li', `${feature.getClassName()} feature`)
const zoom_to = DomUtil.createButtonIcon(
row,
Expand Down Expand Up @@ -62,9 +66,11 @@ export default class Browser {

addDataLayer(datalayer, parent) {
let className = `datalayer ${datalayer.getHidableClass()}`
if (this.mode !== 'layers') className += ' show-list'
const container = DomUtil.create('div', className, parent),
headline = DomUtil.create('h5', '', container)
if (this.mode !== 'layers') {
className += ' show-list'
}
const container = DomUtil.create('div', className, parent)
const headline = DomUtil.create('h5', '', container)
container.id = this.datalayerId(datalayer)
const ul = DomUtil.create('ul', '', container)
this.updateDatalayer(datalayer)
Expand All @@ -75,7 +81,9 @@ export default class Browser {
this.bounds = this.map.getBounds()
const parent = DomUtil.get(this.datalayerId(datalayer))
// Panel is not open
if (!parent) return
if (!parent) {
return
}
parent.classList.toggle('off', !datalayer.isVisible())
const container = parent.querySelector('ul')
const headline = parent.querySelector('h5')
Expand All @@ -90,9 +98,9 @@ export default class Browser {
container.innerHTML = ''
datalayer.eachFeature((feature) => this.addFeature(feature, container))

const total = datalayer.count(),
current = container.querySelectorAll('li').length,
count = total == current ? total : `${current}/${total}`
const total = datalayer.count()
const current = container.querySelectorAll('li').length
const count = total === current ? total : `${current}/${total}`
const counter = DomUtil.create('span', 'datalayer-counter', headline)
counter.textContent = `(${count})`
counter.title = translate(`Features in this layer: ${count}`)
Expand All @@ -112,7 +120,9 @@ export default class Browser {
}

redraw() {
if (this.isOpen()) this.open()
if (this.isOpen()) {
this.open()
}
}

isOpen() {
Expand All @@ -124,16 +134,22 @@ export default class Browser {
}

onMoveEnd() {
if (!this.isOpen()) return
if (!this.isOpen()) {
return
}
const isListDynamic = this.options.inBbox
this.map.eachBrowsableDataLayer((datalayer) => {
if (!isListDynamic && !datalayer.hasDynamicData()) return
if (!isListDynamic && !datalayer.hasDynamicData()) {
return
}
this.updateDatalayer(datalayer)
})
}

update() {
if (!this.isOpen()) return
if (!this.isOpen()) {
return
}
this.dataContainer.innerHTML = ''
this.map.eachBrowsableDataLayer((datalayer) => {
this.addDataLayer(datalayer, this.dataContainer)
Expand All @@ -142,7 +158,9 @@ export default class Browser {

open(mode) {
// Force only if mode is known, otherwise keep current mode.
if (mode) this.mode = mode
if (mode) {
this.mode = mode
}
const container = DomUtil.create('div')
// HOTFIX. Remove when this is released:
// https://github.com/Leaflet/Leaflet/pull/9052
Expand Down Expand Up @@ -185,7 +203,9 @@ export default class Browser {
}
const reset = DomUtil.createButton('flat', formContainer, '', () => {
builder.form.reset()
if (filtersBuilder) filtersBuilder.form.reset()
if (filtersBuilder) {
filtersBuilder.form.reset()
}
})
DomUtil.createIcon(reset, 'icon-restore')
DomUtil.element({
Expand Down
14 changes: 9 additions & 5 deletions umap/static/umap/js/modules/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export default class Caption {
}

refresh() {
if (!this.isOpen()) return
if (!this.isOpen()) {
return
}
this.open()
}

Expand All @@ -39,10 +41,12 @@ export default class Caption {
}

addDataLayer(datalayer, container) {
if (!datalayer.options.inCaption) return
const p = DomUtil.create('p', 'datalayer-legend', container),
legend = DomUtil.create('span', '', p),
headline = DomUtil.create('strong', '', p)
if (!datalayer.options.inCaption) {
return
}
const p = DomUtil.create('p', 'datalayer-legend', container)
const legend = DomUtil.create('span', '', p)
const headline = DomUtil.create('strong', '', p)
datalayer.onceLoaded(() => {
datalayer.renderLegend(legend)
if (datalayer.options.description) {
Expand Down
3 changes: 1 addition & 2 deletions umap/static/umap/js/modules/dompurify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ console.log(DOMPurifyInitializer)
export default function getPurify() {
if (typeof window === 'undefined') {
return DOMPurifyInitializer(new JSDOM('').window)
} else {
return DOMPurifyInitializer(window)
}
return DOMPurifyInitializer(window)
}
22 changes: 14 additions & 8 deletions umap/static/umap/js/modules/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class Facets {
let selected

names.forEach((name) => {
const type = defined[name]['type']
const type = defined[name].type
properties[name] = { type: type }
selected = this.selected[name] || {}
selected.type = type
Expand All @@ -28,18 +28,24 @@ export default class Facets {
datalayer.eachFeature((feature) => {
names.forEach((name) => {
let value = feature.properties[name]
const type = defined[name]['type']
const type = defined[name].type
const parser = this.getParser(type)
value = parser(value)
switch (type) {
case 'date':
case 'datetime':
case 'number':
if (!isNaN(value)) {
if (isNaN(properties[name].min) || properties[name].min > value) {
if (!Number.isNaN(value)) {
if (
Number.isNaN(properties[name].min) ||
properties[name].min > value
) {
properties[name].min = value
}
if (isNaN(properties[name].max) || properties[name].max < value) {
if (
Number.isNaN(properties[name].max) ||
properties[name].max < value
) {
properties[name].max = value
}
}
Expand All @@ -58,7 +64,7 @@ export default class Facets {

isActive() {
for (const { type, min, max, choices } of Object.values(this.selected)) {
if (min !== undefined || max != undefined || choices?.length) {
if (min !== undefined || max !== undefined || choices?.length) {
return true
}
}
Expand All @@ -73,7 +79,7 @@ export default class Facets {
const fields = names.map((name) => {
const criteria = facetProperties[name]
let handler = 'FacetSearchChoices'
switch (criteria['type']) {
switch (criteria.type) {
case 'number':
handler = 'FacetSearchNumber'
break
Expand All @@ -84,7 +90,7 @@ export default class Facets {
handler = 'FacetSearchDateTime'
break
}
const label = defined[name]['label']
const label = defined[name].label
return [
`selected.${name}`,
{
Expand Down
2 changes: 1 addition & 1 deletion umap/static/umap/js/modules/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class Help {
const container = DomUtil.add('div')
DomUtil.createTitle(container, translate('Help'))
// Special dynamic case. Do we still think this dialog is usefull ?
if (entries == 'edit') {
if (entries === 'edit') {
DomUtil.element({
tagName: 'div',
className: 'umap-help-entry',
Expand Down
18 changes: 12 additions & 6 deletions umap/static/umap/js/modules/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ export default class Importer {
this.format === 'umap' || !this.url
)
this.qs('[name=layer-name]').toggleAttribute('hidden', Boolean(this.layerId))
this.qs('#clear').toggleAttribute('hidden', !Boolean(this.layerId))
this.qs('#clear').toggleAttribute('hidden', !this.layerId)
}

onFileChange(e) {
let type = '',
newType
let type = ''
let newType
for (const file of e.target.files) {
newType = U.Utils.detectFileType(file)
if (!type && newType) type = newType
if (!type && newType) {
type = newType
}
if (type && newType !== type) {
type = ''
break
Expand Down Expand Up @@ -223,7 +225,9 @@ export default class Importer {
}

open() {
if (!this.container) this.build()
if (!this.container) {
this.build()
}
const onLoad = this.map.editPanel.open({ content: this.container })
onLoad.then(() => this.onLoad())
}
Expand Down Expand Up @@ -294,7 +298,9 @@ export default class Importer {
return false
}
const layer = this.layer
if (this.clear) layer.empty()
if (this.clear) {
layer.empty()
}
if (this.files.length) {
for (const file of this.files) {
this.map.processFileToImport(file, layer, this.format)
Expand Down
2 changes: 1 addition & 1 deletion umap/static/umap/js/modules/importers/geodatamine.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Importer {
container.innerHTML = TEMPLATE
const response = await importer.map.request.get(`${this.baseUrl}/themes`)
const select = container.querySelector('select')
if (response && response.ok) {
if (response?.ok) {
const { themes } = await response.json()
themes.sort((a, b) => Utils.naturalSort(a['name:fr'], b['name:fr']))
for (const theme of themes) {
Expand Down
12 changes: 9 additions & 3 deletions umap/static/umap/js/modules/importers/overpass.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ export class Importer {
return
}
const outMode = container.querySelector('[name=out-mode]').value
if (!tags.startsWith('[')) tags = `[${tags}]`
if (!tags.startsWith('[')) {
tags = `[${tags}]`
}
let area = '{south},{west},{north},{east}'
if (boundary) area = `area:${boundary}`
if (boundary) {
area = `area:${boundary}`
}
const query = `[out:json];nwr${tags}(${area});out ${outMode};`
importer.url = `${this.baseUrl}?data=${query}`
if (boundary) importer.layerName = boundaryName
if (boundary) {
importer.layerName = boundaryName
}
importer.format = 'osm'
importer.dialog.close()
}
Expand Down
Loading
Loading