add eslint config wix-editor and fix errors
This commit is contained in:
parent
3cd56fe7ef
commit
4c385d5525
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"extends": ["wix-editor/node", "plugin:lodash/recommended"],
|
"extends": ["wix-editor", "wix-editor/node", "plugin:lodash/recommended"],
|
||||||
"plugins": ["lodash", "wix-editor"],
|
"plugins": ["lodash", "wix-editor"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"semi": [2, "always"],
|
"semi": [2, "always"],
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
"prefer-const": 0,
|
"prefer-const": 0,
|
||||||
"prefer-spread": 0,
|
"prefer-spread": 0,
|
||||||
"prefer-template": 0,
|
"prefer-template": 0,
|
||||||
|
"consistent-return": 0,
|
||||||
|
|
||||||
"no-restricted-syntax": [2, "WithStatement", "ContinueStatement", "ForStatement"],
|
"no-restricted-syntax": [2, "WithStatement", "ContinueStatement", "ForStatement"],
|
||||||
"no-negated-condition": 1,
|
"no-negated-condition": 1,
|
||||||
|
|
|
@ -6,5 +6,8 @@
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"node": true,
|
"node": true,
|
||||||
"amd": true
|
"amd": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"requirejs": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,8 @@
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"node": true,
|
"node": true,
|
||||||
"amd": true
|
"amd": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"requirejs": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var util = require('util');
|
|
||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
var reactTemplates = require('./reactTemplates');
|
var reactTemplates = require('./reactTemplates');
|
||||||
var fsUtil = require('./fsUtil');
|
var fsUtil = require('./fsUtil');
|
||||||
|
|
|
@ -18,9 +18,7 @@ function isStale(source, target) {
|
||||||
|
|
||||||
function createRelativeReadFileSync(baseFile) {
|
function createRelativeReadFileSync(baseFile) {
|
||||||
var basePath = path.dirname(baseFile);
|
var basePath = path.dirname(baseFile);
|
||||||
return function(filename) {
|
return filename => fs.readFileSync(path.resolve(basePath, filename));
|
||||||
return fs.readFileSync(path.resolve(basePath, filename));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -278,10 +278,10 @@ function handleStyleProp(val, node, context) {
|
||||||
.filter(i => _.includes(i, ':'))
|
.filter(i => _.includes(i, ':'))
|
||||||
.map(i => {
|
.map(i => {
|
||||||
const pair = i.split(':');
|
const pair = i.split(':');
|
||||||
//const val = pair[1];
|
|
||||||
const val = pair.slice(1).join(':').trim();
|
const value = pair.slice(1).join(':').trim();
|
||||||
return _.camelCase(pair[0].trim()) + ' : ' + convertText(node, context, val.trim());
|
return _.camelCase(pair[0].trim()) + ' : ' + convertText(node, context, value.trim());
|
||||||
//return stringUtils.convertToCamelCase(pair[0].trim()) + ' : ' + convertText(node, context, val.trim())
|
//return stringUtils.convertToCamelCase(pair[0].trim()) + ' : ' + convertText(node, context, value.trim())
|
||||||
})
|
})
|
||||||
.join(',');
|
.join(',');
|
||||||
return `{${styleStr}}`;
|
return `{${styleStr}}`;
|
||||||
|
@ -352,13 +352,12 @@ function convertHtmlToReact(node, context) {
|
||||||
throw RTCodeError.build(context, node, 'rt-include needs a readFileSync polyfill on options');
|
throw RTCodeError.build(context, node, 'rt-include needs a readFileSync polyfill on options');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var newHtml = context.options.readFileSync(srcFile);
|
context.html = context.options.readFileSync(srcFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
throw RTCodeError.build(context, node, `rt-include failed to read file '${srcFile}'`);
|
throw RTCodeError.build(context, node, `rt-include failed to read file '${srcFile}'`);
|
||||||
}
|
}
|
||||||
context.html = newHtml;
|
return parseAndConvertHtmlToReact(context.html, context);
|
||||||
return parseAndConvertHtmlToReact(newHtml, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {name: convertTagNameToConstructor(node.name, context)};
|
var data = {name: convertTagNameToConstructor(node.name, context)};
|
||||||
|
@ -373,7 +372,7 @@ function convertHtmlToReact(node, context) {
|
||||||
data.item = arr[0].trim();
|
data.item = arr[0].trim();
|
||||||
data.collection = arr[1].trim();
|
data.collection = arr[1].trim();
|
||||||
validateJS(data.item, node, context);
|
validateJS(data.item, node, context);
|
||||||
validateJS("(" + data.collection + ")", node, context);
|
validateJS(`(${data.collection})`, node, context);
|
||||||
stringUtils.addIfMissing(context.boundParams, data.item);
|
stringUtils.addIfMissing(context.boundParams, data.item);
|
||||||
stringUtils.addIfMissing(context.boundParams, `${data.item}Index`);
|
stringUtils.addIfMissing(context.boundParams, `${data.item}Index`);
|
||||||
}
|
}
|
||||||
|
@ -410,9 +409,8 @@ function convertHtmlToReact(node, context) {
|
||||||
data.children = utils.concatChildren(children);
|
data.children = utils.concatChildren(children);
|
||||||
|
|
||||||
if (node.name === virtualNode) { //eslint-disable-line wix-editor/prefer-ternary
|
if (node.name === virtualNode) { //eslint-disable-line wix-editor/prefer-ternary
|
||||||
data.body = "[" + _.compact(children).join(',') + "]";
|
data.body = `[${_.compact(children).join(',')}]`;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data.body = _.template(getTagTemplateString(!hasNonSimpleChildren(node), reactSupport.shouldUseCreateElement(context)))(data);
|
data.body = _.template(getTagTemplateString(!hasNonSimpleChildren(node), reactSupport.shouldUseCreateElement(context)))(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,7 +500,7 @@ function handleSelfClosingHtmlTags(nodes) {
|
||||||
if (node.type === 'tag' && (_.includes(reactSupport.htmlSelfClosingTags, node.name) ||
|
if (node.type === 'tag' && (_.includes(reactSupport.htmlSelfClosingTags, node.name) ||
|
||||||
_.includes(reactTemplatesSelfClosingTags, node.name))) {
|
_.includes(reactTemplatesSelfClosingTags, node.name))) {
|
||||||
externalNodes = _.filter(node.children, isTag);
|
externalNodes = _.filter(node.children, isTag);
|
||||||
_.forEach(externalNodes, i => i.parent = node);
|
_.forEach(externalNodes, i => {i.parent = node;});
|
||||||
node.children = _.reject(node.children, isTag);
|
node.children = _.reject(node.children, isTag);
|
||||||
}
|
}
|
||||||
return [node].concat(externalNodes);
|
return [node].concat(externalNodes);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var css = require('css');
|
var css = require('css');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var stringUtils = require('./stringUtils');
|
|
||||||
var rtnData = require('./rt-style-support-data.js');
|
var rtnData = require('./rt-style-support-data.js');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -185,27 +185,27 @@ test('convert jsrt and test source results', function (t) {
|
||||||
|
|
||||||
test('html tests', function (t) {
|
test('html tests', function (t) {
|
||||||
var files = [
|
var files = [
|
||||||
"scope.rt",
|
'scope.rt',
|
||||||
"scope-trailing-semicolon.rt",
|
'scope-trailing-semicolon.rt',
|
||||||
"scope-variable-references.rt",
|
'scope-variable-references.rt',
|
||||||
"lambda.rt",
|
'lambda.rt',
|
||||||
"eval.rt",
|
'eval.rt',
|
||||||
"props.rt",
|
'props.rt',
|
||||||
"custom-element.rt",
|
'custom-element.rt',
|
||||||
"style.rt",
|
'style.rt',
|
||||||
"concat.rt",
|
'concat.rt',
|
||||||
"js-in-attr.rt",
|
'js-in-attr.rt',
|
||||||
"props-class.rt",
|
'props-class.rt',
|
||||||
"rt-class.rt",
|
'rt-class.rt',
|
||||||
"className.rt",
|
'className.rt',
|
||||||
"svg.rt",
|
'svg.rt',
|
||||||
"virtual.rt",
|
'virtual.rt',
|
||||||
"scope-evaluated-after-repeat.rt",
|
'scope-evaluated-after-repeat.rt',
|
||||||
"scope-evaluated-after-repeat2.rt",
|
'scope-evaluated-after-repeat2.rt',
|
||||||
"scope-evaluated-after-if.rt",
|
'scope-evaluated-after-if.rt',
|
||||||
"scope-obj.rt",
|
'scope-obj.rt',
|
||||||
"repeat-literal-collection.rt",
|
'repeat-literal-collection.rt',
|
||||||
"include.rt"
|
'include.rt'
|
||||||
];
|
];
|
||||||
t.plan(files.length);
|
t.plan(files.length);
|
||||||
|
|
||||||
|
@ -259,7 +259,16 @@ test('test shell', function (t) {
|
||||||
r = shell.printResults(newContext);
|
r = shell.printResults(newContext);
|
||||||
t.equal(r, 1);
|
t.equal(r, 1);
|
||||||
var output = JSON.parse(outputJSON);
|
var output = JSON.parse(outputJSON);
|
||||||
t.deepEqual(output, [{column: 1, endOffset: -1, file: null, index: -1, level: 'ERROR', line: 1, msg: 'hi', startOffset: -1}]);
|
t.deepEqual(output, [{
|
||||||
|
column: 1,
|
||||||
|
endOffset: -1,
|
||||||
|
file: null,
|
||||||
|
index: -1,
|
||||||
|
level: 'ERROR',
|
||||||
|
line: 1,
|
||||||
|
msg: 'hi',
|
||||||
|
startOffset: -1
|
||||||
|
}]);
|
||||||
context.clear();
|
context.clear();
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -298,7 +307,6 @@ test('util.isStale', function (t) {
|
||||||
var mtime2 = new Date(1995, 11, 17, 3, 24, 1);
|
var mtime2 = new Date(1995, 11, 17, 3, 24, 1);
|
||||||
fs.utimesSync(b, mtime2, mtime2);
|
fs.utimesSync(b, mtime2, mtime2);
|
||||||
|
|
||||||
var fsUtil = require('../../src/fsUtil');
|
|
||||||
var actual = fsUtil.isStale(a, b);
|
var actual = fsUtil.isStale(a, b);
|
||||||
t.equal(actual, false);
|
t.equal(actual, false);
|
||||||
actual = fsUtil.isStale(b, a);
|
actual = fsUtil.isStale(b, a);
|
||||||
|
|
Loading…
Reference in New Issue