diff --git a/Gruntfile.js b/Gruntfile.js
index e09a4f9..b6aaa40 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -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']);
diff --git a/package.json b/package.json
index a1b92df..571c89f 100644
--- a/package.json
+++ b/package.json
@@ -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"
}
}
diff --git a/playground/main.js b/playground/main.js
index 42e0afb..cc5dcdf 100644
--- a/playground/main.js
+++ b/playground/main.js
@@ -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 = "
hello
";
+var html = 'hello
';
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 = "\n Have {_.filter(this.state.todos, {done:true}).length} todos done,\n and {_.filter(this.state.todos, {done:false}).length} not done\n
\n
\n \n this.toggleChecked(todoIndex)\"/>\n {todo.value}\n
\n
if (e.keyCode == 13) { this.add(); }\" valueLink=\"{this.linkState('edited')}\"/>\n
\n
\n
";
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'));
diff --git a/src/reactTemplates.js b/src/reactTemplates.js
index f79e4ae..7e4e0c5 100644
--- a/src/reactTemplates.js
+++ b/src/reactTemplates.js
@@ -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) {