diff --git a/.eslintrc b/.eslintrc index f6c76c4..c24f3de 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,6 @@ "plugins": ["lodash", "wix-editor"], "rules": { "semi": [2, "always"], - "object-shorthand": 0, "prefer-arrow-callback": 0, "prefer-spread": 0, "prefer-template": 0, diff --git a/playground/.eslintrc b/playground/.eslintrc index 233c9e1..081a12e 100644 --- a/playground/.eslintrc +++ b/playground/.eslintrc @@ -1,7 +1,8 @@ { "rules": { "strict": [2, "function"], - "no-var": 0 + "no-var": 0, + "object-shorthand": 0 }, "env": { "browser": true, diff --git a/sample/.eslintrc b/sample/.eslintrc index 233c9e1..081a12e 100644 --- a/sample/.eslintrc +++ b/sample/.eslintrc @@ -1,7 +1,8 @@ { "rules": { "strict": [2, "function"], - "no-var": 0 + "no-var": 0, + "object-shorthand": 0 }, "env": { "browser": true, diff --git a/src/RTCodeError.js b/src/RTCodeError.js index 789ec8d..2b2e383 100644 --- a/src/RTCodeError.js +++ b/src/RTCodeError.js @@ -121,23 +121,24 @@ function buildError(context, node, msg) { * @return {{pos:Pos, start:number, end:number}} */ function getNodeLoc(context, node) { + const start = node.startIndex; const pos = getLine(context.html, node); let end; if (node.data) { - end = node.startIndex + node.data.length; + end = start + node.data.length; } else if (node.next) { // eslint-disable-line end = node.next.startIndex; } else { end = context.html.length; } return { - pos: pos, - start: node.startIndex, - end: end + pos, + start, + end }; } module.exports = { - RTCodeError: RTCodeError, - getNodeLoc: getNodeLoc + RTCodeError, + getNodeLoc }; diff --git a/src/api.js b/src/api.js index 89ccae0..a8308d7 100644 --- a/src/api.js +++ b/src/api.js @@ -47,7 +47,7 @@ function convertFile(source, target, options, context) { } module.exports = { - convertFile: convertFile, + convertFile, context: require('./context'), _test: {} }; diff --git a/src/cli.js b/src/cli.js index 3ead963..cc7b049 100755 --- a/src/cli.js +++ b/src/cli.js @@ -91,10 +91,10 @@ function execute(args) { } module.exports = { - context: context, - execute: execute, - executeOptions: executeOptions, - handleSingleFile: handleSingleFile, + context, + execute, + executeOptions, + handleSingleFile, convertTemplateToReact: reactTemplates.convertTemplateToReact, convertStyle: rtStyle.convert }; diff --git a/src/context.js b/src/context.js index 3c3413f..e9b6712 100644 --- a/src/context.js +++ b/src/context.js @@ -31,21 +31,21 @@ const context = { color: true, /** @type {string} */ cwd: process.cwd(), - report: function (msg) { + report(msg) { console.log(msg); }, - verbose: function (msg) { + verbose(msg) { if (context.options.verbose) { console.log(msg); } }, - info: function (msg, file, line, column) { + info(msg, file, line, column) { context.issue(MESSAGE_LEVEL.INFO, msg, file, line, column); }, - warn: function (msg, file, line, column, startOffset, endOffset) { + warn(msg, file, line, column, startOffset, endOffset) { context.issue(MESSAGE_LEVEL.WARN, msg, file, line, column, startOffset, endOffset); }, - error: function (msg, file, line, column, startOffset, endOffset) { + error(msg, file, line, column, startOffset, endOffset) { context.issue(MESSAGE_LEVEL.ERROR, msg, file, line, column, startOffset, endOffset); }, /** @@ -57,16 +57,16 @@ const context = { * @param {number=} startOffset * @param {number=} endOffset */ - issue: function (level, msg, file, line, column, startOffset, endOffset) { + issue(level, msg, file, line, column, startOffset, endOffset) { context.messages.push({level, msg, file: file || null, line: norm(line), column: norm(column), index: norm(startOffset), startOffset: norm(startOffset), endOffset: norm(endOffset)}); }, - getMessages: function () { + getMessages() { return context.messages; }, - clear: function () { + clear() { context.messages = []; }, - hasErrors: function () { + hasErrors() { return _.some(context.messages, {level: MESSAGE_LEVEL.ERROR}); }, options: { @@ -74,7 +74,7 @@ const context = { outFile: null, format: 'stylish' }, - MESSAGE_LEVEL: MESSAGE_LEVEL + MESSAGE_LEVEL }; module.exports = context; diff --git a/src/formatters/stylish.js b/src/formatters/stylish.js index ab7d1a7..a569fa3 100644 --- a/src/formatters/stylish.js +++ b/src/formatters/stylish.js @@ -158,9 +158,7 @@ module.exports = function (results) { }), { align: ['', 'r', 'l'], - stringLength: function (str) { - return chalk.stripColor(str).length; - } + stringLength: str => chalk.stripColor(str).length } ).split('\n').map(function (el) { return el.replace(/(\d+)\s+(\d+)/, function (m, p1, p2) { diff --git a/src/fsUtil.js b/src/fsUtil.js index 34f47a5..0bb5baa 100644 --- a/src/fsUtil.js +++ b/src/fsUtil.js @@ -22,6 +22,6 @@ function createRelativeReadFileSync(baseFile) { } module.exports = { - isStale: isStale, - createRelativeReadFileSync: createRelativeReadFileSync + isStale, + createRelativeReadFileSync }; diff --git a/src/reactPropTemplates.js b/src/reactPropTemplates.js index 78ff76c..afddd5c 100644 --- a/src/reactPropTemplates.js +++ b/src/reactPropTemplates.js @@ -14,6 +14,6 @@ const native = { }; module.exports = { - native: native, + native, dom: {} }; diff --git a/src/reactSupport.js b/src/reactSupport.js index cdc6432..02471b9 100644 --- a/src/reactSupport.js +++ b/src/reactSupport.js @@ -56,9 +56,9 @@ const templates = { }; module.exports = { - htmlSelfClosingTags: htmlSelfClosingTags, - attributesMapping: attributesMapping, - classNameProp: classNameProp, - shouldUseCreateElement: shouldUseCreateElement, - templates: templates + htmlSelfClosingTags, + attributesMapping, + classNameProp, + shouldUseCreateElement, + templates }; diff --git a/src/reactTemplates.js b/src/reactTemplates.js index d4c337c..a4153fe 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -317,10 +317,10 @@ function defaultContext(html, options, reportContext) { return { boundParams: [], injectedFunctions: [], - html: html, - options: options, + html, + options, defines: options.defines ? _.clone(options.defines) : defaultDefines, - reportContext: reportContext + reportContext }; } @@ -602,12 +602,10 @@ function generate(data, options) { } module.exports = { - convertTemplateToReact: convertTemplateToReact, - convertRT: convertRT, - convertJSRTToJS: convertJSRTToJS, - RTCodeError: RTCodeError, + convertTemplateToReact, + convertRT, + convertJSRTToJS, + RTCodeError, normalizeName: utils.normalizeName, - _test: { - convertText: convertText - } + _test: {convertText} }; diff --git a/src/rtStyle.js b/src/rtStyle.js index 26e9182..1d5019f 100644 --- a/src/rtStyle.js +++ b/src/rtStyle.js @@ -43,6 +43,6 @@ function convertValue(p, v) { } module.exports = { - convert: convert, - convertBody: convertBody + convert, + convertBody }; diff --git a/test/src/test.js b/test/src/test.js index 9e8ad98..02697af 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -95,7 +95,7 @@ function errorEqualMessage(err, file) { endOffset: err.endOffset, msg: err.message, level: 'ERROR', - file: file + file }; } diff --git a/test/src/util.js b/test/src/util.js index bd1d323..1eb3e47 100644 --- a/test/src/util.js +++ b/test/src/util.js @@ -76,11 +76,11 @@ function codeToHtml(code) { } module.exports = { - normalizeHtml: normalizeHtml, - compareAndWrite: compareAndWrite, - readFileNormalized: readFileNormalized, - readFile: readFile, - joinDataPath: joinDataPath, - rtToHtml: rtToHtml, - codeToHtml: codeToHtml + normalizeHtml, + compareAndWrite, + readFileNormalized, + readFile, + joinDataPath, + rtToHtml, + codeToHtml };