Jforrester has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/374401 )
Change subject: build: Replace jshint and jscs with eslint; bump everything else
......................................................................
build: Replace jshint and jscs with eslint; bump everything else
grunt-banana-checker 0.4.0 → 0.6.0
grunt-jsonlint 1.0.4 → 1.1.0
grunt-stylelint ^0.7.0 → 0.8.0
Change-Id: I331b05e963d8b61296f3633b409b914ee2399d38
---
A .eslintrc.json
D .jscsrc
D .jshintignore
D .jshintrc
M Gruntfile.js
M modules/ext.wikispeech.js
M package.json
A tests/qunit/.eslintrc.json
M tests/qunit/ext.wikispeech.highlighter.test.js
M tests/qunit/ext.wikispeech.test.js
10 files changed, 83 insertions(+), 112 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech
refs/changes/01/374401/1
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..3931182
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,11 @@
+{
+ "extends": "wikimedia",
+ "env": {
+ "browser": true,
+ "jquery": true
+ },
+ "globals": {
+ "mediaWiki": false
+ },
+ "rules": {}
+}
diff --git a/.jscsrc b/.jscsrc
deleted file mode 100644
index a031ea4..0000000
--- a/.jscsrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "preset": "wikimedia"
-}
\ No newline at end of file
diff --git a/.jshintignore b/.jshintignore
deleted file mode 100644
index b512c09..0000000
--- a/.jshintignore
+++ /dev/null
@@ -1 +0,0 @@
-node_modules
\ No newline at end of file
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 95facb2..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "predef": [
- "mediaWiki",
- "jQuery",
- "QUnit",
- "sinon",
- "JSON"
- ],
-
- // Enforcing
- "bitwise": true,
- "eqeqeq": true,
- "es3": true,
- "latedef": true,
- "noarg": true,
- "nonew": true,
- "undef": true,
- "unused": true,
- "strict": false,
-
- // Environment
- "browser": true,
-
- "globals": {
- "mw": false,
- "$": false
- }
-}
diff --git a/Gruntfile.js b/Gruntfile.js
index f2d6f3b..1ded3a3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,27 +1,19 @@
-/*jshint node:true */
+/* eslint-env node, es6 */
module.exports = function ( grunt ) {
var conf = grunt.file.readJSON( 'extension.json' );
- grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+ grunt.loadNpmTasks( 'grunt-eslint' );
+ grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
- grunt.loadNpmTasks( 'grunt-jscs' );
- grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.initConfig( {
- jshint: {
- options: {
- jshintrc: true
- },
+ eslint: {
all: [
'*.js',
'modules/**/*.js',
'tests/**/*.js'
]
},
- jscs: {
- src: '<%= jshint.all %>'
- },
- banana: conf.MessagesDirs,
jsonlint: {
all: [
'*.json',
@@ -30,6 +22,7 @@
'!vendor/**'
]
},
+ banana: conf.MessagesDirs,
stylelint: {
options: {
formatter: 'string',
@@ -46,8 +39,7 @@
grunt.registerTask(
'test',
[
- 'jshint',
- 'jscs',
+ 'eslint',
'jsonlint',
'banana',
'stylelint'
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 065399d..5380360 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -697,11 +697,10 @@
url: serverUrl,
method: 'POST',
data: {
- // jscs:disable
requireCamelCaseOrUpperCaseIdentifiers
lang: mw.config.get(
'wgPageContentLanguage' ),
+ // eslint-disable-next-line camelcase
input_type: 'text',
input: text
- // jscs:enable
requireCamelCaseOrUpperCaseIdentifiers
},
dataType: 'json',
beforeSend: function ( jqXHR, settings ) {
diff --git a/package.json b/package.json
index 96800d8..40c15f1 100644
--- a/package.json
+++ b/package.json
@@ -7,14 +7,14 @@
"test": "grunt test"
},
"devDependencies": {
+ "eslint-config-wikimedia": "0.5.0",
+ "grunt-eslint": "20.0.0",
"grunt": "1.0.1",
- "grunt-banana-checker": "0.4.0",
- "grunt-contrib-jshint": "0.11.3",
- "grunt-jscs": "2.1.0",
- "grunt-jsonlint": "1.0.4",
- "grunt-stylelint": "^0.7.0",
+ "grunt-banana-checker": "0.6.0",
+ "grunt-jsonlint": "1.1.0",
+ "grunt-stylelint": "0.8.0",
"qunitjs": "1.23.1",
"stylelint": "7.8.0",
- "stylelint-config-wikimedia": "^0.4.1"
+ "stylelint-config-wikimedia": "0.4.1"
}
}
diff --git a/tests/qunit/.eslintrc.json b/tests/qunit/.eslintrc.json
new file mode 100644
index 0000000..e74d833
--- /dev/null
+++ b/tests/qunit/.eslintrc.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../../.eslintrc.json",
+ "env": {
+ "qunit": true
+ },
+ "globals": {
+ "sinon": false
+ },
+ "rules": {}
+}
diff --git a/tests/qunit/ext.wikispeech.highlighter.test.js
b/tests/qunit/ext.wikispeech.highlighter.test.js
index 2c0c23a..bef08dd 100644
--- a/tests/qunit/ext.wikispeech.highlighter.test.js
+++ b/tests/qunit/ext.wikispeech.highlighter.test.js
@@ -356,4 +356,4 @@
'Utterance <b>zero</b>. <span
class="ext-wikispeech-highlight-sentence"><span
class="ext-wikispeech-highlight-word">Utterance</span> one.</span>'
);
} );
-} )( mediaWiki, jQuery );
+}( mediaWiki, jQuery ) );
diff --git a/tests/qunit/ext.wikispeech.test.js
b/tests/qunit/ext.wikispeech.test.js
index 5dc49b4..32454ca 100644
--- a/tests/qunit/ext.wikispeech.test.js
+++ b/tests/qunit/ext.wikispeech.test.js
@@ -114,9 +114,7 @@
);
} );
- // jscs:disable validateQuoteMarks
- QUnit.test( "prepareUtterance(): don't request if waiting for
response", function ( assert ) {
- // jscs:enable validateQuoteMarks
+ QUnit.test( 'prepareUtterance(): do not request if waiting for
response', function ( assert ) {
assert.expect( 1 );
sinon.spy( mw.wikispeech.wikispeech, 'loadAudio' );
utterances[ 0 ].waitingForResponse = true;
@@ -129,9 +127,7 @@
);
} );
- // jscs:disable validateQuoteMarks
- QUnit.test( "prepareUtterance(): don't load audio if already loaded",
function ( assert ) {
- // jscs:enable validateQuoteMarks
+ QUnit.test( 'prepareUtterance(): do not load audio if already loaded',
function ( assert ) {
assert.expect( 1 );
utterances[ 0 ].audio = $( '<audio></audio>' )
.attr( 'src', 'http://server.url/audio' );
@@ -160,9 +156,7 @@
);
} );
- // jscs:disable validateQuoteMarks
- QUnit.test( "prepareUtterance(): don't prepare next audio if it doesn't
exist", function ( assert ) {
- // jscs:enable validateQuoteMarks
+ QUnit.test( 'prepareUtterance(): do not prepare next audio if it does
not exist', function ( assert ) {
assert.expect( 1 );
sinon.spy( mw.wikispeech.wikispeech, 'prepareUtterance' );
mw.wikispeech.wikispeech.prepareUtterance( utterances[ 1 ] );
@@ -356,23 +350,14 @@
);
} );
- QUnit.test( 'Clicking play/stop button', function ( assert ) {
- testClickButton(
- assert,
- 'playOrStop',
- '#ext-wikispeech-play-stop-button'
- );
- } );
-
/**
* Test that clicking a button calls the correct function.
*
* @param {QUnit.assert} assert
* @param {string} functionName Name of the function that should
* be called.
- * @param {string} buttonId Id of the button that is clicked.
+ * @param {string} buttonSelector Id of the button that is clicked.
*/
-
function testClickButton( assert, functionName, buttonSelector ) {
assert.expect( 1 );
sinon.stub( mw.wikispeech.wikispeech, functionName );
@@ -385,6 +370,14 @@
true
);
}
+
+ QUnit.test( 'Clicking play/stop button', function ( assert ) {
+ testClickButton(
+ assert,
+ 'playOrStop',
+ '#ext-wikispeech-play-stop-button'
+ );
+ } );
QUnit.test( 'Clicking skip ahead sentence button', function ( assert ) {
testClickButton(
@@ -431,9 +424,23 @@
assert.strictEqual( mw.wikispeech.wikispeech.stop.called, true
);
} );
- QUnit.test( 'Pressing keyboard shortcut for play/stop', function (
assert ) {
- testKeyboardShortcut( assert, 'playOrStop', 32, 'c' );
- } );
+ /**
+ * Create a keydown event.
+ *
+ * @param {number} keyCode The key code for the event.
+ * @param {string} modifiers A string that defines the
+ * modifiers. The characters c, a and s triggers the modifiers
+ * for ctrl, alt and shift, respectively.
+ * @return {jQuery} The created keydown event.
+ */
+ function createKeydownEvent( keyCode, modifiers ) {
+ var event = $.Event( 'keydown' );
+ event.which = keyCode;
+ event.ctrlKey = modifiers.indexOf( 'c' ) >= 0;
+ event.altKey = modifiers.indexOf( 'a' ) >= 0;
+ event.shiftKey = modifiers.indexOf( 's' ) >= 0;
+ return event;
+ }
/**
* Test that a keyboard event triggers the correct function.
@@ -446,7 +453,6 @@
* modifiers. The characters c, a and s triggers the modifiers
* for ctrl, alt and shift, respectively.
*/
-
function testKeyboardShortcut( assert, functionName, keyCode, modifiers
) {
assert.expect( 1 );
utterances[ 0 ].audio = $( '<audio></audio>' ).get( 0 );
@@ -461,24 +467,9 @@
assert.strictEqual( mw.wikispeech.wikispeech[ functionName
].called, true );
}
- /**
- * Create a keydown event.
- *
- * @param {number} keyCode The key code for the event.
- * @param {string} modifiers A string that defines the
- * modifiers. The characters c, a and s triggers the modifiers
- * for ctrl, alt and shift, respectively.
- * @return {jQuery} The created keydown event.
- */
-
- function createKeydownEvent( keyCode, modifiers ) {
- var event = $.Event( 'keydown' );
- event.which = keyCode;
- event.ctrlKey = modifiers.indexOf( 'c' ) >= 0;
- event.altKey = modifiers.indexOf( 'a' ) >= 0;
- event.shiftKey = modifiers.indexOf( 's' ) >= 0;
- return event;
- }
+ QUnit.test( 'Pressing keyboard shortcut for play/stop', function (
assert ) {
+ testKeyboardShortcut( assert, 'playOrStop', 32, 'c' );
+ } );
QUnit.test( 'Pressing keyboard shortcut for skipping ahead sentence',
function ( assert ) {
testKeyboardShortcut( assert, 'skipAheadUtterance', 39, 'c' );
@@ -640,6 +631,20 @@
assert.strictEqual( nextUtterance, null );
} );
+ /**
+ * Add a mw-content-text div element to the QUnit fixture.
+ *
+ * @param {string} html The HTML added to the div element.
+ */
+
+ function addContentText( html ) {
+ $( '#qunit-fixture' ).append(
+ $( '<div></div>' )
+ .attr( 'id', 'mw-content-text' )
+ .html( html )
+ );
+ }
+
QUnit.test( 'addTokens()', function ( assert ) {
var tokens;
@@ -696,20 +701,6 @@
);
} );
- /**
- * Add a mw-content-text div element to the QUnit fixture.
- *
- * @param {string} html The HTML added to the div element.
- */
-
- function addContentText( html ) {
- $( '#qunit-fixture' ).append(
- $( '<div></div>' )
- .attr( 'id', 'mw-content-text' )
- .html( html )
- );
- }
-
QUnit.test( 'addTokens(): handle tag', function ( assert ) {
var tokens;
@@ -746,7 +737,7 @@
assert.strictEqual( utterances[ 0 ].tokens[ 0 ].startOffset, 0
);
assert.strictEqual( utterances[ 0 ].tokens[ 0 ].endOffset, 8 );
assert.deepEqual(
- utterances[ 0 ].tokens[ 1 ].items
+ utterances[ 0 ].tokens[ 1 ].items,
[ utterances[ 0 ].content[ 0 ] ]
);
assert.strictEqual( utterances[ 0 ].tokens[ 1 ].startOffset, 10
);
@@ -1303,4 +1294,4 @@
0.0
);
} );
-} )( mediaWiki, jQuery );
+}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/374401
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I331b05e963d8b61296f3633b409b914ee2399d38
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Jforrester <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits