From 3339d088e14ad0bf04a674c14834179403ae369f Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Tue, 6 Feb 2018 23:12:00 +0000 Subject: [PATCH] Add Prettier with ESLint integration (#1589) * Add Prettier, with basic config and ESLint integration * Apply Prettier to all files using `yarn lint --fix` * Tell Prettier to ignore an empty text in a test output. * Run Prettier on JS files not handled by ESLint, and lint them too --- .eslintrc | 95 ++-- .prettierignore | 5 + examples/check-lists/index.js | 29 +- examples/code-highlighting/index.js | 41 +- examples/embeds/index.js | 10 +- examples/embeds/video.js | 13 +- examples/emojis/index.js | 30 +- examples/forced-layout/index.js | 20 +- examples/history/index.js | 17 +- examples/hovering-menu/index.js | 47 +- examples/huge-document/index.js | 27 +- examples/images/index.js | 23 +- examples/index.js | 39 +- examples/links/index.js | 31 +- examples/markdown-preview/index.js | 55 ++- examples/markdown-shortcuts/index.js | 75 ++-- examples/paste-html/index.js | 101 +++-- examples/plain-text/index.js | 7 +- examples/plugins/index.js | 17 +- examples/read-only/index.js | 7 +- examples/rich-text/index.js | 64 +-- examples/rtl/index.js | 10 +- examples/search-highlighting/index.js | 15 +- examples/syncing-operations/index.js | 41 +- examples/tables/index.js | 34 +- package.json | 11 +- packages/slate-base64-serializer/src/index.js | 3 +- packages/slate-dev-logger/src/index.js | 7 +- .../benchmark/html-serializer/deserialize.js | 24 +- .../benchmark/html-serializer/serialize.js | 23 +- .../slate-html-serializer/benchmark/index.js | 13 +- packages/slate-html-serializer/src/index.js | 130 +++--- .../test/deserialize/block-nested.js | 11 +- .../test/deserialize/block-no-children.js | 7 +- .../test/deserialize/block-with-data.js | 11 +- .../test/deserialize/block-with-is-void.js | 7 +- .../test/deserialize/block.js | 11 +- .../test/deserialize/default-block.js | 15 +- .../test/deserialize/empty-string.js | 1 - .../test/deserialize/html-comment.js | 11 +- .../test/deserialize/inline-nested.js | 11 +- .../test/deserialize/inline-no-children.js | 7 +- .../test/deserialize/inline-with-data.js | 11 +- .../test/deserialize/inline-with-is-void.js | 7 +- .../test/deserialize/inline.js | 11 +- .../test/deserialize/mark-adjacent.js | 7 +- .../test/deserialize/mark-nested.js | 11 +- .../test/deserialize/mark-with-data.js | 7 +- .../test/deserialize/mark.js | 7 +- .../deserialize/multiple-matching-rules.js | 7 +- .../test/deserialize/no-next.js | 7 +- .../test/deserialize/skip-element.js | 7 +- .../test/deserialize/to-json.js | 21 +- .../slate-html-serializer/test/helpers/h.js | 5 +- packages/slate-html-serializer/test/index.js | 11 +- .../test/serialize/block-nested.js | 15 +- .../test/serialize/block-with-data.js | 15 +- .../test/serialize/block-with-is-void.js | 5 +- .../test/serialize/block-with-mark.js | 5 +- .../test/serialize/block.js | 9 +- .../test/serialize/inline-nested.js | 9 +- .../test/serialize/inline-with-data.js | 15 +- .../test/serialize/inline-with-is-void.js | 5 +- .../test/serialize/inline-with-mark.js | 5 +- .../test/serialize/inline.js | 9 +- .../test/serialize/multiple-rules.js | 11 +- packages/slate-hyperscript/src/index.js | 55 +-- .../slate-plain-serializer/benchmark/index.js | 13 +- .../benchmark/plain-serializer/deserialize.js | 6 +- .../benchmark/plain-serializer/serialize.js | 5 +- packages/slate-plain-serializer/src/index.js | 23 +- .../test/deserialize/line-multiple.js | 8 +- .../test/deserialize/line.js | 4 +- .../test/deserialize/to-json.js | 17 +- .../slate-plain-serializer/test/helpers/h.js | 5 +- packages/slate-plain-serializer/test/index.js | 11 +- .../test/serialize/block-multiple-empty.js | 8 +- .../test/serialize/block-multiple.js | 12 +- .../serialize/block-nested-multiple-empty.js | 12 +- .../test/serialize/block-nested-multiple.js | 16 +- .../serialize/block-nested-nested-multiple.js | 16 +- .../block-nested-with-inline-nested.js | 8 +- .../serialize/block-nested-with-inlines.js | 8 +- .../test/serialize/block-with-data.js | 4 +- .../test/serialize/block.js | 4 +- .../test/serialize/inline-nested.js | 4 +- .../test/serialize/inline-with-data.js | 4 +- .../test/serialize/inline.js | 4 +- packages/slate-prop-types/src/index.js | 12 +- packages/slate-react/benchmark/index.js | 13 +- .../slate-react/benchmark/rendering/normal.js | 5 +- .../slate-react/src/components/content.js | 76 ++-- packages/slate-react/src/components/editor.js | 38 +- packages/slate-react/src/components/leaf.js | 11 +- packages/slate-react/src/components/node.js | 29 +- packages/slate-react/src/components/text.js | 7 +- packages/slate-react/src/components/void.js | 18 +- .../slate-react/src/constants/environment.js | 11 +- .../src/constants/event-handlers.js | 1 - packages/slate-react/src/constants/hotkeys.js | 21 +- .../slate-react/src/constants/plugin-props.js | 1 - .../src/constants/transfer-types.js | 1 - packages/slate-react/src/index.js | 1 - packages/slate-react/src/plugins/after.js | 65 +-- packages/slate-react/src/plugins/before.js | 11 +- .../slate-react/src/utils/clone-fragment.js | 20 +- .../src/utils/find-deepest-node.js | 5 +- .../slate-react/src/utils/find-dom-node.js | 5 +- .../slate-react/src/utils/find-dom-point.js | 3 +- .../slate-react/src/utils/find-dom-range.js | 10 +- packages/slate-react/src/utils/find-node.js | 1 - packages/slate-react/src/utils/find-point.js | 19 +- packages/slate-react/src/utils/find-range.js | 14 +- .../slate-react/src/utils/get-event-range.js | 8 +- .../src/utils/get-event-transfer.js | 19 +- .../src/utils/get-html-from-native-paste.js | 1 - packages/slate-react/src/utils/noop.js | 1 - packages/slate-react/src/utils/offset-key.js | 7 +- .../src/utils/scroll-to-selection.js | 35 +- .../src/utils/set-event-transfer.js | 11 +- packages/slate-react/test/helpers/clean.js | 8 +- packages/slate-react/test/helpers/h.js | 5 +- packages/slate-react/test/index.js | 1 - .../plugins/core/on-blur/blur-selection.js | 2 +- .../core/on-key-down/split-empty-block.js | 2 +- .../plugins/core/on-select/move-selection.js | 7 +- packages/slate-react/test/plugins/index.js | 12 +- .../fixtures/custom-block-multiple.js | 23 +- .../rendering/fixtures/custom-block-void.js | 10 +- .../test/rendering/fixtures/custom-block.js | 17 +- .../rendering/fixtures/custom-decorator.js | 23 +- .../fixtures/custom-inline-multiple.js | 21 +- .../rendering/fixtures/custom-inline-void.js | 7 +- .../test/rendering/fixtures/custom-inline.js | 13 +- .../test/rendering/fixtures/custom-mark.js | 3 +- .../fixtures/default-block-with-inline.js | 4 +- .../test/rendering/fixtures/default-block.js | 4 +- .../fixtures/nested-text-direction.js | 8 +- .../fixtures/readonly-custom-block-void.js | 8 +- .../fixtures/readonly-custom-inline-void.js | 7 +- .../test/rendering/fixtures/text-direction.js | 12 +- packages/slate-react/test/rendering/index.js | 6 +- packages/slate-schema-violations/src/index.js | 1 - packages/slate-simulator/src/index.js | 12 +- .../benchmark/changes/delete-backward.js | 5 +- .../slate/benchmark/changes/delete-forward.js | 5 +- .../changes/insert-text-by-key-multiple.js | 10 +- .../benchmark/changes/insert-text-by-key.js | 5 +- .../slate/benchmark/changes/insert-text.js | 5 +- packages/slate/benchmark/changes/normalize.js | 5 +- .../slate/benchmark/changes/split-block.js | 5 +- packages/slate/benchmark/index.js | 13 +- packages/slate/benchmark/models/from-json.js | 18 +- .../benchmark/models/get-blocks-at-range.js | 10 +- packages/slate/benchmark/models/get-blocks.js | 5 +- .../models/get-characters-at-range.js | 10 +- .../slate/benchmark/models/get-characters.js | 5 +- .../benchmark/models/get-inlines-at-range.js | 10 +- .../slate/benchmark/models/get-inlines.js | 5 +- packages/slate/benchmark/models/get-leaves.js | 5 +- .../benchmark/models/get-marks-at-range.js | 10 +- packages/slate/benchmark/models/get-marks.js | 5 +- packages/slate/benchmark/models/get-path.js | 5 +- .../benchmark/models/get-texts-at-range.js | 10 +- packages/slate/benchmark/models/get-texts.js | 5 +- .../benchmark/models/has-node-multiple.js | 12 +- packages/slate/benchmark/models/has-node.js | 5 +- packages/slate/benchmark/models/to-json.js | 5 +- .../slate/benchmark/models/update-node.js | 5 +- .../slate/src/changes/at-current-range.js | 40 +- packages/slate/src/changes/at-range.js | 241 ++++++----- packages/slate/src/changes/by-key.js | 64 ++- packages/slate/src/changes/index.js | 1 - packages/slate/src/changes/on-history.js | 29 +- packages/slate/src/changes/on-selection.js | 97 ++--- packages/slate/src/changes/on-value.js | 14 +- packages/slate/src/changes/with-schema.js | 12 +- .../slate/src/constants/core-schema-rules.js | 76 ++-- packages/slate/src/constants/model-types.js | 1 - .../src/constants/operation-attributes.js | 94 +--- packages/slate/src/index.js | 1 - packages/slate/src/models/block.js | 18 +- packages/slate/src/models/change.js | 18 +- packages/slate/src/models/character.js | 21 +- packages/slate/src/models/data.js | 7 +- packages/slate/src/models/document.js | 20 +- packages/slate/src/models/history.js | 46 +- packages/slate/src/models/inline.js | 18 +- packages/slate/src/models/leaf.js | 31 +- packages/slate/src/models/mark.js | 29 +- packages/slate/src/models/node.js | 409 ++++++++++-------- packages/slate/src/models/operation.js | 37 +- packages/slate/src/models/range.js | 130 +++--- packages/slate/src/models/schema.js | 123 ++++-- packages/slate/src/models/stack.js | 16 +- packages/slate/src/models/text.js | 71 +-- packages/slate/src/models/value.js | 40 +- packages/slate/src/operations/apply.js | 45 +- packages/slate/src/operations/index.js | 1 - packages/slate/src/operations/invert.js | 63 +-- packages/slate/src/utils/generate-key.js | 7 +- packages/slate/src/utils/is-index-in-range.js | 1 - .../slate/src/utils/is-react-component.js | 7 +- packages/slate/src/utils/memoize.js | 12 +- packages/slate/src/utils/string.js | 13 +- .../add-mark/across-blocks.js | 8 +- .../add-mark/across-inlines.js | 16 +- .../add-mark/collapsed-selection.js | 9 +- .../add-mark/existing-marks.js | 14 +- .../add-mark/first-character.js | 6 +- .../add-mark/last-character.js | 6 +- .../add-mark/middle-character.js | 6 +- .../at-current-range/add-mark/whole-word.js | 6 +- .../add-mark/with-mark-object.js | 17 +- .../add-mark/with-plain-object.js | 8 +- .../add-marks/across-blocks.js | 12 +- .../add-marks/across-inlines.js | 20 +- .../add-marks/collapsed-selection.js | 11 +- .../add-marks/existing-marks.js | 16 +- .../add-marks/first-character.js | 8 +- .../add-marks/last-character.js | 8 +- .../add-marks/middle-character.js | 8 +- .../at-current-range/add-marks/whole-word.js | 8 +- .../add-marks/with-mark-object.js | 29 +- .../add-marks/with-plain-object.js | 12 +- .../delete-backward/empty-after-void-block.js | 5 +- .../delete-backward/first-character.js | 2 +- .../delete-backward/inline-after.js | 5 +- .../delete-backward/inline-before.js | 8 +- .../delete-backward/inline-end.js | 8 +- .../delete-backward/inline-inside.js | 6 +- .../join-blocks-with-inline-void.js | 5 +- .../join-blocks-with-inline.js | 6 +- .../delete-backward/join-blocks.js | 6 +- .../delete-backward/join-nested-blocks.js | 6 +- .../delete-backward/last-character.js | 2 +- .../delete-backward/middle-character.js | 2 +- .../delete-backward/multiple-characters.js | 10 +- .../delete-backward/single-non-void-block.js | 2 +- .../delete-backward/single-void-block.js | 2 +- .../delete-backward/start-of-document.js | 2 +- .../inline-after-emoji.js | 5 +- .../delete-char-backward/inline-end-emoji.js | 10 +- .../inline-inside-emoji.js | 10 +- .../delete-char-backward/inline-only-emoji.js | 6 +- .../delete-char-backward/text-end.js | 2 +- .../delete-char-backward/text-middle.js | 2 +- .../delete-char-backward/text-start.js | 2 +- .../inline-before-emoji.js | 5 +- .../inline-middle-emoji.js | 10 +- .../delete-char-forward/inline-start-emoji.js | 10 +- .../delete-char-forward/text-last.js | 2 +- .../delete-char-forward/text-middle.js | 2 +- .../delete-char-forward/text-start.js | 2 +- .../delete-forward/before-inline-sibling.js | 8 +- .../delete-forward/empty-before-void-block.js | 2 +- .../delete-forward/end-of-document.js | 2 +- .../delete-forward/first-character.js | 2 +- .../delete-forward/inside-inline-sibling.js | 10 +- .../join-blocks-with-inline-void.js | 5 +- .../delete-forward/join-blocks-with-inline.js | 2 +- .../delete-forward/join-blocks.js | 6 +- .../delete-forward/join-nested-blocks.js | 6 +- .../delete-forward/last-character.js | 2 +- .../delete-forward/middle-character.js | 2 +- .../delete-forward/multiple-characters.js | 2 +- .../delete-forward/single-non-void-block.js | 2 +- .../delete-forward/single-void-block.js | 2 +- .../start-text-middle-inline.js | 11 +- .../inline-middle-emoji.js | 5 +- .../inline-multi-voids.js | 2 +- .../delete-line-backward/inline-void-first.js | 2 +- .../delete-line-backward/text-end.js | 2 +- .../delete-line-backward/word-middle.js | 2 +- .../inline-after-emoji.js | 2 +- .../inline-middle-emoji.js | 6 +- .../delete-word-backward/text-end.js | 2 +- .../delete-word-backward/word-middle.js | 2 +- .../delete-word-forward/inline-after-emoji.js | 5 +- .../inline-middle-emoji.js | 5 +- .../delete-word-forward/word-middle.js | 2 +- .../delete-word-forward/word-start.js | 2 +- .../delete/across-blocks-inlines.js | 14 +- .../at-current-range/delete/across-depths.js | 2 +- .../delete/across-nested-blocks.js | 14 +- .../delete/across-texts-and-inlines.js | 2 +- .../delete/before-inline-sibling.js | 8 +- .../delete/first-character.js | 2 +- .../hanging-selection-multiple-blocks.js | 6 +- .../delete/hanging-selection-single-block.js | 2 +- .../delete/inside-inline-sibling.js | 6 +- .../delete/join-blocks-and-trim.js | 2 +- .../delete/join-blocks-with-inlines.js | 2 +- .../at-current-range/delete/join-blocks.js | 2 +- .../delete/join-double-nested-blocks.js | 2 +- .../delete/join-nested-blocks.js | 2 +- .../at-current-range/delete/last-character.js | 2 +- .../delete/middle-character.js | 2 +- .../at-current-range/delete/nested-block.js | 6 +- ...-first-with-void-siblings-only-non-void.js | 10 +- ...tially-non-void-and-up-to-start-of-void.js | 10 +- ...id-siblings-partially-non-void-and-void.js | 13 +- ...t-with-void-siblings-partially-non-void.js | 10 +- ...ock-as-first-with-non-void-siblings-all.js | 6 +- ...on-void-siblings-backward-selection-all.js | 6 +- ...-first-with-non-void-siblings-only-void.js | 10 +- ...void-siblings-select-void-and-next-word.js | 10 +- ...-siblings-select-void-end-and-next-word.js | 13 +- .../delete/void-block-as-only.js | 4 +- ...-with-non-void-siblings-only-first-void.js | 14 +- ...first-with-non-void-siblings-only-voids.js | 10 +- ...nline-as-first-with-non-void-block-next.js | 6 +- ...d-inline-as-first-with-non-void-sibling.js | 11 +- .../at-current-range/delete/whole-inline.js | 6 +- .../at-current-range/delete/whole-word.js | 2 +- .../insert-block/block-end.js | 6 +- .../insert-block/block-middle.js | 10 +- .../insert-block/block-start.js | 6 +- .../at-current-range/insert-block/is-empty.js | 10 +- .../insert-block/is-void-end.js | 13 +- .../insert-block/is-void-start.js | 10 +- .../insert-block/with-block.js | 7 +- .../insert-block/with-object.js | 6 +- .../end-block-multiple-blocks.js | 26 +- .../insert-fragment/end-block.js | 10 +- .../insert-fragment/end-inline.js | 17 +- .../fragment-multiple-blocks.js | 18 +- .../insert-fragment/fragment-nested-blocks.js | 18 +- .../insert-fragment/middle-block.js | 10 +- .../middle-inline-fragment-inline.js | 15 +- .../insert-fragment/middle-inline.js | 17 +- .../nested-block-fragment-nested-blocks.js | 18 +- .../start-block-multiple-blocks.js | 26 +- .../insert-fragment/start-block.js | 10 +- .../insert-fragment/start-inline.js | 18 +- .../insert-fragment/start-second-block.js | 18 +- .../with-delete-across-blocks.js | 10 +- .../insert-inline/block-end.js | 9 +- .../insert-inline/block-middle.js | 13 +- .../insert-inline/block-start.js | 9 +- .../insert-inline/inline-middle.js | 15 +- .../insert-inline/is-empty.js | 9 +- .../at-current-range/insert-inline/is-void.js | 4 +- .../insert-inline/with-inline.js | 21 +- .../insert-text/after-mark.js | 10 +- .../insert-text/before-mark.js | 8 +- .../insert-text/during-mark.js | 10 +- .../insert-text/first-character.js | 2 +- .../insert-text/first-space.js | 5 +- .../insert-text/first-words.js | 6 +- .../hanging-selection-multiple-blocks.js | 6 +- .../hanging-selection-single-block.js | 2 +- .../insert-text/inside-void.js | 2 +- .../insert-text/last-character.js | 2 +- .../insert-text/last-space.js | 2 +- .../insert-text/last-words.js | 2 +- .../insert-text/middle-character.js | 2 +- .../insert-text/middle-space.js | 2 +- .../insert-text/middle-words.js | 2 +- .../insert-text/with-marks.js | 5 +- .../remove-mark/across-blocks.js | 8 +- .../remove-mark/across-inlines.js | 20 +- .../remove-mark/collapsed-selection.js | 2 +- .../remove-mark/existing-marks.js | 13 +- .../remove-mark/first-character.js | 6 +- .../remove-mark/last-character.js | 6 +- .../remove-mark/middle-character.js | 6 +- .../remove-mark/whole-word.js | 6 +- .../remove-mark/with-mark-object.js | 16 +- .../remove-mark/with-plain-object.js | 8 +- .../set-block/across-blocks.js | 2 +- .../set-block/across-inlines.js | 18 +- .../at-current-range/set-block/data-only.js | 3 +- .../set-block/nested-block.js | 2 +- .../single-block-string-shorthand.js | 2 +- .../set-block/single-block.js | 2 +- .../set-block/with-data-as-map.js | 4 +- .../set-block/with-data-as-object.js | 4 +- .../set-block/with-is-void.js | 4 +- .../set-inline/across-inlines.js | 18 +- .../at-current-range/set-inline/data-only.js | 10 +- .../set-inline/nested-inline.js | 10 +- .../single-inline-string-shorthand.js | 10 +- .../set-inline/single-inline.js | 10 +- .../set-inline/with-data-object.js | 12 +- .../at-current-range/set-inline/with-data.js | 12 +- .../set-inline/with-is-void.js | 11 +- .../split-block/after-inline-void.js | 5 +- .../split-block/after-inline.js | 5 +- .../split-block/before-inline.js | 14 +- .../at-current-range/split-block/block-end.js | 14 +- .../split-block/block-middle.js | 6 +- .../split-block/block-start.js | 10 +- .../at-current-range/split-block/depth.js | 10 +- .../with-delete-across-blocks-and-inlines.js | 14 +- .../split-block/with-delete-across-blocks.js | 14 +- .../split-block/with-delete.js | 10 +- .../split-block/with-inline.js | 10 +- .../split-inline/block-end.js | 10 +- .../split-inline/block-middle.js | 11 +- .../split-inline/block-start.js | 10 +- .../at-current-range/split-inline/depth.js | 15 +- .../split-inline/with-delete.js | 11 +- .../split-inline/with-marks.js | 17 +- .../toggle-mark/add-across-blocks.js | 8 +- .../toggle-mark/add-across-inlines.js | 18 +- .../add-collapsed-selection-beginning.js | 9 +- .../toggle-mark/add-collapsed-selection.js | 9 +- .../add-existing-marks-partially-marked.js | 15 +- .../toggle-mark/add-existing-marks.js | 13 +- .../toggle-mark/add-first-character.js | 6 +- .../toggle-mark/add-last-character.js | 6 +- .../toggle-mark/add-middle-character.js | 6 +- .../toggle-mark/add-partially-marked.js | 9 +- .../toggle-mark/add-whole-word.js | 6 +- .../toggle-mark/add-with-mark-object.js | 16 +- .../toggle-mark/add-with-plain-object.js | 8 +- .../toggle-mark/remove-across-blocks.js | 8 +- .../toggle-mark/remove-across-inlines.js | 21 +- .../remove-collapsed-selection-beginning.js | 2 +- .../toggle-mark/remove-collapsed-selection.js | 2 +- .../toggle-mark/remove-existing-marks.js | 13 +- .../toggle-mark/remove-first-character.js | 6 +- .../toggle-mark/remove-last-character.js | 6 +- .../toggle-mark/remove-middle-character.js | 6 +- .../toggle-mark/remove-whole-word.js | 6 +- .../toggle-mark/remove-with-mark-object.js | 16 +- .../toggle-mark/remove-with-plain-object.js | 8 +- .../unwrap-block/across-blocks.js | 2 +- .../unwrap-block/across-inlines.js | 18 +- .../unwrap-block/ending-child-blocks.js | 34 +- ...le-child-blocks-with-backward-selection.js | 35 +- .../unwrap-block/middle-child-blocks.js | 34 +- .../unwrap-block/nested-block.js | 2 +- .../unwrap-block/single-block.js | 2 +- .../unwrap-block/starting-child-blocks.js | 34 +- .../unwrap-block/with-object.js | 12 +- .../unwrap-inline/across-blocks.js | 2 +- .../unwrap-inline/across-inlines-and-text.js | 8 +- .../unwrap-inline/across-inlines.js | 24 +- .../unwrap-inline/nested-block.js | 7 +- .../unwrap-inline/only-one.js | 9 +- .../unwrap-inline/single-block.js | 11 +- .../unwrap-inline/with-object.js | 14 +- .../wrap-block/across-blocks.js | 2 +- .../wrap-block/across-inlines.js | 18 +- .../wrap-block/nested-block.js | 2 +- .../wrap-block/single-block.js | 2 +- .../wrap-block/with-object.js | 4 +- .../wrap-inline/across-blocks.js | 9 +- .../wrap-inline/across-inlines.js | 20 +- .../wrap-inline/inline-void.js | 12 +- .../wrap-inline/nested-block.js | 7 +- .../wrap-inline/single-block.js | 7 +- .../at-current-range/wrap-inline/twice.js | 17 +- .../wrap-inline/whole-block.js | 7 +- .../wrap-inline/with-object.js | 9 +- .../wrap-text/across-blocks.js | 2 +- .../wrap-text/across-inlines.js | 18 +- .../wrap-text/backwards-selection.js | 2 +- .../at-current-range/wrap-text/empty-block.js | 2 +- .../wrap-text/end-of-block.js | 2 +- .../wrap-text/middle-of-block.js | 2 +- .../wrap-text/start-of-block.js | 2 +- .../at-current-range/wrap-text/whole-block.js | 2 +- .../wrap-text/without-suffix.js | 2 +- .../insert-fragment-by-key/end-of-target.js | 32 +- .../middle-of-target.js | 40 +- .../insert-fragment-by-key/start-of-target.js | 24 +- .../by-key/insert-node-by-key/block.js | 2 +- .../by-key/insert-node-by-key/duplicate.js | 6 +- .../by-key/insert-node-by-key/inline.js | 25 +- .../insert-text-by-key/selection-after.js | 6 +- .../insert-text-by-key/selection-before.js | 6 +- .../insert-text-by-key/selection-end.js | 6 +- .../insert-text-by-key/selection-middle.js | 6 +- .../insert-text-by-key/selection-start.js | 6 +- .../by-key/insert-text-by-key/start-text.js | 6 +- .../by-key/insert-text-by-key/text-end.js | 6 +- .../text-middle-with-marks.js | 2 +- .../by-key/insert-text-by-key/text-middle.js | 6 +- .../changes/by-key/merge-node-by-key/block.js | 14 +- .../changes/by-key/move-node-by-key/block.js | 10 +- .../changes/by-key/move-node-by-key/inline.js | 10 +- .../changes/by-key/move-node-by-key/text.js | 10 +- .../by-key/move-node-by-key/to-sibling.js | 10 +- .../by-key/remove-node-by-key/block.js | 14 +- .../by-key/remove-node-by-key/inline.js | 10 +- .../remove-node-by-key/selection-inside.js | 10 +- .../changes/by-key/remove-node-by-key/text.js | 10 +- .../adjacent-non-void-inlines.js | 9 +- .../inline-last-character.js | 6 +- .../inline-nested-last-character.js | 10 +- .../by-key/remove-text-by-key/inline-void.js | 9 +- .../by-key/remove-text-by-key/inline.js | 6 +- .../remove-text-by-key/next-void-inline.js | 9 +- .../previous-void-inline.js | 9 +- .../remove-text-by-key/selection-after.js | 6 +- .../remove-text-by-key/selection-before.js | 6 +- .../remove-text-by-key/selection-middle.js | 6 +- .../remove-text-by-key/selection-start.js | 6 +- .../changes/by-key/remove-text-by-key/text.js | 6 +- .../by-key/replace-node-by-key/block.js | 14 +- .../by-key/replace-node-by-key/inline.js | 8 +- .../by-key/replace-node-by-key/text.js | 14 +- .../by-key/set-mark-by-key/with-data.js | 27 +- .../changes/by-key/set-node-by-key/block.js | 10 +- .../set-node-by-key/inline-with-is-void.js | 11 +- .../set-node-by-key/string-shorthand.js | 10 +- .../block-with-selection.js | 6 +- .../by-key/split-descendants-by-key/block.js | 10 +- .../split-node-by-key/block-with-selection.js | 17 +- .../changes/by-key/split-node-by-key/block.js | 5 +- .../unwrap-block-by-key/single-block.js | 18 +- .../unwrap-inline-by-key/single-block.js | 2 +- .../by-key/unwrap-node-by-key/block.js | 10 +- .../by-key/unwrap-node-by-key/first-block.js | 18 +- .../by-key/unwrap-node-by-key/last-block.js | 18 +- .../by-key/unwrap-node-by-key/middle-block.js | 26 +- .../changes/by-key/wrap-block-by-key/block.js | 10 +- .../changes/by-key/wrap-block-by-key/text.js | 6 +- .../changes/general/call/call-no-arguments.js | 17 +- .../general/call/call-with-arguments.js | 17 +- packages/slate/test/changes/index.js | 10 +- .../test/changes/on-selection/blur/basic.js | 6 +- .../collapse-to-anchor/already-collapsed.js | 2 +- .../on-selection/collapse-to-anchor/basic.js | 2 +- .../collapse-to-end/already-collapsed.js | 2 +- .../on-selection/collapse-to-end/basic.js | 2 +- .../on-selection/collapse-to-end/void.js | 7 +- .../collapse-to-focus/already-collapsed.js | 2 +- .../on-selection/collapse-to-focus/basic.js | 2 +- .../collapse-to-start/already-collapsed.js | 2 +- .../on-selection/collapse-to-start/basic.js | 2 +- .../on-selection/collapse-to-start/void.js | 4 +- .../test/changes/on-selection/focus/basic.js | 6 +- .../on-selection/move-to/with-object.js | 2 +- .../on-selection/move-to/with-selection.js | 2 +- .../changes/on-selection/select-all/basic.js | 14 +- .../test/changes/on-state/set-data/simple.js | 20 +- packages/slate/test/helpers/h.js | 5 +- packages/slate/test/history/index.js | 10 +- .../history/undo/add-mark-across-blocks.js | 8 +- .../history/undo/add-mark-across-marks.js | 12 +- .../history/undo/add-mark-across-same-mark.js | 12 +- packages/slate/test/history/undo/add-mark.js | 8 +- .../test/history/undo/delete-across-blocks.js | 8 +- .../history/undo/delete-across-inlines.js | 16 +- .../test/history/undo/delete-across-marks.js | 15 +- packages/slate/test/history/undo/delete.js | 8 +- .../slate/test/history/undo/insert-block.js | 12 +- .../history/undo/insert-text-contiguous.js | 18 +- .../undo/insert-text-not-contiguous.js | 22 +- .../slate/test/history/undo/insert-text.js | 8 +- .../history/undo/move-node-affecting-path.js | 24 +- .../history/undo/move-node-before-itself.js | 36 +- .../test/history/undo/move-node-by-key.js | 16 +- .../slate/test/history/undo/remove-mark.js | 12 +- .../test/history/undo/remove-node-by-key.js | 12 +- .../history/undo/set-node-by-key-with-data.js | 14 +- .../history/undo/split-node-by-key-block.js | 12 +- .../test/history/undo/unwrap-node-by-key.js | 16 +- .../history/undo/wrap-inline-across-blocks.js | 8 +- packages/slate/test/index.js | 1 - ...hout-normalization-normalize-flag-false.js | 9 +- ...thout-normalization-normalize-flag-true.js | 9 +- .../without-normalization-option-override.js | 11 +- .../models/change/without-normalization.js | 10 +- packages/slate/test/models/index.js | 6 +- .../remove_text/cursor-inside-removed-text.js | 16 +- packages/slate/test/operations/index.js | 10 +- .../test/schema/core/block-create-text.js | 14 +- .../core/document-no-inline-children.js | 22 +- .../schema/core/document-no-text-children.js | 18 +- .../schema/core/inline-no-block-children.js | 28 +- .../test/schema/core/inline-text-around.js | 54 ++- .../test/schema/core/remove-empty-inline.js | 12 +- ...hild-kind-invalid-custom-optional-first.js | 16 +- .../custom/child-kind-invalid-custom.js | 18 +- .../custom/child-kind-invalid-default.js | 8 +- .../schema/custom/child-required-custom.js | 15 +- .../schema/custom/child-required-default.js | 8 +- .../custom/child-type-invalid-custom.js | 10 +- .../custom/child-type-invalid-default.js | 8 +- .../schema/custom/child-unknown-custom.js | 28 +- .../schema/custom/child-unknown-default.js | 20 +- .../custom/first-child-kind-invalid-custom.js | 14 +- .../first-child-kind-invalid-default.js | 4 +- .../custom/first-child-type-invalid-custom.js | 6 +- .../first-child-type-invalid-default.js | 6 +- .../custom/last-child-kind-invalid-custom.js | 14 +- .../custom/last-child-kind-invalid-default.js | 4 +- .../custom/last-child-type-invalid-custom.js | 6 +- .../custom/last-child-type-invalid-default.js | 6 +- .../schema/custom/node-data-invalid-custom.js | 10 +- .../node-data-invalid-default-undefined.js | 6 +- .../custom/node-data-invalid-default.js | 6 +- .../custom/node-is-void-invalid-custom.js | 6 +- .../custom/node-is-void-invalid-default.js | 8 +- .../schema/custom/node-mark-invalid-custom.js | 6 +- .../custom/node-mark-invalid-default.js | 10 +- .../schema/custom/node-mark-valid-default.js | 6 +- .../schema/custom/node-text-invalid-custom.js | 10 +- .../custom/node-text-invalid-default.js | 8 +- .../custom/parent-kind-invalid-custom.js | 10 +- .../custom/parent-kind-invalid-default.js | 8 +- .../custom/parent-type-invalid-custom.js | 6 +- .../custom/parent-type-invalid-default.js | 4 +- packages/slate/test/schema/index.js | 11 +- packages/slate/test/serializers/index.js | 11 +- .../raw/deserialize/block-nested.js | 24 +- .../raw/deserialize/block-with-data.js | 22 +- .../raw/deserialize/block-with-is-void.js | 14 +- .../test/serializers/raw/deserialize/block.js | 18 +- .../raw/deserialize/inline-nested.js | 38 +- .../raw/deserialize/inline-with-data.js | 30 +- .../raw/deserialize/inline-with-is-void.js | 24 +- .../serializers/raw/deserialize/inline.js | 28 +- .../raw/deserialize/range-with-mark.js | 18 +- .../serializers/raw/serialize/block-nested.js | 24 +- .../raw/serialize/block-with-data.js | 22 +- .../raw/serialize/block-with-is-void.js | 14 +- .../test/serializers/raw/serialize/block.js | 18 +- .../raw/serialize/inline-nested.js | 38 +- .../raw/serialize/inline-with-data.js | 30 +- .../raw/serialize/inline-with-is-void.js | 24 +- .../test/serializers/raw/serialize/inline.js | 28 +- .../raw/serialize/preserve-data.js | 20 +- .../raw/serialize/preserve-keys.js | 20 +- .../serialize/preserve-selection-and-keys.js | 20 +- .../raw/serialize/preserve-selection.js | 20 +- .../raw/serialize/range-with-mark.js | 18 +- support/benchmark-compare.js | 4 +- support/benchmark-reporter.js | 9 +- support/rollup/examples.js | 26 +- support/rollup/factory.js | 29 +- yarn.lock | 29 ++ 637 files changed, 4432 insertions(+), 4281 deletions(-) create mode 100644 .prettierignore diff --git a/.eslintrc b/.eslintrc index 3d3271873..e48b87ac4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,6 @@ { - "plugins": [ - "import", - "react" - ], + "extends": ["prettier", "prettier/react"], + "plugins": ["import", "react", "prettier"], "settings": { "import/extensions": [".js"] }, @@ -18,19 +16,8 @@ "node": true }, "rules": { - "arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }], - "arrow-spacing": "error", - "block-spacing": "error", - "comma-dangle": ["error", "only-multiline"], - "comma-spacing": ["error", { "before": false, "after": true }], - "comma-style": ["error", "last"], - "computed-property-spacing": ["error", "never"], "constructor-super": "error", - "curly": ["error", "multi-line"], - "dot-location": ["error", "property"], "dot-notation": ["error", { "allowKeywords": true }], - "eol-last": "error", - "func-call-spacing": ["error", "never"], "import/default": "error", "import/export": "error", "import/first": "error", @@ -38,18 +25,25 @@ "import/namespace": "error", "import/newline-after-import": "error", "import/no-deprecated": "error", - "import/no-extraneous-dependencies": ["error", { "peerDependencies": true }], + "import/no-extraneous-dependencies": [ + "error", + { "peerDependencies": true } + ], "import/no-mutable-exports": "error", "import/no-named-as-default": "error", "import/no-named-as-default-member": "error", "import/no-unresolved": "error", - "indent": ["error", 2, { "SwitchCase": 1, "MemberExpression": 1 }], - "jsx-quotes": ["error", "prefer-double"], - "key-spacing": ["error", { "beforeColon": false, "afterColon": true }], - "keyword-spacing": ["error", { "before": true, "after": true }], "linebreak-style": "error", - "lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true, "allowBlockStart": true, "allowObjectStart": true, "allowArrayStart": true }], - "new-parens": "error", + "lines-around-comment": [ + "error", + { + "beforeBlockComment": true, + "afterBlockComment": true, + "allowBlockStart": true, + "allowObjectStart": true, + "allowArrayStart": true + } + ], "no-array-constructor": "error", "no-class-assign": "error", "no-console": "error", @@ -68,9 +62,6 @@ "no-func-assign": "error", "no-invalid-regexp": "error", "no-lonely-if": "error", - "no-mixed-spaces-and-tabs": ["error", false], - "no-multi-spaces": "error", - "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }], "no-native-reassign": "error", "no-negated-in-lhs": "error", "no-new-object": "error", @@ -78,15 +69,29 @@ "no-path-concat": "error", "no-redeclare": "error", "no-regex-spaces": "error", - "no-restricted-globals": ["error", "Debug", "document", "Document", "event", "history", "History", "length", "Map", "Node", "parent", "Range", "Selection", "Set", "Text"], + "no-restricted-globals": [ + "error", + "Debug", + "document", + "Document", + "event", + "history", + "History", + "length", + "Map", + "Node", + "parent", + "Range", + "Selection", + "Set", + "Text" + ], "no-sequences": "error", "no-shadow": "error", "no-shadow-restricted-names": "error", - "no-spaced-func": "error", "no-tabs": "error", "no-this-before-super": "error", "no-throw-literal": "error", - "no-trailing-spaces": "error", "no-undef": "error", "no-unneeded-ternary": "error", "no-unreachable": "error", @@ -100,31 +105,24 @@ "no-useless-rename": "error", "no-var": "error", "no-void": "error", - "no-whitespace-before-property": "error", "no-with": "error", - "object-curly-spacing": ["error", "always", { "objectsInObjects": false }], - "object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }], "object-shorthand": ["error", "always"], - "operator-linebreak": ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" }}], - "padded-blocks": ["error", { "blocks": "never", "classes": "always" }], "prefer-arrow-callback": "error", - "prefer-const": ["error", { "destructuring": "all", "ignoreReadBeforeAssign": true }], + "prefer-const": [ + "error", + { "destructuring": "all", "ignoreReadBeforeAssign": true } + ], "prefer-rest-params": "error", "prefer-spread": "error", "prefer-template": "error", - "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "prettier/prettier": "error", "radix": "error", "react/jsx-boolean-value": ["error", "never"], - "react/jsx-closing-bracket-location": "error", - "react/jsx-curly-spacing": ["error", "never"], - "react/jsx-equals-spacing": "error", - "react/jsx-first-prop-new-line": ["error", "multiline"], "react/jsx-key": "error", "react/jsx-no-bind": "error", "react/jsx-no-duplicate-props": "error", "react/jsx-no-target-blank": "error", "react/jsx-no-undef": "error", - "react/jsx-tag-spacing": ["error", { "beforeSelfClosing": "always" }], "react/jsx-uses-react": "error", "react/jsx-uses-vars": "error", "react/jsx-wrap-multilines": "error", @@ -136,19 +134,12 @@ "react/react-in-jsx-scope": "error", "react/self-closing-comp": "error", "react/sort-prop-types": "error", - "rest-spread-spacing": ["error", "never"], - "semi": ["error", "never"], - "space-before-blocks": "error", - "space-before-function-paren": ["error", { "anonymous": "always", "named": "never" }], - "space-in-parens": "error", - "space-infix-ops": "error", - "space-unary-ops": ["error", { "words": true, "nonwords": false }], - "spaced-comment": ["error", "always", { "exceptions": ["-"]}], - "template-curly-spacing": "error", - "template-tag-spacing": ["error", "never"], - "unicode-bom": ["error", "never"], + "spaced-comment": ["error", "always", { "exceptions": ["-"] }], "use-isnan": "error", - "valid-jsdoc": ["error", { "prefer": { "return": "returns" }, "requireReturn": false }], + "valid-jsdoc": [ + "error", + { "prefer": { "return": "returns" }, "requireReturn": false } + ], "valid-typeof": "error", "yield-star-spacing": ["error", "after"], "yoda": ["error", "never"] diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..a790ef1b4 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +examples/build.prod.js +package.json +packages/*/dist/ +packages/*/lib/ +tmp/ diff --git a/examples/check-lists/index.js b/examples/check-lists/index.js index 348ad2dcc..a637caeec 100644 --- a/examples/check-lists/index.js +++ b/examples/check-lists/index.js @@ -1,4 +1,3 @@ - import { Editor } from 'slate-react' import { Value } from 'slate' @@ -12,17 +11,16 @@ import initialValue from './value.json' */ class CheckListItem extends React.Component { - /** * On change, set the new checked value on the block. * * @param {Event} event */ - onChange = (event) => { + onChange = event => { const checked = event.target.checked const { editor, node } = this.props - editor.change(c => c.setNodeByKey(node.key, { data: { checked }})) + editor.change(c => c.setNodeByKey(node.key, { data: { checked } })) } /** @@ -42,11 +40,7 @@ class CheckListItem extends React.Component { {...attributes} > - + {children} @@ -54,7 +48,6 @@ class CheckListItem extends React.Component { ) } - } /** @@ -64,7 +57,6 @@ class CheckListItem extends React.Component { */ class CheckLists extends React.Component { - /** * Deserialize the initial editor value. * @@ -72,7 +64,7 @@ class CheckLists extends React.Component { */ state = { - value: Value.fromJSON(initialValue) + value: Value.fromJSON(initialValue), } /** @@ -102,11 +94,8 @@ class CheckLists extends React.Component { onKeyDown = (event, change) => { const { value } = change - if ( - event.key == 'Enter' && - value.startBlock.type == 'check-list-item' - ) { - change.splitBlock().setBlock({ data: { checked: false }}) + if (event.key == 'Enter' && value.startBlock.type == 'check-list-item') { + change.splitBlock().setBlock({ data: { checked: false } }) return true } @@ -151,12 +140,12 @@ class CheckLists extends React.Component { * @return {Element} */ - renderNode = (props) => { + renderNode = props => { switch (props.node.type) { - case 'check-list-item': return + case 'check-list-item': + return } } - } /** diff --git a/examples/code-highlighting/index.js b/examples/code-highlighting/index.js index f645e6180..64c8929bc 100644 --- a/examples/code-highlighting/index.js +++ b/examples/code-highlighting/index.js @@ -1,4 +1,3 @@ - import { Editor } from 'slate-react' import { Value } from 'slate' @@ -18,7 +17,9 @@ function CodeBlock(props) { const language = node.data.get('language') function onChange(event) { - editor.change(c => c.setNodeByKey(node.key, { data: { language: event.target.value }})) + editor.change(c => + c.setNodeByKey(node.key, { data: { language: event.target.value } }) + ) } return ( @@ -30,7 +31,7 @@ function CodeBlock(props) { contentEditable={false} style={{ position: 'absolute', top: '5px', right: '5px' }} > - @@ -41,9 +42,7 @@ function CodeBlock(props) { } function CodeBlockLine(props) { - return ( -
{props.children}
- ) + return
{props.children}
} /** @@ -53,7 +52,6 @@ function CodeBlockLine(props) { */ class CodeHighlighting extends React.Component { - /** * Deserialize the raw initial value. * @@ -61,7 +59,7 @@ class CodeHighlighting extends React.Component { */ state = { - value: Value.fromJSON(initialValue) + value: Value.fromJSON(initialValue), } /** @@ -121,10 +119,12 @@ class CodeHighlighting extends React.Component { * @return {Element} */ - renderNode = (props) => { + renderNode = props => { switch (props.node.type) { - case 'code': return - case 'code_line': return + case 'code': + return + case 'code_line': + return } } @@ -135,17 +135,21 @@ class CodeHighlighting extends React.Component { * @return {Element} */ - renderMark = (props) => { + renderMark = props => { const { children, mark } = props switch (mark.type) { - case 'comment': return {children} - case 'keyword': return {children} - case 'tag': return {children} - case 'punctuation': return {children} + case 'comment': + return {children} + case 'keyword': + return {children} + case 'tag': + return {children} + case 'punctuation': + return {children} } } - tokenToContent = (token) => { + tokenToContent = token => { if (typeof token == 'string') { return token } else if (typeof token.content == 'string') { @@ -162,7 +166,7 @@ class CodeHighlighting extends React.Component { * @return {Array} */ - decorateNode = (node) => { + decorateNode = node => { if (node.type != 'code') return const language = node.data.get('language') @@ -215,7 +219,6 @@ class CodeHighlighting extends React.Component { return decorations } - } /** diff --git a/examples/embeds/index.js b/examples/embeds/index.js index 518982acb..8eac41b44 100644 --- a/examples/embeds/index.js +++ b/examples/embeds/index.js @@ -1,4 +1,3 @@ - import { Editor } from 'slate-react' import { Value } from 'slate' @@ -13,7 +12,6 @@ import initialValue from './value.json' */ class Embeds extends React.Component { - /** * Deserialize the raw initial value. * @@ -21,7 +19,7 @@ class Embeds extends React.Component { */ state = { - value: Value.fromJSON(initialValue) + value: Value.fromJSON(initialValue), } /** @@ -60,12 +58,12 @@ class Embeds extends React.Component { * @return {Element} */ - renderNode = (props) => { + renderNode = props => { switch (props.node.type) { - case 'video': return