diff --git a/.eslintrc b/.eslintrc index f67b7d0..e95eda4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,5 @@ { - "extends": "wix-editor/node", + "extends": ["wix-editor/node", "plugin:lodash/recommended"], "plugins": ["lodash", "wix-editor"], "rules": { "semi": [2, "always"], @@ -13,29 +13,13 @@ "no-restricted-syntax": [2, "WithStatement", "ContinueStatement", "ForStatement"], "no-negated-condition": 1, - "lodash/prop-shorthand": 2, - "lodash/matches-shorthand": [2, "always"], - "lodash/matches-prop-shorthand": [2, "always"], - "lodash/prefer-chain": 2, - "lodash/preferred-alias": 2, - "lodash/no-single-chain": 2, - "lodash/prefer-reject": [2, 3], + "lodash/prefer-filter": 0, - "lodash/callback-binding": 2, - "lodash/unwrap": 2, - "lodash/prefer-lodash-chain": 2, - "lodash/prefer-compact": 2, - "lodash/no-double-unwrap": 2, + "lodash/prefer-map": 0, - "lodash/prefer-wrapper-method": 2, - "lodash/prefer-thru": 2, - "lodash/prefer-get": [2, 3], - "lodash/collection-return": 2, - "lodash/prefer-times": 2, - "lodash/chain-style": [2, "as-needed"], "lodash/path-style": 0, "lodash/no-extra-args": 2, - "lodash/identity-shorthand": [2, "always"], + "lodash/prefer-lodash-method": 0, "wix-editor/augmented-assignment": 1, "wix-editor/no-not-not": 1, diff --git a/playground/aceEditor.js b/playground/aceEditor.js index 776c46b..c1186b5 100644 --- a/playground/aceEditor.js +++ b/playground/aceEditor.js @@ -19,8 +19,7 @@ define(['react', 'lodash']/*, 'ace'*/, function (React, _/*, ace*/) { editorId: _.uniqueId() }; }, - componentWillMount: function () { - }, + componentWillMount: _.noop, render: function () { var props = _.omit(this.props, ['ref', 'key', 'value', 'valueLink', 'onChange']); props.id = this.props.id || this.state.editorId; @@ -63,4 +62,4 @@ define(['react', 'lodash']/*, 'ace'*/, function (React, _/*, ace*/) { this.editor.destroy(); } }); -}); \ No newline at end of file +}); diff --git a/sample/ImageSearch.js b/sample/ImageSearch.js index 834e22b..a7264b6 100644 --- a/sample/ImageSearch.js +++ b/sample/ImageSearch.js @@ -43,7 +43,7 @@ define([ }, loadMore: function (done) { - done = done || function () {}; + done = done || _.noop; if (!this.hasMore) { done(); return; diff --git a/src/reactTemplates.js b/src/reactTemplates.js index 140f5e6..99d8238 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -119,7 +119,7 @@ function convertText(node, context, txt) { var res = ''; var first = true; var concatChar = node.type === 'text' ? ',' : '+'; - while (txt.indexOf('{') !== -1) { + while (_.includes(txt, '{')) { var start = txt.indexOf('{'); var pre = txt.substr(0, start); if (pre) { @@ -227,7 +227,7 @@ function generateProps(node, context) { if (props.hasOwnProperty(propKey) && propKey !== reactSupport.classNameProp) { throw RTCodeError.build(context, node, `duplicate definition of ${propKey} ${JSON.stringify(node.attribs)}`); } - if (key.indexOf('on') === 0 && !utils.isStringOnlyCode(val)) { + if (_.startsWith(key, 'on') && !utils.isStringOnlyCode(val)) { props[propKey] = handleEventHandler(val, context, node, key); } else if (key === 'style' && !utils.isStringOnlyCode(val)) { props[propKey] = handleStyleProp(val, node, context); @@ -241,7 +241,7 @@ function generateProps(node, context) { } else if (key === classAttr || key === reactSupport.classNameProp) { props[propKey] = existing + convertText(node, context, val.trim()); } - } else if (key.indexOf('rt-') !== 0) { + } else if (!_.startsWith(key, 'rt-')) { props[propKey] = convertText(node, context, val.trim()); } }); @@ -496,8 +496,7 @@ function isTag(node) { } function handleSelfClosingHtmlTags(nodes) { - return _(nodes) - .map(function (node) { + return _.flatMap(nodes, function (node) { var externalNodes = []; node.children = handleSelfClosingHtmlTags(node.children); if (node.type === 'tag' && (_.includes(reactSupport.htmlSelfClosingTags, node.name) || @@ -507,9 +506,7 @@ function handleSelfClosingHtmlTags(nodes) { node.children = _.reject(node.children, isTag); } return [node].concat(externalNodes); - }) - .flatten() - .value(); + }); } function convertTemplateToReact(html, options) { diff --git a/src/utils.js b/src/utils.js index cd2f872..4b6cfdd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,7 +52,7 @@ function addIfMissing(array, obj) { function concatChildren(children) { var res = ''; _.forEach(children, function (child) { - if (child && child.indexOf(' /*') !== 0) { + if (child && !_.startsWith(child, ' /*')) { res += ','; } res += child;