diff --git a/package.json b/package.json index 244237c..f79a78b 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "karma-jasmine": "^1.1.0", "karma-webpack": "^2.0.4", "mkdirp": "0.5.1", - "prettier": "1.7.4", + "prettier": "1.11.1", "prop-types": "^15.6.0", "react": "^16.0.0", "react-dom": "^16.0.0", @@ -77,7 +77,7 @@ "prepublishOnly": "npm run build", "storybook": "start-storybook -p 6006", "build-storybook": "build-storybook", - "prettier": "prettier --no-semi --single-quote --trailing-comma es5 --write \"{src,spec}/**/*.js\"" + "prettier": "prettier --write \"{src,spec}/**/*.js\"" }, "size-limit": [ { diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..383d1ab --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,6 @@ +module.exports = { + semi: false, + singleQuote: true, + trailingComma: 'all', + arrowParens: 'always', +} diff --git a/spec/emoji-index-spec.js b/spec/emoji-index-spec.js index 78c6771..a542cae 100644 --- a/spec/emoji-index-spec.js +++ b/spec/emoji-index-spec.js @@ -17,11 +17,11 @@ describe('#emojiIndex', () => { }) it('should filter only emojis we care about, exclude pineapple', () => { - let emojisToShowFilter = data => { + let emojisToShowFilter = (data) => { data.unified !== '1F34D' } expect( - emojiIndex.search('apple', { emojisToShowFilter }).map(obj => obj.id) + emojiIndex.search('apple', { emojisToShowFilter }).map((obj) => obj.id), ).not.toContain('pineapple') }) @@ -30,13 +30,13 @@ describe('#emojiIndex', () => { }) it('can search for thinking_face', () => { - expect(emojiIndex.search('thinking_fac').map(x => x.id)).toEqual([ + expect(emojiIndex.search('thinking_fac').map((x) => x.id)).toEqual([ 'thinking_face', ]) }) it('can search for woman-facepalming', () => { - expect(emojiIndex.search('woman-facep').map(x => x.id)).toEqual([ + expect(emojiIndex.search('woman-facep').map((x) => x.id)).toEqual([ 'woman-facepalming', ]) }) diff --git a/spec/picker-spec.js b/spec/picker-spec.js index 4829ca7..57040de 100644 --- a/spec/picker-spec.js +++ b/spec/picker-spec.js @@ -30,14 +30,14 @@ describe('Picker', () => { }) it('will not show some based upon our filter', () => { - subject = render({ emojisToShowFilter: unified => false }) + subject = render({ emojisToShowFilter: (unified) => false }) expect(subject.categories.length).toEqual(2) }) it('maintains category ids after it is filtered', () => { - subject = render({ emojisToShowFilter: emoji => true }) + subject = render({ emojisToShowFilter: (emoji) => true }) const categoriesWithIds = subject.categories.filter( - category => category.id + (category) => category.id, ) expect(categoriesWithIds.length).toEqual(10) }) diff --git a/src/components/anchors.js b/src/components/anchors.js index b97e2d8..e620387 100644 --- a/src/components/anchors.js +++ b/src/components/anchors.js @@ -7,7 +7,9 @@ export default class Anchors extends React.PureComponent { constructor(props) { super(props) - let defaultCategory = props.categories.filter(category => category.first)[0] + let defaultCategory = props.categories.filter( + (category) => category.first, + )[0] this.state = { selected: defaultCategory.name, @@ -58,9 +60,9 @@ export default class Anchors extends React.PureComponent { title={i18n.categories[id]} data-index={i} onClick={this.handleClick} - className={`emoji-mart-anchor ${isSelected - ? 'emoji-mart-anchor-selected' - : ''}`} + className={`emoji-mart-anchor ${ + isSelected ? 'emoji-mart-anchor-selected' : '' + }`} style={{ color: isSelected ? color : null }} >
diff --git a/src/components/category.js b/src/components/category.js index a9579b8..710f288 100644 --- a/src/components/category.js +++ b/src/components/category.js @@ -101,15 +101,15 @@ export default class Category extends React.Component { if (frequentlyUsed.length) { emojis = frequentlyUsed - .map(id => { - const emoji = custom.filter(e => e.id === id)[0] + .map((id) => { + const emoji = custom.filter((e) => e.id === id)[0] if (emoji) { return emoji } return id }) - .filter(id => !!getData(id)) + .filter((id) => !!getData(id)) } if (emojis.length === 0 && frequentlyUsed.length > 0) { @@ -168,9 +168,9 @@ export default class Category extends React.Component { return (
- {emojis && emojis.map(emoji => Emoji({ emoji: emoji, ...emojiProps }))} + {emojis && + emojis.map((emoji) => Emoji({ emoji: emoji, ...emojiProps }))} {emojis && !emojis.length && ( diff --git a/src/components/emoji.js b/src/components/emoji.js index 6938992..5e344e2 100644 --- a/src/components/emoji.js +++ b/src/components/emoji.js @@ -6,19 +6,19 @@ import { getData, getSanitizedData, unifiedToNative } from '../utils' const SHEET_COLUMNS = 52 -const _getPosition = props => { +const _getPosition = (props) => { var { sheet_x, sheet_y } = _getData(props), multiply = 100 / (SHEET_COLUMNS - 1) return `${multiply * sheet_x}% ${multiply * sheet_y}%` } -const _getData = props => { +const _getData = (props) => { var { emoji, skin, set } = props return getData(emoji, skin, set) } -const _getSanitizedData = props => { +const _getSanitizedData = (props) => { var { emoji, skin, set } = props return getSanitizedData(emoji, skin, set) } @@ -53,11 +53,11 @@ const _handleLeave = (e, props) => { onLeave(emoji, e) } -const _isNumeric = value => { +const _isNumeric = (value) => { return !isNaN(value - parseFloat(value)) } -const _convertStyleToCSS = style => { +const _convertStyleToCSS = (style) => { let div = document.createElement('div') for (let key in style) { @@ -73,7 +73,7 @@ const _convertStyleToCSS = style => { return div.getAttribute('style') } -const Emoji = props => { +const Emoji = (props) => { for (let k in Emoji.defaultProps) { if (props[k] == undefined && Emoji.defaultProps[k] != undefined) { props[k] = Emoji.defaultProps[k] @@ -134,7 +134,7 @@ const Emoji = props => { display: 'inline-block', backgroundImage: `url(${props.backgroundImageFn( props.set, - props.sheetSize + props.sheetSize, )})`, backgroundSize: `${100 * SHEET_COLUMNS}%`, backgroundPosition: _getPosition(props), @@ -144,16 +144,16 @@ const Emoji = props => { if (props.html) { style = _convertStyleToCSS(style) - return `${children || ''}` + return `${children || ''}` } else { return ( _handleClick(e, props)} - onMouseEnter={e => _handleOver(e, props)} - onMouseLeave={e => _handleLeave(e, props)} + onClick={(e) => _handleClick(e, props)} + onMouseEnter={(e) => _handleOver(e, props)} + onMouseLeave={(e) => _handleLeave(e, props)} title={title} className={className} > diff --git a/src/components/picker.js b/src/components/picker.js index f2c03a1..47edc92 100644 --- a/src/components/picker.js +++ b/src/components/picker.js @@ -51,7 +51,7 @@ export default class Picker extends React.PureComponent { let allCategories = [].concat(data.categories) if (props.custom.length > 0) { - this.CUSTOM_CATEGORY.emojis = props.custom.map(emoji => { + this.CUSTOM_CATEGORY.emojis = props.custom.map((emoji) => { return { ...emoji, // `` expects emoji to have an `id`. @@ -188,7 +188,7 @@ export default class Picker extends React.PureComponent { const prefixes = ['', '-webkit-', '-ms-', '-moz-', '-o-'] prefixes.forEach( - prefix => (stickyTestElement.style.position = `${prefix}sticky`) + (prefix) => (stickyTestElement.style.position = `${prefix}sticky`), ) this.hasStickyPosition = !!stickyTestElement.style.position.length @@ -202,7 +202,7 @@ export default class Picker extends React.PureComponent { // Use Array.prototype.find() when it is more widely supported. const emojiData = this.CUSTOM_CATEGORY.emojis.filter( - customEmoji => customEmoji.id === emoji.id + (customEmoji) => customEmoji.id === emoji.id, )[0] for (let key in emojiData) { if (emojiData.hasOwnProperty(key)) { @@ -300,7 +300,7 @@ export default class Picker extends React.PureComponent { if (scrollTop < minTop) { activeCategory = this.categories.filter( - category => !(category.anchor === false) + (category) => !(category.anchor === false), )[0] } else if (scrollTop + this.clientHeight >= this.scrollHeight) { activeCategory = this.categories[this.categories.length - 1] @@ -382,12 +382,15 @@ export default class Picker extends React.PureComponent { case 13: let emoji - if (this.SEARCH_CATEGORY.emojis && (emoji = this.SEARCH_CATEGORY.emojis[0])) { + if ( + this.SEARCH_CATEGORY.emojis && + (emoji = this.SEARCH_CATEGORY.emojis[0]) + ) { this.handleEmojiSelect(emoji) } handled = true - break; + break } if (handled) { @@ -463,7 +466,11 @@ export default class Picker extends React.PureComponent { width = perLine * (emojiSize + 12) + 12 + 2 + measureScrollbar() return ( -
+
{ + emoticons.forEach((emoticon) => { if (knownEmoticons.indexOf(emoticon.toLowerCase()) >= 0) { return } @@ -44,14 +44,14 @@ export default class Preview extends React.PureComponent {
{emoji.name}
- {emojiData.short_names.map(short_name => ( + {emojiData.short_names.map((short_name) => ( :{short_name}: ))}
- {listedEmoticons.map(emoticon => ( + {listedEmoticons.map((emoticon) => ( {emoticon} diff --git a/src/components/search.js b/src/components/search.js index aabe5b7..71e8dc4 100644 --- a/src/components/search.js +++ b/src/components/search.js @@ -20,7 +20,7 @@ export default class Search extends React.PureComponent { include: this.props.include, exclude: this.props.exclude, custom: this.props.custom, - }) + }), ) } diff --git a/src/components/skins.js b/src/components/skins.js index b05a4a8..1430c50 100644 --- a/src/components/skins.js +++ b/src/components/skins.js @@ -39,25 +39,25 @@ export default class Skins extends React.PureComponent { skinToneNodes.push( - + , ) } return (
{skinToneNodes}
diff --git a/src/polyfills/inherits.js b/src/polyfills/inherits.js index 142d3dd..7725ddb 100644 --- a/src/polyfills/inherits.js +++ b/src/polyfills/inherits.js @@ -4,7 +4,7 @@ export default function inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError( 'Super expression must either be null or a function, not ' + - typeof superClass + typeof superClass, ) } diff --git a/src/polyfills/possibleConstructorReturn.js b/src/polyfills/possibleConstructorReturn.js index 0659e96..37d61f8 100644 --- a/src/polyfills/possibleConstructorReturn.js +++ b/src/polyfills/possibleConstructorReturn.js @@ -1,7 +1,7 @@ export default function possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError( - "this hasn't been initialised - super() hasn't been called" + "this hasn't been initialised - super() hasn't been called", ) } diff --git a/src/utils/build-search.js b/src/utils/build-search.js index 54fa661..c2ca655 100644 --- a/src/utils/build-search.js +++ b/src/utils/build-search.js @@ -1,4 +1,4 @@ -export default data => { +export default (data) => { const search = [] var addToSearch = (strings, split) => { @@ -6,8 +6,8 @@ export default data => { return } - ;(Array.isArray(strings) ? strings : [strings]).forEach(string => { - ;(split ? string.split(/[-|_|\s]+/) : [string]).forEach(s => { + ;(Array.isArray(strings) ? strings : [strings]).forEach((string) => { + ;(split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => { s = s.toLowerCase() if (search.indexOf(s) == -1) { diff --git a/src/utils/emoji-index.js b/src/utils/emoji-index.js index f4de0a2..950d15d 100644 --- a/src/utils/emoji-index.js +++ b/src/utils/emoji-index.js @@ -13,7 +13,7 @@ for (let emoji in data.emojis) { id = short_names[0] if (emoticons) { - emoticons.forEach(emoticon => { + emoticons.forEach((emoticon) => { if (emoticonsList[emoticon]) { return } @@ -27,7 +27,7 @@ for (let emoji in data.emojis) { } function clearCustomEmojis(pool) { - customEmojisList.forEach(emoji => { + customEmojisList.forEach((emoji) => { let emojiId = emoji.id || emoji.short_names[0] delete pool[emojiId] @@ -38,7 +38,7 @@ function clearCustomEmojis(pool) { function addCustomToPool(custom, pool) { if (customEmojisList.length) clearCustomEmojis(pool) - custom.forEach(emoji => { + custom.forEach((emoji) => { let emojiId = emoji.id || emoji.short_names[0] if (emojiId && !pool[emojiId]) { @@ -53,7 +53,7 @@ function addCustomToPool(custom, pool) { function search( value, - { emojisToShowFilter, maxResults, include, exclude, custom = [] } = {} + { emojisToShowFilter, maxResults, include, exclude, custom = [] } = {}, ) { if (customEmojisList != custom) addCustomToPool(custom, originalPool) @@ -79,7 +79,7 @@ function search( if (include.length || exclude.length) { pool = {} - data.categories.forEach(category => { + data.categories.forEach((category) => { let isIncluded = include && include.length ? include.indexOf(category.id) > -1 : true let isExcluded = @@ -89,7 +89,7 @@ function search( } category.emojis.forEach( - emojiId => (pool[emojiId] = data.emojis[emojiId]) + (emojiId) => (pool[emojiId] = data.emojis[emojiId]), ) }) @@ -105,7 +105,7 @@ function search( } allResults = values - .map(value => { + .map((value) => { var aPool = pool, aIndex = index, length = 0 @@ -153,7 +153,7 @@ function search( return aIndex.results }) - .filter(a => a) + .filter((a) => a) if (allResults.length > 1) { results = intersect.apply(null, allResults) @@ -166,7 +166,7 @@ function search( if (results) { if (emojisToShowFilter) { - results = results.filter(result => emojisToShowFilter(pool[result.id])) + results = results.filter((result) => emojisToShowFilter(pool[result.id])) } if (results && results.length > maxResults) { diff --git a/src/utils/index.js b/src/utils/index.js index 49811b4..43bd6f2 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -9,7 +9,7 @@ const SKINS = ['1F3FA', '1F3FB', '1F3FC', '1F3FD', '1F3FE', '1F3FF'] function unifiedToNative(unified) { var unicodes = unified.split('-'), - codePoints = unicodes.map(u => `0x${u}`) + codePoints = unicodes.map((u) => `0x${u}`) return stringFromCodePoint.apply(null, codePoints) } @@ -145,7 +145,7 @@ function intersect(a, b) { const uniqA = uniq(a) const uniqB = uniq(b) - return uniqA.filter(item => uniqB.indexOf(item) >= 0) + return uniqA.filter((item) => uniqB.indexOf(item) >= 0) } function deepMerge(a, b) { diff --git a/yarn.lock b/yarn.lock index 73250e5..4f6d4a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4741,9 +4741,9 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.7.4: - version "1.7.4" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.4.tgz#5e8624ae9363c80f95ec644584ecdf55d74f93fa" +prettier@1.11.1: + version "1.11.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.11.1.tgz#61e43fc4cd44e68f2b0dfc2c38cd4bb0fccdcc75" private@^0.1.6, private@^0.1.7, private@~0.1.5: version "0.1.7"