Skip to content

Commit

Permalink
Merge pull request #18 from tillarnold/dev
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
tillarnold committed Feb 6, 2015
2 parents 4a2be69 + 9d0d2f2 commit 1d8c652
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ jshint: {
}
```

Your jsx files need to have a `.jsx` or `.react.js` file extension or start with
```js
/** @jsx React.DOM */
```

Your jsx files need to have a `.jsx` or `.react.js` file extension.

If `grunt-jsxhint` is lacking a feature or if you found bug (or a typo in the README) feel free to submit a pull request or file an issue.



## Release History
* 2014-10-29   v0.4.0   Add support for `.react.js` suffix
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
"node": ">= 0.10.0"
},
"dependencies": {
"proxyquire": "~1.1.0",
"rewire": "~2.1.0",
"grunt-contrib-jshint": "0.10.0",
"jshint": "~2.5.1",
"jstransform": "~8.2.0"
"proxyquire": "~1.3.1",
"rewire": "~2.1.5",
"grunt-contrib-jshint": "0.11.0",
"jshint": "~2.6.0"
},
"devDependencies": {
"react-tools": "~0.12.0"
Expand Down
32 changes: 19 additions & 13 deletions tasks/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,32 @@ try {
}

var jshintcli = rewire('jshint/src/cli');
var docblock = require('jstransform/src/docblock');

//Get the original lint function
var origLint = jshintcli.__get__('lint');

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

function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}

function endsWithOneOf(string, suffixes) {
for(var i = 0; i < suffixes.length; i++) {
if(endsWith(string,suffixes[i])) {
return true;
}
}

return false;
}

var defaultSuffixes = ['.jsx','.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;
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 hasSuffix = endsWithOneOf(file,defaultSuffixes);

if (hasSuffix) {
var compiled;

try {
Expand Down

0 comments on commit 1d8c652

Please sign in to comment.