diff --git a/.eslintrc b/.eslintrc index c24f3de..be5a694 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,6 @@ "plugins": ["lodash", "wix-editor"], "rules": { "semi": [2, "always"], - "prefer-arrow-callback": 0, "prefer-spread": 0, "prefer-template": 0, "consistent-return": 0, diff --git a/Gruntfile.js b/Gruntfile.js index 9f094e3..521d98b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -105,7 +105,7 @@ module.exports = function (grunt) { grunt.registerTask('lint', ['eslint:all']); grunt.registerTask('test', ['tape']); - grunt.registerTask('rt', function () { + grunt.registerTask('rt', () => { const reactTemplates = require('./src/cli'); const files = grunt.file.expand('playground/*.rt'); const ret = reactTemplates.execute({modules: 'amd', force: true, _: files}); diff --git a/playground/.eslintrc b/playground/.eslintrc index 081a12e..0552bd6 100644 --- a/playground/.eslintrc +++ b/playground/.eslintrc @@ -2,7 +2,8 @@ "rules": { "strict": [2, "function"], "no-var": 0, - "object-shorthand": 0 + "object-shorthand": 0, + "prefer-arrow-callback": 0 }, "env": { "browser": true, diff --git a/sample/.eslintrc b/sample/.eslintrc index 081a12e..0552bd6 100644 --- a/sample/.eslintrc +++ b/sample/.eslintrc @@ -2,7 +2,8 @@ "rules": { "strict": [2, "function"], "no-var": 0, - "object-shorthand": 0 + "object-shorthand": 0, + "prefer-arrow-callback": 0 }, "env": { "browser": true, diff --git a/src/formatters/stylish.js b/src/formatters/stylish.js index a569fa3..deb04e4 100644 --- a/src/formatters/stylish.js +++ b/src/formatters/stylish.js @@ -6,20 +6,6 @@ const chalk = require('chalk'); const _ = require('lodash'); const table = require('text-table'); -///** -// * @param {MESSAGE} message -// * @return {string} -// */ -//function getMessageType(message) { -// if (message.level === 'WARN') { -// return chalk.yellow('warning'); -// } -// if (message.level === 'ERROR') { -// return chalk.red('error'); -// } -// return chalk.cyan('info'); -//} - /** * Given a word and a count, append an s if count is not one. * @param {string} word A word in its singular form. @@ -29,11 +15,6 @@ const table = require('text-table'); function pluralize(word, count) { return count === 1 ? word : word + 's'; } - -//function pluralize(n, single, plural) { -// return n === 1 ? single : plural; -//} - /** * @param {number} line * @return {string} @@ -42,74 +23,6 @@ function lineText(line) { return line < 1 ? '' : line; } -//module.exports = function (warnings/*, config*/) { -// const _ = require('lodash'); -// const table = require('text-table'); -// //const verbosity = false; -// const UNICODE_HEAVY_MULTIPLICATION_X = '\u2716'; -// -// // context.report(JSON.stringify(warnings, undefined, 2)); -// const output = table( -// warnings.map(function (message) { -// return [ -// '', -// message.file || '', -// lineText(message.line || 0), -// lineText(message.column || 0), -// getMessageType(message), -// // message.message.replace(/\.$/, ''), -// message.msg || '' -// // chalk.gray(message.ruleId) -// ]; -// }), -// { -// align: ['', 'r', 'l'], -// stringLength: function (str) { -// return chalk.stripColor(str).length; -// } -// } -// //} -// ); -// -// const buf = []; -// -// buf.push(output); -// -// const grouped = _.groupBy(warnings, 'level'); -// -// const errCount = grouped.ERROR ? grouped.ERROR.length : 0; -// const warnCount = grouped.WARN ? grouped.WARN.length : 0; -// //const infoCount = grouped.INFO ? grouped.INFO.length : 0; -// -//// buf.push(errCount + ' ' + warnCount + ' ' + infoCount + '\n'); -// -// if (errCount === 0 && warnCount === 0) { -// buf.push(chalk.green('React templates done')); -// } else { -// const msg = []; -// if (errCount > 0) { -// msg.push(errCount + ' ' + pluralize(errCount, 'error', 'errors')); -// } else { -// msg.push(warnCount + ' ' + pluralize(warnCount, 'warning', 'warnings')); -// } -// buf.push(chalk.red.bold(UNICODE_HEAVY_MULTIPLICATION_X + ' ' + msg.join(', '))); -// if (errCount > 0) { -// buf.push(chalk.red('React templates failed due to errors')); -// } else { -// buf.push(chalk.yellow('React templates done with warnings')); -// } -// } -// -//// context.report(JSON.stringify(grouped, undefined, 2)); -//// if (grouped.ERROR && grouped.ERROR.length > 0) { -////// throw new Error(errorMessages.VERIFY_FAILED.format(grouped.ERROR.length, pluralize(grouped.ERROR.length, 'error', 'errors'))); -//// } else { -//// buf.push(chalk.red.bold(UNICODE_HEAVY_MULTIPLICATION_X + ' ' + warnings.length + ' ' + pluralize(warnings.length, 'problem', 'problems')) + '\n'); -//// buf.push('React templates done with warnings\n'); -//// } -// return buf.join('\n'); -//}; - module.exports = function (results) { results = _.groupBy(results, 'file'); @@ -120,7 +33,7 @@ module.exports = function (results) { let infos = 0; let summaryColor = 'cyan'; - _.forEach(results, function (result, k) { + _.forEach(results, (result, k) => { const messages = result; if (messages.length === 0) { @@ -131,7 +44,7 @@ module.exports = function (results) { output += chalk.underline(k) + '\n'; output += table( - messages.map(function (message) { + messages.map(message => { let messageType; if (message.level === 'ERROR') { @@ -160,11 +73,7 @@ module.exports = function (results) { align: ['', 'r', 'l'], stringLength: str => chalk.stripColor(str).length } - ).split('\n').map(function (el) { - return el.replace(/(\d+)\s+(\d+)/, function (m, p1, p2) { - return chalk.gray(p1 + ':' + p2); - }); - }).join('\n') + '\n\n'; + ).split('\n').map(el => el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.gray(p1 + ':' + p2))).join('\n') + '\n\n'; }); if (total > 0) { diff --git a/src/reactSupport.js b/src/reactSupport.js index 02471b9..acbc4bf 100644 --- a/src/reactSupport.js +++ b/src/reactSupport.js @@ -26,7 +26,7 @@ const reactSupportedAttributes = ['accept', 'acceptCharset', 'accessKey', 'actio const classNameProp = 'className'; const attributesMapping = {'class': classNameProp, 'rt-class': classNameProp, 'for': 'htmlFor'}; //eslint-disable-line quote-props -_.forEach(reactSupportedAttributes, function (attributeReactName) { +_.forEach(reactSupportedAttributes, attributeReactName => { if (attributeReactName !== attributeReactName.toLowerCase()) { attributesMapping[attributeReactName.toLowerCase()] = attributeReactName; } diff --git a/src/reactTemplates.js b/src/reactTemplates.js index a4153fe..9537abb 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -170,7 +170,7 @@ function generateInjectedFunc(context, namePrefix, body, params) { function generateTemplateProps(node, context) { const propTemplateDefinition = context.options.propTemplates[node.name]; const propertiesTemplates = _(node.children) - .map(function (child, index) { + .map((child, index) => { let templateProp = null; if (child.name === templateNode) { // Generic explicit template tag if (!_.has(child.attribs, 'prop')) { @@ -198,7 +198,7 @@ function generateTemplateProps(node, context) { .compact() .value(); - return _.transform(propertiesTemplates, function (props, templateProp) { + return _.transform(propertiesTemplates, (props, templateProp) => { const functionParams = _.values(context.boundParams).concat(templateProp.arguments); const oldBoundParams = context.boundParams; @@ -222,7 +222,7 @@ function generateTemplateProps(node, context) { */ function generateProps(node, context) { const props = {}; - _.forOwn(node.attribs, function (val, key) { + _.forOwn(node.attribs, (val, key) => { const propKey = reactSupport.attributesMapping[key.toLowerCase()] || key; if (props.hasOwnProperty(propKey) && propKey !== reactSupport.classNameProp) { throw RTCodeError.build(context, node, `duplicate definition of ${propKey} ${JSON.stringify(node.attribs)}`); @@ -400,7 +400,7 @@ function convertHtmlToReact(node, context) { } } - const children = _.map(node.children, function (child) { + const children = _.map(node.children, child => { const code = convertHtmlToReact(child, context); validateJS(code, child, context); return code; @@ -494,7 +494,7 @@ function isTag(node) { } function handleSelfClosingHtmlTags(nodes) { - return _.flatMap(nodes, function (node) { + return _.flatMap(nodes, node => { let externalNodes = []; node.children = handleSelfClosingHtmlTags(node.children); if (node.type === 'tag' && (_.includes(reactSupport.htmlSelfClosingTags, node.name) || @@ -521,7 +521,7 @@ function parseAndConvertHtmlToReact(html, context) { throw new RTCodeError('Document should have a root element'); } let firstTag = null; - _.forEach(rootTags, function (tag) { + _.forEach(rootTags, tag => { if (tag.name === 'rt-require') { if (!tag.attribs.dependency || !tag.attribs.as) { throw RTCodeError.build(context, tag, "rt-require needs 'dependency' and 'as' attributes"); diff --git a/src/utils.js b/src/utils.js index 89c5888..ae29179 100644 --- a/src/utils.js +++ b/src/utils.js @@ -51,7 +51,7 @@ function addIfMissing(array, obj) { */ function concatChildren(children) { let res = ''; - _.forEach(children, function (child) { + _.forEach(children, child => { if (child && !_.startsWith(child, ' /*')) { res += ','; } diff --git a/test/src/styleTest.js b/test/src/styleTest.js index bb2f8fa..8a6b9bc 100644 --- a/test/src/styleTest.js +++ b/test/src/styleTest.js @@ -4,7 +4,7 @@ const rtStyle = require('../../src/rtStyle'); const text = '.text { background-color: #00346E; padding: 3px; }'; const textEp = '{\n "text": {\n "backgroundColor": "#00346E",\n "padding": 3\n }\n}'; -test('html tests', function (t) { +test('html tests', t => { const res = rtStyle.convertBody(text); t.equal(res, textEp); t.end(); diff --git a/test/src/test.js b/test/src/test.js index 02697af..980d33e 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -31,7 +31,7 @@ const invalidFiles = [ {file: 'invalid-virtual.rt', issue: new RTCodeError('Document should not have as root element', 0, 60, 1, 1)} ]; -test('invalid tests', function (t) { +test('invalid tests', t => { t.plan(invalidFiles.length); invalidFiles.forEach(check); @@ -62,7 +62,7 @@ function normalizeError(err) { return err; } -test('invalid tests json', function (t) { +test('invalid tests json', t => { const cli = require('../../src/cli'); t.plan(invalidFiles.length); @@ -99,17 +99,17 @@ function errorEqualMessage(err, file) { }; } -test('rt-if with rt-scope test', function (t) { +test('rt-if with rt-scope test', t => { const files = ['if-with-scope/valid-if-scope.rt']; testFiles(t, files); }); -test('conversion test', function (t) { +test('conversion test', t => { const files = ['div.rt', 'test.rt', 'repeat.rt', 'inputs.rt', 'require.rt']; testFiles(t, files); }); -test('prop template conversion test', function (t) { +test('prop template conversion test', t => { const options = { propTemplates: { List: { @@ -134,7 +134,7 @@ function testFiles(t, files, options) { files.forEach(checkFile.bind(this, t, options)); } -test('conversion test - native', function (t) { +test('conversion test - native', t => { const options = { propTemplates: { MyComp: { @@ -147,7 +147,7 @@ test('conversion test - native', function (t) { testFiles(t, files, options); }); -test('convert div with all module types', function (t) { +test('convert div with all module types', t => { const files = [ {source: 'div.rt', expected: 'div.rt.commonjs.js', options: {modules: 'commonjs'}}, {source: 'div.rt', expected: 'div.rt.amd.js', options: {modules: 'amd', name: 'div'}}, @@ -167,7 +167,7 @@ test('convert div with all module types', function (t) { } }); -test('convert jsrt and test source results', function (t) { +test('convert jsrt and test source results', t => { const files = ['simple.jsrt']; t.plan(files.length); files.forEach(check); @@ -181,7 +181,7 @@ test('convert jsrt and test source results', function (t) { } }); -test('html tests', function (t) { +test('html tests', t => { const files = [ 'scope.rt', 'scope-trailing-semicolon.rt', @@ -231,7 +231,7 @@ test('html tests', function (t) { } }); -test('test context', function (t) { +test('test context', t => { context.clear(); t.equal(context.hasErrors(), false); context.error('hi', '', 1, 1); @@ -242,7 +242,7 @@ test('test context', function (t) { t.end(); }); -test('test shell', function (t) { +test('test shell', t => { const shell = require('../../src/shell'); const newContext = _.cloneDeep(context); let outputJSON = ''; @@ -268,7 +268,7 @@ test('test shell', function (t) { t.end(); }); -test('test shell', function (t) { +test('test shell', t => { const filename = path.join(dataPath, 'div.rt'); const cli = require('../../src/cli'); const r = cli.execute(`${filename} -r --dry-run`); @@ -276,7 +276,7 @@ test('test shell', function (t) { t.end(); }); -test('test convertText', function (t) { +test('test convertText', t => { const texts = [ {input: '{}', expected: '()'}, {input: "a {'b'}", expected: '"a "+(\'b\')'} @@ -289,7 +289,7 @@ test('test convertText', function (t) { } }); -test('util.isStale', function (t) { +test('util.isStale', t => { const a = path.join(dataPath, 'a.tmp'); const b = path.join(dataPath, 'b.tmp');