Ver código fonte

Add eslint checks to all Oscar JS to the travis build.

master
Samir Shah 7 anos atrás
pai
commit
06b1b5fa73

+ 21
- 0
.eslintrc.json Ver arquivo

@@ -0,0 +1,21 @@
1
+{
2
+    "env": {
3
+        "browser": true
4
+    },
5
+    "extends": "eslint:recommended",
6
+    "rules": {
7
+        "indent": [
8
+            "error",
9
+            4
10
+        ],
11
+        "linebreak-style": [
12
+            "error",
13
+            "unix"
14
+        ],
15
+        "quotes": "off",
16
+        "semi": [
17
+            "error",
18
+            "always"
19
+        ]
20
+    }
21
+}

+ 1748
- 566
package-lock.json
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 6
- 4
package.json Ver arquivo

@@ -1,12 +1,13 @@
1 1
 {
2 2
   "name": "django-oscar",
3
-  "version": "1.1.1",
3
+  "version": "1.6.0",
4 4
   "description": "A domain-driven e-commerce framework for Django",
5 5
   "main": "index.js",
6 6
   "dependencies": {},
7 7
   "devDependencies": {
8 8
     "bootstrap": "^3.3.7",
9 9
     "bootstrap-datetime-picker": "^2.4.4",
10
+    "eslint": "^4.19.1",
10 11
     "gulp": "~3.9.1",
11 12
     "gulp-autoprefixer": "~1.0.1",
12 13
     "gulp-concat": "^2.6.1",
@@ -20,13 +21,14 @@
20 21
     "less": "^2.5.3",
21 22
     "pump": "^1.0.1",
22 23
     "require-dir": "^0.3.0",
23
-    "tinymce": "^4.7.6",
24 24
     "select2": "4.0.5",
25
-    "select2-bootstrap-theme": "0.1.0-beta.10"
25
+    "select2-bootstrap-theme": "0.1.0-beta.10",
26
+    "tinymce": "^4.7.6"
26 27
   },
27 28
   "scripts": {
28 29
     "build": "gulp",
29
-    "start": "gulp watch"
30
+    "start": "gulp watch",
31
+    "eslint": "./node_modules/.bin/eslint src/oscar/static/oscar/js/oscar/"
30 32
   },
31 33
   "license": "MIT",
32 34
   "homepage": "https://github.com/django-oscar/django-oscar#readme"

+ 9
- 8
src/oscar/static/oscar/js/oscar/RelatedObjectLookups.js Ver arquivo

@@ -1,3 +1,4 @@
1
+/*global jQuery,oscar */
1 2
 /*!
2 3
  * Code in this file copied and modified from Django's admin app
3 4
  * Source-code file: django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
@@ -28,11 +29,11 @@
28 29
      * Date: 2017-08-25T12:16:21+03:00
29 30
      */
30 31
     o.interpolate = function(fmt, obj, named) {
31
-      if (named) {
32
-        return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
33
-      } else {
34
-        return fmt.replace(/%s/g, function(match){return String(obj.shift())});
35
-      }
32
+        if (named) {
33
+            return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)]);});
34
+        } else {
35
+            return fmt.replace(/%s/g, function(){return String(obj.shift());});
36
+        }
36 37
     };
37 38
 
38 39
     // IE doesn't accept periods or dashes in the window name, but the element IDs
@@ -41,7 +42,7 @@
41 42
     // element when the popup window is dismissed.
42 43
     o.id_to_windowname = function(text) {
43 44
         text = text.replace(/\./g, '__dot__');
44
-        text = text.replace(/\-/g, '__dash__');
45
+        text = text.replace(/-/g, '__dash__');
45 46
         return text;
46 47
     };
47 48
 
@@ -111,7 +112,7 @@
111 112
             }
112 113
         }).trigger('change');
113 114
         win.close();
114
-    }
115
+    };
115 116
 
116 117
     o.dismissDeleteRelatedObjectPopup = function(win, objId) {
117 118
         var id = o.windowname_to_id(win.name).replace(/^delete_/, '');
@@ -135,7 +136,7 @@
135 136
             }
136 137
         }
137 138
     });
138
-    $('body').on('change', '.related-widget-wrapper select', function(e) {
139
+    $('body').on('change', '.related-widget-wrapper select', function() {
139 140
         var event = $.Event('oscar:update-related');
140 141
         $(this).trigger(event);
141 142
         if (!event.isDefaultPrevented()) {

+ 61
- 59
src/oscar/static/oscar/js/oscar/dashboard.js Ver arquivo

@@ -1,3 +1,5 @@
1
+/*global jQuery */
2
+
1 3
 var oscar = (function(o, $) {
2 4
 
3 5
     o.getCsrfToken = function() {
@@ -5,7 +7,7 @@ var oscar = (function(o, $) {
5 7
         var cookies = document.cookie.split(';');
6 8
         var csrf_token = null;
7 9
         $.each(cookies, function(index, cookie) {
8
-            cookieParts = $.trim(cookie).split('=');
10
+            var cookieParts = $.trim(cookie).split('=');
9 11
             if (cookieParts[0] == 'csrftoken') {
10 12
                 csrf_token = cookieParts[1];
11 13
             }
@@ -47,7 +49,7 @@ var oscar = (function(o, $) {
47 49
 
48 50
             $(".category-select ul").prev('a').on('click', function(){
49 51
                 var $this = $(this),
50
-                plus = $this.hasClass('ico_expand');
52
+                    plus = $this.hasClass('ico_expand');
51 53
                 if (plus) {
52 54
                     $this.removeClass('ico_expand').addClass('ico_contract');
53 55
                 } else {
@@ -58,8 +60,8 @@ var oscar = (function(o, $) {
58 60
 
59 61
             // Adds error icon if there are errors in the product update form
60 62
             $('[data-behaviour="affix-nav-errors"] .tab-pane').each(function(){
61
-              var productErrorListener = $(this).find('[class*="error"]:not(:empty)').closest('.tab-pane').attr('id');
62
-              $('[data-spy="affix"] a[href="#' + productErrorListener + '"]').append('<i class="icon-info-sign pull-right"></i>');
63
+                var productErrorListener = $(this).find('[class*="error"]:not(:empty)').closest('.tab-pane').attr('id');
64
+                $('[data-spy="affix"] a[href="#' + productErrorListener + '"]').append('<i class="icon-info-sign pull-right"></i>');
63 65
             });
64 66
 
65 67
             o.dashboard.filereader.init();
@@ -82,7 +84,7 @@ var oscar = (function(o, $) {
82 84
             o.dashboard.initSelects(el);
83 85
         },
84 86
         initMasks: function(el) {
85
-            $(el).find(':input').inputmask()
87
+            $(el).find(':input').inputmask();
86 88
         },
87 89
         initSelects: function(el) {
88 90
             // Adds type/search for select fields
@@ -118,7 +120,7 @@ var oscar = (function(o, $) {
118 120
                     'language': o.dashboard.options.languageCode,
119 121
                     'minView': 2
120 122
                 };
121
-                $dates = $(el).find('[data-oscarWidget="date"]').not('.no-widget-init').not('.no-widget-init *')
123
+                var $dates = $(el).find('[data-oscarWidget="date"]').not('.no-widget-init').not('.no-widget-init *');
122 124
                 $dates.each(function(ind, ele) {
123 125
                     var $ele = $(ele),
124 126
                         config = $.extend({}, defaultDatepickerConfig, {
@@ -134,12 +136,12 @@ var oscar = (function(o, $) {
134 136
                     'language': o.dashboard.options.languageCode,
135 137
                     'initialDate': o.dashboard.options.initialDate
136 138
                 };
137
-                $datetimes = $(el).find('[data-oscarWidget="datetime"]').not('.no-widget-init').not('.no-widget-init *')
139
+                var $datetimes = $(el).find('[data-oscarWidget="datetime"]').not('.no-widget-init').not('.no-widget-init *');
138 140
                 $datetimes.each(function(ind, ele) {
139 141
                     var $ele = $(ele),
140 142
                         config = $.extend({}, defaultDatetimepickerConfig, {
141
-                          'format': $ele.data('datetimeformat'),
142
-                          'minuteStep': $ele.data('stepminute')
143
+                            'format': $ele.data('datetimeformat'),
144
+                            'minuteStep': $ele.data('stepminute')
143 145
                         });
144 146
                     $ele.datetimepicker(config);
145 147
                 });
@@ -151,15 +153,15 @@ var oscar = (function(o, $) {
151 153
                     'language': o.dashboard.options.languageCode,
152 154
                     'initialDate': o.dashboard.options.initialDate
153 155
                 };
154
-                $times = $(el).find('[data-oscarWidget="time"]').not('.no-widget-init').not('.no-widget-init *')
156
+                var $times = $(el).find('[data-oscarWidget="time"]').not('.no-widget-init').not('.no-widget-init *');
155 157
                 $times.each(function(ind, ele) {
156 158
                     var $ele = $(ele),
157 159
                         config = $.extend({}, defaultTimepickerConfig, {
158
-                          'format': $ele.data('timeformat'),
159
-                          'minuteStep': $ele.data('stepminute'),
160
-                          'startView': 1,
161
-                          'maxView': 1,
162
-                          'formatViewType': 'time'
160
+                            'format': $ele.data('timeformat'),
161
+                            'minuteStep': $ele.data('stepminute'),
162
+                            'startView': 1,
163
+                            'maxView': 1,
164
+                            'formatViewType': 'time'
163 165
                         });
164 166
                     $ele.datetimepicker(config);
165 167
                 });
@@ -167,7 +169,7 @@ var oscar = (function(o, $) {
167 169
         },
168 170
         initWYSIWYG: function(el) {
169 171
             // Use TinyMCE by default
170
-            $textareas = $(el).find('textarea').not('.no-widget-init textarea').not('.no-widget-init');
172
+            var $textareas = $(el).find('textarea').not('.no-widget-init textarea').not('.no-widget-init');
171 173
             $textareas.filter('form.wysiwyg textarea').tinymce(o.dashboard.options.tinyConfig);
172 174
             $textareas.filter('.wysiwyg').tinymce(o.dashboard.options.tinyConfig);
173 175
         },
@@ -205,11 +207,11 @@ var oscar = (function(o, $) {
205 207
             init: function(){
206 208
                 var type_selects = $("select[name$=type]");
207 209
 
208
-                type_selects.each(function(index){
210
+                type_selects.each(function(){
209 211
                     o.dashboard.product_attributes.toggleOptionGroup($(this));
210 212
                 });
211 213
 
212
-                type_selects.change(function(e){
214
+                type_selects.change(function(){
213 215
                     o.dashboard.product_attributes.toggleOptionGroup($(this));
214 216
                 });
215 217
             },
@@ -223,7 +225,7 @@ var oscar = (function(o, $) {
223 225
         ranges: {
224 226
             init: function() {
225 227
                 $('[data-behaviours~="remove"]').click(function() {
226
-                    $this = $(this);
228
+                    var $this = $(this);
227 229
                     $this.parents('table').find('input').prop('checked', false);
228 230
                     $this.parents('tr').find('input').prop('checked', true);
229 231
                     $this.parents('form').submit();
@@ -252,48 +254,48 @@ var oscar = (function(o, $) {
252 254
         },
253 255
         reordering: (function() {
254 256
             var options = {
255
-                handle: '.btn-handle',
256
-                submit_url: '#'
257
-            },
258
-            saveOrder = function(data) {
257
+                    handle: '.btn-handle',
258
+                    submit_url: '#'
259
+                },
260
+                saveOrder = function(data) {
259 261
                 // Get the csrf token, otherwise django will not accept the
260 262
                 // POST request.
261
-                var csrf = o.getCsrfToken();
262
-                $.ajax({
263
-                    type: 'POST',
264
-                    data: $.param(data),
265
-                    dataType: "json",
266
-                    url: options.submit_url,
267
-                    beforeSend: function(xhr, settings) {
268
-                        xhr.setRequestHeader("X-CSRFToken", csrf);
269
-                    }
270
-                });
271
-            },
272
-            init = function(user_options) {
273
-                options = $.extend(options, user_options);
274
-                var group = $(options.wrapper).sortable({
275
-                    group: 'serialization',
276
-                    containerSelector: 'tbody',
277
-                    itemSelector: 'tr',
278
-                    handle: options.handle,
279
-                    vertical: true,
280
-                    onDrop: function ($item, container, _super) {
281
-                        var data = group.sortable("serialize");
282
-                        saveOrder(data);
283
-                        _super($item, container);
284
-                    },
285
-                    placeholder: '<tr class="placeholder"/>',
286
-                    serialize: function (parent, children, isContainer) {
287
-                        if (isContainer) {
288
-                            return children;
263
+                    var csrf = o.getCsrfToken();
264
+                    $.ajax({
265
+                        type: 'POST',
266
+                        data: $.param(data),
267
+                        dataType: "json",
268
+                        url: options.submit_url,
269
+                        beforeSend: function(xhr) {
270
+                            xhr.setRequestHeader("X-CSRFToken", csrf);
289 271
                         }
290
-                        else {
291
-                            var parts = parent.attr('id').split('_');
292
-                            return {'name': parts[0], 'value': parts[1]};
272
+                    });
273
+                },
274
+                init = function(user_options) {
275
+                    options = $.extend(options, user_options);
276
+                    var group = $(options.wrapper).sortable({
277
+                        group: 'serialization',
278
+                        containerSelector: 'tbody',
279
+                        itemSelector: 'tr',
280
+                        handle: options.handle,
281
+                        vertical: true,
282
+                        onDrop: function ($item, container, _super) {
283
+                            var data = group.sortable("serialize");
284
+                            saveOrder(data);
285
+                            _super($item, container);
286
+                        },
287
+                        placeholder: '<tr class="placeholder"/>',
288
+                        serialize: function (parent, children, isContainer) {
289
+                            if (isContainer) {
290
+                                return children;
291
+                            }
292
+                            else {
293
+                                var parts = parent.attr('id').split('_');
294
+                                return {'name': parts[0], 'value': parts[1]};
295
+                            }
293 296
                         }
294
-                    }
295
-                });
296
-            };
297
+                    });
298
+                };
297 299
 
298 300
             return {
299 301
                 init: init,
@@ -305,7 +307,7 @@ var oscar = (function(o, $) {
305 307
                 var searchForm = $(".orders_search"),
306 308
                     searchLink = $('.pull_out'),
307 309
                     doc = $('document');
308
-                searchForm.each(function(index) {
310
+                searchForm.each(function() {
309 311
                     doc.css('height', doc.height());
310 312
                 });
311 313
                 searchLink.on('click', function() {
@@ -314,7 +316,7 @@ var oscar = (function(o, $) {
314 316
                         .toggleClass('no-float')
315 317
                         .end().end()
316 318
                         .slideToggle("fast");
317
-                    }
319
+                }
318 320
                 );
319 321
             }
320 322
         },

+ 16
- 14
src/oscar/static/oscar/js/oscar/ui.js Ver arquivo

@@ -1,3 +1,5 @@
1
+/*global jQuery */
2
+
1 3
 var oscar = (function(o, $) {
2 4
     // Replicate Django's flash messages so they can be used by AJAX callbacks.
3 5
     o.messages = {
@@ -82,19 +84,19 @@ var oscar = (function(o, $) {
82 84
             });
83 85
             // stuff for star rating on review page
84 86
             // show clickable stars instead of a select dropdown for product rating
85
-            ratings = $('.reviewrating');
87
+            var ratings = $('.reviewrating');
86 88
             if(ratings.length){
87 89
                 ratings.find('.star-rating i').on('click',o.forms.reviewRatingClick);
88 90
             }
89 91
         },
90
-        submitIfNotLocked: function(event) {
92
+        submitIfNotLocked: function() {
91 93
             var $form = $(this);
92 94
             if ($form.data('locked')) {
93 95
                 return false;
94 96
             }
95 97
             $form.data('locked', true);
96 98
         },
97
-        reviewRatingClick: function(event){
99
+        reviewRatingClick: function(){
98 100
             var ratings = ['One','Two','Three','Four','Five']; //possible classes for display state
99 101
             $(this).parent().removeClass('One Two Three Four Five').addClass(ratings[$(this).index()]);
100 102
             $(this).closest('.controls').find('select').val($(this).index() + 1); //select is hidden, set value
@@ -182,7 +184,7 @@ var oscar = (function(o, $) {
182 184
                 o.basket.checkAndSubmit($(this), 'form', 'save_for_later');
183 185
                 event.preventDefault();
184 186
             });
185
-            $('#content_inner').on('click', '#saved_basket_formset a[data-behaviours~="move"]', function(event) {
187
+            $('#content_inner').on('click', '#saved_basket_formset a[data-behaviours~="move"]', function() {
186 188
                 o.basket.checkAndSubmit($(this), 'saved', 'move_to_basket');
187 189
             });
188 190
             $('#content_inner').on('click', '#saved_basket_formset a[data-behaviours~="remove"]', function(event) {
@@ -285,7 +287,7 @@ var oscar = (function(o, $) {
285 287
                     'language': o.datetimepickers.options.languageCode,
286 288
                     'minView': 2
287 289
                 };
288
-                $dates = $(el).find('[data-oscarWidget="date"]').not('.no-widget-init').not('.no-widget-init *');
290
+                var $dates = $(el).find('[data-oscarWidget="date"]').not('.no-widget-init').not('.no-widget-init *');
289 291
                 $dates.each(function(ind, ele) {
290 292
                     var $ele = $(ele),
291 293
                         config = $.extend({}, defaultDatepickerConfig, {
@@ -300,12 +302,12 @@ var oscar = (function(o, $) {
300 302
                     'autoclose': true,
301 303
                     'language': o.datetimepickers.options.languageCode
302 304
                 };
303
-                $datetimes = $(el).find('[data-oscarWidget="datetime"]').not('.no-widget-init').not('.no-widget-init *');
305
+                var $datetimes = $(el).find('[data-oscarWidget="datetime"]').not('.no-widget-init').not('.no-widget-init *');
304 306
                 $datetimes.each(function(ind, ele) {
305 307
                     var $ele = $(ele),
306 308
                         config = $.extend({}, defaultDatetimepickerConfig, {
307
-                          'format': $ele.data('datetimeformat'),
308
-                          'minuteStep': $ele.data('stepminute')
309
+                            'format': $ele.data('datetimeformat'),
310
+                            'minuteStep': $ele.data('stepminute')
309 311
                         });
310 312
                     $ele.datetimepicker(config);
311 313
                 });
@@ -316,15 +318,15 @@ var oscar = (function(o, $) {
316 318
                     'autoclose': true,
317 319
                     'language': o.datetimepickers.options.languageCode
318 320
                 };
319
-                $times = $(el).find('[data-oscarWidget="time"]').not('.no-widget-init').not('.no-widget-init *')
321
+                var $times = $(el).find('[data-oscarWidget="time"]').not('.no-widget-init').not('.no-widget-init *');
320 322
                 $times.each(function(ind, ele) {
321 323
                     var $ele = $(ele),
322 324
                         config = $.extend({}, defaultTimepickerConfig, {
323
-                          'format': $ele.data('timeformat'),
324
-                          'minuteStep': $ele.data('stepminute'),
325
-                          'startView': 1,
326
-                          'maxView': 1,
327
-                          'formatViewType': 'time'
325
+                            'format': $ele.data('timeformat'),
326
+                            'minuteStep': $ele.data('stepminute'),
327
+                            'startView': 1,
328
+                            'maxView': 1,
329
+                            'formatViewType': 'time'
328 330
                         });
329 331
                     $ele.datetimepicker(config);
330 332
                 });

+ 2
- 0
tox.ini Ver arquivo

@@ -37,8 +37,10 @@ deps =
37 37
     flake8
38 38
     isort
39 39
 commands =
40
+    npm install
40 41
     flake8 src tests setup.py
41 42
     isort -q --recursive --diff src/ tests/
43
+    npm run eslint
42 44
     django-admin.py compilemessages
43 45
 
44 46
 

Carregando…
Cancelar
Salvar