Skip to content

Commit

Permalink
Apply recommended rule of ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
lqez committed Jan 13, 2020
1 parent e7cd78a commit e3d77b7
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 67 deletions.
44 changes: 25 additions & 19 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
{
"extends": "standard",
"plugins": [
"chai-friendly"
],
"rules": {
"indent": ["warn", 2, {"ArrayExpression": "off", "SwitchCase": 1}],
"semi": [2, "always"],
"space-before-function-paren": ["error", "never"],
"no-useless-escape": 0,
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2,
"comma-dangle": ["error", "always-multiline"]
},
"env": {
"es6": true,
"browser": true,
"jquery": true,
"mocha": true
}
"extends": "eslint:recommended",
"plugins": [
"chai-friendly"
],
"rules": {
"indent": ["warn", 2, {"ArrayExpression": "off", "SwitchCase": 1}],
"semi": [2, "always"],
"space-before-function-paren": ["error", "never"],
"no-useless-escape": 0,
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2,
"comma-dangle": ["error", "always-multiline"]
},
"env": {
"amd": true,
"browser": true,
"es6": true,
"jquery": true,
"mocha": true,
"node": true
},
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
}
}
3 changes: 3 additions & 0 deletions config/build-fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const webfontConfig = {
normalize: true,
};

// eslint-disable-next-line
console.log('Building fonts...');

