Skip to content

Commit

Permalink
JS linting and add Styler GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Mar 16, 2024
1 parent 58757fb commit 57f1521
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 155 deletions.
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
"parserOptions": {
"ecmaVersion": 6
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"linebreak-style": "off", // Disable linebreak style rule
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{"args": "none"}
],
"no-console": "off",
"no-restricted-syntax": [
"error",
{
"selector": "CallExpression[callee.object.name='console'][callee.property.name!=/^(log|warn|error|info|trace)$/]",
"message": "Unexpected property on console object was called"
}
],
"no-var": "off", // Allow var declarations
"prefer-const": "error", // Enforce the use of const where possible
"no-assign-const": "off"
}
};
75 changes: 75 additions & 0 deletions .github/workflows/styler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["**.[rR]", "**.[qrR]md", "**.[rR]markdown", "**.[rR]nw", "**.[rR]profile"]

name: Style

jobs:
style:
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::styler, any::roxygen2
needs: styler

- name: Enable styler cache
run: styler::cache_activate()
shell: Rscript {0}

- name: Determine cache location
id: styler-location
run: |
cat(
"location=",
styler::cache_info(format = "tabular")$location,
"\n",
file = Sys.getenv("GITHUB_OUTPUT"),
append = TRUE,
sep = ""
)
shell: Rscript {0}

- name: Cache styler
uses: actions/cache@v4
with:
path: ${{ steps.styler-location.outputs.location }}
key: ${{ runner.os }}-styler-${{ github.sha }}
restore-keys: |
${{ runner.os }}-styler-
${{ runner.os }}-
- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: Commit and push changes
run: |
if FILES_TO_COMMIT=($(git diff-index --name-only ${{ github.sha }} \
| egrep --ignore-case '\.(R|[qR]md|Rmarkdown|Rnw|Rprofile)$'))
then
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git commit ${FILES_TO_COMMIT[*]} -m "Style code (GHA)"
git pull --ff-only
git push origin
else
echo "No changes to commit."
fi
33 changes: 0 additions & 33 deletions inst/htmlwidgets/bindings/.eslintrc.js

This file was deleted.

92 changes: 46 additions & 46 deletions inst/htmlwidgets/bindings/lfx-bouncemarker-bindings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global LeafletWidget, L */
/* global LeafletWidget, $, L */

