From 62dff6ab7ff94c38b19208dd1423ad0be5cb9dcf Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 1 Apr 2019 21:33:17 +0100 Subject: [PATCH 1/2] Replace jshint with eslint --- .travis.yml | 2 +- Gemfile | 4 +++- Gemfile.lock | 13 ++++++++----- config/eslint.json | 30 ++++++++++++++++++++++++++++++ config/jshint.yml | 30 ------------------------------ 5 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 config/eslint.json delete mode 100644 config/jshint.yml diff --git a/.travis.yml b/.travis.yml index 9b848200fb..a0ed70c196 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,6 @@ before_script: - bundle exec rake i18n:js:export script: - bundle exec rubocop -f fuubar - - bundle exec rake jshint + - bundle exec rake eslint:run_all - bundle exec erblint . - bundle exec rake test:db diff --git a/Gemfile b/Gemfile index ce37b7c440..d2e0167a58 100644 --- a/Gemfile +++ b/Gemfile @@ -145,8 +145,10 @@ group :development, :test do gem "capybara", "~> 2.13" gem "coveralls", :require => false gem "erb_lint", :require => false + gem "eslint-rails-ee" + gem "execjs" gem "factory_bot_rails" - gem "jshint" gem "poltergeist" gem "puma", "~> 3.7" + gem "therubyracer", :platforms => :ruby end diff --git a/Gemfile.lock b/Gemfile.lock index 32496e129b..d850c7aebe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,6 +99,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) + colorize (0.8.1) composite_primary_keys (11.1.0) activerecord (~> 5.2.1) concurrent-ruby (1.1.5) @@ -161,6 +162,10 @@ GEM rubocop (~> 0.51) smart_properties erubi (1.8.0) + eslint-rails-ee (1.0.2) + colorize + execjs + railties (>= 3.2) execjs (2.7.0) exifr (1.3.6) factory_bot (5.0.2) @@ -204,10 +209,6 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jshint (1.5.0) - execjs (>= 1.4.0) - multi_json (~> 1.0) - therubyracer (~> 0.12.1) json (2.2.0) jsonify (0.3.1) multi_json (~> 1.0) @@ -459,6 +460,8 @@ DEPENDENCIES delayed_job_active_record dynamic_form erb_lint + eslint-rails-ee + execjs factory_bot_rails fakefs faraday @@ -469,7 +472,6 @@ DEPENDENCIES i18n-js (>= 3.0.0) image_optim_rails jquery-rails - jshint json jsonify-rails kgio @@ -506,6 +508,7 @@ DEPENDENCIES sanitize sassc-rails secure_headers + therubyracer uglifier (>= 1.3.0) validates_email_format_of (>= 1.5.1) vendorer diff --git a/config/eslint.json b/config/eslint.json new file mode 100644 index 0000000000..28ec4d3731 --- /dev/null +++ b/config/eslint.json @@ -0,0 +1,30 @@ +{ + "env": { + "browser": true, + "jquery": true + }, + "extends": [ + "eslint:recommended" + ], + "globals": { + "bowser": "readonly", + "I18n": "readonly", + "L": "readonly", + "OSM": "writable", + "Piwik": "readonly", + "querystring": "readonly", + "require": "readonly", + "updateLinks": "readonly" + }, + "rules": { + "eqeqeq": ["error", "smart"], + "no-caller": "error", + "no-extend-native": "error", + "no-new": "error", + "no-trailing-spaces": "error", + "no-undef": "error", + "no-unused-vars": "error", + "no-use-before-define": ["error", {"functions": false}], + "semi": ["error", "always"] + } +} diff --git a/config/jshint.yml b/config/jshint.yml deleted file mode 100644 index a7e22486be..0000000000 --- a/config/jshint.yml +++ /dev/null @@ -1,30 +0,0 @@ -files: - - "**/*.js" -exclude_paths: - - "app/assets/javascripts/i18n" - - "vendor/assets/javascripts" -options: - eqeqeq: true - freeze: true - latedef: "nofunc" - noarg: true - noempty: true - nonew: true - undef: true - browser: true - jquery: true - unused: true - trailing: true - globals: - I18n: false - L: true - OSM: true - Piwik: false - alert: false - escape: false - maximiseMap: false - minimiseMap: false - querystring: true - require: false - updateLinks: false - bowser: false From 1f13321a60239881f7016044b79e9a4d58045e30 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 1 Apr 2019 21:33:33 +0100 Subject: [PATCH 2/2] Fix issues found by eslint --- app/assets/javascripts/index.js | 12 ++++---- app/assets/javascripts/index/directions.js | 33 ++++++++++------------ app/assets/javascripts/index/note.js | 2 +- app/assets/javascripts/index/search.js | 4 +-- app/assets/javascripts/piwik.js | 4 +-- app/assets/javascripts/richtext.js | 4 +-- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index e8e566f53a..d1527207ff 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -25,6 +25,12 @@ $(document).ready(function () { var loaderTimeout; + var map = new L.OSM.Map("map", { + zoomControl: false, + layerControl: false, + contextmenu: true + }); + OSM.loadSidebarContent = function(path, callback) { map.setSidebarOverlaid(false); @@ -78,12 +84,6 @@ $(document).ready(function () { var params = OSM.mapParams(); - var map = new L.OSM.Map("map", { - zoomControl: false, - layerControl: false, - contextmenu: true - }); - map.attributionControl.setPrefix(''); map.updateLayers(params.layers); diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index bdba41ec25..dd408debcf 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -28,6 +28,20 @@ OSM.Directions = function (map) { var expiry = new Date(); expiry.setYear(expiry.getFullYear() + 10); + var engines = OSM.Directions.engines; + + engines.sort(function (a, b) { + a = I18n.t('javascripts.directions.engines.' + a.id); + b = I18n.t('javascripts.directions.engines.' + b.id); + return a.localeCompare(b); + }); + + var select = $('select.routing_engines'); + + engines.forEach(function(engine, i) { + select.append(""); + }); + function Endpoint(input, iconUrl) { var endpoint = {}; @@ -60,7 +74,7 @@ OSM.Directions = function (map) { input.on("change", function (e) { awaitingGeocode = true; - + // make text the same in both text boxes var value = e.target.value; endpoint.setValue(value); @@ -245,7 +259,6 @@ OSM.Directions = function (map) { .html(html); // Add each row - var cumulative = 0; route.steps.forEach(function (step) { var ll = step[0], direction = step[1], @@ -253,8 +266,6 @@ OSM.Directions = function (map) { dist = step[3], lineseg = step[4]; - cumulative += dist; - if (dist < 5) { dist = ""; } else if (dist < 200) { @@ -304,20 +315,6 @@ OSM.Directions = function (map) { }); } - var engines = OSM.Directions.engines; - - engines.sort(function (a, b) { - a = I18n.t('javascripts.directions.engines.' + a.id); - b = I18n.t('javascripts.directions.engines.' + b.id); - return a.localeCompare(b); - }); - - var select = $('select.routing_engines'); - - engines.forEach(function(engine, i) { - select.append(""); - }); - var chosenEngineIndex = findEngine('fossgis_osrm_car'); if ($.cookie('_osm_directions_engine')) { chosenEngineIndex = findEngine($.cookie('_osm_directions_engine')); diff --git a/app/assets/javascripts/index/note.js b/app/assets/javascripts/index/note.js index 3973420bdd..85267ab93e 100644 --- a/app/assets/javascripts/index/note.js +++ b/app/assets/javascripts/index/note.js @@ -40,7 +40,7 @@ OSM.Note = function (map) { initialize(function() { var data = $('.details').data(), latLng = L.latLng(data.coordinates.split(',')); - if (!map.getBounds().contains(latLng)) moveToNote(); + if (!map.getBounds().contains(latLng)) moveToNote(); }); }); }; diff --git a/app/assets/javascripts/index/search.js b/app/assets/javascripts/index/search.js index ea6140e582..6ca145c032 100644 --- a/app/assets/javascripts/index/search.js +++ b/app/assets/javascripts/index/search.js @@ -55,6 +55,8 @@ OSM.Search = function(map) { }); }); + var markers = L.layerGroup().addTo(map); + function clickSearchMore(e) { e.preventDefault(); e.stopPropagation(); @@ -115,8 +117,6 @@ OSM.Search = function(map) { e.stopPropagation(); } - var markers = L.layerGroup().addTo(map); - var page = {}; page.pushstate = page.popstate = function(path) { diff --git a/app/assets/javascripts/piwik.js b/app/assets/javascripts/piwik.js index 19b5619a25..5353a99ac1 100644 --- a/app/assets/javascripts/piwik.js +++ b/app/assets/javascripts/piwik.js @@ -9,14 +9,14 @@ if (OSM.PIWIK) { cache: true, success: function () { piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK.site); - + if (OSM.user) { piwikTracker.setUserId(OSM.user.toString()); } piwikTracker.trackPageView(); piwikTracker.enableLinkTracking(); - + $("meta[name=piwik-goal]").each(function () { piwikTracker.trackGoal($(this).attr("content")); }); diff --git a/app/assets/javascripts/richtext.js b/app/assets/javascripts/richtext.js index a5323bc077..ea2efcfadc 100644 --- a/app/assets/javascripts/richtext.js +++ b/app/assets/javascripts/richtext.js @@ -2,12 +2,12 @@ $(document).ready(function () { /* Hide the preview panes */ $(".richtext_preview").hide(); - /* + /* * When the text in an edit pane is changed, clear the contents of * the associated preview pne so that it will be regenerated when * the user next switches to it. */ - $(".richtext_content textarea").change(function () { + $(".richtext_content textarea").change(function () { $(this).parents(".richtext_container").find(".richtext_preview").empty(); });