mirror of
https://github.com/facebook/lexical.git
synced 2025-05-16 22:48:52 +08:00
Configure ESLint: enable curly rule, fix on save (#5666)
This commit is contained in:

committed by
GitHub

parent
ea11763efd
commit
6e4f072ea1
@ -128,6 +128,7 @@ module.exports = {
|
||||
|
||||
'brace-style': [ERROR, '1tbs'],
|
||||
'consistent-return': OFF,
|
||||
curly: [ERROR, 'all'],
|
||||
'dot-location': [ERROR, 'property'],
|
||||
// We use console['error']() as a signal to not transform it:
|
||||
'dot-notation': [ERROR, {allowPattern: '^(error|warn)$'}],
|
||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,8 +1,7 @@
|
||||
{
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"eslint.alwaysShowStatus": true,
|
||||
"javascript.validate.enable": false,
|
||||
"[javascript]": {
|
||||
"[javascript][typescript]": {
|
||||
"editor.codeActionsOnSave": [
|
||||
// Run ESLint fixers _before_ prettier to ensure the user doesn't need to do multiple saves
|
||||
"source.fixAll.eslint",
|
||||
|
@ -272,7 +272,9 @@ export class CodeNode extends ElementNode {
|
||||
let spaces = 0;
|
||||
const text = node.getTextContent();
|
||||
const textSize = node.getTextContentSize();
|
||||
for (; spaces < textSize && text[spaces] === ' '; spaces++);
|
||||
while (spaces < textSize && text[spaces] === ' ') {
|
||||
spaces++;
|
||||
}
|
||||
if (spaces !== 0) {
|
||||
insertNodes.push($createCodeHighlightNode(' '.repeat(spaces)));
|
||||
}
|
||||
|
@ -138,7 +138,9 @@ function $appendNodesToHTML(
|
||||
|
||||
if (after) {
|
||||
const newElement = after.call(target, element);
|
||||
if (newElement) element.replaceWith(newElement);
|
||||
if (newElement) {
|
||||
element.replaceWith(newElement);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
parentElement.append(fragment);
|
||||
|
@ -175,7 +175,9 @@ export class ListItemNode extends ElementNode {
|
||||
}
|
||||
this.setIndent(0);
|
||||
const list = this.getParentOrThrow();
|
||||
if (!$isListNode(list)) return replaceWithNode;
|
||||
if (!$isListNode(list)) {
|
||||
return replaceWithNode;
|
||||
}
|
||||
if (list.__first === this.getKey()) {
|
||||
list.insertBefore(replaceWithNode);
|
||||
} else if (list.__last === this.getKey()) {
|
||||
|
@ -122,7 +122,9 @@ export class MarkNode extends ElementNode {
|
||||
self.__ids = ids;
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
// If we already have it, don't add again
|
||||
if (id === ids[i]) return;
|
||||
if (id === ids[i]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ids.push(id);
|
||||
}
|
||||
|
@ -855,7 +855,7 @@ test.describe('Composition', () => {
|
||||
text: 'もじあ',
|
||||
});
|
||||
|
||||
if (browserName === 'webkit')
|
||||
if (browserName === 'webkit') {
|
||||
await assertHTML(
|
||||
page,
|
||||
html`
|
||||
@ -868,8 +868,9 @@ test.describe('Composition', () => {
|
||||
</p>
|
||||
`,
|
||||
);
|
||||
}
|
||||
/* eslint-disable no-irregular-whitespace */
|
||||
if (browserName === 'chromium')
|
||||
if (browserName === 'chromium') {
|
||||
await assertHTML(
|
||||
page,
|
||||
html`
|
||||
@ -880,6 +881,7 @@ test.describe('Composition', () => {
|
||||
</p>
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
await assertSelection(page, {
|
||||
anchorOffset: 12,
|
||||
|
@ -110,7 +110,9 @@ export class PageBreakNode extends DecoratorNode<JSX.Element> {
|
||||
return {
|
||||
figure: (domNode: HTMLElement) => {
|
||||
const tp = domNode.getAttribute('type');
|
||||
if (tp !== this.getType()) return null;
|
||||
if (tp !== this.getType()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
conversion: convertPageBreakElement,
|
||||
|
@ -743,7 +743,9 @@ export default function CommentPlugin({
|
||||
comment,
|
||||
thread,
|
||||
);
|
||||
if (!deletionInfo) return;
|
||||
if (!deletionInfo) {
|
||||
return;
|
||||
}
|
||||
const {markedComment, index} = deletionInfo;
|
||||
commentStore.addComment(markedComment, thread, index);
|
||||
} else {
|
||||
|
@ -24,10 +24,11 @@ export default function PageBreakPlugin(): JSX.Element | null {
|
||||
const [editor] = useLexicalComposerContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor.hasNodes([PageBreakNode]))
|
||||
if (!editor.hasNodes([PageBreakNode])) {
|
||||
throw new Error(
|
||||
'PageBreakPlugin: PageBreakNode is not registered on editor',
|
||||
);
|
||||
}
|
||||
|
||||
return mergeRegister(
|
||||
editor.registerCommand(
|
||||
@ -35,7 +36,9 @@ export default function PageBreakPlugin(): JSX.Element | null {
|
||||
() => {
|
||||
const selection = $getSelection();
|
||||
|
||||
if (!$isRangeSelection(selection)) return false;
|
||||
if (!$isRangeSelection(selection)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const focusNode = selection.focus.getNode();
|
||||
if (focusNode !== null) {
|
||||
|
@ -144,7 +144,9 @@ function TableCellResizer({editor}: {editor: LexicalEditor}): JSX.Element {
|
||||
}, [activeCell, draggingDirection, editor, resetState]);
|
||||
|
||||
const isHeightChanging = (direction: MouseDraggingDirection) => {
|
||||
if (direction === 'bottom') return true;
|
||||
if (direction === 'bottom') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
@ -194,8 +194,11 @@ const ELEMENT_FORMAT_OPTIONS: {
|
||||
};
|
||||
|
||||
function dropDownActiveClass(active: boolean) {
|
||||
if (active) return 'active dropdown-item-active';
|
||||
else return '';
|
||||
if (active) {
|
||||
return 'active dropdown-item-active';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function BlockFormatDropDown({
|
||||
@ -271,8 +274,9 @@ function BlockFormatDropDown({
|
||||
const codeNode = $createCodeNode();
|
||||
selection.insertNodes([codeNode]);
|
||||
selection = $getSelection();
|
||||
if ($isRangeSelection(selection))
|
||||
if ($isRangeSelection(selection)) {
|
||||
selection.insertRawText(textContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -100,7 +100,9 @@ export default function ColorPicker({
|
||||
}, [selfColor, onChange]);
|
||||
|
||||
useEffect(() => {
|
||||
if (color === undefined) return;
|
||||
if (color === undefined) {
|
||||
return;
|
||||
}
|
||||
const newColor = transformColor('hex', color);
|
||||
setSelfColor(newColor);
|
||||
setInputColor(newColor.hex);
|
||||
@ -184,7 +186,9 @@ function MoveWrapper({className, style, onChange, children}: MoveWrapperProps) {
|
||||
};
|
||||
|
||||
const onMouseDown = (e: React.MouseEvent): void => {
|
||||
if (e.button !== 0) return;
|
||||
if (e.button !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
move(e);
|
||||
|
||||
|
@ -85,7 +85,9 @@ function DropDownItems({
|
||||
);
|
||||
|
||||
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
if (!items) return;
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
|
||||
const key = event.key;
|
||||
|
||||
@ -97,13 +99,17 @@ function DropDownItems({
|
||||
onClose();
|
||||
} else if (key === 'ArrowUp') {
|
||||
setHighlightedItem((prev) => {
|
||||
if (!prev) return items[0];
|
||||
if (!prev) {
|
||||
return items[0];
|
||||
}
|
||||
const index = items.indexOf(prev) - 1;
|
||||
return items[index === -1 ? items.length - 1 : index];
|
||||
});
|
||||
} else if (key === 'ArrowDown') {
|
||||
setHighlightedItem((prev) => {
|
||||
if (!prev) return items[0];
|
||||
if (!prev) {
|
||||
return items[0];
|
||||
}
|
||||
return items[items.indexOf(prev) + 1];
|
||||
});
|
||||
}
|
||||
@ -187,8 +193,9 @@ export default function DropDown({
|
||||
if (
|
||||
dropDownRef.current &&
|
||||
dropDownRef.current.contains(target as Node)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!button.contains(target as Node)) {
|
||||
setShowDropDown(false);
|
||||
|
@ -48,7 +48,9 @@ export function createLinkMatcherWithRegExp(
|
||||
) {
|
||||
return (text: string) => {
|
||||
const match = regExp.exec(text);
|
||||
if (match === null) return null;
|
||||
if (match === null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
index: match.index,
|
||||
length: match[0].length,
|
||||
|
@ -369,7 +369,9 @@ function printRangeSelection(selection: RangeSelection): string {
|
||||
}
|
||||
|
||||
function printNodeSelection(selection: BaseSelection): string {
|
||||
if (!$isNodeSelection(selection)) return '';
|
||||
if (!$isNodeSelection(selection)) {
|
||||
return '';
|
||||
}
|
||||
return `: node\n └ [${Array.from(selection._nodes).join(', ')}]`;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,9 @@ export type MenuRenderFn<TOption extends MenuOption> = (
|
||||
|
||||
const scrollIntoViewIfNeeded = (target: HTMLElement) => {
|
||||
const typeaheadContainerNode = document.getElementById('typeahead-menu');
|
||||
if (!typeaheadContainerNode) return;
|
||||
if (!typeaheadContainerNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
const typeaheadRect = typeaheadContainerNode.getBoundingClientRect();
|
||||
|
||||
|
@ -153,7 +153,9 @@ export class QuoteNode extends ElementNode {
|
||||
const {element} = super.exportDOM(editor);
|
||||
|
||||
if (element && isHTMLElement(element)) {
|
||||
if (this.isEmpty()) element.append(document.createElement('br'));
|
||||
if (this.isEmpty()) {
|
||||
element.append(document.createElement('br'));
|
||||
}
|
||||
|
||||
const formatType = this.getFormatType();
|
||||
element.style.textAlign = formatType;
|
||||
@ -313,7 +315,9 @@ export class HeadingNode extends ElementNode {
|
||||
const {element} = super.exportDOM(editor);
|
||||
|
||||
if (element && isHTMLElement(element)) {
|
||||
if (this.isEmpty()) element.append(document.createElement('br'));
|
||||
if (this.isEmpty()) {
|
||||
element.append(document.createElement('br'));
|
||||
}
|
||||
|
||||
const formatType = this.getFormatType();
|
||||
element.style.textAlign = formatType;
|
||||
|
@ -2516,7 +2516,9 @@ describe('LexicalSelection tests', () => {
|
||||
invariant($isElementNode(column));
|
||||
const paragraph = column.getFirstChild();
|
||||
invariant($isElementNode(paragraph));
|
||||
if (paragraph.getFirstChild()) paragraph.getFirstChild().remove();
|
||||
if (paragraph.getFirstChild()) {
|
||||
paragraph.getFirstChild().remove();
|
||||
}
|
||||
root.append(table);
|
||||
|
||||
const selection = $createRangeSelection();
|
||||
|
@ -133,7 +133,9 @@ export class TableNode extends ElementNode {
|
||||
}
|
||||
|
||||
const x = row.findIndex((cell) => {
|
||||
if (!cell) return;
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
const {elem} = cell;
|
||||
const cellNode = $getNearestNodeFromDOMNode(elem);
|
||||
return cellNode === tableCellNode;
|
||||
|
@ -50,13 +50,19 @@ export function $createTableNodeWithDimensions(
|
||||
let headerState = TableCellHeaderStates.NO_STATUS;
|
||||
|
||||
if (typeof includeHeaders === 'object') {
|
||||
if (iRow === 0 && includeHeaders.rows)
|
||||
if (iRow === 0 && includeHeaders.rows) {
|
||||
headerState |= TableCellHeaderStates.ROW;
|
||||
if (iColumn === 0 && includeHeaders.columns)
|
||||
}
|
||||
if (iColumn === 0 && includeHeaders.columns) {
|
||||
headerState |= TableCellHeaderStates.COLUMN;
|
||||
}
|
||||
} else if (includeHeaders) {
|
||||
if (iRow === 0) headerState |= TableCellHeaderStates.ROW;
|
||||
if (iColumn === 0) headerState |= TableCellHeaderStates.COLUMN;
|
||||
if (iRow === 0) {
|
||||
headerState |= TableCellHeaderStates.ROW;
|
||||
}
|
||||
if (iColumn === 0) {
|
||||
headerState |= TableCellHeaderStates.COLUMN;
|
||||
}
|
||||
}
|
||||
|
||||
const tableCellNode = $createTableCellNode(headerState);
|
||||
|
@ -143,7 +143,9 @@ class NoInheritPlugin {
|
||||
}
|
||||
// As we move up the chain, check if the reflection parent is in the noInherit list
|
||||
const parent = current.parent;
|
||||
if (!parent) return false;
|
||||
if (!parent) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
this.isNoInherit(parent) &&
|
||||
(depth === 0 || this.isInherited(current))
|
||||
|
@ -853,7 +853,9 @@ export class LexicalNode {
|
||||
replace<N extends LexicalNode>(replaceWith: N, includeChildren?: boolean): N {
|
||||
errorOnReadOnly();
|
||||
let selection = $getSelection();
|
||||
if (selection !== null) selection = selection.clone();
|
||||
if (selection !== null) {
|
||||
selection = selection.clone();
|
||||
}
|
||||
errorOnInsertTextNodeOnRoot(this, replaceWith);
|
||||
const self = this.getLatest();
|
||||
const toReplaceKey = this.__key;
|
||||
|
@ -71,7 +71,9 @@ export class ParagraphNode extends ElementNode {
|
||||
const {element} = super.exportDOM(editor);
|
||||
|
||||
if (element && isHTMLElement(element)) {
|
||||
if (this.isEmpty()) element.append(document.createElement('br'));
|
||||
if (this.isEmpty()) {
|
||||
element.append(document.createElement('br'));
|
||||
}
|
||||
|
||||
const formatType = this.getFormatType();
|
||||
element.style.textAlign = formatType;
|
||||
|
Reference in New Issue
Block a user