function asArray(value) {
if (value instanceof Array)
Expand All @@ -10,7 +10,7 @@ function unpackStrings(iconset) {
if (!iconset) {
return iconset;
}
if (typeof(iconset.index) === "undefined") {
if (typeof(iconset.index) === 'undefined') {
return iconset;
}

Expand All @@ -30,46 +30,47 @@ LeafletWidget.methods.addBounceMarkers = function(

let icondf;
let getIcon;

if (icon) {
// Unpack icons
icon.iconUrl = unpackStrings(icon.iconUrl);
icon.iconRetinaUrl = unpackStrings(icon.iconRetinaUrl);
icon.shadowUrl = unpackStrings(icon.shadowUrl);
icon.shadowRetinaUrl = unpackStrings(icon.shadowRetinaUrl);

// This cbinds the icon URLs and any other icon options; they're all
// present on the icon object.
icondf = new LeafletWidget.DataFrame().cbind(icon);

// Constructs an icon from a specified row of the icon dataframe.
getIcon = function(i) {
let opts = icondf.get(i);
if (!opts.iconUrl) {
return new L.Icon.Default();
}

// Composite options (like points or sizes) are passed from R with each
// individual component as its own option. We need to combine them now
// into their composite form.
if (opts.iconWidth) {
opts.iconSize = [opts.iconWidth, opts.iconHeight];
}
if (opts.shadowWidth) {
opts.shadowSize = [opts.shadowWidth, opts.shadowHeight];
}
if (opts.iconAnchorX) {
opts.iconAnchor = [opts.iconAnchorX, opts.iconAnchorY];
}
if (opts.shadowAnchorX) {
opts.shadowAnchor = [opts.shadowAnchorX, opts.shadowAnchorY];
}
if (opts.popupAnchorX) {
opts.popupAnchor = [opts.popupAnchorX, opts.popupAnchorY];
}

return new L.Icon(opts);
};
}
// Unpack icons
icon.iconUrl = unpackStrings(icon.iconUrl);
icon.iconRetinaUrl = unpackStrings(icon.iconRetinaUrl);
icon.shadowUrl = unpackStrings(icon.shadowUrl);
icon.shadowRetinaUrl = unpackStrings(icon.shadowRetinaUrl);

// This cbinds the icon URLs and any other icon options; they're all
// present on the icon object.
icondf = new LeafletWidget.DataFrame().cbind(icon);

// Constructs an icon from a specified row of the icon dataframe.
getIcon = function(i) {
var opts = icondf.get(i);
if (!opts.iconUrl) {
return new L.Icon.Default();
}

// Composite options (like points or sizes) are passed from R with each
// individual component as its own option. We need to combine them now
// into their composite form.
if (opts.iconWidth) {
opts.iconSize = [opts.iconWidth, opts.iconHeight];
}
if (opts.shadowWidth) {
opts.shadowSize = [opts.shadowWidth, opts.shadowHeight];
}
if (opts.iconAnchorX) {
opts.iconAnchor = [opts.iconAnchorX, opts.iconAnchorY];
}
if (opts.shadowAnchorX) {
opts.shadowAnchor = [opts.shadowAnchorX, opts.shadowAnchorY];
}
if (opts.popupAnchorX) {
opts.popupAnchor = [opts.popupAnchorX, opts.popupAnchorY];
}

return new L.Icon(opts);
};
}

if(!($.isEmptyObject(lat) || $.isEmptyObject(lng)) ||
($.isNumeric(lat) && $.isNumeric(lng))) {
Expand All @@ -88,18 +89,17 @@ LeafletWidget.methods.addBounceMarkers = function(
if (icon) icondf.effectiveLength = df.nrow();

LeafletWidget.methods.addGenericMarkers(
this, df, group, clusterOptions, clusterId, (df, i) => {
this, df, group, clusterOptions, clusterId, function(df, i) {
var options = df.get(i);
if (icon) options.icon = getIcon(i);
options.bounceOnAdd = true;
options.bounceOnAddOptions = {
duration: duration,
height: height
duration: duration,
height: height
};
return L.marker([df.get(i, 'lat'), df.get(i, 'lng')], options);
});
}

}
).call(this);
}).call(this);
};
58 changes: 14 additions & 44 deletions inst/htmlwidgets/bindings/lfx-draw-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,50 +72,20 @@ LeafletWidget.methods.addDrawToolbar = function(targetLayerId, targetGroup, opti
if (options && options.toolbar) {
var rtool = options.toolbar;
var tooldef = L.drawLocal.draw.toolbar;
L.drawLocal.draw.toolbar.buttons = {
...tooldef.buttons,
...rtool.buttons
};
L.drawLocal.draw.toolbar.actions = {
...tooldef.actions,
...rtool.actions
};
L.drawLocal.draw.toolbar.finish = {
...tooldef.finish,
...rtool.finish
};
L.drawLocal.draw.toolbar.undo = {
...tooldef.undo,
...rtool.undo
};
L.drawLocal.draw.toolbar.buttons = Object.assign({}, tooldef.buttons, rtool.buttons);
L.drawLocal.draw.toolbar.actions = Object.assign({}, tooldef.actions, rtool.actions);
L.drawLocal.draw.toolbar.finish = Object.assign({}, tooldef.finish, rtool.finish);
L.drawLocal.draw.toolbar.undo = Object.assign({}, tooldef.undo, rtool.undo);
}
if (options && options.handlers) {
var rhand = options.handlers;
var handldef = L.drawLocal.draw.handlers;
L.drawLocal.draw.handlers.circle = {
...handldef.circle,
...rhand.circle
};
L.drawLocal.draw.handlers.circlemarker = {
...handldef.circlemarker,
...rhand.circlemarker
};
L.drawLocal.draw.handlers.marker = {
...handldef.marker,
...rhand.marker
};
L.drawLocal.draw.handlers.polygon = {
...handldef.polygon,
...rhand.polygon
};
L.drawLocal.draw.handlers.polyline = {
...handldef.polyline,
...rhand.polyline
};
L.drawLocal.draw.handlers.rectangle = {
...handldef.rectangle,
...rhand.rectangle
};
L.drawLocal.draw.handlers.circle = Object.assign({}, handldef.circle, rhand.circle);
L.drawLocal.draw.handlers.circlemarker = Object.assign({}, handldef.circlemarker, rhand.circlemarker);
L.drawLocal.draw.handlers.marker = Object.assign({}, handldef.marker, rhand.marker);
L.drawLocal.draw.handlers.polygon = Object.assign({}, handldef.polygon, rhand.polygon);
L.drawLocal.draw.handlers.polyline = Object.assign({}, handldef.polyline, rhand.polyline);
L.drawLocal.draw.handlers.rectangle = Object.assign({}, handldef.rectangle, rhand.rectangle);
}

// Create new Drawing Control
Expand Down Expand Up @@ -167,11 +137,11 @@ LeafletWidget.methods.addDrawToolbar = function(targetLayerId, targetGroup, opti
editableFeatureGroup.toGeoJSON());
});

