Javascript grunt jsxhint和jsxhint的作用不同

Javascript grunt jsxhint和jsxhint的作用不同,javascript,gruntjs,react-native,grunt-jsxhint,jsxhint,Javascript,Gruntjs,React Native,Grunt Jsxhint,Jsxhint,当我使用npm安装-g jsxhint时,我可以使用它来lint我的jsx代码,如下所示: 但是当我尝试使用grunt jsxhint设置lint命令时,它失败了: 我的GrunFile非常简单: module.exports = function(grunt) { grunt.loadNpmTasks('grunt-jsxhint'); /* Project configuration */ grunt.initConfig({ options: { j

当我使用
npm安装-g jsxhint
时,我可以使用它来lint我的jsx代码,如下所示:

但是当我尝试使用
grunt jsxhint
设置lint命令时,它失败了:

我的GrunFile非常简单:

module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-jsxhint');

  /* Project configuration */
  grunt.initConfig({
    options: {
      jshintrc: '.jshintrc',
      ignores: [],
      additionalSuffixes: ['.js', '.ios.js']
    },
    jshint: {
      all: ['./app/index.ios.js']
    }
  });

  /* Test Tasks */
  grunt.registerTask('test', ['jshint']);
};
为什么这些输出的结果不同


JsxHint和JSHint不是linting JSX的最佳工具。JSHint不支持JSX,JsxHint所做的只是转换JSX,然后在转换后的代码上运行JSHint。 我一直在使用(并强烈推荐)的。这更好,因为Eslint可以使用自定义解析器解析任何Javascript风格(如

示例
.eslintrc
文件:

{
    "parser": "esprima-fb",
    "env": {
        "browser": true,
        "node": true
    },

    "rules": {
        "no-mixed-requires": [0, false],
        "quotes": [2, "single"],
        "strict": [1, "never"],
        "semi": [2, "always"],
        "curly": 1,
        "no-bitwise": 1,
        "max-len": [1, 110, 4],
        "vars-on-top": 0,
        "guard-for-in": 1,
        "react/display-name": 1,
        "react/jsx-quotes": [2, "double", "avoid-escape"],
        "react/jsx-no-undef": 2,
        "react/jsx-sort-props": 0,
        "react/jsx-uses-react": 1,
        "react/jsx-uses-vars": 1,
        "react/no-did-mount-set-state": 2,
        "react/no-did-update-set-state": 2,
        "react/no-multi-comp": 0,
        "react/no-unknown-property": 1,
        "react/prop-types": 2,
        "react/react-in-jsx-scope": 1,
        "react/self-closing-comp": 1,
        "react/wrap-multilines": 2
    },

    "ecmaFeatures": {
        "jsx": true
    },

    "plugins": [ "react" ],

    "globals": {
        "d3": true,
        "require": "true",
        "module": "true",
        "$": "true",
        "d3": "true"
    }
}

我发现我的Grunfile有什么问题

您需要在以下位置加载任务:
grunt.loadNpmTasks('grunt-jsxhint')

设置
grunt.initConfig({})
之后

这看起来像这样:

module.exports = function(grunt) {

  /* Project configuration */
  grunt.initConfig({
    options: {
      jshintrc: '.jshintrc',
      ignores: [],
      additionalSuffixes: ['.js', '.ios.js']
    },
    jshint: {
      all: ['./app/index.ios.js']
    }
  });

  grunt.loadNpmTasks('grunt-jsxhint');

  /* Test Tasks */
  grunt.registerTask('test', ['jshint']);
};