Skip to content

Commit f741760

Browse files
flodolopascalchevrel
authored andcommitted
Add ESLint for JavaScript files
Fix #713
1 parent b1e8678 commit f741760

File tree

11 files changed

+160
-74
lines changed

11 files changed

+160
-74
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web/js/sorttable.js

.eslintrc.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"jquery": true
5+
},
6+
"extends": "eslint:recommended",
7+
"globals": {
8+
"Clipboard": true,
9+
"supportedLocales": true
10+
},
11+
"rules": {
12+
"camelcase": [
13+
2,
14+
{
15+
"properties": "always"
16+
}
17+
],
18+
"curly": [
19+
2,
20+
"all"
21+
],
22+
"eqeqeq": [
23+
2,
24+
"smart"
25+
],
26+
"indent": [
27+
2,
28+
4
29+
],
30+
"linebreak-style": [
31+
2,
32+
"unix"
33+
],
34+
"new-cap": 2,
35+
"no-spaced-func": 2,
36+
"one-var-declaration-per-line": [
37+
2,
38+
"always"
39+
],
40+
"quotes": [
41+
2,
42+
"single"
43+
],
44+
"semi": [
45+
2,
46+
"always"
47+
],
48+
"space-before-function-paren": [
49+
2,
50+
"never"
51+
]
52+
}
53+
};

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ before_script:
1111
- composer install --no-interaction --prefer-dist
1212
## Travis configuration
1313
- cp app/config/config.ini-travis app/config/config.ini
14+
## Install ESLint
15+
- npm install -g eslint
1416
script:
1517
- vendor/atoum/atoum/bin/atoum -d tests/units/
1618
- php tests/functional/api.php
1719
- php tests/functional/pages.php
1820
- vendor/bin/php-cs-fixer --diff --dry-run -v fix
21+
- eslint web/js
1922
notifications:
2023
irc:
2124
channels:

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ The Transvision team uses Git and GitHub for both development and issue tracking
2727

2828
## Dependencies
2929

