├── .eslintrc ├── .gitignore ├── README.md ├── index.js ├── lib └── rules │ └── no-condition.js ├── package.json └── tests └── rules └── no-condition.js /.eslintrc: -------------------------------------------------------------------------------- 1 | root: true 2 | 3 | env: 4 | node: true 5 | 6 | extends: 7 | "eslint:recommended" 8 | 9 | rules: 10 | indent: [2, 4, {SwitchCase: 1}] 11 | brace-style: [2, "1tbs"] 12 | camelcase: [2, { properties: "never" }] 13 | callback-return: [2, ["cb", "callback", "next"]] 14 | comma-spacing: 2 15 | comma-style: [2, "last"] 16 | consistent-return: 2 17 | curly: [2, "all"] 18 | default-case: 2 19 | dot-notation: [2, { allowKeywords: true }] 20 | eol-last: 2 21 | eqeqeq: 2 22 | func-style: [2, "declaration"] 23 | guard-for-in: 2 24 | key-spacing: [2, { beforeColon: false, afterColon: true }] 25 | new-cap: 2 26 | new-parens: 2 27 | no-alert: 2 28 | no-array-constructor: 2 29 | no-caller: 2 30 | no-console: 0 31 | no-delete-var: 2 32 | no-empty-label: 2 33 | no-eval: 2 34 | no-extend-native: 2 35 | no-extra-bind: 2 36 | no-fallthrough: 2 37 | no-floating-decimal: 2 38 | no-implied-eval: 2 39 | no-invalid-this: 2 40 | no-iterator: 2 41 | no-label-var: 2 42 | no-labels: 2 43 | no-lone-blocks: 2 44 | no-loop-func: 2 45 | no-mixed-spaces-and-tabs: [2, false] 46 | no-multi-spaces: 2 47 | no-multi-str: 2 48 | no-native-reassign: 2 49 | no-nested-ternary: 2 50 | no-new: 2 51 | no-new-func: 2 52 | no-new-object: 2 53 | no-new-wrappers: 2 54 | no-octal: 2 55 | no-octal-escape: 2 56 | no-process-exit: 2 57 | no-proto: 2 58 | no-redeclare: 2 59 | no-return-assign: 2 60 | no-script-url: 2 61 | no-sequences: 2 62 | no-shadow: 2 63 | no-shadow-restricted-names: 2 64 | no-spaced-func: 2 65 | no-trailing-spaces: 2 66 | no-undef: 2 67 | no-undef-init: 2 68 | no-undefined: 2 69 | no-underscore-dangle: 2 70 | no-unused-expressions: 2 71 | no-unused-vars: [2, {vars: "all", args: "after-used"}] 72 | no-use-before-define: 2 73 | no-with: 2 74 | quotes: [2, "double"] 75 | radix: 2 76 | semi: 2 77 | semi-spacing: [2, {before: false, after: true}] 78 | space-after-keywords: [2, "always"] 79 | space-before-blocks: 2 80 | space-before-function-paren: [2, "never"] 81 | space-infix-ops: 2 82 | space-return-throw-case: 2 83 | space-unary-ops: [2, {words: true, nonwords: false}] 84 | spaced-comment: [2, "always", { exceptions: ["-"]}] 85 | strict: [2, "global"] 86 | valid-jsdoc: [2, { prefer: { "return": "returns"}}] 87 | wrap-iife: 2 88 | yoda: [2, "never"] 89 | 90 | # Previously on by default in node environment 91 | no-catch-shadow: 0 92 | no-console: 0 93 | no-mixed-requires: 2 94 | no-new-require: 2 95 | no-path-concat: 2 96 | no-process-exit: 2 97 | global-strict: [0, "always"] 98 | handle-callback-err: [2, "err"] 99 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eslint-plugin-arrow-function 2 | 3 | *deprecated* 4 | 5 | marged into eslint http://eslint.org/docs/rules/no-arrow-condition. 6 | use this instead. 7 | 8 | Jxck 9 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | rules: { 5 | "no-condition": require("./lib/rules/no-condition") 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /lib/rules/no-condition.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = function(context) { 4 | var message = "suspicious code: it seemd to be comparison `>=`, not arrow function `=>`"; 5 | 6 | function testProp(node) { 7 | if (node.test.type === "ArrowFunctionExpression") { 8 | context.report(node, message); 9 | } 10 | } 11 | 12 | // for "a => 1 ? 2 : 3" 13 | function arrowFunc(node) { 14 | if (node.body.type === "ConditionalExpression") { 15 | context.report(node, message); 16 | } 17 | } 18 | 19 | return { 20 | "IfStatement": testProp, 21 | "WhileStatement": testProp, 22 | "ForStatement": testProp, 23 | "ConditionalExpression": testProp, 24 | "ArrowFunctionExpression": arrowFunc 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-plugin-arrow-function", 3 | "description": "custom ESLint rule, ckecks arrow function literal.", 4 | "version": "2.0.0", 5 | "author": { 6 | "name": "Jxck" 7 | }, 8 | "bugs": { 9 | "url": "https://github.com/Jxck/eslint-plugin-arrow-function/issues" 10 | }, 11 | "devDependencies": { 12 | "eslint": "^1.0.0", 13 | "mocha": "^2.2.5" 14 | }, 15 | "homepage": "https://github.com/Jxck/eslint-plugin-arrow-function", 16 | "keywords": [ 17 | "eslint", 18 | "eslint-plugin", 19 | "eslintplugin", 20 | "lint" 21 | ], 22 | "license": "MIT", 23 | "main": "index.js", 24 | "peerDependencies": { 25 | "eslint": ">=0.20.0" 26 | }, 27 | "repository": { 28 | "type": "git", 29 | "url": "https://github.com/Jxck/eslint-plugin-arrow-function" 30 | }, 31 | "scripts": { 32 | "test": "mocha tests/rules/", 33 | "lint": "eslint -c .eslintrc index.js lib/**/*.js tests/**/*.js" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/rules/no-condition.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var rule = require("../../lib/rules/no-condition"), 4 | RuleTester = require("eslint").RuleTester; 5 | 6 | var ruleTester = new RuleTester(); 7 | 8 | var valid = [ 9 | "if (a >= 1) {}", 10 | "while (a >= 1) {}", 11 | "for (var a = 1; a >= 10; a++) {}", 12 | "a >= 1 ? 2 : 3", 13 | "(a >= 1) ? 2 : 3", 14 | "[1,2,3].filter(n => n > 2)" 15 | ].map(function(code) { 16 | return { 17 | code: code, 18 | ecmaFeatures: { arrowFunctions: true } 19 | }; 20 | }); 21 | 22 | var message = "suspicious code: it seemd to be comparison `>=`, not arrow function `=>`"; 23 | 24 | var invalid = [ 25 | "if (a => 1) {}", 26 | "if ((a) => 1) {}", 27 | "while (a => 1) {}", 28 | "for (var a = 1; a => 10; a++) {}", 29 | "a => 1 ? 2 : 3", 30 | "(a => 1) ? 2 : 3" 31 | ].map(function(code) { 32 | return { 33 | code: code, 34 | ecmaFeatures: { arrowFunctions: true }, 35 | errors: [{ message: message }] 36 | }; 37 | }); 38 | 39 | ruleTester.run("./lib/rules/no-condition", rule, { 40 | valid: valid, 41 | invalid: invalid 42 | }); 43 | --------------------------------------------------------------------------------