Skip to content

Commit

Permalink
Merge pull request #5334 from Gustry/update-eslint
Browse files Browse the repository at this point in the history
Update eslint
  • Loading branch information
Gustry authored Feb 3, 2025
2 parents 9c377c8 + edb5c96 commit 69cc4a1
Show file tree
Hide file tree
Showing 44 changed files with 1,219 additions and 2,303 deletions.
31 changes: 0 additions & 31 deletions .eslintrc.json

This file was deleted.

29 changes: 23 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,26 @@ jobs:
name: "PHP-CS-Fixer"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "PHP-CS-Fixer"
# Version must match the one from the Makefile
uses: docker://oskarstark/php-cs-fixer-ga:3.26.0
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes --dry-run --diff

- name: "Checkout"
uses: actions/checkout@v4

- name: "PHP-CS-Fixer"
# Version must match the one from the Makefile
uses: docker://oskarstark/php-cs-fixer-ga:3.26.0
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes --dry-run --diff

eslint:
name: "ESLint 🇯‌🇸‌"
runs-on: ubuntu-latest
steps:

- name: "Checkout"
uses: actions/checkout@v4

- name: Install modules
run: npm install

- name: Run ESLint
run: npm run pretest-fix
2 changes: 1 addition & 1 deletion assets/src/components/ActionSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default class ActionSelector extends HTMLElement {
}
}

