add eslint config wix-editor and fix errors

This commit is contained in:
Omer Ganim 2016-04-27 14:01:18 +03:00
parent 3cd56fe7ef
commit 4c385d5525
8 changed files with 62 additions and 53 deletions

View File

@ -1,5 +1,5 @@
{
"extends": ["wix-editor/node", "plugin:lodash/recommended"],
"extends": ["wix-editor", "wix-editor/node", "plugin:lodash/recommended"],
"plugins": ["lodash", "wix-editor"],
"rules": {
"semi": [2, "always"],
@ -9,6 +9,7 @@
"prefer-const": 0,
"prefer-spread": 0,
"prefer-template": 0,
"consistent-return": 0,
"no-restricted-syntax": [2, "WithStatement", "ContinueStatement", "ForStatement"],
"no-negated-condition": 1,

View File

@ -6,5 +6,8 @@
"browser": true,
"node": true,
"amd": true
},
"globals": {
"requirejs": true
}
}

View File

@ -6,5 +6,8 @@
"browser": true,
"node": true,
"amd": true
},
"globals": {
"requirejs": true
}
}

View File

@ -2,7 +2,6 @@
var fs = require('fs');
var path = require('path');
var util = require('util');
var chalk = require('chalk');
var reactTemplates = require('./reactTemplates');
var fsUtil = require('./fsUtil');

View File

@ -18,9 +18,7 @@ function isStale(source, target) {
function createRelativeReadFileSync(baseFile) {
var basePath = path.dirname(baseFile);
return function(filename) {
return fs.readFileSync(path.resolve(basePath, filename));
};
return filename => fs.readFileSync(path.resolve(basePath, filename));
}
module.exports = {

View File

@ -278,10 +278,10 @@ function handleStyleProp(val, node, context) {
.filter(i => _.includes(i, ':'))
.map(i => {
const pair = i.split(':');
//const val = pair[1];
const val = pair.slice(1).join(':').trim();
return _.camelCase(pair[0].trim()) + ' : ' + convertText(node, context, val.trim());
//return stringUtils.convertToCamelCase(pair[0].trim()) + ' : ' + convertText(node, context, val.trim())
const value = pair.slice(1).join(':').trim();
return _.camelCase(pair[0].trim()) + ' : ' + convertText(node, context, value.trim());
//return stringUtils.convertToCamelCase(pair[0].trim()) + ' : ' + convertText(node, context, value.trim())
})
.join(',');
return `{${styleStr}}`;
@ -352,13 +352,12 @@ function convertHtmlToReact(node, context) {
throw RTCodeError.build(context, node, 'rt-include needs a readFileSync polyfill on options');
}
try {
var newHtml = context.options.readFileSync(srcFile);
context.html = context.options.readFileSync(srcFile);
} catch (e) {
console.error(e);
throw RTCodeError.build(context, node, `rt-include failed to read file '${srcFile}'`);
}
context.html = newHtml;
return parseAndConvertHtmlToReact(newHtml, context);
return parseAndConvertHtmlToReact(context.html, context);
}
var data = {name: convertTagNameToConstructor(node.name, context)};
@ -373,7 +372,7 @@ function convertHtmlToReact(node, context) {
data.item = arr[0].trim();
data.collection = arr[1].trim();
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}Index`);
}
@ -410,9 +409,8 @@ function convertHtmlToReact(node, context) {
data.children = utils.concatChildren(children);
if (node.name === virtualNode) { //eslint-disable-line wix-editor/prefer-ternary
data.body = "[" + _.compact(children).join(',') + "]";
}
else {
data.body = `[${_.compact(children).join(',')}]`;
} else {
data.body = _.template(getTagTemplateString(!hasNonSimpleChildren(node), reactSupport.shouldUseCreateElement(context)))(data);
}
@ -497,16 +495,16 @@ function isTag(node) {
function handleSelfClosingHtmlTags(nodes) {
return _.flatMap(nodes, function (node) {
var externalNodes = [];
node.children = handleSelfClosingHtmlTags(node.children);
if (node.type === 'tag' && (_.includes(reactSupport.htmlSelfClosingTags, node.name) ||
_.includes(reactTemplatesSelfClosingTags, node.name))) {
externalNodes = _.filter(node.children, isTag);
_.forEach(externalNodes, i => i.parent = node);
node.children = _.reject(node.children, isTag);
}
return [node].concat(externalNodes);
});
var externalNodes = [];
node.children = handleSelfClosingHtmlTags(node.children);
if (node.type === 'tag' && (_.includes(reactSupport.htmlSelfClosingTags, node.name) ||
_.includes(reactTemplatesSelfClosingTags, node.name))) {
externalNodes = _.filter(node.children, isTag);
_.forEach(externalNodes, i => {i.parent = node;});
node.children = _.reject(node.children, isTag);
}
return [node].concat(externalNodes);
});
}
function convertTemplateToReact(html, options) {

View File

@ -1,7 +1,6 @@
'use strict';
var css = require('css');
var _ = require('lodash');
var stringUtils = require('./stringUtils');
var rtnData = require('./rt-style-support-data.js');

View File

@ -184,29 +184,29 @@ test('convert jsrt and test source results', function (t) {
});
test('html tests', function (t) {
var files = [
"scope.rt",
"scope-trailing-semicolon.rt",
"scope-variable-references.rt",
"lambda.rt",
"eval.rt",
"props.rt",
"custom-element.rt",
"style.rt",
"concat.rt",
"js-in-attr.rt",
"props-class.rt",
"rt-class.rt",
"className.rt",
"svg.rt",
"virtual.rt",
"scope-evaluated-after-repeat.rt",
"scope-evaluated-after-repeat2.rt",
"scope-evaluated-after-if.rt",
"scope-obj.rt",
"repeat-literal-collection.rt",
"include.rt"
];
var files = [
'scope.rt',
'scope-trailing-semicolon.rt',
'scope-variable-references.rt',
'lambda.rt',
'eval.rt',
'props.rt',
'custom-element.rt',
'style.rt',
'concat.rt',
'js-in-attr.rt',
'props-class.rt',
'rt-class.rt',
'className.rt',
'svg.rt',
'virtual.rt',
'scope-evaluated-after-repeat.rt',
'scope-evaluated-after-repeat2.rt',
'scope-evaluated-after-if.rt',
'scope-obj.rt',
'repeat-literal-collection.rt',
'include.rt'
];
t.plan(files.length);
files.forEach(check);
@ -214,7 +214,7 @@ test('html tests', function (t) {
function check(testFile) {
var filename = path.join(dataPath, testFile);
var options = {
readFileSync: fsUtil.createRelativeReadFileSync(filename)
readFileSync: fsUtil.createRelativeReadFileSync(filename)
};
var code = '';
try {
@ -259,7 +259,16 @@ test('test shell', function (t) {
r = shell.printResults(newContext);
t.equal(r, 1);
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();
t.end();
});
@ -298,7 +307,6 @@ test('util.isStale', function (t) {
var mtime2 = new Date(1995, 11, 17, 3, 24, 1);
fs.utimesSync(b, mtime2, mtime2);
var fsUtil = require('../../src/fsUtil');
var actual = fsUtil.isStale(a, b);
t.equal(actual, false);
actual = fsUtil.isStale(b, a);