From 95f640d3c54c3452889132ea8a77065aaf669f99 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 19:06:40 +0200 Subject: [PATCH 1/8] Add coffeelint configuration file --- coffeelint.json | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 coffeelint.json diff --git a/coffeelint.json b/coffeelint.json new file mode 100644 index 000000000..c69c63f10 --- /dev/null +++ b/coffeelint.json @@ -0,0 +1,114 @@ +{ + "coffeescript_error": { + "level": "error" + }, + "arrow_spacing": { + "name": "arrow_spacing", + "level": "warn" + }, + "no_tabs": { + "name": "no_tabs", + "level": "error" + }, + "no_trailing_whitespace": { + "name": "no_trailing_whitespace", + "level": "warn", + "allowed_in_comments": false, + "allowed_in_empty_lines": true + }, + "max_line_length": { + "name": "max_line_length", + "value": 140, + "level": "warn", + "limitComments": true + }, + "line_endings": { + "name": "line_endings", + "level": "ignore", + "value": "unix" + }, + "no_trailing_semicolons": { + "name": "no_trailing_semicolons", + "level": "error" + }, + "indentation": { + "name": "indentation", + "value": 2, + "level": "error" + }, + "camel_case_classes": { + "name": "camel_case_classes", + "level": "error" + }, + "colon_assignment_spacing": { + "name": "colon_assignment_spacing", + "level": "warn", + "spacing": { + "left": 0, + "right": 1 + } + }, + "no_implicit_braces": { + "name": "no_implicit_braces", + "level": "ignore", + "strict": true + }, + "no_plusplus": { + "name": "no_plusplus", + "level": "ignore" + }, + "no_throwing_strings": { + "name": "no_throwing_strings", + "level": "error" + }, + "no_backticks": { + "name": "no_backticks", + "level": "error" + }, + "no_implicit_parens": { + "name": "no_implicit_parens", + "level": "ignore" + }, + "no_empty_param_list": { + "name": "no_empty_param_list", + "level": "warn" + }, + "no_stand_alone_at": { + "name": "no_stand_alone_at", + "level": "ignore" + }, + "space_operators": { + "name": "space_operators", + "level": "warn" + }, + "duplicate_key": { + "name": "duplicate_key", + "level": "error" + }, + "empty_constructor_needs_parens": { + "name": "empty_constructor_needs_parens", + "level": "ignore" + }, + "cyclomatic_complexity": { + "name": "cyclomatic_complexity", + "value": 10, + "level": "ignore" + }, + "newlines_after_classes": { + "name": "newlines_after_classes", + "value": 3, + "level": "ignore" + }, + "no_unnecessary_fat_arrows": { + "name": "no_unnecessary_fat_arrows", + "level": "warn" + }, + "missing_fat_arrows": { + "name": "missing_fat_arrows", + "level": "ignore" + }, + "non_empty_constructor_needs_parens": { + "name": "non_empty_constructor_needs_parens", + "level": "ignore" + } +} From 6eb2647c1c01651070655cd6b00ad6da76a14d3b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 00:01:05 +0200 Subject: [PATCH 2/8] Fix CoffeeLint rule 'Line contains a trailing semicolon' across multiple files --- app/assets/javascripts/advanced_search.js.coffee | 4 ++-- app/assets/javascripts/allow_participation.js.coffee | 8 ++++---- app/assets/javascripts/fixed_bar.js.coffee | 2 +- app/assets/javascripts/ie_alert.js.coffee | 2 +- app/assets/javascripts/registration_form.js.coffee | 2 +- app/assets/javascripts/tags.js.coffee | 2 +- app/assets/javascripts/users.js.coffee | 2 +- app/assets/javascripts/votes.js.coffee | 8 ++++---- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/advanced_search.js.coffee b/app/assets/javascripts/advanced_search.js.coffee index b38efb874..003fabd7f 100644 --- a/app/assets/javascripts/advanced_search.js.coffee +++ b/app/assets/javascripts/advanced_search.js.coffee @@ -4,7 +4,7 @@ App.AdvancedSearch = $('#js-advanced-search').data('advanced-search-terms') toggle_form: (event) -> - event.preventDefault(); + event.preventDefault() $('#js-advanced-search').slideToggle() toggle_date_options: -> @@ -39,4 +39,4 @@ App.AdvancedSearch = $('#js-advanced-search-date-min').on change: -> - App.AdvancedSearch.toggle_date_options() \ No newline at end of file + App.AdvancedSearch.toggle_date_options() diff --git a/app/assets/javascripts/allow_participation.js.coffee b/app/assets/javascripts/allow_participation.js.coffee index 116e374ca..da6bf47bb 100644 --- a/app/assets/javascripts/allow_participation.js.coffee +++ b/app/assets/javascripts/allow_participation.js.coffee @@ -3,10 +3,10 @@ App.AllowParticipation = initialize: -> $(document).on { 'mouseenter focus': -> - $(this).find(".js-participation-not-allowed").show(); - $(this).find(".js-participation-allowed").hide(); + $(this).find(".js-participation-not-allowed").show() + $(this).find(".js-participation-allowed").hide() mouseleave: -> - $(this).find(".js-participation-not-allowed").hide(); - $(this).find(".js-participation-allowed").show(); + $(this).find(".js-participation-not-allowed").hide() + $(this).find(".js-participation-allowed").show() }, ".js-participation" false diff --git a/app/assets/javascripts/fixed_bar.js.coffee b/app/assets/javascripts/fixed_bar.js.coffee index 8ccbf987f..5421d79e9 100644 --- a/app/assets/javascripts/fixed_bar.js.coffee +++ b/app/assets/javascripts/fixed_bar.js.coffee @@ -7,7 +7,7 @@ App.FixedBar = $(window).on 'scroll', -> if $(window).scrollTop() > fixedBarTopPosition $this.addClass('is-fixed') - $("#check-ballot").css({ 'display': "inline-block" }); + $("#check-ballot").css({ 'display': "inline-block" }) else $this.removeClass('is-fixed') $("#check-ballot").hide() diff --git a/app/assets/javascripts/ie_alert.js.coffee b/app/assets/javascripts/ie_alert.js.coffee index b756f0f8a..cab566b73 100644 --- a/app/assets/javascripts/ie_alert.js.coffee +++ b/app/assets/javascripts/ie_alert.js.coffee @@ -1,7 +1,7 @@ App.IeAlert = set_cookie_and_hide: (event) -> event.preventDefault() - $.cookie('ie_alert_closed', 'true', { path: '/', expires: 365 }); + $.cookie('ie_alert_closed', 'true', { path: '/', expires: 365 }) $('.ie-callout').remove() initialize: -> diff --git a/app/assets/javascripts/registration_form.js.coffee b/app/assets/javascripts/registration_form.js.coffee index 13233b68d..b4ba32d0a 100644 --- a/app/assets/javascripts/registration_form.js.coffee +++ b/app/assets/javascripts/registration_form.js.coffee @@ -21,5 +21,5 @@ App.RegistrationForm = if registrationForm.length > 0 usernameInput.on "focusout", -> clearUsernameMessage() - username = usernameInput.val(); + username = usernameInput.val() validateUsername(username) if username != "" diff --git a/app/assets/javascripts/tags.js.coffee b/app/assets/javascripts/tags.js.coffee index adbcad3e8..6e3c7165c 100644 --- a/app/assets/javascripts/tags.js.coffee +++ b/app/assets/javascripts/tags.js.coffee @@ -12,7 +12,7 @@ App.Tags = current_tags = $tag_input.val().split(',').filter(Boolean) if $.inArray(name, current_tags) >= 0 - current_tags.splice($.inArray(name, current_tags), 1); + current_tags.splice($.inArray(name, current_tags), 1) else current_tags.push name diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee index 9c4fa42b0..2b1bc15de 100644 --- a/app/assets/javascripts/users.js.coffee +++ b/app/assets/javascripts/users.js.coffee @@ -1,5 +1,5 @@ App.Users = initialize: -> - $('.initialjs-avatar').initial(); + $('.initialjs-avatar').initial() false diff --git a/app/assets/javascripts/votes.js.coffee b/app/assets/javascripts/votes.js.coffee index 0f6dfcfc5..9176fea1a 100644 --- a/app/assets/javascripts/votes.js.coffee +++ b/app/assets/javascripts/votes.js.coffee @@ -3,11 +3,11 @@ App.Votes = hoverize: (votes) -> $(document).on { 'mouseenter focus': -> - $("div.participation-not-allowed", this).show(); - $("div.participation-allowed", this).hide(); + $("div.participation-not-allowed", this).show() + $("div.participation-allowed", this).hide() mouseleave: -> - $("div.participation-not-allowed", this).hide(); - $("div.participation-allowed", this).show(); + $("div.participation-not-allowed", this).hide() + $("div.participation-allowed", this).show() }, votes initialize: -> From 2c4139d4ac25911ec8335980d81ebec25b2ade6b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 00:02:06 +0200 Subject: [PATCH 3/8] Remove trailing whitespace from tracks coffee file --- app/assets/javascripts/tracks.js.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/tracks.js.coffee b/app/assets/javascripts/tracks.js.coffee index 1b6cfe82e..74fc305e8 100644 --- a/app/assets/javascripts/tracks.js.coffee +++ b/app/assets/javascripts/tracks.js.coffee @@ -1,13 +1,13 @@ App.Tracks = - - tracking_enabled: -> + + tracking_enabled: -> _paq? - set_custom_var: (id, name, value, scope) -> + set_custom_var: (id, name, value, scope) -> _paq.push(['setCustomVariable', id, name, value, scope]) _paq.push(['trackPageView']) - track_event: ($this) -> + track_event: ($this) -> category = $this.data('track-event-category') action = $this.data('track-event-action') _paq.push(['trackEvent', category, action]) @@ -17,9 +17,9 @@ App.Tracks = $('[data-track-usertype]').each -> $this = $(this) usertype = $this.data('track-usertype') - App.Tracks.set_custom_var(1, "usertype", usertype, "visit") + App.Tracks.set_custom_var(1, "usertype", usertype, "visit") - $('[data-track-event-category]').each -> + $('[data-track-event-category]').each -> $this = $(this) App.Tracks.track_event($this) From 8f682901ed12092aa27bf1067021cc0cf11766b6 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 00:03:34 +0200 Subject: [PATCH 4/8] Fix Operators must be spaced properly rule on multiple coffeescript files --- app/assets/javascripts/legislation_admin.js.coffee | 2 +- app/assets/javascripts/legislation_annotatable.js.coffee | 4 ++-- app/assets/javascripts/tree_navigator.js.coffee | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/legislation_admin.js.coffee b/app/assets/javascripts/legislation_admin.js.coffee index c61d9cea1..fc1d7cab4 100644 --- a/app/assets/javascripts/legislation_admin.js.coffee +++ b/app/assets/javascripts/legislation_admin.js.coffee @@ -6,7 +6,7 @@ App.LegislationAdmin = checkbox = $(this) parent = $(this).parents('.row:eq(0)') date_selector = $(this).data('disable-date') - parent.find("input[type='text'][id^='"+date_selector+"']").each -> + parent.find("input[type='text'][id^='" + date_selector + "']").each -> if checkbox.is(':checked') $(this).removeAttr("disabled") else diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 6b7e2e603..4b24e0e1c 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -66,7 +66,7 @@ App.LegislationAnnotatable = $(elem).data("annotation-id") annotation_id = target.data('annotation-id') - $('[data-annotation-id="'+annotation_id+'"]').addClass('current-annotation') + $('[data-annotation-id="' + annotation_id + '"]').addClass('current-annotation') $('#comments-box').html('') App.LegislationAllegations.show_comments() @@ -154,7 +154,7 @@ App.LegislationAnnotatable = ), 100) propotionalWeight: (v, max) -> - Math.floor(v*5/(max+1)) + 1 + Math.floor(v * 5 / (max + 1)) + 1 addWeightClasses: -> annotationsLoaded: (annotations) -> diff --git a/app/assets/javascripts/tree_navigator.js.coffee b/app/assets/javascripts/tree_navigator.js.coffee index 1fdc50ba2..385d1bbbd 100644 --- a/app/assets/javascripts/tree_navigator.js.coffee +++ b/app/assets/javascripts/tree_navigator.js.coffee @@ -30,7 +30,7 @@ App.TreeNavigator = elem.siblings('ul').show() if anchor = $(location).attr('hash') - if link = elem.find('a[href="'+anchor+'"]') + if link = elem.find('a[href="' + anchor + '"]') link.parents('ul').each -> $(this).show() $(this).siblings('span').removeClass('closed').addClass('open') From 3db13da2b1a802a6a4640ef0945b3835d363465f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 00:05:07 +0200 Subject: [PATCH 5/8] Fix indentation on multiple coffeescript files --- app/assets/javascripts/banners.js.coffee | 2 +- .../legislation_allegations.js.coffee | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/banners.js.coffee b/app/assets/javascripts/banners.js.coffee index ec00abe95..66d3a8df7 100644 --- a/app/assets/javascripts/banners.js.coffee +++ b/app/assets/javascripts/banners.js.coffee @@ -5,7 +5,7 @@ App.Banners = update_style: (selector, style) -> $(selector).removeClass($(selector).attr("class"), true) - .addClass(style, true) + .addClass(style, true) initialize: -> $('[data-js-banner-title]').on diff --git a/app/assets/javascripts/legislation_allegations.js.coffee b/app/assets/javascripts/legislation_allegations.js.coffee index e5c8ea62f..9b9c95d8d 100644 --- a/app/assets/javascripts/legislation_allegations.js.coffee +++ b/app/assets/javascripts/legislation_allegations.js.coffee @@ -11,15 +11,15 @@ App.LegislationAllegations = initialize: -> $('.js-toggle-allegations .draft-panel').on - click: (e) -> - e.preventDefault() - e.stopPropagation() - if !App.LegislationAnnotatable.isMobile() - App.LegislationAllegations.toggle_comments() + click: (e) -> + e.preventDefault() + e.stopPropagation() + if !App.LegislationAnnotatable.isMobile() + App.LegislationAllegations.toggle_comments() $('.js-toggle-allegations').on - click: (e) -> - # Toggle comments when the section title is visible - if !App.LegislationAnnotatable.isMobile() - if $(this).find('.draft-panel .panel-title:visible').length == 0 - App.LegislationAllegations.toggle_comments() + click: (e) -> + # Toggle comments when the section title is visible + if !App.LegislationAnnotatable.isMobile() + if $(this).find('.draft-panel .panel-title:visible').length == 0 + App.LegislationAllegations.toggle_comments() From 0379a66c7742c2da801528476d814cd4e7a291f6 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 00:06:26 +0200 Subject: [PATCH 6/8] Remove unnecesary empty parameter list on coffeescript file --- app/assets/javascripts/legislation_annotatable.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 4b24e0e1c..141bcb858 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -84,7 +84,7 @@ App.LegislationAnnotatable = annotation_id: pid annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url") - isMobile: () -> + isMobile: -> return window.innerWidth <= 652 viewerExtension: (viewer) -> From 2965b31504f9e268429b2cef2bf6137ab1acd6d5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 00:06:42 +0200 Subject: [PATCH 7/8] Remove unnecesary space on coffeescript file --- app/assets/javascripts/advanced_search.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/advanced_search.js.coffee b/app/assets/javascripts/advanced_search.js.coffee index 003fabd7f..e768e09a3 100644 --- a/app/assets/javascripts/advanced_search.js.coffee +++ b/app/assets/javascripts/advanced_search.js.coffee @@ -22,7 +22,7 @@ App.AdvancedSearch = $('.js-calendar').datepicker regional: locale - maxDate: "+0d" + maxDate: "+0d" $('.js-calendar-full').datepicker regional: locale From 06525cb462bbeecce870e7d20419fd4516520f22 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 16 Jun 2017 17:54:18 +0200 Subject: [PATCH 8/8] Add coffeelint install & usage instructions on readme files --- README.md | 6 ++++++ README_ES.md | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 6a1bb19ac..4c2b5fe92 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,12 @@ Run the tests with: bin/rspec ``` +Run the [coffeelint](http://www.coffeelint.org/) linter for coffeescript (install with `npm install -g coffeelint`) : + +``` +coffeelint . +``` + You can use the default admin user from the seeds file: **user:** admin@consul.dev diff --git a/README_ES.md b/README_ES.md index bbe821608..d7fef7f89 100644 --- a/README_ES.md +++ b/README_ES.md @@ -58,6 +58,12 @@ Para ejecutar los tests: bin/rspec ``` +Usa el linter coffeescript [coffeelint](http://www.coffeelint.org/) (puedes instalaro con `npm install -g coffeelint`) : + +``` +coffeelint . +``` + Puedes usar el usuario administrador por defecto del fichero seeds: **user:** admin@consul.dev