onActionDeactivateClick(event) {
onActionDeactivateClick() {
// Deactivate the current active action
mainLizmap.digitizing.eraseAll();
mainLizmap.action.resetLizmapAction();
Expand Down
19 changes: 11 additions & 8 deletions assets/src/components/FeatureToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export default class FeatureToolbar extends HTMLElement {
* Feature can be deleted if it is editable & if it has delete capabilities & if layer is not pivot
* If layer is a pivot, unlink button is displayed but a delete action is made instead
* @readonly
* @returns {boolean} - True if feature can be deleted
*/
get isDeletable(){
return this._isFeatureEditable
Expand All @@ -307,6 +308,7 @@ export default class FeatureToolbar extends HTMLElement {
/**
* Return true if childLayer has a relation with parentLayer
* @readonly
* @returns {boolean} - True if childLayer has a relation with parentLayer
*/
get hasRelation(){
return lizMap.config?.relations?.[this.parentLayerId]?.some((relation) => relation.referencingLayer === this.layerId);
Expand All @@ -315,6 +317,7 @@ export default class FeatureToolbar extends HTMLElement {
/**
* Return true if layer has geometry, WFS capability and popup_allow_download = true
* @readonly
* @returns {boolean} - True if layer has geometry, WFS capability and popup_allow_download = true
*/
get isFeatureExportable(){
return this.attributeTableConfig &&
Expand Down Expand Up @@ -362,7 +365,7 @@ export default class FeatureToolbar extends HTMLElement {

/**
* Return the list of children layers for which a feature can be created
* @returns array
* @returns {Array} - List of children layers for which a feature can be created
*/
get editableChildrenLayers() {
const editableChildrenLayers = [];
Expand Down Expand Up @@ -493,12 +496,12 @@ export default class FeatureToolbar extends HTMLElement {
lizMap.deleteEditionFeature(this.pivotLayerId, pivotFeatureId, unlinkMessage, ()=>{
// refresh mlayer
lizMap.events.triggerEvent("lizmapeditionfeaturedeleted",
{
'layerId': this.layerId,
'featureId': this.fid,
'featureType': this.featureType,
'updateDrawing': true
});
{
'layerId': this.layerId,
'featureId': this.fid,
'featureType': this.featureType,
'updateDrawing': true
});
});
}
}
Expand Down Expand Up @@ -707,7 +710,7 @@ export default class FeatureToolbar extends HTMLElement {

/**
* Launch the creation of a new feature for the given child layer
* @param childItem
* @param {object} childItem - Child layer configuration
*/
createChild(childItem) {
// Get the parent feature corresponding to the popup
Expand Down
73 changes: 52 additions & 21 deletions assets/src/components/FeaturesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import GeoJSON from 'ol/format/GeoJSON.js';
* @name FeaturesTable
* @summary Allows to display a compact list of vector layer features labels
* @augments HTMLElement
* @element lizmap-features-table
* @fires features.table.item.highlighted
* @fires features.table.item.dragged
* @fires features.table.rendered
* @description lizmap-features-table
* @fires FeaturesTable#features.table.item.highlighted
* @fires FeaturesTable#features.table.item.dragged
* @fires FeaturesTable#features.table.rendered
* @example <caption>Example of use</caption>
* <lizmap-features-table draggable="yes" sortingOrder="asc" sortingField="libsquart"
* withGeometry="1" expressionFilter="quartmno = 'HO'"
Expand Down Expand Up @@ -188,9 +188,8 @@ export default class FeaturesTable extends HTMLElement {

/**
* Get the feature corresponding to the given feature ID
*
* @param {Number} featureId WFS Feature ID
* @return {Object|null} WFS Feature
* @param {number} featureId WFS Feature ID
* @returns {object | null} WFS Feature
*/
getFeatureById(featureId) {
if (this.features.length === 0) {
Expand Down Expand Up @@ -305,8 +304,7 @@ export default class FeaturesTable extends HTMLElement {
/**
* Get the feature popup HTML content
* and display it
*
* @param {Object} feature WFS feature
* @param {object} feature WFS feature
*/
displayFeaturePopup(feature) {
// Get the default title for the table lines (tr)
Expand Down Expand Up @@ -362,9 +360,8 @@ export default class FeaturesTable extends HTMLElement {

/**
* Display a popup when a feature item is clicked
*
* @param {Event} event Click event on a feature item
* @param {Number} featureId WFS feature ID
* @param {number} featureId WFS feature ID
*/
onItemClick(event, featureId) {
// console.log('onItemClick - top');
Expand Down Expand Up @@ -402,15 +399,27 @@ export default class FeaturesTable extends HTMLElement {
});

// Utility functions for drag & drop capability
/**
* Action when an item is dragged
* @param {Event} e Drag event
*/
function onDragStart (e) {
const index = [].indexOf.call(e.target.parentElement.children, e.target);
e.dataTransfer.setData('text/plain', index)
}

/**
* Action on drag enter
* @param {Event} e Drag event
*/
function onDragEnter (e) {
cancelDefault(e);
}

/**
* Action when an item is dragged over another
* @param {Event} e Drag event
*/
function onDragOver (e) {
// Change the target element's style to signify a drag over event
// has occurred
Expand All @@ -419,16 +428,29 @@ export default class FeaturesTable extends HTMLElement {
cancelDefault(e);
}

/**
* Action when an item is dragged out of another
* @param {Event} e Drag event
*/
function onDragLeave (e) {
// Change the target element's style back to default
e.currentTarget.style.background = "";
cancelDefault(e);
}

/**
* Wait for a delay
* @param {number} delay Delay in milliseconds
* @returns {Promise} Promise that resolves after the delay
*/
function waitForIt(delay) {
return new Promise((resolve) => setTimeout(resolve, delay))
}

/**
* Action when an item is dropped
* @param {Event} e Drag event
*/
function OnDropped (e) {
cancelDefault(e)

Expand Down Expand Up @@ -485,6 +507,10 @@ export default class FeaturesTable extends HTMLElement {
});
}

/**
* Action when an item has finished being dragged
* @param {Event} e Drag event
*/
async function onDragEnd (e) {
// Restore style after some time
await waitForIt(3000);
Expand All @@ -494,11 +520,16 @@ export default class FeaturesTable extends HTMLElement {
cancelDefault(e);
}

/**
* Prevent the default behavior of an event
* @param {Event} e event
* @returns {boolean} False
*/
function cancelDefault (e) {
e.preventDefault();
e.stopPropagation();
e.preventDefault();
e.stopPropagation();

return false;
return false;
}


Expand Down Expand Up @@ -541,23 +572,23 @@ export default class FeaturesTable extends HTMLElement {
<div class="lizmap-features-table-toolbar">
<button class="btn btn-mini previous-popup"
title="${lizDict['featuresTable.toolbar.previous']}"
@click=${event => {
@click=${() => {
// Click on the previous item
const lineNumber = this.activeItemLineNumber - 1;
const featureDiv = this.querySelector(`tr.lizmap-features-table-item[data-line-id="${lineNumber}"]`);
if (featureDiv) featureDiv.click();
}}></button>
<button class="btn btn-mini next-popup"
title="${lizDict['featuresTable.toolbar.next']}"
@click=${event => {
@click=${() => {
// Click on the next item
const lineNumber = this.activeItemLineNumber + 1;
const featureDiv = this.querySelector(`tr.lizmap-features-table-item[data-line-id="${lineNumber}"]`);
if (featureDiv) featureDiv.click();
}}></button>
<button class="btn btn-mini close-popup"
title="${lizDict['featuresTable.toolbar.close']}"
@click=${event => {
@click=${() => {
const checkFeatureId = (this.dataset.activeItemFeatureId) ?? "";
if (!checkFeatureId) return;
this.dataset.activeItemFeatureId = ""
Expand Down Expand Up @@ -594,8 +625,8 @@ export default class FeaturesTable extends HTMLElement {

/**
* Build the columns of the table
* @param properties - Object containing the properties of the feature
* @returns {TemplateResult<1>} The columns of the table
* @param {object} properties - Object containing the properties of the feature
* @returns {TemplateResult} The columns of the table
*/
buildColumns(properties) {

Expand Down Expand Up @@ -625,7 +656,7 @@ export default class FeaturesTable extends HTMLElement {
/**
* Initialize tab with the first column "display_expression"
* @param {object} properties - Object containing the properties of the feature
* @returns {TemplateResult<1>} The first column of the table
* @returns {TemplateResult} The first column of the table
*/
buildDisplayExpressionColumn(properties) {
if (this.isGeneralLabelExisting()) {
Expand All @@ -641,7 +672,7 @@ export default class FeaturesTable extends HTMLElement {

/**
* Initialize the labels of the table
* @returns {TemplateResult<1>} The labels of the table
* @returns {TemplateResult} The labels of the table
*/
buildLabels() {
if (this.isAdditionalFieldsEmpty()) {
Expand Down
3 changes: 2 additions & 1 deletion assets/src/components/MousePosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export default class MousePosition extends HTMLElement {
}

/**
* @param {string} unit
* Update the display unit of the mouse position
* @param {string} unit - Unit to display 'm', 'mgrs' ...
*/
set displayUnit(unit){
unit === 'm' ? this._numDigits = 0 : this._numDigits = 5;
Expand Down
3 changes: 2 additions & 1 deletion assets/src/components/Print.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ export default class Print extends HTMLElement {
}

/**
* @param {string | number} index
* Update print template
* @param {string | number} index - Index of the print template
*/
set printTemplate(index){
// No print templates defined do nothing
Expand Down
15 changes: 8 additions & 7 deletions assets/src/dependencies/mgrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ export function inverse(mgrs) {
}

/**
*
* @param mgrs
* Convert MGRS string to lat/lon.
* @param {string} mgrs MGRS string.
* @returns {[number,number]} An array with longitude and latitude.
*/
export function toPoint(mgrs) {
if (mgrs === '') {
Expand Down Expand Up @@ -321,7 +322,7 @@ function UTMtoLL(utm) {
* @private
* @param {number} latitude The latitude in WGS84 to get the letter designator
* for.
* @returns {string} The letter designator.
* @returns {string|void} The letter designator.
*/
export function getLetterDesignator(latitude) {
if (latitude <= 84 && latitude >= 72) {
Expand Down Expand Up @@ -361,9 +362,9 @@ function encode(utm, accuracy) {
* Get the two letter 100k designator for a given UTM easting,
* northing and zone number value.
* @private
* @param {number} easting
* @param {number} northing
* @param {number} zoneNumber
* @param {number} easting the easting value within the UTM zone.
* @param {number} northing the northing value within the UTM zone.
* @param {number} zoneNumber the UTM zone number.
* @returns {string} the two letter 100k designator for the given UTM location.
*/
function get100kID(easting, northing, zoneNumber) {
Expand Down Expand Up @@ -654,7 +655,7 @@ function getNorthingFromChar(n, set) {
* Ported from Geotrans' c Lattitude_Band_Value structure table.
* @private
* @param {string} zoneLetter The MGRS zone to get the min northing for.
* @returns {number}
* @returns {number} the minimum northing value of the given zone.
*/
function getMinNorthing(zoneLetter) {
let northing;
Expand Down
Loading

0 comments on commit 69cc4a1

Please sign in to comment.