map.on(L.Draw.Event.EDITSTART, function (e) {
map.on(L.Draw.Event.EDITSTART, function () {
if (!HTMLWidgets.shinyMode) return;
Shiny.onInputChange(map.id+'_draw_editstart', true);
});
map.on(L.Draw.Event.EDITSTOP, function (e) {
map.on(L.Draw.Event.EDITSTOP, function () {
if (!HTMLWidgets.shinyMode) return;
Shiny.onInputChange(map.id+'_draw_editstop', true);
});
Expand Down Expand Up @@ -201,12 +171,12 @@ LeafletWidget.methods.addDrawToolbar = function(targetLayerId, targetGroup, opti
editableFeatureGroup.toGeoJSON());
});

map.on(L.Draw.Event.DELETESTART, function (e) {
map.on(L.Draw.Event.DELETESTART, function () {
if (!HTMLWidgets.shinyMode) return;
Shiny.onInputChange(map.id+'_draw_deletestart', true);
});

map.on(L.Draw.Event.DELETESTOP, function (e) {
map.on(L.Draw.Event.DELETESTOP, function () {
if (!HTMLWidgets.shinyMode) return;
Shiny.onInputChange(map.id+'_draw_deletestop', true);
});
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/bindings/lfx-gps-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LeafletWidget.methods.addControlGPS = function(options) {
'radius': e.marker._radius
});
});
map.gpscontrol.on('gps:disabled', function(e){
map.gpscontrol.on('gps:disabled', function(){
// Shiny stuff
if (!HTMLWidgets.shinyMode) return;
Shiny.onInputChange(map.id+'_gps_disabled',{});
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/bindings/lfx-omnivore-bindings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global LeafletWidget, $, L, topojson, csv2geojson, toGeoJSON */
/* global LeafletWidget, $, L, DOMParser, topojson, csv2geojson, toGeoJSON */

// parse an XML
LeafletWidget.utils.parseXML = function(str) {
Expand Down
4 changes: 2 additions & 2 deletions inst/htmlwidgets/bindings/lfx-pulse-icon-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ LeafletWidget.methods.addPulseMarkers = function(
lat, lng, icon, layerId, group, options,
popup, popupOptions, clusterOptions, clusterId, label, labelOptions) {
(function(){
var icondf;

var getIcon;
let icondf;
let getIcon;
if (icon) {

// This cbinds the icon URLs and any other icon options; they're all
Expand Down
Loading

0 comments on commit 57f1521

Please sign in to comment.