From 2ae438cc767bf6da5a08455fa47dd9cc3307dd03 Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 13 Feb 2015 12:35:26 -0800 Subject: [PATCH] [Lint] Update linter to use babel-lint and lint JSX/React directly - Upgraded eslint - Installed babel-eslint so that we can parse JSX and ES6 - Installed eslint-react-plugin so we can lint JSX directly w/o a transform - `no-comma-dangle` was replaced with `comma-dangle` - `space-unary-word-ops` was replaced with `space-unary-ops`. --- .eslintrc | 33 ++++++++++++++-- lint/linterTransform.js | 84 ----------------------------------------- linter.js | 5 --- package.json | 6 ++- 4 files changed, 34 insertions(+), 94 deletions(-) delete mode 100644 lint/linterTransform.js diff --git a/.eslintrc b/.eslintrc index a81fb56f319173..0294718d73f718 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,19 @@ { + "parser": "babel-eslint", + + "ecmaFeatures": { + "jsx": true + }, + "env": { + "es6": true, "jasmine": true, }, + "plugins": [ + "react" + ], + // Map from global var to bool specifying if it can be redefined "globals": { "__DEV__": true, @@ -35,10 +46,10 @@ }, "rules": { + "comma-dangle": 0, // disallow trailing commas in object literals "no-cond-assign": 1, // disallow assignment in conditional expressions "no-console": 0, // disallow use of console (off by default in the node environment) "no-constant-condition": 0, // disallow use of constant expressions in conditions - "no-comma-dangle": 0, // disallow trailing commas in object literals "no-control-regex": 1, // disallow control characters in regular expressions "no-debugger": 1, // disallow use of debugger "no-dupe-keys": 1, // disallow duplicate keys when creating object literals @@ -176,7 +187,7 @@ "space-in-parens": 0, // require or disallow spaces inside parentheses (off by default) "space-infix-ops": 1, // require spaces around operators "space-return-throw-case": 1, // require a space after return, throw, and case - "space-unary-word-ops": 1, // require a space around word operators such as typeof (off by default) + "space-unary-ops": [1, { "words": true, "nonwords": false }], // require or disallow spaces before/after unary operators (words on by default, nonwords off by default) "max-nested-callbacks": 0, // specify the maximum depth callbacks can be nested (off by default) "one-var": 0, // allow just one var statement per function (off by default) "wrap-regex": 0, // require regex literals to be wrapped in parentheses (off by default) @@ -189,6 +200,22 @@ "max-params": 0, // limits the number of parameters that can be used in the function declaration. (off by default) "max-statements": 0, // specify the maximum number of statement allowed in a function (off by default) "no-bitwise": 1, // disallow use of bitwise operators (off by default) - "no-plusplus": 0 // disallow use of unary operators, ++ and -- (off by default) + "no-plusplus": 0, // disallow use of unary operators, ++ and -- (off by default) + + "react/display-name": 0, + "react/jsx-boolean-value": 0, + "react/jsx-quotes": [1, "double", "avoid-escape"], + "react/jsx-no-undef": 1, + "react/jsx-sort-props": 0, + "react/jsx-uses-react": 0, + "react/jsx-uses-vars": 1, + "react/no-did-mount-set-state": 0, + "react/no-did-update-set-state": 0, + "react/no-multi-comp": 0, + "react/no-unknown-property": 0, + "react/prop-types": 0, + "react/react-in-jsx-scope": 0, + "react/self-closing-comp": 1, + "react/wrap-multilines": 0 } } diff --git a/lint/linterTransform.js b/lint/linterTransform.js deleted file mode 100644 index 669baf556c442c..00000000000000 --- a/lint/linterTransform.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -'use strict'; - -var eslint = require('eslint'); - -var ignoredStylisticRules = { - 'key-spacing': false, - 'comma-spacing': true, - 'no-multi-spaces': true, - 'brace-style': true, - 'camelcase': true, - 'consistent-this': true, - 'eol-last': true, - 'func-names': true, - 'func-style': true, - 'new-cap': true, - 'new-parens': true, - 'no-nested-ternary': true, - 'no-array-constructor': true, - 'no-lonely-if': true, - 'no-new-object': true, - 'no-spaced-func': true, - 'no-space-before-semi': true, - 'no-ternary': true, - 'no-trailing-spaces': true, - 'no-underscore-dangle': true, - 'no-wrap-func': true, - 'no-mixed-spaces-and-tabs': true, - 'quotes': true, - 'quote-props': true, - 'semi': true, - 'sort-vars': true, - 'space-after-keywords': true, - 'space-in-brackets': true, - 'space-in-parens': true, - 'space-infix-ops': true, - 'space-return-throw-case': true, - 'space-unary-word-ops': true, - 'max-nested-callbacks': true, - 'one-var': true, - 'wrap-regex': true, - 'curly': true, - 'no-mixed-requires': true, -}; - -function setLinterTransform(transformSource) { - var originalVerify = eslint.linter.verify; - eslint.linter.verify = function(text, config, filename, saveState) { - var transformedText; - try { - transformedText = transformSource(text, filename); - } catch (e) { - return [{ - severity: 2, - line: e.lineNumber, - message: e.message, - source: text - }]; - } - var originalLines = text.split('\n'); - var transformedLines = transformedText.split('\n'); - var warnings = originalVerify.call(eslint.linter, transformedText, config, filename, saveState); - - // JSX and ES6 transforms usually generate pretty ugly code. Let's skip lint warnings - // about code style for lines that have been changed by transform step. - // Note that more important issues, like use of undefined vars, will still be reported. - return warnings.filter(function(error) { - var lineHasBeenTransformed = originalLines[error.line - 1] !== transformedLines[error.line - 1]; - var shouldIgnore = ignoredStylisticRules[error.ruleId] && lineHasBeenTransformed; - return !shouldIgnore; - }); - }; -} - -module.exports = { - setLinterTransform: setLinterTransform, -}; diff --git a/linter.js b/linter.js index f243a2d2fb8ce3..4bd2fbe9ca9e9c 100644 --- a/linter.js +++ b/linter.js @@ -8,10 +8,5 @@ */ 'use strict'; -var transformSource = require('./jestSupport/scriptPreprocess.js').transformSource; -var linterTransform = require('./lint/linterTransform'); - -linterTransform.setLinterTransform(transformSource); - // Run the original CLI require('eslint/bin/eslint'); diff --git a/package.json b/package.json index fde82307eaefa9..0b5e00bbc61470 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,9 @@ "yargs": "1.3.2" }, "devDependencies": { - "jest-cli": "0.2.1", - "eslint": "0.9.2" + "babel-eslint": "^3.0.1", + "eslint": "^0.19.0", + "eslint-plugin-react": "^2.1.1", + "jest-cli": "0.2.1" } }