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 #1944

Merged
merged 9 commits into from
Jun 26, 2024
5 changes: 4 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
"enabled": true,
"rules": {
"style": {
"useBlockStatements": "warn",
"useBlockStatements": "off",
"noShoutyConstants": "warn"
},
"performance": {
"noDelete": "off"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions umap/static/umap/js/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ export class BaseAjax extends BaseAutocomplete {
return
}
if (val === this.cache) return
else this.cache = val
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
10 changes: 5 additions & 5 deletions umap/static/umap/js/modules/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ 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)
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 @@ -90,9 +90,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 Down
6 changes: 3 additions & 3 deletions umap/static/umap/js/modules/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ 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)
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)
}
18 changes: 12 additions & 6 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,17 +28,23 @@ 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 (!Number.isNaN(value)) {
// Special cases where we want to be lousy when checking isNaN without
// coercing to a Number first because we handle multiple types.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/
// Reference/Global_Objects/Number/isNaN
// biome-ignore lint/suspicious/noGlobalIsNan: see above.
if (isNaN(properties[name].min) || properties[name].min > value) {
properties[name].min = value
}
// biome-ignore lint/suspicious/noGlobalIsNan: see above.
if (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
6 changes: 3 additions & 3 deletions umap/static/umap/js/modules/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ 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
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
4 changes: 2 additions & 2 deletions umap/static/umap/js/modules/orderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default class Orderable {
const dst = this.findTarget(e.target)
if (!dst || dst === this.src) return
this.dst = dst
const targetIndex = this.nodeIndex(this.dst),
srcIndex = this.nodeIndex(this.src)
const targetIndex = this.nodeIndex(this.dst)
const srcIndex = this.nodeIndex(this.src)
if (targetIndex > srcIndex) this.parent.insertBefore(this.dst, this.src)
else this.parent.insertBefore(this.src, this.dst)
}
Expand Down
11 changes: 6 additions & 5 deletions umap/static/umap/js/modules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Rule {
}

not_equal(other) {
return this.expected != other
return this.expected !== other
}

gt(other) {
Expand All @@ -71,9 +71,10 @@ class Rule {
break
}
}
if (vars.length != 2) return
if (vars.length !== 2) return
this.key = vars[0]
this.expected = vars[1]
// biome-ignore lint/suspicious/noGlobalIsNan: expected might not be a number.
davidbgk marked this conversation as resolved.
Show resolved Hide resolved
if (!isNaN(this.expected)) this.cast = Number.parseFloat
else if (['true', 'false'].includes(this.expected)) this.cast = (v) => !!v
this.expected = this.cast(this.expected)
Expand Down Expand Up @@ -161,7 +162,7 @@ class Rule {
}

_delete() {
this.map.rules.rules = this.map.rules.rules.filter((rule) => rule != this)
this.map.rules.rules = this.map.rules.rules.filter((rule) => rule !== this)
}
}

Expand All @@ -181,8 +182,8 @@ export default class Rules {
}

onReorder(src, dst, initialIndex, finalIndex) {
const moved = this.rules.find((rule) => stamp(rule) == src.dataset.id)
const reference = this.rules.find((rule) => stamp(rule) == dst.dataset.id)
const moved = this.rules.find((rule) => stamp(rule) === src.dataset.id)
const reference = this.rules.find((rule) => stamp(rule) === dst.dataset.id)
const movedIdx = this.rules.indexOf(moved)
let referenceIdx = this.rules.indexOf(reference)
const minIndex = Math.min(movedIdx, referenceIdx)
Expand Down
2 changes: 1 addition & 1 deletion umap/static/umap/js/modules/sync/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SyncEngine {

// This method is called by the transport layer on new messages
receive({ kind, ...payload }) {
if (kind == 'operation') {
if (kind === 'operation') {
const updater = this._getUpdater(payload.subject, payload.metadata)
updater.applyMessage(payload)
} else {
Expand Down
3 changes: 2 additions & 1 deletion umap/static/umap/js/modules/sync/updaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ export class FeatureUpdater extends BaseUpdater {
console.error(`Unable to find feature with id = ${metadata.id}.`)
}
switch (key) {
case 'geometry':
case 'geometry': {
davidbgk marked this conversation as resolved.
Show resolved Hide resolved
const datalayer = this.getDataLayerFromID(metadata.layerId)
datalayer.geoJSONToLeaflet({ geometry: value, id: metadata.id, feature })
}
default:
this.updateObjectValue(feature, key, value)
feature.datalayer.indexProperties(feature)
Expand Down
8 changes: 4 additions & 4 deletions umap/static/umap/js/modules/ui/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export default class Tooltip {
anchorAbsolute() {
this.container.className = ''
const left =
this.parent.offsetLeft +
this.parent.clientWidth / 2 -
this.container.clientWidth / 2,
top = this.parent.offsetTop + 75
this.parent.offsetLeft +
this.parent.clientWidth / 2 -
this.container.clientWidth / 2
const top = this.parent.offsetTop + 75
this.setPosition({ top: top, left: left })
}

Expand Down
3 changes: 1 addition & 2 deletions umap/static/umap/js/modules/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export default class URLs {

if (this.urls.hasOwnProperty(urlName)) {
return template(this.urls[urlName], params)
} else {
throw `Unable to find a URL for route ${urlName}`
}
throw `Unable to find a URL for route ${urlName}`
}

// Update if map_id is passed, create otherwise.
Expand Down
26 changes: 13 additions & 13 deletions umap/static/umap/js/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ export function getImpactsFromSchema(fields, schema) {
export default function getPurify() {
if (typeof window === 'undefined') {
return DOMPurifyInitializer(new global.JSDOM('').window)
} else {
return DOMPurifyInitializer(window)
}
return DOMPurifyInitializer(window)
}

export function escapeHTML(s) {
Expand Down Expand Up @@ -114,7 +113,7 @@ export function escapeHTML(s) {

export function toHTML(r, options) {
if (!r) return ''
const target = (options && options.target) || 'blank'
const target = options?.target || 'blank'

// unordered lists
r = r.replace(/^\*\* (.*)/gm, '<ul><ul><li>$1</li></ul></ul>')
Expand Down Expand Up @@ -271,8 +270,8 @@ export function sortFeatures(features, sortKey, lang) {
const sortKeys = (sortKey || 'name').split(',')

const sort = (a, b, i) => {
let sortKey = sortKeys[i],
reverse = 1
let sortKey = sortKeys[i]
let reverse = 1
if (sortKey[0] === '-') {
reverse = -1
sortKey = sortKey.substring(1)
Expand Down Expand Up @@ -315,19 +314,19 @@ export function getBaseUrl() {
}

export function hasVar(value) {
return typeof value === 'string' && value.indexOf('{') != -1
return typeof value === 'string' && value.indexOf('{') !== -1
}

export function isPath(value) {
return value && value.length && value.startsWith('/')
return value?.length && value.startsWith('/')
}

export function isRemoteUrl(value) {
return value && value.length && value.startsWith('http')
return value?.length && value.startsWith('http')
}

export function isDataImage(value) {
return value && value.length && value.startsWith('data:image')
return value?.length && value.startsWith('data:image')
}

/**
Expand All @@ -349,15 +348,16 @@ export function normalize(s) {

// Vendorized from leaflet.utils
// https://github.com/Leaflet/Leaflet/blob/108c6717b70f57c63645498f9bd66b6677758786/src/core/Util.js#L132-L151
var templateRe = /\{ *([\w_ -]+) *\}/g
const templateRe = /\{ *([\w_ -]+) *\}/g

export function template(str, data) {
return str.replace(templateRe, (str, key) => {
var value = data[key]
let value = data[key]

if (value === undefined) {
throw new Error('No value provided for variable ' + str)
} else if (typeof value === 'function') {
throw new Error(`No value provided for variable ${str}`)
}
if (typeof value === 'function') {
value = value(data)
}
return value
Expand Down
Loading
Loading