From 031f6e860f392bd0b84e6b411ad717e0fbc92e8d Mon Sep 17 00:00:00 2001 From: mattia richetto Date: Mon, 17 Dec 2018 16:13:12 -0800 Subject: [PATCH] Update string-width to support emoji natively (#5646) the `string-width` package v3 now supports emoji width https://github.com/sindresorhus/string-width/pull/17 --- package.json | 3 +-- src/common/util.js | 6 +----- yarn.lock | 36 +++++++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index b7163cf7..4bb7015a 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "diff": "3.2.0", "editorconfig": "0.15.2", "editorconfig-to-prettier": "0.1.1", - "emoji-regex": "6.5.1", "escape-string-regexp": "1.0.5", "esutils": "2.0.2", "find-parent-dir": "0.3.0", @@ -65,7 +64,7 @@ "remark-parse": "5.0.0", "resolve": "1.5.0", "semver": "5.4.1", - "string-width": "2.1.1", + "string-width": "3.0.0", "typescript": "3.2.1", "typescript-estree": "6.0.0-rc.1", "unicode-regex": "2.0.0", diff --git a/src/common/util.js b/src/common/util.js index 891a061a..e4b035dc 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -1,7 +1,6 @@ "use strict"; const stringWidth = require("string-width"); -const emojiRegex = require("emoji-regex")(); const escapeStringRegexp = require("escape-string-regexp"); // eslint-disable-next-line no-control-regex @@ -594,10 +593,7 @@ function getStringWidth(text) { return text.length; } - // emojis are considered 2-char width for consistency - // see https://github.com/sindresorhus/string-width/issues/11 - // for the reason why not implemented in `string-width` - return stringWidth(text.replace(emojiRegex, " ")); + return stringWidth(text); } function hasIgnoreComment(path) { diff --git a/yarn.lock b/yarn.lock index ba3cb50e..b80bcb9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -779,6 +779,11 @@ ansi-regex@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" +ansi-regex@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.0.0.tgz#70de791edf021404c3fd615aa89118ae0432e5a9" + integrity sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w== + ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" @@ -1951,9 +1956,10 @@ elliptic@^6.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.0" -emoji-regex@6.5.1: - version "6.5.1" - resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-6.5.1.tgz#9baea929b155565c11ea41c6626eaa65cef992c2" +emoji-regex@^7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.1.tgz#5a132b28ebf84a289ba692862f7d4206ebcd32d0" + integrity sha512-cjx7oFbFIyZMpmWaEBnKeJXWAVzjXwK6yHiz/5X73A2Ww4pnabw+4ZaA/MxLroIQQrB3dL6XzEz8P3aZsSdj8Q== emojis-list@^2.0.0: version "2.1.0" @@ -5567,12 +5573,14 @@ string-length@^2.0.0: astral-regex "^1.0.0" strip-ansi "^4.0.0" -string-width@2.1.1, string-width@^2.0.0, string-width@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" +string-width@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.0.0.tgz#5a1690a57cc78211fffd9bf24bbe24d090604eb1" + integrity sha512-rr8CUxBbvOZDUvc5lNIJ+OC1nPVpz+Siw9VBtUjB9b6jZehZLFt0JMCZzShFHIsI8cbhm0EsNIfWJMFV3cu3Ew== dependencies: + emoji-regex "^7.0.1" is-fullwidth-code-point "^2.0.0" - strip-ansi "^4.0.0" + strip-ansi "^5.0.0" string-width@^1.0.1, string-width@^1.0.2: version "1.0.2" @@ -5582,6 +5590,13 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" +string-width@^2.0.0, string-width@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + string_decoder@^0.10.25: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" @@ -5608,6 +5623,13 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1: dependencies: ansi-regex "^2.0.0" +strip-ansi@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.0.0.tgz#f78f68b5d0866c20b2c9b8c61b5298508dc8756f" + integrity sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow== + dependencies: + ansi-regex "^4.0.0" + strip-bom@3.0.0, strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"