Commit Graph

14280 Commits

Author SHA1 Message Date
Javi Martín
c55a1a9faf Simplify finding rows for sortable tables
Including the table body is more intuitive than excluding the first row
and the table foot.
2019-09-11 03:14:17 +02:00
Javi Martín
936aa7af0f Simplify adding rows to sortable tables
The `append` method can handle arrays, so there's no need to loop
through each element.

There's more to improve on this method, like the `asc` variable being
global to a table instead of depending on the current column, but for
now I'm only refactoring and maintaining the current behaviour.
2019-09-11 03:14:16 +02:00
Javi Martín
4d7c124188 Remove unnecessary conditions
The code won't do anything if there are no elements, so there's no need
to check that condition.
2019-09-11 03:14:16 +02:00
Javi Martín
1cc3324468 Use each and forEach instead of for .. in
We're planning to replace CoffeeScript with JavaScript, and CoffeeScript
compiles `for .. in` to complex JavaScript code.
2019-09-11 03:14:16 +02:00
Javi Martín
3120e0aa41 Use ECMAScript 5 array and string methods
These methods were added in 2009 and are supported by 98.5% of the
browsers, including Internet Explorer 9, 10 and 11. We were already
using them in some places.
2019-09-11 03:14:16 +02:00
Javi Martín
49b4a0c71d Simplify banners JavaScript
There were functions which were just simple wrappers to common jQuery
functions.
2019-09-11 03:14:16 +02:00
Javi Martín
1f828bf4d4 Simplify code to check form changes 2019-09-11 03:14:16 +02:00
Javier Martín
de50317d25 Merge pull request #3654 from consul/fix_javascript_typos
Fix JavaScript Lint errors
2019-09-11 03:13:24 +02:00
Javier Martín
031fb08f39 Merge pull request #3652 from consul/remove_unused_javascript
Remove unused JavaScript code
2019-09-11 02:40:54 +02:00
Javi Martín
eab35dc9b0 Don't call hasOwnProperty directly
Calling it directly might make it difficult to detect bugs, particularly
when we don't trust the data we receive:

https://eslint.org/docs/rules/no-prototype-builtins

If we trust the data we receive, then IMHO we shouldn't even check for
`hasOwnProperty`, since we know what we're going to receive.
2019-09-11 02:07:35 +02:00
Javi Martín
5ad41d9ac7 Add a break to avoid case fallthrough
In JavaScript, when there isn't a `break` or `return` statement inside a
`switch` case, the next case will be executed as well.

That wasn't a problem here because CoffeeScript automatically inserts a
`return` statement in this specific situation. However, since we don't
want to return the result of the `hide()` operation, it might be easy to
accidentally remove the `return` statement, causing the code to break.

I've added a test for the scenario where neither `break` nor `return`
statements are present, so we don't run into this error.
2019-09-11 02:05:04 +02:00
taitus
10a2e91f1c Fix wrong js 2019-09-11 02:05:04 +02:00
Alceu Medeiros
1f059d44cf Set current locale as default for datepicker translation 2019-09-11 02:05:04 +02:00
Javi Martín
e4985d371d Remove code added for debugging purposes 2019-09-11 01:56:27 +02:00
Javi Martín
f28a5cc49b Remove unused piwik-related code
This code requires the variable `_paq` to be set somewhere, but we never
set it.

In the past Decide Madrid added some custom JavaScript using this code.
However, in CONSUL we're using Ahoy to track events, and we don't have
any documentation about adding custom JavaScript to use piwik nor we've
got any other piwik integration.
2019-09-11 01:56:27 +02:00
Javi Martín
a9d28bee15 Remove unused code in App.Cookies
The `removeCookie` function is never called, and the `initialize`
function doesn't do anything. The only functions we use here are
`getCookie` and `saveCookie`.
2019-09-11 01:56:27 +02:00
Javi Martín
bf20c93e99 Remove legacy annotations JavaScript file
This code isn't used since commit 54e59a8a.
2019-09-11 01:56:27 +02:00
Javi Martín
457ec11e6d Remove unnecessary return false statements
The `initialize` functions don't need to return anything, since their
returned value is never used.

Returning false is a common practice in jQuery to stop an event, but in
plain JavaScript methods it doesn't have any side effects.
2019-09-11 01:56:27 +02:00
Javi Martín
36a557927a Remove unused variables 2019-09-11 01:56:27 +02:00
Javi Martín
0ef75ff199 Remove unused JavaScript banners code
The banner `update_style` method isn't used since commit 82cb8d4c.
2019-09-11 01:56:27 +02:00
Javi Martín
2af09d65c7 Remove unused JavaScript poll token code
We don't load the token message since commit 585f9ea5, so the JavaScript
to show it wasn't doing anything anymore.
2019-09-11 01:56:27 +02:00
Javier Martín
dca090d7a1 Merge pull request #3649 from consul/remove_ie8_code
Remove code specific to Internet Explorer 8
2019-09-11 01:42:34 +02:00
Javier Martín
4b7755791d Merge pull request #3637 from consul/remove_rubocop_rules
Remove unused rubocop rules
2019-09-10 23:05:27 +02:00
Javi Martín
738e9ebc8b Remove code specific to Internet Explorer 8
Internet Explorer 9 was released eight years ago. Besides that, we don't
really support IE8 anyway, since we show a popup to IE8 users saying
we don't support it, we haven't maintained the IE8-specific CSS file for
years, and we don't test our JavaScript against IE8.
2019-09-10 22:43:37 +02:00
Javi Martín
97ec8776ab Reduce severity of LineLength rule
Since we're ignoring this rule in many places, we're marking it in a
different way so it's clear we're not as strict with this rule.
2019-09-10 22:27:33 +02:00
Javi Martín
7e9e1be1aa Remove Bundler/InsecureProtocolSource rubocop rule
Since we're using rubygems as the only source, this rule is not
necessary.
2019-09-10 22:27:33 +02:00
Javi Martín
16b8bee140 Remove unused rspec rubocop rules
We consider these rules either return false positives or we don't have a
strong opinion about them.
2019-09-10 22:27:33 +02:00
Javi Martín
3fa3801a49 Remove unused rails rubocop rules
We consider these rules either return false positives or we don't have a
strong opinion about them.
2019-09-10 22:27:33 +02:00
Javi Martín
d639cd587a Remove unnecessary uniq calls
The code `where(id: ids)` is equivalent to `where(id: ids.uniq)`.

Since Rails 5 uses `distinct` instead of `uniq` and in most cases where
we use `uniq` with `pluck` we should simply remove the `uniq` call (as
done in this commit), we're also removing the `Rails/UniqBeforePluck`
rubocop rule.
2019-09-10 22:27:33 +02:00
Javi Martín
9fb1d7df31 Remove obsolete ScopeArgs rubocop rule
This rule doesn't make sense with Rails 5 anymore, since breaking it
will raise an error.
2019-09-10 22:27:33 +02:00
Javi Martín
ea17256e3a Remove gemspec rubocop rules
We don't have a gemspec file, so we don't need these ones.
2019-09-10 22:27:33 +02:00
Javi Martín
9d566a2250 Remove most performance rubocop rules
For performance purposes, we need to find bottlenecks in our
application. Optimizing the performance of small methods doesn't make
the application faster.

I've kept a few cops because applying these ones IMHO make the code
easier to read.
2019-09-10 22:27:33 +02:00
Javier Martín
274fd1af4d Merge pull request #3636 from consul/change_basic_rubocop_rules
Change basic rubocop rules
2019-09-10 22:27:08 +02:00
Javi Martín
2243809d2e Move basic RSpec rubocop rules to basic cops
These are rules we were already applying.

We've excluded the `factories` folder for some rules because there's a
factory defining a `context` attribute, which rubocop thought was the
`context` RSpec keyword.
2019-09-10 21:43:39 +02:00
Javi Martín
59e107e565 Apply RSpec/HookArgument rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
9541ce892c Apply Bundler rubocop rules
We're not using the InsecureProtocolSource rule because I don't feel
it's necessary.
2019-09-10 21:43:39 +02:00
Javi Martín
c05b9c2aac Apply Capybara/CurrentPathExpectation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
969a4e21c9 Apply RSpec/RepeatedExample rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
044eabd7ef Apply Rspec/LetSetup rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
58ba517717 Apply RSpec/ExampleWording rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
0788925c1b Apply Rails/Validation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
27c73c22ea Configure Rails/UnknownEnv rubocop rule
We use staging and preproduction environments, which are not valid by
default.

This rule is useful because misspelling the name of an environment might
otherwise go unnoticed.
2019-09-10 21:43:39 +02:00
Javi Martín
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
daa86ca3fc Apply Rails/RequestReferer rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
a5ba13b599 Apply Rails/Presence rubocop rule 2019-09-10 21:43:38 +02:00
Javi Martín
adc5906253 Apply Rails/PluralizationGrammar rubocop rule 2019-09-10 21:43:38 +02:00
Javier Martín
1821a18c61 Merge pull request #3631 from consul/add_spacing_rules
Add rubocop spacing rules
2019-09-10 21:42:44 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javier Martín
c7f64f8493 Merge pull request #3629 from consul/rubocop_rules
Apply Rubocop rules
2019-09-10 20:48:30 +02:00
Javi Martín
f74971060b Apply SpaceInHtmlTag ERB Lint rule 2019-09-10 20:02:15 +02:00