eslint fixes

This commit is contained in:
ido 2014-11-18 16:06:25 +02:00
parent 80fdb2aa01
commit 18137686c7
4 changed files with 25 additions and 18 deletions

View File

@ -1,5 +1,5 @@
'use strict';
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
clean: {
main: {
@ -9,7 +9,8 @@ module.exports = function (grunt) {
eslint: {
all: {
src: [
'src/**/*.js'
'src/**/*.js', 'playground/**/*.js',
'!playground/main.browser.js'
]
},
teamcity: {
@ -48,6 +49,7 @@ module.exports = function (grunt) {
});
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint', 'build_sources', 'check', 'build']);
grunt.registerTask('test', ['jasmine_node']);

View File

@ -31,6 +31,7 @@
"codemirror": "^4.7.0",
"grunt": "^0.4.5",
"grunt-browserify": "^3.2.0",
"grunt-eslint": "^2.0.0",
"tape": "^3.0.2"
}
}

View File

@ -1,3 +1,5 @@
'use strict';
/*eslint-env browser*/
var reactTemplates = require('../src/reactTemplates');
var playgroundTemplate = require('./playground.rt.js');
var htmlMode = require('codemirror/mode/htmlmixed/htmlmixed');
@ -11,7 +13,7 @@ var React = require('react/addons');
var _ = require('lodash');
var html = "<div>hello</div>";
var html = '<div>hello</div>';
var res = reactTemplates.convertTemplateToReact(html.trim());
console.log(res);
@ -22,7 +24,7 @@ function emptyFunc() {
function generateTemplateSource(html) {
var code = null;
try {
code = reactTemplates.convertTemplateToReact(html.trim().replace(/\r/g, ""));
code = reactTemplates.convertTemplateToReact(html.trim().replace(/\r/g, ''));
} catch (e) {
}
return code;
@ -30,17 +32,18 @@ function generateTemplateSource(html) {
function generateTemplateFunction(code) {
try {
var defineMap = {"react":React,"lodash":_};
var define = function (requirementsNames,content) {
var defineMap = {react: React, lodash: _};
var define = function (requirementsNames, content) {
var requirements = _.map(requirementsNames,function (reqName) {
return defineMap[reqName];
});
return content.apply(this,requirements);
};
/*eslint no-eval:0*/
var res = eval(code);
return res;
} catch (e) {
return emptyFunc
return emptyFunc;
}
}
@ -48,17 +51,17 @@ function generateRenderFunc(renderFunc) {
return function() {
var res = null;
try {
res = renderFunc.apply(this)
res = renderFunc.apply(this);
} catch (e) {
res = React.DOM.div.apply(this,[{style:{color:"red"}},"Exception:"+e.message]);
res = React.DOM.div.apply(this, [{style: {color: 'red'}}, 'Exception:' + e.message]);
}
return React.DOM.div.apply(this, _.flatten([
{key:"result"},
{key: 'result'},
res
]));
}
};
}
var z = {getInitialState: function() {return {name:"reactTemplates"}}};
var z = {getInitialState: function() {return {name: 'reactTemplates'};}};
var templateHTML = "<div>\n Have {_.filter(this.state.todos, {done:true}).length} todos done,\n and {_.filter(this.state.todos, {done:false}).length} not done\n <br/>\n <div rt-repeat=\"todo in this.state.todos\" key=\"{todo.key}\">\n <button onClick=\"(e)=>e.preventDefault(); this.remove(todo)\">x</button>\n <input type=\"checkbox\" checked=\"{todo.done}\" onChange=\"()=>this.toggleChecked(todoIndex)\"/>\n <span style=\"text-decoration: {todo.done ? 'line-through': 'none'}\">{todo.value}</span>\n </div>\n <input key=\"myinput\" type=\"text\" onKeyDown=\"(e) => if (e.keyCode == 13) { this.add(); }\" valueLink=\"{this.linkState('edited')}\"/>\n <button onClick=\"(e)=>e.preventDefault(); this.add()\" >Add</button><br/>\n <button onClick=\"(e)=>e.preventDefault(); this.clearDone()\">Clear done</button>\n</div>";
var templateProps = "{\n mixins: [React.addons.LinkedStateMixin],\n getInitialState: function () {\n return {edited: '', todos: [], counter: 0};\n },\n add: function () {\n if (this.state.edited.trim().length === 0) {\n return;\n }\n var newTodo = {value: this.state.edited, done: false, key: this.state.counter};\n this.setState({todos: this.state.todos.concat(newTodo), edited: '', counter: this.state.counter + 1});\n },\n remove: function (todo) {\n this.setState({todos: _.reject(this.state.todos, todo)});\n },\n toggleChecked: function (index) {\n var todos = _.cloneDeep(this.state.todos);\n todos[index].done = !todos[index].done;\n this.setState({todos: todos});\n },\n clearDone: function () {\n this.setState({todos: _.filter(this.state.todos, {done: false})});\n }\n}";
@ -76,9 +79,9 @@ var Playground = React.createClass({
try {
this.validProps = true;
console.log(state.templateProps);
classBase = eval("("+state.templateProps+")");
classBase = eval('(' + state.templateProps + ')');
if (!_.isObject(classBase)) {
throw "failed to eval";
throw 'failed to eval';
}
} catch (e) {
classBase = {};
@ -91,13 +94,13 @@ var Playground = React.createClass({
getInitialState: function () {
var currentState = {
templateHTML:templateHTML,
templateHTML: templateHTML,
templateProps: templateProps
};
this.updateSample(currentState);
return currentState;
},
componentWillUpdate: function (nextProps,nextState) {
componentWillUpdate: function (nextProps, nextState) {
if (nextState.templateHTML !== this.state.templateHTML || nextState.templateProps !== this.state.templateProps) {
this.updateSample(nextState);
}
@ -108,4 +111,4 @@ var Playground = React.createClass({
}
});
React.render(Playground(),document.getElementById('playground'));
React.render(Playground(), document.getElementById('playground'));

View File

@ -246,6 +246,7 @@ function extractDefinesFromJSXTag(html, defines) {
var match = true;
while (match) {
match = false;
/*eslint no-loop-func:0*/
reqStr = reqStr.replace(/\s*(\w+)\s*\=\s*\"([^\"]*)\"\s*/, function(full, varName, reqPath) {
defines[reqPath] = varName;
match = true;
@ -259,7 +260,7 @@ function extractDefinesFromJSXTag(html, defines) {
/**
* @param {string} html
* @param {{commonJS:boolean}} options
* @param {{commonJS:boolean}?} options
* @return {string}
*/
function convertTemplateToReact(html, options) {