30-
- Bash scripting support
31-
- Python
32-
- PHP >= 5.6
33-
- Composer (Dependency Manager for PHP, https://getcomposer.org/)
34-
- mercurial, git, svn to check out data sources (only for a Full installation for production)
35-
- php5-xsl and GraphViz packages for generating the documentation with [phpDocumentor][]
36-
- libpspell-dev, php5-pspell and aspell-en packages for running spell checking in English on [Unlocalized words view][].
37-
- Apache with mod_rewrite activated
30+
* Bash scripting support
31+
* Python
32+
* PHP >= 5.6
33+
* Composer (Dependency Manager for PHP, https://getcomposer.org/)
34+
* mercurial, git, svn to check out data sources (only for a Full installation for production)
35+
* php5-xsl and GraphViz packages for generating the documentation with [phpDocumentor][]
36+
* libpspell-dev, php5-pspell and aspell-en packages for running spell checking in English on [Unlocalized words view][]
37+
* Apache with mod_rewrite activated
38+
* [npm][] and eslint for JavaScript files (optional)
39+
```
40+
npm install -g eslint
41+
eslint web/js
42+
```
3843

3944
## Full Installation (production or heavy development)
4045

@@ -71,5 +76,6 @@ MPL 2
7176
[Transvision classes]: https://transvision-beta.mozfr.org/docs
7277
[Transvision Project]: https://github.com/mozfr/transvision
7378
[phpDocumentor]: http://phpdoc.org/
79+
[npm]: https://www.npmjs.com
7480
[Unlocalized words view]: https://transvision.mozfr.org/unlocalized
7581
[Coding Standards]:https://github.com/mozfr/transvision/wiki/Code-conventions

app/views/templates/base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<?php endforeach?>
156156

157157
<script>
158-
var supported_locales = [];
158+
var supportedLocales = [];
159159
<?php
160160
/*
161161
Building array of supported locales for JavaScript functions.
@@ -164,7 +164,7 @@
164164
that json_encode returns an array and not an object.
165165
*/
166166
foreach (Project::getSupportedRepositories() as $repo_id => $repo_name) {
167-
print " supported_locales['{$repo_id}'] = " .
167+
print " supportedLocales['{$repo_id}'] = " .
168168
json_encode(array_values(Project::getRepositoryLocales($repo_id))) .
169169
";\n";
170170
}

start.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#! /usr/bin/env bash
22

3+
standard_color=$(tput sgr0)
4+
green=$(tput setab 2)
5+
red=$(tput setab 1)
6+
7+
function echored() {
8+
echo -e "$red$*$standard_color"
9+
}
10+
11+
function echogreen() {
12+
echo -e "$green$*$standard_color"
13+
}
14+
315
# Use 'start.sh -remote' if you want to access the server from another machine (or a VM)
416
SERVER="localhost:8082"
517

@@ -49,6 +61,16 @@ case "$1" in
4961
php ./tests/functional/api.php
5062
php ./tests/functional/pages.php
5163
vendor/bin/php-cs-fixer --diff --dry-run -v fix
64+
echo "Checking JavaScript files with ESLint..."
65+
if hash eslint 2>/dev/null
66+
then
67+
if eslint web/js
68+
then
69+
echogreen "No issues found in JavaScript files."
70+
fi
71+
else
72+
echored "WARNING: eslint is not available. See README.md for instructions."
73+
fi
5274
exit 1
5375
;;
5476
-tests-server)

tests/functional/pages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
['productization/', 200, 'Show productization', 'firefox'],
1414
['showrepos/?locale=en-GB', 200, 'Health Status for en-GB', 'General metrics'],
1515
['stats/', 200, 'Repository status overview', 'Status estimate'],
16-
['string/?entity=browser/chrome/browser/places/places.properties:bookmarkResultLabel&repo=central', 200, 'supported_locales', 'Marque-page'],
16+
['string/?entity=browser/chrome/browser/places/places.properties:bookmarkResultLabel&repo=central', 200, 'supportedLocales', 'Marque-page'],
1717
['unchanged/', 200, 'Display a list of strings identical', 'Locale'],
1818
['unlocalized/', 200, 'Display the list of the most common untranslated words', 'Occurrences'],
1919
['variables/', 200, 'Show potential errors related to', 'no errors found'],

web/js/base.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ $(document).ready(function() {
3232
// Associate code to repository switch in simple search form.
3333
$('#simplesearch_repository').on('change', function(){
3434
// Store locale currently selected
35-
var current_locale = $('#simplesearch_locale').val();
36-
var repository_id = this.value;
35+
var currentLocale = $('#simplesearch_locale').val();
36+
var repositoryID = this.value;
3737

3838
// Empty the select
3939
$('#simplesearch_locale')
4040
.find('option')
4141
.remove();
4242

4343
// Rebuild options with locales for new repository.
44-
$.each(supported_locales[this.value], function(key, locale) {
44+
$.each(supportedLocales[this.value], function(key, locale) {
4545
$('#simplesearch_locale')
4646
.append($('<option>', {value : locale})
4747
.text(locale));
4848
});
4949

5050
// Hide elements (e.g. filters in Consistency view) if it's not a desktop repository
51-
var desktop_repositories = ['central', 'aurora', 'beta', 'release'];
52-
if (desktop_repositories.indexOf(repository_id) === -1) {
51+
var desktopRepositories = ['central', 'aurora', 'beta', 'release'];
52+
if (desktopRepositories.indexOf(repositoryID) === -1) {
5353
$('.desktop_repo_only').hide();
5454
} else {
5555
$('.desktop_repo_only').show();
5656
}
5757

5858
// Try to select the same locale previously selected.
59-
$('#simplesearch_locale option[value="' + current_locale + '"]')
59+
$('#simplesearch_locale option[value="' + currentLocale + '"]')
6060
.prop('selected', true);
6161
});
6262

@@ -71,11 +71,10 @@ $(document).ready(function() {
7171

7272
var clipboard = new Clipboard('.clipboard');
7373
clipboard.on('success', function(e) {
74-
e.trigger.setAttribute('data-title', 'Translation copied!');
75-
e.trigger.setAttribute('class', 'clipboard tooltip');
76-
setTimeout(function(arg1) {
77-
arg1.trigger.setAttribute('class', 'clipboard')
78-
}, 1000, e);
79-
e.clearSelection();
80-
}
81-
);
74+
e.trigger.setAttribute('data-title', 'Translation copied!');
75+
e.trigger.setAttribute('class', 'clipboard tooltip');
76+
setTimeout(function(arg1) {
77+
arg1.trigger.setAttribute('class', 'clipboard');
78+
}, 1000, e);
79+
e.clearSelection();
80+
});

web/js/component_filter.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ $(document).ready(function() {
33
e.preventDefault();
44
$('#filters a').removeClass('selected');
55

6-
var available_searches = [];
6+
var availableSearches = [];
77
$('.results_table').each(function() {
8-
var search_id = $(this).attr('class').split(/\s+/).pop();
9-
available_searches.push(search_id);
8+
var searchID = $(this).attr('class').split(/\s+/).pop();
9+
availableSearches.push(searchID);
1010
});
1111

1212
if (e.target.id === 'showall') {
@@ -21,20 +21,20 @@ $(document).ready(function() {
2121
}
2222

2323
// Update results count
24-
available_searches.forEach(function(search_id) {
25-
var class_name;
26-
class_name = e.target.id === 'showall'
27-
? 'tr.' + search_id
28-
: 'tr.' + search_id + '.' + e.target.id;
24+
availableSearches.forEach(function(searchID) {
25+
var className;
26+
className = e.target.id === 'showall'
27+
? 'tr.' + searchID
28+
: 'tr.' + searchID + '.' + e.target.id;
2929

30-
var results_count = $(class_name).length;
31-
var results_message =
32-
results_count == 1
30+
var resultsCount = $(className).length;
31+
var resultsMessage =
32+
resultsCount === 1
3333
? '1 result'
34-
: results_count + ' results';
34+
: resultsCount + ' results';
3535

36-
$('.results_count_' + search_id).text(results_message);
37-
})
36+
$('.results_count_' + searchID).text(resultsMessage);
37+
});
3838
});
3939

4040
// We want URL anchors to also work as filters

0 commit comments

Comments
 (0)