build: Remove jshint/jscs, add eslint/stylelint

Change-Id: I4304ca95de7dd395676f40bcbb35a447c039ba21
This commit is contained in:
Ed Sanders 2016-12-09 13:21:02 +00:00
parent 4c00f18b3d
commit 7fddf35aa8
9 changed files with 65 additions and 72 deletions

15
.eslintrc.json Normal file
View file

@ -0,0 +1,15 @@
{
"extends": "wikimedia",
"env": {
"browser": true,
"jquery": true,
"qunit": true
},
"globals": {
"mediaWiki": false,
"OO": false
},
"rules": {
"dot-notation": [ "error", { "allowKeywords": true } ]
}
}

View file

@ -1,3 +0,0 @@
{
"preset": "wikimedia"
}

View file

@ -1,5 +0,0 @@
node_modules/
vendor/
# 3rd party lib
modules/ace/

View file

@ -1,30 +0,0 @@
{
// Enforcing
"bitwise": true,
"curly": true,
"eqeqeq": true,
"freeze": true,
"latedef": true,
"immed": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"quotmark": "single",
"strict": false,
"trailing": true,
"undef": true,
"unused": true,
// Relaxing
"es5": false,
// Environment
"browser": true,
"jquery": true,
"globals": {
"mediaWiki": false,
"OO": false
}
}

3
.stylelintrc Normal file
View file

@ -0,0 +1,3 @@
{
"extends": "stylelint-config-wikimedia"
}

View file

@ -4,27 +4,30 @@
* @package CodeEditor * @package CodeEditor
*/ */
/*jshint node:true */ /* eslint-env node */
module.exports = function ( grunt ) { module.exports = function ( grunt ) {
var conf = grunt.file.readJSON( 'extension.json' ); var conf = grunt.file.readJSON( 'extension.json' );
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-banana-checker' ); grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-jscs' ); grunt.loadNpmTasks( 'grunt-eslint' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.initConfig( { grunt.initConfig( {
jshint: { eslint: {
options: {
jshintrc: true
},
all: [ all: [
'**/*.js', '**/*.js',
'!node_modules/**', '!node_modules/**',
'!modules/ace/**' '!modules/ace/**'
] ]
}, },
jscs: { stylelint: {
src: '<%= jshint.all %>' all: [
'**/*.css',
'**/*.less',
'!node_modules/**',
'!modules/ace/**'
]
}, },
banana: conf.MessagesDirs, banana: conf.MessagesDirs,
jsonlint: { jsonlint: {
@ -35,6 +38,6 @@ module.exports = function ( grunt ) {
} }
} ); } );
grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ] ); grunt.registerTask( 'test', [ 'eslint', 'stylelint', 'jsonlint', 'banana' ] );
grunt.registerTask( 'default', 'test' ); grunt.registerTask( 'default', 'test' );
}; };

View file

