瀏覽代碼

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

master
Samir Shah 7 年之前
父節點
當前提交
06b1b5fa73

+ 21
- 0
.eslintrc.json 查看文件

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
文件差異過大導致無法顯示
查看文件


+ 6
- 4
package.json 查看文件

1
 {
1
 {
2
   "name": "django-oscar",
2
   "name": "django-oscar",
3
-  "version": "1.1.1",
3
+  "version": "1.6.0",
4
   "description": "A domain-driven e-commerce framework for Django",
4
   "description": "A domain-driven e-commerce framework for Django",
5
   "main": "index.js",
5
   "main": "index.js",
6
   "dependencies": {},
6
   "dependencies": {},
7
   "devDependencies": {
7
   "devDependencies": {
8
     "bootstrap": "^3.3.7",
8
     "bootstrap": "^3.3.7",
9
     "bootstrap-datetime-picker": "^2.4.4",
9
     "bootstrap-datetime-picker": "^2.4.4",
10
+    "eslint": "^4.19.1",
10
     "gulp": "~3.9.1",
11
     "gulp": "~3.9.1",
11
     "gulp-autoprefixer": "~1.0.1",
12
     "gulp-autoprefixer": "~1.0.1",
12
     "gulp-concat": "^2.6.1",
13
     "gulp-concat": "^2.6.1",
20
     "less": "^2.5.3",
21
     "less": "^2.5.3",
21
     "pump": "^1.0.1",
22
     "pump": "^1.0.1",
22
     "require-dir": "^0.3.0",
23
     "require-dir": "^0.3.0",
23
-    "tinymce": "^4.7.6",
24
     "select2": "4.0.5",
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
   "scripts": {
28
   "scripts": {
28
     "build": "gulp",
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
   "license": "MIT",
33
   "license": "MIT",
32
   "homepage": "https://github.com/django-oscar/django-oscar#readme"
34
   "homepage": "https://github.com/django-oscar/django-oscar#readme"

+ 9
- 8
src/oscar/static/oscar/js/oscar/RelatedObjectLookups.js 查看文件

1
+/*global jQuery,oscar */
1
 /*!
2
 /*!
2
  * Code in this file copied and modified from Django's admin app
3
  * Code in this file copied and modified from Django's admin app
3
  * Source-code file: django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
4
  * Source-code file: django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
28
      * Date: 2017-08-25T12:16:21+03:00
29
      * Date: 2017-08-25T12:16:21+03:00
29
      */
30
      */
30
     o.interpolate = function(fmt, obj, named) {
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
     // IE doesn't accept periods or dashes in the window name, but the element IDs
39
     // IE doesn't accept periods or dashes in the window name, but the element IDs
41
     // element when the popup window is dismissed.
42
     // element when the popup window is dismissed.
42
     o.id_to_windowname = function(text) {
43
     o.id_to_windowname = function(text) {
43
         text = text.replace(/\./g, '__dot__');
44
         text = text.replace(/\./g, '__dot__');
44
-        text = text.replace(/\-/g, '__dash__');
45
+        text = text.replace(/-/g, '__dash__');
45
         return text;
46
         return text;
46
     };
47
     };
47
 
48
 
111
             }
112
             }
112
         }).trigger('change');
113
         }).trigger('change');
113
         win.close();
114
         win.close();
114
-    }
115
+    };
115
 
116
 
116
     o.dismissDeleteRelatedObjectPopup = function(win, objId) {
117
     o.dismissDeleteRelatedObjectPopup = function(win, objId) {
117
         var id = o.windowname_to_id(win.name).replace(/^delete_/, '');
118
         var id = o.windowname_to_id(win.name).replace(/^delete_/, '');
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
         var event = $.Event('oscar:update-related');
140
         var event = $.Event('oscar:update-related');
140
         $(this).trigger(event);
141
         $(this).trigger(event);
141
         if (!event.isDefaultPrevented()) {
142
         if (!event.isDefaultPrevented()) {

+ 61
- 59
src/oscar/static/oscar/js/oscar/dashboard.js 查看文件

1
+/*global jQuery */
2
+
1
 var oscar = (function(o, $) {
3
 var oscar = (function(o, $) {
2
 
4
 
3
     o.getCsrfToken = function() {
5
     o.getCsrfToken = function() {
5
         var cookies = document.cookie.split(';');
7
         var cookies = document.cookie.split(';');
6
         var csrf_token = null;
8
         var csrf_token = null;
7
         $.each(cookies, function(index, cookie) {
9
         $.each(cookies, function(index, cookie) {
8
-            cookieParts = $.trim(cookie).split('=');
10
+            var cookieParts = $.trim(cookie).split('=');
9
             if (cookieParts[0] == 'csrftoken') {
11
             if (cookieParts[0] == 'csrftoken') {
10
                 csrf_token = cookieParts[1];
12
                 csrf_token = cookieParts[1];
11
             }
13
             }
47
 
49
 
48
             $(".category-select ul").prev('a').on('click', function(){
50
             $(".category-select ul").prev('a').on('click', function(){
49
                 var $this = $(this),
51
                 var $this = $(this),
50
-                plus = $this.hasClass('ico_expand');
52
+                    plus = $this.hasClass('ico_expand');
51
                 if (plus) {
53
                 if (plus) {
52
                     $this.removeClass('ico_expand').addClass('ico_contract');
54
                     $this.removeClass('ico_expand').addClass('ico_contract');
53
                 } else {
55
                 } else {
58
 
60
 
59
             // Adds error icon if there are errors in the product update form
61
             // Adds error icon if there are errors in the product update form
60
             $('[data-behaviour="affix-nav-errors"] .tab-pane').each(function(){
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
             o.dashboard.filereader.init();
67
             o.dashboard.filereader.init();
82
             o.dashboard.initSelects(el);
84
             o.dashboard.initSelects(el);
83
         },
85
         },
84
         initMasks: function(el) {
86
         initMasks: function(el) {
85
-            $(el).find(':input').inputmask()
87
+            $(el).find(':input').inputmask();
86
         },
88
         },
87
         initSelects: function(el) {
89
         initSelects: function(el) {
88
             // Adds type/search for select fields
90
             // Adds type/search for select fields
118
                     'language': o.dashboard.options.languageCode,
120
                     'language': o.dashboard.options.languageCode,
119
                     'minView': 2
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
                 $dates.each(function(ind, ele) {
124
                 $dates.each(function(ind, ele) {
123
                     var $ele = $(ele),
125
                     var $ele = $(ele),
124
                         config = $.extend({}, defaultDatepickerConfig, {
126
                         config = $.extend({}, defaultDatepickerConfig, {
134
                     'language': o.dashboard.options.languageCode,
136
                     'language': o.dashboard.options.languageCode,
135
                     'initialDate': o.dashboard.options.initialDate
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
                 $datetimes.each(function(ind, ele) {
140
                 $datetimes.each(function(ind, ele) {
139
                     var $ele = $(ele),
141
                     var $ele = $(ele),
140
                         config = $.extend({}, defaultDatetimepickerConfig, {
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
                     $ele.datetimepicker(config);
146
                     $ele.datetimepicker(config);
145
                 });
147
                 });
151
                     'language': o.dashboard.options.languageCode,
153
                     'language': o.dashboard.options.languageCode,
152
                     'initialDate': o.dashboard.options.initialDate
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
                 $times.each(function(ind, ele) {
157
                 $times.each(function(ind, ele) {
156
                     var $ele = $(ele),
158
                     var $ele = $(ele),
157
                         config = $.extend({}, defaultTimepickerConfig, {
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
                     $ele.datetimepicker(config);
166
                     $ele.datetimepicker(config);
165
                 });
167
                 });
167
         },
169
         },
168
         initWYSIWYG: function(el) {
170
         initWYSIWYG: function(el) {
169
             // Use TinyMCE by default
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
             $textareas.filter('form.wysiwyg textarea').tinymce(o.dashboard.options.tinyConfig);
173
             $textareas.filter('form.wysiwyg textarea').tinymce(o.dashboard.options.tinyConfig);
172
             $textareas.filter('.wysiwyg').tinymce(o.dashboard.options.tinyConfig);
174
             $textareas.filter('.wysiwyg').tinymce(o.dashboard.options.tinyConfig);
173
         },
175
         },
205
             init: function(){
207
             init: function(){
206
                 var type_selects = $("select[name$=type]");
208
                 var type_selects = $("select[name$=type]");
207
 
209
 
208
-                type_selects.each(function(index){
210
+                type_selects.each(function(){
209
                     o.dashboard.product_attributes.toggleOptionGroup($(this));
211
                     o.dashboard.product_attributes.toggleOptionGroup($(this));
210
                 });
212
                 });
211
 
213
 
212
-                type_selects.change(function(e){
214
+                type_selects.change(function(){
213
                     o.dashboard.product_attributes.toggleOptionGroup($(this));
215
                     o.dashboard.product_attributes.toggleOptionGroup($(this));
214
                 });
216
                 });
215
             },
217
             },
223
         ranges: {
225
         ranges: {
224
             init: function() {
226
             init: function() {
225
                 $('[data-behaviours~="remove"]').click(function() {
227
                 $('[data-behaviours~="remove"]').click(function() {
226
-                    $this = $(this);
228
+                    var $this = $(this);
227
                     $this.parents('table').find('input').prop('checked', false);
229
                     $this.parents('table').find('input').prop('checked', false);
228
                     $this.parents('tr').find('input').prop('checked', true);
230
                     $this.parents('tr').find('input').prop('checked', true);
229
                     $this.parents('form').submit();
231
                     $this.parents('form').submit();
252
         },
254
         },
253
         reordering: (function() {
255
         reordering: (function() {
254
             var options = {
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
                 // Get the csrf token, otherwise django will not accept the
261
                 // Get the csrf token, otherwise django will not accept the
260
                 // POST request.
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
             return {
300
             return {
299
                 init: init,
301
                 init: init,
305
                 var searchForm = $(".orders_search"),
307
                 var searchForm = $(".orders_search"),
306
                     searchLink = $('.pull_out'),
308
                     searchLink = $('.pull_out'),
307
                     doc = $('document');
309
                     doc = $('document');
308
-                searchForm.each(function(index) {
310
+                searchForm.each(function() {
309
                     doc.css('height', doc.height());
311
                     doc.css('height', doc.height());
310
                 });
312
                 });
311
                 searchLink.on('click', function() {
313
                 searchLink.on('click', function() {
314
                         .toggleClass('no-float')
316
                         .toggleClass('no-float')
315
                         .end().end()
317
                         .end().end()
316
                         .slideToggle("fast");
318
                         .slideToggle("fast");
317
-                    }
319
+                }
318
                 );
320
                 );
319
             }
321
             }
320
         },
322
         },

+ 16
- 14
src/oscar/static/oscar/js/oscar/ui.js 查看文件

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

+ 2
- 0
tox.ini 查看文件

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

Loading…
取消
儲存