Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvements] ESLint action #1099

Merged
merged 7 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
manually fix some issues
  • Loading branch information
neSpecc committed Apr 11, 2020
commit ae91212b6fcd9c698b8318f43210f05bdbaa39d1
15 changes: 14 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"extends": [
"codex"
]
],
"rules": {
/**
* Temporary suppress some errors. We need to fix them partially in next patches
*/
"@typescript-eslint/explicit-function-return-type": ["warn"],
"@typescript-eslint/explicit-member-accessibility": ["warn"],
"@typescript-eslint/member-ordering": ["warn"],
"@typescript-eslint/no-empty-function": ["warn"],
"no-prototype-builtins": ["warn"],
"no-mixed-operators": ["warn"],
"import/no-duplicates": ["warn"],
"no-case-declarations": ["warn"]
}
}
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/editor.js.LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Editor.js
*
* Short Description (눈_눈;)
*
* @version 2.0
*
* @licence Apache-2.0
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build:dev": "webpack --mode development --progress --display-error-details --display-entrypoints --watch",
"build:prod": "webpack --mode production",
"lint": "eslint src/ --ext .ts",
"lint:errors": "eslint src/ --ext .ts --quiet",
"lint:fix": "eslint src/ --ext .ts --fix",
"svg:win": "if not exist dist md dist && yarn svg",
"svg": "svg-sprite-generate -d src/assets/ -o dist/sprite.svg",
Expand Down
5 changes: 3 additions & 2 deletions src/components/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export default class Block {
*/
if (this.tool[methodName] && this.tool[methodName] instanceof Function) {
try {
// eslint-disable-next-line no-useless-call
this.tool[methodName].call(this.tool, params);
} catch (e) {
_.log(`Error during '${methodName}' call: ${e.message}`, 'error');
Expand Down Expand Up @@ -522,8 +523,8 @@ export default class Block {
const tunesList = [MoveUpTune, DeleteTune, MoveDownTune];

// Pluck tunes list and return tune instances with passed Editor API and settings
return tunesList.map((tune: BlockTuneConstructable) => {
return new tune({
return tunesList.map((Tune: BlockTuneConstructable) => {
return new Tune({
api: this.api,
settings: this.settings,
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/inline-tools/inline-tool-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ export default class LinkInlineTool implements InlineTool {
* 2) Anchors looks like "#results"
* 3) Protocol-relative URLs like "//google.com"
*/
const isInternal = /^\/[^\/\s]/.test(link),
const isInternal = /^\/[^/\s]/.test(link),
isAnchor = link.substring(0, 1) === '#',
isProtocolRelative = /^\/\/[^\/\s]/.test(link);
isProtocolRelative = /^\/\/[^/\s]/.test(link);

if (!isInternal && !isAnchor && !isProtocolRelative) {
link = 'http://' + link;
Expand Down
14 changes: 0 additions & 14 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export default class BlockEvents extends Module {
case _.keyCodes.ESC:
this.escapePressed(event);
break;
default:
this.defaultHandler();
break;
}
}

Expand Down Expand Up @@ -114,12 +111,6 @@ export default class BlockEvents extends Module {
this.Editor.UI.checkEmptiness();
}

/**
* Mouse up on Block:
*/
public mouseUp(): void {
}

/**
* Set up mouse selection handlers
*
Expand Down Expand Up @@ -542,11 +533,6 @@ export default class BlockEvents extends Module {
this.Editor.BlockSelection.clearSelection(event);
}

/**
* Default keydown handler
*/
private defaultHandler(): void {}

/**
* Cases when we need to close Toolbar
*
Expand Down
5 changes: 3 additions & 2 deletions src/components/modules/blockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ export default class BlockManager extends Module {
* Remove selection from all Blocks
*/
public clearFocused(): void {
this.blocks.forEach((block) => block.focused = false);
this.blocks.forEach((block) => {
block.focused = false;
});
}

/**
Expand Down Expand Up @@ -644,7 +646,6 @@ export default class BlockManager extends Module {
const { BlockEvents, Listeners } = this.Editor;

Listeners.on(block.holder, 'keydown', (event) => BlockEvents.keydown(event as KeyboardEvent), true);
Listeners.on(block.holder, 'mouseup', (event) => BlockEvents.mouseUp());
Listeners.on(block.holder, 'mousedown', (event: MouseEvent) => BlockEvents.mouseDown(event));
Listeners.on(block.holder, 'keyup', (event) => BlockEvents.keyup(event));
Listeners.on(block.holder, 'dragover', (event) => BlockEvents.dragOver(event as DragEvent));
Expand Down
4 changes: 3 additions & 1 deletion src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export default class BlockSelection extends Module {
public set allBlocksSelected(state: boolean) {
const { BlockManager } = this.Editor;

BlockManager.blocks.forEach((block) => block.selected = state);
BlockManager.blocks.forEach((block) => {
block.selected = state;
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/components/modules/dragNDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default class DragNDrop extends Module {

dropEvent.preventDefault();

BlockManager.blocks.forEach((block) => block.dropTarget = false);
BlockManager.blocks.forEach((block) => {
block.dropTarget = false;
});

if (SelectionUtils.isAtEditor && !SelectionUtils.isCollapsed && this.isStartedAtEditor) {
document.execCommand('delete');
Expand Down
7 changes: 2 additions & 5 deletions src/components/modules/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ export default class Paste extends Module {

/** If target is native input or is not Block, use browser behaviour */
if (
!BlockManager.currentBlock ||
this.isNativeBehaviour(event.target) && !event.clipboardData.types.includes('Files')
!BlockManager.currentBlock || this.isNativeBehaviour(event.target) && !event.clipboardData.types.includes('Files')
) {
return;
}
Expand Down Expand Up @@ -647,13 +646,11 @@ export default class Paste extends Module {
const blockData = await this.processPattern(content.textContent);

if (blockData) {
let insertedBlock;

const needToReplaceCurrentBlock = BlockManager.currentBlock &&
Tools.isInitial(BlockManager.currentBlock.tool) &&
BlockManager.currentBlock.isEmpty;

insertedBlock = BlockManager.paste(blockData.tool, blockData.event, needToReplaceCurrentBlock);
const insertedBlock = BlockManager.paste(blockData.tool, blockData.event, needToReplaceCurrentBlock);

Caret.setToBlock(insertedBlock, Caret.positions.END);

Expand Down
1 change: 1 addition & 0 deletions src/components/modules/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Module from '../__module';
/* eslint-disable import/no-duplicates */
import * as _ from '../utils';
import { ChainData } from '../utils';
import { BlockToolData } from '../../../types';
Expand Down
13 changes: 9 additions & 4 deletions src/components/modules/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export default class Tools extends Module {
*/
const result = {};

tools.forEach(([name, tool]) => result[name] = tool);
tools.forEach(([name, tool]) => {
result[name] = tool;
});

/**
* Cache prepared Tools
Expand All @@ -120,7 +122,9 @@ export default class Tools extends Module {
*/
const result = {};

tools.forEach(([name, tool]) => result[name] = tool);
tools.forEach(([name, tool]) => {
result[name] = tool;
});

return result;
}
Expand Down Expand Up @@ -325,7 +329,7 @@ export default class Tools extends Module {
* @returns {BlockTool}
*/
public construct(tool, data) {
const plugin = this.toolsClasses[tool];
const Plugin = this.toolsClasses[tool];

/**
* Configuration to be passed to the Tool's constructor
Expand All @@ -346,7 +350,7 @@ export default class Tools extends Module {
data,
};

return new plugin(constructorOptions);
return new Plugin(constructorOptions);
}

/**
Expand All @@ -365,6 +369,7 @@ export default class Tools extends Module {
config: (toolSettings[this.USER_SETTINGS.CONFIG] || {}) as ToolSettings,
};

// eslint-disable-next-line new-cap
return new tool(constructorOptions) as InlineTool;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if (!Element.prototype.matches) {
*/
if (!Element.prototype.closest) {
Element.prototype.closest = function (s) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let el = this;

if (!document.documentElement.contains(el)) {
Expand Down
29 changes: 17 additions & 12 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ _log.logLevel = LogLevels.VERBOSE;
*
* @param {LogLevels} logLevel - log level to set
*/
export function setLogLevel(logLevel: LogLevels) {
export function setLogLevel(logLevel: LogLevels): void {
_log.logLevel = logLevel;
}

Expand Down Expand Up @@ -185,7 +185,7 @@ export function isPrintableKey(keyCode: number): boolean {
}

/**
* Fires a promise sequence asyncronically
* Fires a promise sequence asynchronously
*
* @param {ChainData[]} chains - list or ChainData's
* @param {Function} success - success callback
Expand All @@ -195,8 +195,10 @@ export function isPrintableKey(keyCode: number): boolean {
*/
export async function sequence(
chains: ChainData[],
success: (data: any) => void = () => {},
fallback: (data: any) => void = () => {}
// eslint-disable-next-line @typescript-eslint/no-empty-function
success: (data: any) => void = (): void => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
fallback: (data: any) => void = (): void => {},
): Promise<void> {
/**
* Decorator
Expand Down Expand Up @@ -228,7 +230,7 @@ export async function sequence(
* reduce current element will not be able to continue while can't get
* a resolved Promise
*/
return await chains.reduce(async (previousValue, currentValue) => {
return chains.reduce(async (previousValue, currentValue) => {
await previousValue;

return waitNextBlock(currentValue, success, fallback);
Expand Down Expand Up @@ -297,8 +299,10 @@ export function isPromise(object: any): boolean {
* @param {number} timeout
*/
export function delay(method: (...args: any[]) => any, timeout: number) {
return function () {
return function() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this,
// eslint-disable-next-line prefer-rest-params
args = arguments;

window.setTimeout(() => method.apply(context, args), timeout);
Expand Down Expand Up @@ -339,10 +343,13 @@ export function isValidMimeType(type: string): boolean {
export function debounce(func: () => void, wait?: number, immediate?: boolean): () => void {
let timeout;

return () => {
return (): void => {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this,
// eslint-disable-next-line prefer-rest-params
args = arguments;

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const later = () => {
timeout = null;
if (!immediate) {
Expand All @@ -363,9 +370,9 @@ export function debounce(func: () => void, wait?: number, immediate?: boolean):
/**
* Copies passed text to the clipboard
*
* @param text
* @param text - text to copy
*/
export function copyTextToClipboard(text) {
export function copyTextToClipboard(text): void {
const el = Dom.make('div', 'codex-editor-clipboard', {
innerHTML: text,
});
Expand All @@ -386,8 +393,6 @@ export function copyTextToClipboard(text) {

/**
* Returns object with os name as key and boolean as value. Shows current user OS
*
* @returns {[key: string]: boolean}
*/
export function getUserOS(): {[key: string]: boolean} {
const OS = {
Expand Down Expand Up @@ -425,7 +430,7 @@ export function capitalize(text: string): string {
* @param {object[]} sources
* @returns {object}
*/
export function deepMerge(target, ...sources) {
export function deepMerge(target, ...sources): {[key: string]: any} {
const isObject = (item) => item && typeOf(item) === 'object';

if (!sources.length) {
Expand Down
Loading