Skip to content

Commit

Permalink
Merge pull request #14 from tillarnold/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
tillarnold committed Oct 29, 2014
2 parents c7be184 + 8cf3a41 commit b7d53fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jshint: {
}
```

Your jsx files need to have a `.jsx` file extension or start with
Your jsx files need to have a `.jsx` or `.react.js` file extension or start with
```js
/** @jsx React.DOM */
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"rewire": "~2.1.0",
"grunt-contrib-jshint": "0.10.0",
"jshint":"~2.5.1",
"jstransform": "~6.1.0"
"jstransform": "~7.0.0"
},
"devDependencies": {
"react-tools": "~0.11.1"
"react-tools": "~0.12.0"
},
"peerDependencies": {
"grunt": "~0.4.0"
Expand Down
47 changes: 24 additions & 23 deletions tasks/jshint.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var rewire = require('rewire');
var proxyquire = require('proxyquire');
try {
var react = require('react-tools');
}
catch(e) {
throw new Error('grunt-jsxhint: The module `react-tools` was not found. ' +
var react = require('react-tools');
} catch (e) {
throw new Error('grunt-jsxhint: The module `react-tools` was not found. ' +
'To fix this error run `npm install react-tools --save-dev`.', e);
}

Expand All @@ -15,42 +14,44 @@ var docblock = require('jstransform/src/docblock');
var origLint = jshintcli.__get__("lint");

var jsxSuffix = ".jsx";
var reactJsSuffix = '.react.js';

//override the lint function to also transform the jsx code
jshintcli.__set__("lint", function myLint(code, results, config, data, file) {
var isJsxFile = file.indexOf(jsxSuffix, file.length - jsxSuffix.length) !== -1;
//added check for having /** @jsx React.DOM */ comment
var hasDocblock = docblock.parseAsObject(docblock.extract(code)).jsx;
if (isJsxFile && !hasDocblock) {
code = '/** @jsx React.DOM */' + code;
}
if (isJsxFile || hasDocblock) {
var compiled;

try {
compiled = react.transform(code);
} catch (err) {
throw new Error('grunt-jsxhint: Error while running JSXTransformer on ' + file + '\n' + err.message);
}
var isJsxFile = file.indexOf(jsxSuffix, file.length - jsxSuffix.length) !== -1;
var isReactJsFile = file.indexOf(reactJsSuffix, file.length - reactJsSuffix.length) !== -1;
var hasSuffix = isJsxFile || isReactJsFile;

//added check for having /** @jsx React.DOM */ comment
var hasDocblock = docblock.parseAsObject(docblock.extract(code)).jsx;
if (hasSuffix && !hasDocblock) {
code = '/** @jsx React.DOM */' + code;
}
if (hasSuffix || hasDocblock) {
var compiled;

origLint(compiled, results, config, data, file);
try {
compiled = react.transform(code);
} catch (err) {
throw new Error('grunt-jsxhint: Error while running JSXTransformer on ' + file + '\n' + err.message);
}
else {

origLint(compiled, results, config, data, file);
} else {
origLint(code, results, config, data, file);
}
});

//override the jshint cli in the grunt-contrib-jshint lib folder
var libJsHint = proxyquire('grunt-contrib-jshint/tasks/lib/jshint',{
var libJsHint = proxyquire('grunt-contrib-jshint/tasks/lib/jshint', {
'jshint/src/cli': jshintcli
});


//insert the modified version of the jshint lib to the grunt-contrib-jshint taks
var gruntContribJshint = proxyquire('grunt-contrib-jshint/tasks/jshint',{
var gruntContribJshint = proxyquire('grunt-contrib-jshint/tasks/jshint', {
'./lib/jshint': libJsHint
});

//return the modified grunt-contrib-jshint version
module.exports = gruntContribJshint;

0 comments on commit b7d53fc

Please sign in to comment.