Skip to content

Commit

Permalink
style: eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylrj committed Jun 9, 2021
1 parent 4dbb8ab commit 1a33a13
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/component/base/DraftEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
textDirectionality,
} = this.props;

const {contentsKey, blockKeyMap} = this.state;
const {blockKeyMap} = this.state;

const rootClass = cx({
'DraftEditor/root': true,
Expand Down
28 changes: 14 additions & 14 deletions src/component/contents/__tests__/DraftEditorTextNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const expectPopulatedSpan = (stub, testString) => {
expect(node.firstChild && node.firstChild.textContent).toBe(testString);
};

test('must initialize correctly with an empty string, non-IE', function () {
test('must initialize correctly with an empty string, non-IE', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{''}</DraftEditorTextNode>,
Expand All @@ -66,31 +66,31 @@ test('must initialize correctly with an empty string, non-IE', function () {
expect(ReactDOM.findDOMNode(stub).tagName).toBe('BR');
});

test('must initialize correctly with an empty string, IE', function () {
test('must initialize correctly with an empty string, IE', function() {
initializeAsIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{''}</DraftEditorTextNode>,
);
expectPopulatedSpan(stub, BLOCK_DELIMITER_CHAR);
});

test('must initialize correctly with a string, non-IE', function () {
test('must initialize correctly with a string, non-IE', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
);
expectPopulatedSpan(stub, TEST_A);
});

test('must initialize correctly with a string, IE', function () {
test('must initialize correctly with a string, IE', function() {
initializeAsIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
);
expectPopulatedSpan(stub, TEST_A);
});

test('must update from empty to non-empty, non-IE', function () {
test('must update from empty to non-empty, non-IE', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{''}</DraftEditorTextNode>,
Expand All @@ -100,7 +100,7 @@ test('must update from empty to non-empty, non-IE', function () {
expectPopulatedSpan(stub, TEST_A);
});

test('must update from empty to non-empty, IE', function () {
test('must update from empty to non-empty, IE', function() {
initializeAsIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{''}</DraftEditorTextNode>,
Expand All @@ -110,7 +110,7 @@ test('must update from empty to non-empty, IE', function () {
expectPopulatedSpan(stub, TEST_A);
});

test('must update from non-empty to non-empty, non-IE', function () {
test('must update from non-empty to non-empty, non-IE', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand All @@ -126,7 +126,7 @@ test('must update from non-empty to non-empty, non-IE', function () {
expectPopulatedSpan(stub, TEST_B);
});

test('must update from non-empty to non-empty, non-IE', function () {
test('must update from non-empty to non-empty, non-IE', function() {
initializeAsIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand All @@ -141,7 +141,7 @@ test('must update from non-empty to non-empty, non-IE', function () {
expectPopulatedSpan(stub, TEST_B);
});

test('must skip updates if text already matches DOM, non-IE', function () {
test('must skip updates if text already matches DOM, non-IE', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand All @@ -163,7 +163,7 @@ test('must skip updates if text already matches DOM, non-IE', function () {
expect(stub.render.mock.calls.length).toBe(1);
});

test('must skip updates if text already matches DOM, IE', function () {
test('must skip updates if text already matches DOM, IE', function() {
initializeAsIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand All @@ -185,7 +185,7 @@ test('must skip updates if text already matches DOM, IE', function () {
expect(stub.render.mock.calls.length).toBe(1);
});

test('must update from non-empty to empty, non-IE', function () {
test('must update from non-empty to empty, non-IE', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand All @@ -198,7 +198,7 @@ test('must update from non-empty to empty, non-IE', function () {
expect(ReactDOM.findDOMNode(stub).tagName).toBe('BR');
});

test('must update from non-empty to empty, IE', function () {
test('must update from non-empty to empty, IE', function() {
initializeAsIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand All @@ -209,7 +209,7 @@ test('must update from non-empty to empty, IE', function () {
expectPopulatedSpan(stub, BLOCK_DELIMITER_CHAR);
});

test('must render properly into a parent DOM node', function () {
test('must render properly into a parent DOM node', function() {
initializeAsNonIE();
renderIntoContainer(
<div>
Expand All @@ -218,7 +218,7 @@ test('must render properly into a parent DOM node', function () {
);
});

test('must force unchanged text back into the DOM', function () {
test('must force unchanged text back into the DOM', function() {
initializeAsNonIE();
const stub = renderIntoContainer(
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ const assertCutOperation = (
SelectionState.createEmpty(content[0].key).merge(selection),
),
);
const expected = result.getCurrentContent().getBlockMap().toJS();
const expected = result
.getCurrentContent()
.getBlockMap()
.toJS();

expect(expected).toMatchSnapshot();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function keyCommandBackspaceWord(editorState: EditorState): EditorState {
}
const key = selection.getStartKey();
const content = strategyState.getCurrentContent();
const text = content.getBlockForKey(key).getText().slice(0, offset);
const text = content
.getBlockForKey(key)
.getText()
.slice(0, offset);
const toRemove = DraftRemovableWord.getBackward(text);
return moveSelectionBackward(strategyState, toRemove.length || 1);
},
Expand Down
5 changes: 4 additions & 1 deletion src/component/handlers/edit/commands/keyCommandDeleteWord.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ function keyCommandDeleteWord(editorState: EditorState): EditorState {
const offset = selection.getStartOffset();
const key = selection.getStartKey();
const content = strategyState.getCurrentContent();
const text = content.getBlockForKey(key).getText().slice(offset);
const text = content
.getBlockForKey(key)
.getText()
.slice(offset);
const toRemove = DraftRemovableWord.getForward(text);

// If there are no words in front of the cursor, remove the newline.
Expand Down
2 changes: 1 addition & 1 deletion src/component/handlers/edit/editOnBlur.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function editOnBlur(editor: DraftEditor, e: SyntheticEvent<HTMLElement>): void {
// opposed to clicking to another tab or window).
const {ownerDocument} = e.currentTarget;
if (
!Boolean(editor.props.preserveSelectionOnBlur) &&
!editor.props.preserveSelectionOnBlur &&
getActiveElement(ownerDocument) === ownerDocument.body
) {
const selection: SelectionObject = ownerDocument.defaultView.getSelection();
Expand Down
2 changes: 1 addition & 1 deletion src/component/selection/getRangeClientRects.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function getRangeClientRectsChrome(range: Range): Array<ClientRect> {
*/
const getRangeClientRects = ((isChrome
? getRangeClientRectsChrome
: function (range: Range): Array<ClientRect> {
: function(range: Range): Array<ClientRect> {
return Array.from(range.getClientRects());
}): (range: Range) => Array<ClientRect>);

Expand Down
2 changes: 1 addition & 1 deletion src/component/selection/setDraftEditorSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function addFocusToSelection(
}
} catch (e) {
DraftJsDebugLogging.logSelectionStateFailure({
anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
anonymizedDom: getAnonymizedEditorDOM(node, function(n) {
const labels = [];
if (n === activeElement) {
labels.push('active element');
Expand Down
8 changes: 4 additions & 4 deletions src/component/utils/getTextContentFromFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function getTextContentFromFiles(
): void {
let readCount = 0;
const results = [];
files.forEach(function (/*blob*/ file) {
readFile(file, function (/*string*/ text) {
files.forEach(function(/*blob*/ file) {
readFile(file, function(/*string*/ text) {
readCount++;
text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
if (readCount == files.length) {
Expand Down Expand Up @@ -67,15 +67,15 @@ function readFile(file: File, callback: (contents: string) => void): void {
}

const reader = new FileReader();
reader.onload = function () {
reader.onload = function() {
const result = reader.result;
invariant(
typeof result === 'string',
'We should be calling "FileReader.readAsText" which returns a string',
);
callback(result);
};
reader.onerror = function () {
reader.onerror = function() {
callback('');
};
reader.readAsText(file);
Expand Down
3 changes: 1 addition & 2 deletions src/model/immutable/ContentBlockNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ const decorateCharacterList = (
return config;
};

class ContentBlockNode
extends (Record(defaultRecord): any)
class ContentBlockNode extends (Record(defaultRecord): any)
implements BlockNode {
constructor(props: ContentBlockNodeConfig = defaultRecord) {
/* eslint-disable-next-line constructor-super */
Expand Down
10 changes: 8 additions & 2 deletions src/model/immutable/EditorState.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ class EditorState {
if (contentState.getBlockMap().count() === 0) {
return EditorState.createEmpty(decorator);
}
const firstKey = contentState.getBlockMap().first().getKey();
const firstKey = contentState
.getBlockMap()
.first()
.getKey();
return EditorState.create({
currentContent: contentState,
undoStack: Stack(),
Expand Down Expand Up @@ -343,7 +346,10 @@ class EditorState {
}

isSelectionAtStartOfContent(): boolean {
const firstKey = this.getCurrentContent().getBlockMap().first().getKey();
const firstKey = this.getCurrentContent()
.getBlockMap()
.first()
.getKey();
return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
}

Expand Down

0 comments on commit 1a33a13

Please sign in to comment.