@ -661,6 +661,9 @@
/** /**
* Override the base functions in a way that lets * Override the base functions in a way that lets
* us fall back to the originals when we turn off. * us fall back to the originals when we turn off.
*
* @param {Object} base
* @param {Object} extended
*/ */
saveAndExtend = function ( base, extended ) { saveAndExtend = function ( base, extended ) {
$.map( extended, function ( func, name ) { $.map( extended, function ( func, name ) {
@ -724,6 +727,8 @@
/** /**
* Gets the currently selected text in the content * Gets the currently selected text in the content
* DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
*
* @return {string}
*/ */
getSelection: function () { getSelection: function () {
return context.codeEditor.getCopyText(); return context.codeEditor.getCopyText();
@ -733,6 +738,9 @@
* Inserts text at the begining and end of a text selection, optionally inserting text at the caret when * Inserts text at the begining and end of a text selection, optionally inserting text at the caret when
* selection is empty. * selection is empty.
* DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
*
* @param {Object} options
* @return {jQuery}
*/ */
encapsulateSelection: function ( options ) { encapsulateSelection: function ( options ) {
var sel, range, selText, isSample, text; var sel, range, selText, isSample, text;
@ -776,6 +784,7 @@
* DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
* *
* @param {Object} options * @param {Object} options
* @return {jQuery}
*/ */
setSelection: function ( options ) { setSelection: function ( options ) {
var doc, lines, offsetToPos, start, end, sel, range; var doc, lines, offsetToPos, start, end, sel, range;
@ -814,6 +823,8 @@
/** /**
* Scroll a textarea to the current cursor position. You can set the cursor position with setSelection() * Scroll a textarea to the current cursor position. You can set the cursor position with setSelection()
* DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
*
* @return {jQuery}
*/ */
scrollToCaretPosition: function () { scrollToCaretPosition: function () {
mw.log( 'codeEditor stub function scrollToCaretPosition called' ); mw.log( 'codeEditor stub function scrollToCaretPosition called' );

View file

@ -1,4 +1,4 @@
@import "mediawiki.mixins"; @import 'mediawiki.mixins';
.group-codeeditor-format, .group-codeeditor-format,
.group-codeeditor-style, .group-codeeditor-style,
@ -16,20 +16,23 @@
display: block; display: block;
} }
/* stylelint-disable no-descending-specificity */
.group-codeeditor-main, .group-codeeditor-main,
.group-codeeditor-format, .group-codeeditor-format,
.group-codeeditor-style { .group-codeeditor-style {
.tool { .tool {
opacity: 0.7; opacity: 0.7;
/* stylelint-disable-next-line declaration-no-important */
background-position: 1px 1px !important; background-position: 1px 1px !important;
&.icon-active { &.icon-active {
opacity: 1; opacity: 1;
} }
} }
} }
/* stylelint-enable no-descending-specificity */
// TODO: Use this icon from OOUI // TODO: Use this icon from OOUI
.group-codeeditor-main .tool[rel=codeEditor] { .group-codeeditor-main .tool[rel='codeEditor'] {
.background-image-svg( '../images/code.svg', '../images/code.png' ); .background-image-svg( '../images/code.svg', '../images/code.png' );
&.icon-active { &.icon-active {
.background-image-svg( '../images/code-progressive.svg', '../images/code-progressive.png' ); .background-image-svg( '../images/code-progressive.svg', '../images/code-progressive.png' );
@ -37,17 +40,17 @@
} }
// TODO: Use this icon from OOUI // TODO: Use this icon from OOUI
.codeEditor-ui-toolbar .tool[rel=indent] { .codeEditor-ui-toolbar .tool[rel='indent'] {
.background-image-svg( '../images/indent.svg', '../images/indent.png' ); .background-image-svg( '../images/indent.svg', '../images/indent.png' );
} }
// TODO: Use this icon from OOUI // TODO: Use this icon from OOUI
.codeEditor-ui-toolbar .tool[rel=outdent] { .codeEditor-ui-toolbar .tool[rel='outdent'] {
.background-image-svg( '../images/outdent.svg', '../images/outdent.png' ); .background-image-svg( '../images/outdent.svg', '../images/outdent.png' );
} }
// TODO: Upstream this icon to OOUI and use it from there // TODO: Upstream this icon to OOUI and use it from there
.codeEditor-ui-toolbar .tool[rel=invisibleChars] { .codeEditor-ui-toolbar .tool[rel='invisibleChars'] {
.background-image-svg( '../images/pilcrow.svg', '../images/pilcrow.png' ); .background-image-svg( '../images/pilcrow.svg', '../images/pilcrow.png' );
&.icon-active { &.icon-active {
.background-image-svg( '../images/pilcrow-progressive.svg', '../images/pilcrow-progressive.png' ); .background-image-svg( '../images/pilcrow-progressive.svg', '../images/pilcrow-progressive.png' );
@ -55,7 +58,7 @@
} }
// TODO: Upstream this icon to OOUI and use it from there // TODO: Upstream this icon to OOUI and use it from there
.codeEditor-ui-toolbar .tool[rel=lineWrapping] { .codeEditor-ui-toolbar .tool[rel='lineWrapping'] {
.background-image-svg( '../images/wrapping.svg', '../images/wrapping.png' ); .background-image-svg( '../images/wrapping.svg', '../images/wrapping.png' );
&.icon-active { &.icon-active {
.background-image-svg( '../images/wrapping-progressive.svg', '../images/wrapping-progressive.png' ); .background-image-svg( '../images/wrapping-progressive.svg', '../images/wrapping-progressive.png' );
@ -63,12 +66,12 @@
} }
// TODO: Upstream this icon to OOUI and use it from there // TODO: Upstream this icon to OOUI and use it from there
.codeEditor-ui-toolbar .tool[rel=gotoLine] { .codeEditor-ui-toolbar .tool[rel='gotoLine'] {
.background-image-svg( '../images/gotoLine.svg', '../images/gotoLine.png' ); .background-image-svg( '../images/gotoLine.svg', '../images/gotoLine.png' );
} }
// TODO: Use this icon from OOUI // TODO: Use this icon from OOUI
.codeEditor-ui-toolbar .tool[rel=toggleSearchReplace] { .codeEditor-ui-toolbar .tool[rel='toggleSearchReplace'] {
.background-image-svg( '../images/find.svg', '../images/find.png' ); .background-image-svg( '../images/find.svg', '../images/find.png' );
} }
@ -79,8 +82,8 @@
.codeEditor-status { .codeEditor-status {
clear: both; clear: both;
width: 100%; width: 100%;
background-color: #F0F0F0; background-color: #f0f0f0;
border-top: 1px solid silver; border-top: 1px solid #c0c0c0;
display: table; display: table;
} }
@ -93,18 +96,14 @@
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
display: table-cell; display: table-cell;
*float: left;
*width: 10em;
} }
.codeEditor-status-message { .codeEditor-status-message {
border-left: 1px solid silver; border-left: 1px solid #c0c0c0;
border-right: 1px solid silver; border-right: 1px solid #c0c0c0;
padding: 0 0.3em; padding: 0 0.3em;
width: 100%; width: 100%;
display: table-cell; display: table-cell;
*float: left;
*width: auto;
} }
.codeEditor-status-line { .codeEditor-status-line {
@ -112,6 +111,4 @@
text-align: right; text-align: right;
white-space: nowrap; white-space: nowrap;
display: table-cell; display: table-cell;
*float: right;
*width: 4em;
} }

View file

@ -7,10 +7,12 @@
"test": "grunt test" "test": "grunt test"
}, },
"devDependencies": { "devDependencies": {
"eslint-config-wikimedia": "0.3.0",
"grunt": "1.0.1", "grunt": "1.0.1",
"grunt-contrib-jshint": "1.0.0",
"grunt-banana-checker": "0.5.0", "grunt-banana-checker": "0.5.0",
"grunt-jscs": "2.3.0", "grunt-eslint": "19.0.0",
"grunt-jsonlint": "1.1.0" "grunt-jsonlint": "1.1.0",
"grunt-stylelint": "0.6.0",
"stylelint-config-wikimedia": "0.3.0"
} }
} }