diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..00e24462 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,16 @@ +{ + "extends": "wikimedia", + "env": { + "browser": true, + "jquery": true, + "qunit": true + }, + "globals": { + "mediaWiki": false, + "OO": false + }, + "rules": { + "dot-notation": 0, + "wrap-iife": 0 + } +} diff --git a/.jsbeautifyrc b/.jsbeautifyrc deleted file mode 100644 index cfa5b279..00000000 --- a/.jsbeautifyrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "preserve_newlines": true, - "jslint_happy": true, - "keep_array_indentation": true, - "space_before_conditional": true, - "max_preserve_newlines": 10, - "brace_style": "collapse", - "keep_function_indentation": false, - "break_chained_methods": false, - "eval_code": false, - "unescape_strings": false, - "wrap_line_length": 0, - "space_in_paren": true, - "git_happy": true, - "indent_with_tabs": true, - "end_with_newline": true -} diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 1959eea8..00000000 --- a/.jscsrc +++ /dev/null @@ -1,21 +0,0 @@ -{ - "preset": "wikimedia", - - "jsDoc": { - "checkAnnotations": { - "preset": "jsduck5", - "extra": { - "this": true, - "source": true, - "see": true - } - }, - "checkTypes": "strictNativeCase", - "checkParamNames": true, - "checkRedundantAccess": true, - "checkRedundantReturns": true, - "requireNewlineAfterDescription": true, - "requireParamTypes": true, - "requireReturnTypes": true - } -} diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index a1bbf645..00000000 --- a/.jshintignore +++ /dev/null @@ -1,5 +0,0 @@ -# upstream libs -lib/* -# Generated file that contains JSON. Would fail "Strings must use singlequote." -resources/js/ext.uls.webfonts.repository.js -vendor/* diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index f2fa9d3f..00000000 --- a/.jshintrc +++ /dev/null @@ -1,26 +0,0 @@ -{ - // Enforcing - "bitwise": true, - "eqeqeq": true, - "freeze": true, - "latedef": "nofunc", - "futurehostile": true, - "noarg": true, - "nonew": true, - "undef": true, - "unused": true, - - "strict": false, - - // Relaxing - - // Environment - "browser": true, - "jquery": true, - - "globals": { - "mediaWiki": false, - "OO": false, - "QUnit": false - } -} diff --git a/Gruntfile.js b/Gruntfile.js index 38a5102c..aa27902a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,19 +1,21 @@ -/*jshint node:true */ +/* eslint-env node */ module.exports = function ( grunt ) { 'use strict'; grunt.loadNpmTasks( 'grunt-banana-checker' ); - grunt.loadNpmTasks( 'grunt-contrib-jshint' ); - grunt.loadNpmTasks( 'grunt-jscs' ); + grunt.loadNpmTasks( 'grunt-eslint' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.loadNpmTasks( 'grunt-stylelint' ); grunt.initConfig( { - jshint: { - options: { - jshintrc: true + eslint: { + fix: { + options: { + fix: true + }, + src: '<%= eslint.main %>' }, - all: [ + main: [ '**/*.js', '!lib/**', '!node_modules/**', @@ -21,9 +23,6 @@ module.exports = function ( grunt ) { '!resources/js/ext.uls.webfonts.repository.js' ] }, - jscs: { - src: '<%= jshint.all %>' - }, stylelint: { options: { syntax: 'less' @@ -48,6 +47,6 @@ module.exports = function ( grunt ) { } } ); - grunt.registerTask( 'test', [ 'jshint', 'jscs', 'stylelint', 'jsonlint', 'banana' ] ); + grunt.registerTask( 'test', [ 'eslint:main', 'stylelint', 'jsonlint', 'banana' ] ); grunt.registerTask( 'default', 'test' ); }; diff --git a/package.json b/package.json index d29dbcc3..0eb05f3b 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "test": "grunt test" }, "devDependencies": { + "eslint-config-wikimedia": "0.2.0", "grunt": "1.0.1", "grunt-banana-checker": "0.5.0", - "grunt-contrib-jshint": "1.0.0", - "grunt-jscs": "2.8.0", - "grunt-jsonlint": "1.0.7", + "grunt-eslint": "19.0.0", + "grunt-jsonlint": "1.1.0", "grunt-stylelint": "0.6.0", "stylelint-config-wikimedia": "0.3.0" } diff --git a/resources/js/ext.uls.common.js b/resources/js/ext.uls.common.js index 0e10fbcb..265e2add 100644 --- a/resources/js/ext.uls.common.js +++ b/resources/js/ext.uls.common.js @@ -132,9 +132,7 @@ }; mw.uls.getCountryCode = function () { - // jscs:disable requireCamelCaseOrUpperCaseIdentifiers return window.Geo && ( window.Geo.country || window.Geo.country_code ); - // jscs:enable requireCamelCaseOrUpperCaseIdentifiers }; mw.uls.getAcceptLanguageList = function () { diff --git a/resources/js/ext.uls.compactlinks.js b/resources/js/ext.uls.compactlinks.js index 4ec13d35..6e1b4b01 100644 --- a/resources/js/ext.uls.compactlinks.js +++ b/resources/js/ext.uls.compactlinks.js @@ -17,6 +17,8 @@ * @licence MIT License */ +/* eslint-disable no-use-before-define */ + ( function ( $, mw ) { 'use strict'; @@ -51,6 +53,9 @@ /** * @class + * @constructor + * @param {string|jQuery} interlanguageList Selector for interlanguage list + * @param {Object} options */ function CompactInterlanguageList( interlanguageList, options ) { this.$interlanguageList = $( interlanguageList ); @@ -289,7 +294,8 @@ * Not all previous languages will be present in interlanguage links, * so we are filtering them. * - * @return {Array} List of language codes supported by the article + * @param {string[]} languages Language codes + * @return {string[]} List of language codes supported by the article */ function filterByPreviousLanguages( languages ) { var previousLanguages = mw.uls.getPreviousLanguages(); @@ -302,7 +308,8 @@ /** * Filter the language list by site picks. * - * @return {Array} List of language codes supported by the article + * @param {string[]} languages Language codes + * @return {string[]} List of language codes supported by the article */ function filterBySitePicks( languages ) { var picks = mw.config.get( 'wgULSCompactLinksPrepend' ) || []; @@ -316,7 +323,8 @@ * Filter the language list by common languages. * Common languages are the most probable languages predicted by ULS. * - * @return {Array} List of language codes supported by the article + * @param {string[]} languages Language codes + * @return {string[]} List of language codes supported by the article */ function filterByCommonLanguages( languages ) { var commonLanguages = mw.uls.getFrequentLanguageList(); @@ -330,12 +338,15 @@ * Filter the language list by globally common languages, i.e. * this list is not user specific. * - * @return {Array} List of language codes supported by the article + * @param {string[]} languages Language codes + * @return {string[]} List of language codes supported by the article */ function getExtraCommonLanguages( languages ) { - var commonLanguages = [ 'zh', 'en', 'hi', 'ur', 'es', 'ar', 'ru', 'id', 'ms', 'pt', - 'fr', 'de', 'bn', 'ja', 'pnb', 'pa', 'jv', 'te', 'ta', 'ko', 'mr', 'tr', 'vi', - 'it', 'fa', 'sv', 'nl', 'pl' ]; + var commonLanguages = [ + 'zh', 'en', 'hi', 'ur', 'es', 'ar', 'ru', 'id', 'ms', 'pt', + 'fr', 'de', 'bn', 'ja', 'pnb', 'pa', 'jv', 'te', 'ta', 'ko', 'mr', 'tr', 'vi', + 'it', 'fa', 'sv', 'nl', 'pl' + ]; return $.grep( commonLanguages, function ( language ) { return $.inArray( language, languages ) >= 0; @@ -346,7 +357,8 @@ * Filter the language list by Translate's assistant languages. * Where available, they're languages deemed useful by the user. * - * @return {Array} List of those language codes which are supported by article + * @param {string[]} languages Language codes + * @return {string[]} List of language codes supported by the article */ function filterByAssistantLanguages( languages ) { var assistantLanguages = mw.user.options.get( 'translate-editlangs' ); @@ -369,7 +381,8 @@ * The reader doesn't necessarily know this language, but it * appears relevant to the page. * - * @return {Array} List of language codes supported by the article + * @param {string[]} languages Language codes + * @return {string[]} List of language codes supported by the article */ CompactInterlanguageList.prototype.filterByLangsInText = function ( languages ) { var languagesInText = []; @@ -440,7 +453,8 @@ /** * Get common languages - the most probable languages predicted by ULS. * - * @param {Array} languages Array of all languages. + * @param {string[]} languages Language codes + * @return {string[]} List of all common language codes */ CompactInterlanguageList.prototype.getCommonLanguages = function ( languages ) { if ( this.commonInterlanguageList === null ) { diff --git a/resources/js/ext.uls.displaysettings.js b/resources/js/ext.uls.displaysettings.js index 8fa8f943..95fc770b 100644 --- a/resources/js/ext.uls.displaysettings.js +++ b/resources/js/ext.uls.displaysettings.js @@ -296,7 +296,7 @@ left: displaySettings.$parent.left, top: displaySettings.$parent.top, onReady: function () { - var $wrap, + var $wrap, uls = this, $back = $( '