Skip to content

Commit

Permalink
fix : address feedback from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
idebenone committed Sep 17, 2024
1 parent 5ef0292 commit fd664cc
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 232 deletions.
89 changes: 38 additions & 51 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,45 @@ import Codex from "eslint-config-codex";
import { plugin as TsPlugin, parser as TsParser } from 'typescript-eslint';

export default [
...Codex,
{
files: ['src/**/*.ts'],
languageOptions: {
parser: TsParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: './',
sourceType: 'module',
},
...Codex,
{
files: ['src/**/*.ts'],
languageOptions: {
parser: TsParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: './',
sourceType: 'module',
},
},
rules: {
'n/no-missing-import': ['off'],
'n/no-unsupported-features/node-builtins': ['off'],
'jsdoc/require-returns-description': ['off'],
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'variable',
'format': ['camelCase'],
'leadingUnderscore': 'allow'
},
rules: {
'n/no-missing-import': ['off'],
'n/no-unsupported-features/node-builtins': ['off'],
'jsdoc/require-returns-description': ['off'],
'jsdoc/require-jsdoc': [
'error',
{
'require': {
'FunctionDeclaration': true,
'MethodDefinition': true,
'ClassDeclaration': true,
'ArrowFunctionExpression': false,
'FunctionExpression': false,
}
}
],
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'variable',
'format': ['camelCase'],
'leadingUnderscore': 'allow'
},
],
'@typescript-eslint/no-unsafe-member-access': ['off'],
'@typescript-eslint/no-restricted-types': ['error',
{
'types': {
'String': "Use 'string' instead.",
'Boolean': "Use 'boolean' instead.",
'Number': "Use 'number' instead.",
'Symbol': "Use 'symbol' instead.",
'Object': "Use 'object' instead, or define a more specific type.",
'Function': "Use a specific function type instead, like '(arg: type) => returnType'."
}
}
]
],
'@typescript-eslint/no-unsafe-member-access': ['off'],
'@typescript-eslint/no-restricted-types': ['error',
{
'types': {
'String': "Use 'string' instead.",
'Boolean': "Use 'boolean' instead.",
'Number': "Use 'number' instead.",
'Symbol': "Use 'symbol' instead.",
'Object': "Use 'object' instead, or define a more specific type.",
'Function': "Use a specific function type instead, like '(arg: type) => returnType'."
}
}
},
{
ignores: ['dev/**', 'eslint.config.mjs', 'vite.config.js', 'postcss.config.js']
]
}
},
{
ignores: ['dev/**', 'eslint.config.mjs', 'vite.config.js', 'postcss.config.js']
}
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"eslint-config-codex": "^2.0.2",
"typescript": "^5.5.3",
"typescript-eslint": "^8.4.0",
"vite": "^4.5.0",
"vite": "^5.4.3",
"vite-plugin-css-injected-by-js": "^3.3.0",
"vite-plugin-dts": "^3.9.1"
},
Expand Down
35 changes: 20 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './index.css';
import { getLineStartPosition } from './utils/string';
import { IconBrackets } from '@codexteam/icons';
import type { API, BlockTool, BlockToolConstructorOptions, PasteEvent, SanitizerConfig } from '@editorjs/editorjs';
import type { API, BlockTool, BlockToolConstructorOptions, BlockToolData, PasteConfig, PasteEvent, SanitizerConfig, ToolboxConfig } from '@editorjs/editorjs';

/**
* CodeTool for Editor.js
Expand All @@ -12,7 +12,7 @@ import type { API, BlockTool, BlockToolConstructorOptions, PasteEvent, Sanitizer
/**
* Data structure for CodeTool's data
*/
export interface CodeData {
export interface CodeData extends BlockToolData {
/**
* The code content input by the user
*/
Expand Down Expand Up @@ -53,6 +53,16 @@ interface CodeToolNodes {
textarea: HTMLTextAreaElement | null;
}

/**
* Options passed to the constructor of a block tool
*/
interface CodeToolConstructorOptions extends BlockToolConstructorOptions {
/**
* Data specific to the CodeTool
*/
data: CodeData;
}

/**
* Code Tool for the Editor.js allows to include code examples in your articles.
*/
Expand Down Expand Up @@ -86,7 +96,7 @@ export default class CodeTool implements BlockTool {
* Notify core that read-only mode is supported
* @returns true if read-only mode is supported
*/
static get isReadOnlySupported(): boolean {
public static get isReadOnlySupported(): boolean {
return true;
}

Expand All @@ -95,15 +105,10 @@ export default class CodeTool implements BlockTool {
* This enables multi-line input within the code editor.
* @returns true if line breaks are allowed in the textarea
*/
static get enableLineBreaks(): boolean {
public static get enableLineBreaks(): boolean {
return true;
}

/**
* CodeData — plugin saved data
* code - previously saved plugin code
*/

/**
* Render plugin`s main Element and fill it with saved data
* @param options - tool constricting options
Expand All @@ -112,7 +117,7 @@ export default class CodeTool implements BlockTool {
* @param options.api - Editor.js API
* @param options.readOnly - read only mode flag
*/
constructor({ data, config, api, readOnly }: BlockToolConstructorOptions) {
constructor({ data, config, api, readOnly }: CodeToolConstructorOptions) {
this.api = api;
this.readOnly = readOnly;

Expand All @@ -131,7 +136,7 @@ export default class CodeTool implements BlockTool {
};

this.data = {
code: data.code as string || '',
code: data.code ?? '',
};

this.nodes.holder = this.drawView();
Expand Down Expand Up @@ -199,7 +204,7 @@ export default class CodeTool implements BlockTool {
* - icon: SVG representation of the Tool's icon
* - title: Title to show in the toolbox
*/
static get toolbox(): { icon: string; title: string } {
public static get toolbox(): ToolboxConfig {
return {
icon: IconBrackets,
title: 'Code',
Expand All @@ -210,7 +215,7 @@ export default class CodeTool implements BlockTool {
* Default placeholder for CodeTool's textarea
* @returns
*/
static get DEFAULT_PLACEHOLDER(): string {
public static get DEFAULT_PLACEHOLDER(): string {
return 'Enter a code';
}

Expand All @@ -219,7 +224,7 @@ export default class CodeTool implements BlockTool {
* Provides configuration to handle CODE tag.
* @returns
*/
static get pasteConfig(): { tags: string[] } {
public static get pasteConfig(): PasteConfig {
return {
tags: ['pre'],
};
Expand All @@ -229,7 +234,7 @@ export default class CodeTool implements BlockTool {
* Automatic sanitize config
* @returns
*/
static get sanitize(): SanitizerConfig {
public static get sanitize(): SanitizerConfig {
return {
code: true, // Allow HTML tags
};
Expand Down
Loading

0 comments on commit fd664cc

Please sign in to comment.