webfont(webfontConfig).then(result => {
Expand All @@ -36,11 +37,13 @@ webfont(webfontConfig).then(result => {
} else {
file = path.resolve(webfontConfig['destTemplate']);
}
// eslint-disable-next-line
console.log('Writing ', file);

fs.writeFileSync(file, content);
});
}).catch(error => {
// eslint-disable-next-line
console.log(error);
throw error;
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@babel/preset-env": "^7.7.7",
"autoprefixer": "^9.7.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.5",
"bootstrap": "^4.4.1",
"chai": "^4.2.0",
Expand Down
2 changes: 2 additions & 0 deletions plugin/hello/summernote-ext-hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
this.events = {
// This will be called after modules are initialized.
'summernote.init': function(we, e) {
// eslint-disable-next-line
console.log('summernote initialized', we, e);
},
// This will be called when user releases a key on editable.
'summernote.keyup': function(we, e) {
// eslint-disable-next-line
console.log('summernote keyup', we, e);
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/js/base/core/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ function isSpacePoint(point) {

const ch = point.node.nodeValue.charAt(point.offset - 1);
return ch === ' ' || ch === NBSP_CHAR;
};
}

/**
* @method walkPoint
Expand Down
4 changes: 2 additions & 2 deletions src/js/base/core/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class WrappedRange {
endPoint.node,
endPoint.offset
);
};
}

/**
* returns range for words before cursor that match with a Regex
Expand Down Expand Up @@ -700,7 +700,7 @@ class WrappedRange {
} else {
return null;
}
};
}

/**
* create offsetPath bookmark
Expand Down
4 changes: 3 additions & 1 deletion src/js/base/editing/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export default class Style {
'font-strikethrough': document.queryCommandState('strikethrough') ? 'strikethrough' : 'normal',
'font-family': document.queryCommandValue('fontname') || styleInfo['font-family'],
});
} catch (e) {}
} catch (e) {
// eslint-disable-next-line
}

// list-style-type to list-style(unordered, ordered)
if (!rng.isOnList()) {
Expand Down
78 changes: 42 additions & 36 deletions src/js/base/editing/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const TableResultAction = function(startPoint, where, action, domTable) {
*/
function setStartPoint() {
if (!startPoint || !startPoint.tagName || (startPoint.tagName.toLowerCase() !== 'td' && startPoint.tagName.toLowerCase() !== 'th')) {
console.error('Impossible to identify start Cell point.', startPoint);
// Impossible to identify start Cell point
return;
}
_startPoint.colPos = startPoint.cellIndex;
if (!startPoint.parentElement || !startPoint.parentElement.tagName || startPoint.parentElement.tagName.toLowerCase() !== 'tr') {
console.error('Impossible to identify start Row point.', startPoint);
// Impossible to identify start Row point
return;
}
_startPoint.rowPos = startPoint.parentElement.rowIndex;
Expand Down Expand Up @@ -325,18 +325,20 @@ export default class Table {
html.append('<td' + tdAttributes + '>' + dom.blank + '</td>');
break;
case TableResultAction.resultAction.SumSpanCount:
if (position === 'top') {
const baseCellTr = currentCell.baseCell.parent;
const isTopFromRowSpan = (!baseCellTr ? 0 : currentCell.baseCell.closest('tr').rowIndex) <= currentTr[0].rowIndex;
if (isTopFromRowSpan) {
const newTd = $('<div></div>').append($('<td' + tdAttributes + '>' + dom.blank + '</td>').removeAttr('rowspan')).html();
html.append(newTd);
break;
{
if (position === 'top') {
const baseCellTr = currentCell.baseCell.parent;
const isTopFromRowSpan = (!baseCellTr ? 0 : currentCell.baseCell.closest('tr').rowIndex) <= currentTr[0].rowIndex;
if (isTopFromRowSpan) {
const newTd = $('<div></div>').append($('<td' + tdAttributes + '>' + dom.blank + '</td>').removeAttr('rowspan')).html();
html.append(newTd);
break;
}
}
let rowspanNumber = parseInt(currentCell.baseCell.rowSpan, 10);
rowspanNumber++;
currentCell.baseCell.setAttribute('rowSpan', rowspanNumber);
}
let rowspanNumber = parseInt(currentCell.baseCell.rowSpan, 10);
rowspanNumber++;
currentCell.baseCell.setAttribute('rowSpan', rowspanNumber);
break;
}
}
Expand Down Expand Up @@ -452,19 +454,21 @@ export default class Table {
case TableResultAction.resultAction.Ignore:
continue;
case TableResultAction.resultAction.AddCell:
const nextRow = row.next('tr')[0];
if (!nextRow) { continue; }
const cloneRow = row[0].cells[cellPos];
if (hasRowspan) {
if (rowspanNumber > 2) {
rowspanNumber--;
nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
nextRow.cells[cellPos].setAttribute('rowSpan', rowspanNumber);
nextRow.cells[cellPos].innerHTML = '';
} else if (rowspanNumber === 2) {
nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
nextRow.cells[cellPos].removeAttribute('rowSpan');
nextRow.cells[cellPos].innerHTML = '';
{
const nextRow = row.next('tr')[0];
if (!nextRow) { continue; }
const cloneRow = row[0].cells[cellPos];
if (hasRowspan) {
if (rowspanNumber > 2) {
rowspanNumber--;
nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
nextRow.cells[cellPos].setAttribute('rowSpan', rowspanNumber);
nextRow.cells[cellPos].innerHTML = '';
} else if (rowspanNumber === 2) {
nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
nextRow.cells[cellPos].removeAttribute('rowSpan');
nextRow.cells[cellPos].innerHTML = '';
}
}
}
continue;
Expand Down Expand Up @@ -511,17 +515,19 @@ export default class Table {
case TableResultAction.resultAction.Ignore:
continue;
case TableResultAction.resultAction.SubtractSpanCount:
const baseCell = actions[actionIndex].baseCell;
const hasColspan = (baseCell.colSpan && baseCell.colSpan > 1);
if (hasColspan) {
let colspanNumber = (baseCell.colSpan) ? parseInt(baseCell.colSpan, 10) : 0;
if (colspanNumber > 2) {
colspanNumber--;
baseCell.setAttribute('colSpan', colspanNumber);
if (baseCell.cellIndex === cellPos) { baseCell.innerHTML = ''; }
} else if (colspanNumber === 2) {
baseCell.removeAttribute('colSpan');
if (baseCell.cellIndex === cellPos) { baseCell.innerHTML = ''; }
{
const baseCell = actions[actionIndex].baseCell;
const hasColspan = (baseCell.colSpan && baseCell.colSpan > 1);
if (hasColspan) {
let colspanNumber = (baseCell.colSpan) ? parseInt(baseCell.colSpan, 10) : 0;
if (colspanNumber > 2) {
colspanNumber--;
baseCell.setAttribute('colSpan', colspanNumber);
if (baseCell.cellIndex === cellPos) { baseCell.innerHTML = ''; }
} else if (colspanNumber === 2) {
baseCell.removeAttribute('colSpan');
if (baseCell.cellIndex === cellPos) { baseCell.innerHTML = ''; }
}
}
}
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/js/base/module/Codeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class CodeView {
cmEditor.on('blur', (event) => {
this.context.triggerEvent('blur.codeview', cmEditor.getValue(), event);
});
cmEditor.on('change', (event) => {
cmEditor.on('change', () => {
this.context.triggerEvent('change.codeview', cmEditor.getValue(), cmEditor);
});

Expand All @@ -112,7 +112,7 @@ export default class CodeView {
this.$codable.on('blur', (event) => {
this.context.triggerEvent('blur.codeview', this.$codable.val(), event);
});
this.$codable.on('input', (event) => {
this.$codable.on('input', () => {
this.context.triggerEvent('change.codeview', this.$codable.val(), this.$codable);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/base/module/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Editor {
};
})(idx);
this.context.memo('help.formatH' + idx, this.lang.help['formatH' + idx]);
};
}

this.insertParagraph = this.wrapCommand(() => {
this.typing.insertParagraph(this.editable);
Expand Down Expand Up @@ -376,7 +376,7 @@ export default class Editor {
}).on('paste', (event) => {
this.setLastRange();
this.context.triggerEvent('paste', event);
}).on('input', (event) => {
}).on('input', () => {
// To limit composition characters (e.g. Korean)
if (this.isLimited(0) && this.snapshot) {
this.history.applySnapshot(this.snapshot);
Expand Down
2 changes: 1 addition & 1 deletion src/js/base/module/HintPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class HintPopover {

createItemTemplates(hintIdx, items) {
const hint = this.hints[hintIdx];
return items.map((item, idx) => {
return items.map((item /*, idx */) => {
const $item = $('<div class="note-hint-item"/>');
$item.append(hint.template ? hint.template(item) : item + '');
$item.data({
Expand Down
4 changes: 2 additions & 2 deletions src/js/base/module/VideoDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ export default class VideoDialog {
}

/**
* show image dialog
* show video dialog
*
* @param {jQuery} $dialog
* @return {Promise}
*/
showVideoDialog(text) {
showVideoDialog(/* text */) {
return $.Deferred((deferred) => {
const $videoUrl = this.$dialog.find('.note-video-url');
const $videoBtn = this.$dialog.find('.note-video-btn');
Expand Down
2 changes: 1 addition & 1 deletion src/js/lite/ui/ModalUI.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import $ from 'jquery';

class ModalUI {
constructor($node, options) {
constructor($node /*, options */) {
this.$modal = $node;
this.$backdrop = $('<div class="note-modal-backdrop"/>');
}
Expand Down

0 comments on commit e3d77b7

Please sign in to comment.