diff --git a/README.md b/README.md index 9b37459..0564e4f 100644 --- a/README.md +++ b/README.md @@ -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 */ ``` diff --git a/package.json b/package.json index a92ffec..cbbd378 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/tasks/jshint.js b/tasks/jshint.js index 404ddb5..7607c64 100644 --- a/tasks/jshint.js +++ b/tasks/jshint.js @@ -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); } @@ -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; -