├── .gitignore ├── packages ├── eslint-config-airbnb │ ├── base.js │ ├── legacy.js │ ├── index.js │ ├── .eslintrc │ ├── test │ │ ├── .eslintrc │ │ ├── test-base.js │ │ └── test-react-order.js │ ├── README.md │ ├── package.json │ ├── rules │ │ ├── react-a11y.js │ │ └── react.js │ └── CHANGELOG.md └── eslint-config-airbnb-base │ ├── rules │ ├── strict.js │ ├── node.js │ ├── variables.js │ ├── errors.js │ ├── es6.js │ ├── imports.js │ ├── best-practices.js │ └── style.js │ ├── .eslintrc │ ├── index.js │ ├── test │ ├── .eslintrc │ └── test-base.js │ ├── legacy.js │ ├── CHANGELOG.md │ ├── README.md │ └── package.json ├── linters ├── .eslintrc ├── .jshintrc └── SublimeLinter │ └── SublimeLinter.sublime-settings ├── .travis.yml ├── package.json ├── react └── README.md └── es5 └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/base.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['eslint-config-airbnb-base'].map(require.resolve), 3 | rules: {}, 4 | }; 5 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/legacy.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['eslint-config-airbnb-base/legacy'].map(require.resolve), 3 | rules: {}, 4 | }; 5 | -------------------------------------------------------------------------------- /linters/.eslintrc: -------------------------------------------------------------------------------- 1 | // Use this file as a starting point for your project's .eslintrc. 2 | // Copy this file, and add rule overrides as needed. 3 | { 4 | "extends": "airbnb" 5 | } 6 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/strict.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // babel inserts `'use strict';` for us 4 | strict: [2, 'never'] 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'eslint-config-airbnb-base', 4 | 'eslint-config-airbnb-base/rules/strict', 5 | './rules/react', 6 | './rules/react-a11y', 7 | ].map(require.resolve), 8 | rules: {} 9 | }; 10 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./index.js", 3 | "rules": { 4 | // disable requiring trailing commas because it might be nice to revert to 5 | // being JSON at some point, and I don't want to make big changes now. 6 | "comma-dangle": 0 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./index.js", 3 | "rules": { 4 | // disable requiring trailing commas because it might be nice to revert to 5 | // being JSON at some point, and I don't want to make big changes now. 6 | "comma-dangle": 0 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | './legacy', 4 | './rules/es6', 5 | './rules/imports', 6 | ].map(require.resolve), 7 | parserOptions: { 8 | ecmaVersion: 7, 9 | sourceType: 'module', 10 | }, 11 | rules: { 12 | strict: 2, 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | // disabled because I find it tedious to write tests while following this 4 | // rule 5 | "no-shadow": 0, 6 | // tests uses `t` for tape 7 | "id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | // disabled because I find it tedious to write tests while following this 4 | // rule 5 | "no-shadow": 0, 6 | // tests uses `t` for tape 7 | "id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/legacy.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | './rules/best-practices', 4 | './rules/errors', 5 | './rules/node', 6 | './rules/style', 7 | './rules/variables' 8 | ].map(require.resolve), 9 | env: { 10 | browser: true, 11 | node: true, 12 | amd: false, 13 | mocha: false, 14 | jasmine: false 15 | }, 16 | ecmaFeatures: {}, 17 | globals: {}, 18 | rules: {} 19 | }; 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | - "5" 5 | - "4" 6 | - "iojs" 7 | env: 8 | - 'TEST_DIR=packages/eslint-config-airbnb' 9 | - 'TEST_DIR=packages/eslint-config-airbnb-base' 10 | before_install: 11 | - 'cd $TEST_DIR' 12 | - 'if [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' 13 | - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' 14 | script: 15 | - 'npm run travis' 16 | sudo: false 17 | matrix: 18 | fast_finish: true 19 | allow_failures: 20 | - node_js: "iojs" 21 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/test/test-base.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | import test from 'tape'; 4 | 5 | const index = require('../'); 6 | 7 | const files = { index }; 8 | 9 | fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => { 10 | files[name] = require(`../rules/${name}`); // eslint-disable-line global-require 11 | }); 12 | 13 | Object.keys(files).forEach(name => { 14 | const config = files[name]; 15 | 16 | test(`${name}: does not reference react`, t => { 17 | t.plan(2); 18 | 19 | // scan plugins for react and fail if it is found 20 | const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') && 21 | config.plugins.indexOf('react') !== -1; 22 | t.notOk(hasReactPlugin, 'there is no react plugin'); 23 | 24 | // scan rules for react/ and fail if any exist 25 | const reactRuleIds = Object.keys(config.rules) 26 | .filter(ruleId => ruleId.indexOf('react/') === 0); 27 | t.deepEquals(reactRuleIds, [], 'there are no react/ rules'); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/node.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true 4 | }, 5 | 6 | rules: { 7 | // enforce return after a callback 8 | 'callback-return': 0, 9 | 10 | // require all requires be top-level 11 | // http://eslint.org/docs/rules/global-require 12 | 'global-require': 2, 13 | 14 | // enforces error handling in callbacks (node environment) 15 | 'handle-callback-err': 0, 16 | 17 | // disallow mixing regular variable and require declarations 18 | 'no-mixed-requires': [0, false], 19 | 20 | // disallow use of new operator with the require function 21 | 'no-new-require': 0, 22 | 23 | // disallow string concatenation with __dirname and __filename 24 | 'no-path-concat': 0, 25 | 26 | // disallow use of process.env 27 | 'no-process-env': 0, 28 | 29 | // disallow process.exit() 30 | 'no-process-exit': 0, 31 | 32 | // restrict usage of specified node modules 33 | 'no-restricted-modules': 0, 34 | 35 | // disallow use of synchronous methods (off by default) 36 | 'no-sync': 0 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/test/test-base.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | import test from 'tape'; 4 | 5 | const base = require('../base'); 6 | 7 | const files = { base }; 8 | 9 | fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => { 10 | if (name === 'react.js' || name === 'react-a11y.js') { 11 | return; 12 | } 13 | 14 | files[name] = require(`../rules/${name}`); // eslint-disable-line global-require 15 | }); 16 | 17 | Object.keys(files).forEach(name => { 18 | const config = files[name]; 19 | 20 | test(`${name}: does not reference react`, t => { 21 | t.plan(2); 22 | 23 | // scan plugins for react and fail if it is found 24 | const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') && 25 | config.plugins.indexOf('react') !== -1; 26 | t.notOk(hasReactPlugin, 'there is no react plugin'); 27 | 28 | // scan rules for react/ and fail if any exist 29 | const reactRuleIds = Object.keys(config.rules) 30 | .filter(ruleId => ruleId.indexOf('react/') === 0); 31 | t.deepEquals(reactRuleIds, [], 'there are no react/ rules'); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/variables.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // enforce or disallow variable initializations at definition 4 | 'init-declarations': 0, 5 | 6 | // disallow the catch clause parameter name being the same as a variable in the outer scope 7 | 'no-catch-shadow': 0, 8 | 9 | // disallow deletion of variables 10 | 'no-delete-var': 2, 11 | 12 | // disallow labels that share a name with a variable 13 | 'no-label-var': 0, 14 | 15 | // disallow specific globals 16 | 'no-restricted-globals': 0, 17 | 18 | // disallow declaration of variables already declared in the outer scope 19 | 'no-shadow': 2, 20 | 21 | // disallow shadowing of names such as arguments 22 | 'no-shadow-restricted-names': 2, 23 | 24 | // disallow use of undeclared variables unless mentioned in a /*global */ block 25 | 'no-undef': 2, 26 | 27 | // disallow use of undefined when initializing variables 28 | 'no-undef-init': 0, 29 | 30 | // disallow use of undefined variable 31 | 'no-undefined': 0, 32 | 33 | // disallow declaration of variables that are not used in the code 34 | 'no-unused-vars': [2, { vars: 'local', args: 'after-used' }], 35 | 36 | // disallow use of variables before they are defined 37 | 'no-use-before-define': 2 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 3.0.1 / 2016-05-08 2 | ================== 3 | - [patch] re-disable `no-extra-parens` (#869, #867) 4 | 5 | 3.0.0 / 2016-05-07 6 | ================== 7 | - [breaking] enable `import/no-mutable-exports` 8 | - [breaking] enable `no-class-assign` rule, to pair with `no-func-assign` 9 | - [breaking] widen `no-extra-parens` to include everything, except `nestedBinaryExpressions` 10 | - [breaking] Re-enabling `newline-per-chained-call` (#748) 11 | - [minor] enable `import/no-amd` 12 | - [patch] enable `import/no-duplicates` 13 | - [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules` 14 | 15 | 2.0.0 / 2016-04-29 16 | ================== 17 | - [breaking] enable `no-unsafe-finally` rule 18 | - [semver-minor] enable `no-useless-computed-key` rule 19 | - [deps] update `eslint`, `eslint-plugin-import` 20 | 21 | 1.0.4 / 2016-04-26 22 | ================== 23 | - [deps] update `eslint-find-rules`, `eslint-plugin-import` 24 | 25 | 1.0.3 / 2016-04-21 26 | ================== 27 | - [patch: loosen rules] Allow empty class/object methods 28 | 29 | 1.0.2 / 2016-04-20 30 | ================== 31 | - [patch: loosen rules] Allow `break` (#840) 32 | 33 | 1.0.1 / 2016-04-19 34 | ================== 35 | - [patch: loosen rules] Allow `== null` (#542) 36 | 37 | 1.0.0 / 2016-04-19 38 | ================== 39 | - Initial commmit; moved content over from `eslint-config-airbnb` package. 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "airbnb-style", 3 | "version": "2.0.0", 4 | "description": "A mostly reasonable approach to JavaScript.", 5 | "scripts": { 6 | "preinstall": "npm run install:config && npm run install:config:base", 7 | "install:config": "cd packages/eslint-config-airbnb && npm prune && npm install", 8 | "install:config:base": "cd packages/eslint-config-airbnb-base && npm prune && npm install", 9 | "test": "npm run --silent test:config && npm run --silent test:config:base", 10 | "test:config": "cd packages/eslint-config-airbnb; npm test", 11 | "test:config:base": "cd packages/eslint-config-airbnb-base; npm test", 12 | "travis": "npm run --silent travis:config && npm run --silent travis:config:base", 13 | "travis:config": "cd packages/eslint-config-airbnb; npm run travis", 14 | "travis:config:base": "cd packages/eslint-config-airbnb-base; npm run travis" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/airbnb/javascript.git" 19 | }, 20 | "keywords": [ 21 | "style guide", 22 | "lint", 23 | "airbnb", 24 | "es6", 25 | "es2015", 26 | "react", 27 | "jsx" 28 | ], 29 | "author": "Harrison Shoff (https://twitter.com/hshoff)", 30 | "license": "MIT", 31 | "bugs": { 32 | "url": "https://github.com/airbnb/javascript/issues" 33 | }, 34 | "homepage": "https://github.com/airbnb/javascript" 35 | } 36 | -------------------------------------------------------------------------------- /linters/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | /* 3 | * ENVIRONMENTS 4 | * ================= 5 | */ 6 | 7 | // Define globals exposed by modern browsers. 8 | "browser": true, 9 | 10 | // Define globals exposed by jQuery. 11 | "jquery": true, 12 | 13 | // Define globals exposed by Node.js. 14 | "node": true, 15 | 16 | // Allow ES6. 17 | "esversion": 6, 18 | 19 | /* 20 | * ENFORCING OPTIONS 21 | * ================= 22 | */ 23 | 24 | // Force all variable names to use either camelCase style or UPPER_CASE 25 | // with underscores. 26 | "camelcase": true, 27 | 28 | // Prohibit use of == and != in favor of === and !==. 29 | "eqeqeq": true, 30 | 31 | // Enforce tab width of 2 spaces. 32 | "indent": 2, 33 | 34 | // Prohibit use of a variable before it is defined. 35 | "latedef": true, 36 | 37 | // Enforce line length to 100 characters 38 | "maxlen": 100, 39 | 40 | // Require capitalized names for constructor functions. 41 | "newcap": true, 42 | 43 | // Enforce use of single quotation marks for strings. 44 | "quotmark": "single", 45 | 46 | // Enforce placing 'use strict' at the top function scope 47 | "strict": true, 48 | 49 | // Prohibit use of explicitly undeclared variables. 50 | "undef": true, 51 | 52 | // Warn when variables are defined but never used. 53 | "unused": true, 54 | 55 | /* 56 | * RELAXING OPTIONS 57 | * ================= 58 | */ 59 | 60 | // Suppress warnings about == null comparisons. 61 | "eqnull": true 62 | } 63 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-airbnb-base 2 | 3 | [![npm version](https://badge.fury.io/js/eslint-config-airbnb-base.svg)](http://badge.fury.io/js/eslint-config-airbnb-base) 4 | 5 | This package provides Airbnb's base JS .eslintrc as an extensible shared config. 6 | 7 | ## Usage 8 | 9 | We export two ESLint configurations for your usage. 10 | 11 | ### eslint-config-airbnb-base 12 | 13 | Our default export contains all of our ESLint rules, including ECMAScript 6+. It requires `eslint` and `eslint-plugin-import`. 14 | 15 | 1. `npm install --save-dev eslint-config-airbnb-base eslint-plugin-import eslint` 16 | 2. add `"extends": "airbnb-base"` to your .eslintrc 17 | 18 | ### eslint-config-airbnb-base/legacy 19 | 20 | Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`. 21 | 22 | 1. `npm install --save-dev eslint-config-airbnb-base eslint-plugin-import eslint` 23 | 2. add `"extends": "airbnb-base/legacy"` to your .eslintrc 24 | 25 | See [Airbnb's overarching ESLint config](https://npmjs.com/eslint-config-airbnb), [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript), and the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information. 26 | 27 | ## Improving this config 28 | 29 | Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc? 30 | 31 | You can run tests with `npm test`. 32 | 33 | You can make sure this module lints with itself using `npm run lint`. 34 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-airbnb 2 | 3 | [![npm version](https://badge.fury.io/js/eslint-config-airbnb.svg)](http://badge.fury.io/js/eslint-config-airbnb) 4 | 5 | This package provides Airbnb's .eslintrc as an extensible shared config. 6 | 7 | ## Usage 8 | 9 | We export three ESLint configurations for your usage. 10 | 11 | ### eslint-config-airbnb 12 | 13 | Our default export contains all of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, and `eslint-plugin-jsx-a11y`. 14 | 15 | 1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint` 16 | 2. add `"extends": "airbnb"` to your .eslintrc 17 | 18 | ### eslint-config-airbnb/base 19 | 20 | This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base). 21 | 22 | ### eslint-config-airbnb/legacy 23 | 24 | This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base). 25 | 26 | See [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript) and 27 | the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) 28 | for more information. 29 | 30 | ## Improving this config 31 | 32 | Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc? 33 | 34 | You can run tests with `npm test`. 35 | 36 | You can make sure this module lints with itself using `npm run lint`. 37 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-airbnb-base", 3 | "version": "3.0.1", 4 | "description": "Airbnb's base JS ESLint config, following our styleguide", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "eslint .", 8 | "tests-only": "babel-tape-runner ./test/test-*.js", 9 | "prepublish": "not-in-install && (eslint-find-rules --unused && npm test) || in-install", 10 | "pretest": "npm run --silent lint", 11 | "test": "npm run --silent tests-only", 12 | "travis": "npm run --silent test" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/airbnb/javascript" 17 | }, 18 | "keywords": [ 19 | "eslint", 20 | "eslintconfig", 21 | "config", 22 | "airbnb", 23 | "javascript", 24 | "styleguide" 25 | ], 26 | "author": "Jake Teton-Landis (https://twitter.com/@jitl)", 27 | "contributors": [ 28 | { 29 | "name": "Jake Teton-Landis", 30 | "url": "https://twitter.com/jitl" 31 | }, 32 | { 33 | "name": "Jordan Harband", 34 | "email": "ljharb@gmail.com", 35 | "url": "http://ljharb.codes" 36 | }, 37 | { 38 | "name": "Harrison Shoff", 39 | "url": "https://twitter.com/hshoff" 40 | } 41 | ], 42 | "license": "MIT", 43 | "bugs": { 44 | "url": "https://github.com/airbnb/javascript/issues" 45 | }, 46 | "homepage": "https://github.com/airbnb/javascript", 47 | "devDependencies": { 48 | "babel-tape-runner": "^1.3.1", 49 | "eslint": "^2.11.1", 50 | "eslint-find-rules": "^1.9.2", 51 | "eslint-plugin-import": "^1.8.1", 52 | "tape": "^4.5.1", 53 | "in-publish": "^2.0.0" 54 | }, 55 | "peerDependencies": { 56 | "eslint": "^2.11.1", 57 | "eslint-plugin-import": "^1.8.1" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-airbnb", 3 | "version": "9.0.1", 4 | "description": "Airbnb's ESLint config, following our styleguide", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "eslint .", 8 | "tests-only": "babel-tape-runner ./test/test-*.js", 9 | "prepublish": "not-in-install && (eslint-find-rules --unused && npm test) || in-install", 10 | "pretest": "npm run --silent lint", 11 | "test": "npm run --silent tests-only", 12 | "travis": "cd ../eslint-config-airbnb-base && npm link && cd - && npm link eslint-config-airbnb-base && npm run --silent test ; npm unlink eslint-config-airbnb-base >/dev/null &" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/airbnb/javascript" 17 | }, 18 | "keywords": [ 19 | "eslint", 20 | "eslintconfig", 21 | "config", 22 | "airbnb", 23 | "javascript", 24 | "styleguide" 25 | ], 26 | "author": "Jake Teton-Landis (https://twitter.com/@jitl)", 27 | "contributors": [ 28 | { 29 | "name": "Jake Teton-Landis", 30 | "url": "https://twitter.com/jitl" 31 | }, 32 | { 33 | "name": "Jordan Harband", 34 | "email": "ljharb@gmail.com", 35 | "url": "http://ljharb.codes" 36 | }, 37 | { 38 | "name": "Harrison Shoff", 39 | "url": "https://twitter.com/hshoff" 40 | } 41 | ], 42 | "license": "MIT", 43 | "bugs": { 44 | "url": "https://github.com/airbnb/javascript/issues" 45 | }, 46 | "homepage": "https://github.com/airbnb/javascript", 47 | "dependencies": { 48 | "eslint-config-airbnb-base": "^3.0.1" 49 | }, 50 | "devDependencies": { 51 | "babel-tape-runner": "^1.3.1", 52 | "eslint": "^2.10.2", 53 | "eslint-find-rules": "^1.9.2", 54 | "eslint-plugin-import": "^1.8.0", 55 | "eslint-plugin-jsx-a11y": "^1.2.2", 56 | "eslint-plugin-react": "^5.1.1", 57 | "react": ">= 0.13.0", 58 | "tape": "^4.5.1", 59 | "in-publish": "^2.0.0" 60 | }, 61 | "peerDependencies": { 62 | "eslint": "^2.10.2", 63 | "eslint-plugin-jsx-a11y": "^1.2.2", 64 | "eslint-plugin-import": "^1.8.0", 65 | "eslint-plugin-react": "^5.1.1" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /linters/SublimeLinter/SublimeLinter.sublime-settings: -------------------------------------------------------------------------------- 1 | /** 2 | * Airbnb JSHint settings for use with SublimeLinter and Sublime Text 2. 3 | * 4 | * 1. Install SublimeLinter at https://github.com/SublimeLinter/SublimeLinter 5 | * 2. Open user preferences for the SublimeLinter package in Sublime Text 2 6 | * * For Mac OS X go to _Sublime Text 2_ > _Preferences_ > _Package Settings_ > _SublimeLinter_ > _Settings - User_ 7 | * 3. Paste the contents of this file into your settings file 8 | * 4. Save the settings file 9 | * 10 | * @version 0.3.0 11 | * @see https://github.com/SublimeLinter/SublimeLinter 12 | * @see http://www.jshint.com/docs/ 13 | */ 14 | { 15 | "jshint_options": 16 | { 17 | /* 18 | * ENVIRONMENTS 19 | * ================= 20 | */ 21 | 22 | // Define globals exposed by modern browsers. 23 | "browser": true, 24 | 25 | // Define globals exposed by jQuery. 26 | "jquery": true, 27 | 28 | // Define globals exposed by Node.js. 29 | "node": true, 30 | 31 | /* 32 | * ENFORCING OPTIONS 33 | * ================= 34 | */ 35 | 36 | // Force all variable names to use either camelCase style or UPPER_CASE 37 | // with underscores. 38 | "camelcase": true, 39 | 40 | // Prohibit use of == and != in favor of === and !==. 41 | "eqeqeq": true, 42 | 43 | // Suppress warnings about == null comparisons. 44 | "eqnull": true, 45 | 46 | // Enforce tab width of 2 spaces. 47 | "indent": 2, 48 | 49 | // Prohibit use of a variable before it is defined. 50 | "latedef": true, 51 | 52 | // Require capitalized names for constructor functions. 53 | "newcap": true, 54 | 55 | // Enforce use of single quotation marks for strings. 56 | "quotmark": "single", 57 | 58 | // Prohibit trailing whitespace. 59 | "trailing": true, 60 | 61 | // Prohibit use of explicitly undeclared variables. 62 | "undef": true, 63 | 64 | // Warn when variables are defined but never used. 65 | "unused": true, 66 | 67 | // Enforce line length to 80 characters 68 | "maxlen": 80, 69 | 70 | // Enforce placing 'use strict' at the top function scope 71 | "strict": true 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/test/test-react-order.js: -------------------------------------------------------------------------------- 1 | import test from 'tape'; 2 | import { CLIEngine } from 'eslint'; 3 | import eslintrc from '../'; 4 | import reactRules from '../rules/react'; 5 | import reactA11yRules from '../rules/react-a11y'; 6 | 7 | const cli = new CLIEngine({ 8 | useEslintrc: false, 9 | baseConfig: eslintrc, 10 | 11 | // This rule fails when executing on text. 12 | rules: { indent: 0 }, 13 | }); 14 | 15 | function lint(text) { 16 | // @see http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles 17 | // @see http://eslint.org/docs/developer-guide/nodejs-api.html#executeontext 18 | const linter = cli.executeOnText(text); 19 | return linter.results[0]; 20 | } 21 | 22 | function wrapComponent(body) { 23 | return ` 24 | import React from 'react'; 25 | export default class MyComponent extends React.Component { 26 | /* eslint no-empty-function: 0 */ 27 | ${body} 28 | } 29 | `; 30 | } 31 | 32 | test('validate react prop order', (t) => { 33 | t.test('make sure our eslintrc has React and JSX linting dependencies', (t) => { 34 | t.plan(2); 35 | t.deepEqual(reactRules.plugins, ['react']); 36 | t.deepEqual(reactA11yRules.plugins, ['jsx-a11y', 'react']); 37 | }); 38 | 39 | t.test('passes a good component', (t) => { 40 | t.plan(3); 41 | const result = lint(wrapComponent(` 42 | componentWillMount() {} 43 | componentDidMount() {} 44 | setFoo() {} 45 | getFoo() {} 46 | setBar() {} 47 | someMethod() {} 48 | renderDogs() {} 49 | render() { return
; } 50 | `)); 51 | 52 | t.notOk(result.warningCount, 'no warnings'); 53 | t.notOk(result.errorCount, 'no errors'); 54 | t.deepEquals(result.messages, [], 'no messages in results'); 55 | }); 56 | 57 | t.test('order: when random method is first', t => { 58 | t.plan(2); 59 | const result = lint(wrapComponent(` 60 | someMethod() {} 61 | componentWillMount() {} 62 | componentDidMount() {} 63 | setFoo() {} 64 | getFoo() {} 65 | setBar() {} 66 | renderDogs() {} 67 | render() { return
; } 68 | `)); 69 | 70 | t.ok(result.errorCount, 'fails'); 71 | t.equal(result.messages[0].ruleId, 'react/sort-comp', 'fails due to sort'); 72 | }); 73 | 74 | t.test('order: when random method after lifecycle methods', t => { 75 | t.plan(2); 76 | const result = lint(wrapComponent(` 77 | componentWillMount() {} 78 | componentDidMount() {} 79 | someMethod() {} 80 | setFoo() {} 81 | getFoo() {} 82 | setBar() {} 83 | renderDogs() {} 84 | render() { return
; } 85 | `)); 86 | 87 | t.ok(result.errorCount, 'fails'); 88 | t.equal(result.messages[0].ruleId, 'react/sort-comp', 'fails due to sort'); 89 | }); 90 | }); 91 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/errors.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // require trailing commas in multiline object literals 4 | 'comma-dangle': [2, 'always-multiline'], 5 | 6 | // disallow assignment in conditional expressions 7 | 'no-cond-assign': [2, 'always'], 8 | 9 | // disallow use of console 10 | 'no-console': 1, 11 | 12 | // disallow use of constant expressions in conditions 13 | 'no-constant-condition': 1, 14 | 15 | // disallow control characters in regular expressions 16 | 'no-control-regex': 2, 17 | 18 | // disallow use of debugger 19 | 'no-debugger': 2, 20 | 21 | // disallow duplicate arguments in functions 22 | 'no-dupe-args': 2, 23 | 24 | // disallow duplicate keys when creating object literals 25 | 'no-dupe-keys': 2, 26 | 27 | // disallow a duplicate case label. 28 | 'no-duplicate-case': 2, 29 | 30 | // disallow empty statements 31 | 'no-empty': 2, 32 | 33 | // disallow the use of empty character classes in regular expressions 34 | 'no-empty-character-class': 2, 35 | 36 | // disallow assigning to the exception in a catch block 37 | 'no-ex-assign': 2, 38 | 39 | // disallow double-negation boolean casts in a boolean context 40 | 'no-extra-boolean-cast': 0, 41 | 42 | // disallow unnecessary parentheses 43 | // http://eslint.org/docs/rules/no-extra-parens 44 | 'no-extra-parens': [0, 'all', { 45 | conditionalAssign: true, 46 | nestedBinaryExpressions: false, 47 | returnAssign: false, 48 | }], 49 | 50 | // disallow unnecessary semicolons 51 | 'no-extra-semi': 2, 52 | 53 | // disallow overwriting functions written as function declarations 54 | 'no-func-assign': 2, 55 | 56 | // disallow function or variable declarations in nested blocks 57 | 'no-inner-declarations': 2, 58 | 59 | // disallow invalid regular expression strings in the RegExp constructor 60 | 'no-invalid-regexp': 2, 61 | 62 | // disallow irregular whitespace outside of strings and comments 63 | 'no-irregular-whitespace': 2, 64 | 65 | // disallow negation of the left operand of an in expression 66 | 'no-negated-in-lhs': 2, 67 | 68 | // disallow the use of object properties of the global object (Math and JSON) as functions 69 | 'no-obj-calls': 2, 70 | 71 | // disallow use of Object.prototypes builtins directly 72 | // http://eslint.org/docs/rules/no-prototype-builtins 73 | 'no-prototype-builtins': 2, 74 | 75 | // disallow multiple spaces in a regular expression literal 76 | 'no-regex-spaces': 2, 77 | 78 | // disallow sparse arrays 79 | 'no-sparse-arrays': 2, 80 | 81 | // Avoid code that looks like two expressions but is actually one 82 | 'no-unexpected-multiline': 0, 83 | 84 | // disallow unreachable statements after a return, throw, continue, or break statement 85 | 'no-unreachable': 2, 86 | 87 | // disallow return/throw/break/continue inside finally blocks 88 | // http://eslint.org/docs/rules/no-unsafe-finally 89 | 'no-unsafe-finally': 2, 90 | 91 | // disallow comparisons with the value NaN 92 | 'use-isnan': 2, 93 | 94 | // ensure JSDoc comments are valid 95 | // http://eslint.org/docs/rules/valid-jsdoc 96 | 'valid-jsdoc': 0, 97 | 98 | // ensure that the results of typeof are compared against a valid string 99 | 'valid-typeof': 2 100 | } 101 | }; 102 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/rules/react-a11y.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | 'jsx-a11y', 4 | 'react' 5 | ], 6 | ecmaFeatures: { 7 | jsx: true 8 | }, 9 | rules: { 10 | // Require ARIA roles to be valid and non-abstract 11 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md 12 | 'jsx-a11y/aria-role': 2, 13 | 14 | // Enforce all aria-* props are valid. 15 | // TODO: enable 16 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-props.md 17 | 'jsx-a11y/aria-props': 0, 18 | 19 | // Enforce ARIA state and property values are valid. 20 | // TODO: enable 21 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-proptypes.md 22 | 'jsx-a11y/aria-proptypes': 0, 23 | 24 | // Enforce that elements that do not support ARIA roles, states, and 25 | // properties do not have those attributes. 26 | // TODO: enable 27 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-unsupported-elements.md 28 | 'jsx-a11y/aria-unsupported-elements': 0, 29 | 30 | // disallow href "#" 31 | // TODO: enable 32 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/href-no-hash.md 33 | 'jsx-a11y/href-no-hash': 0, 34 | 35 | // Require to have a non-empty `alt` prop, or role="presentation" 36 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-has-alt.md 37 | 'jsx-a11y/img-has-alt': 2, 38 | 39 | // Prevent img alt text from containing redundant words like "image", "picture", or "photo" 40 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md 41 | 'jsx-a11y/img-redundant-alt': 2, 42 | 43 | // require that JSX labels use "htmlFor" 44 | // TODO: enable 45 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md 46 | 'jsx-a11y/label-has-for': 0, 47 | 48 | // require that mouseover/out come with focus/blur, for keyboard-only users 49 | // TODO: enable? 50 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md 51 | 'jsx-a11y/mouse-events-have-key-events': 0, 52 | 53 | // Prevent use of `accessKey` 54 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md 55 | 'jsx-a11y/no-access-key': 2, 56 | 57 | // require onBlur instead of onChange 58 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md 59 | 'jsx-a11y/no-onchange': 0, 60 | 61 | // Enforce that elements with onClick handlers must be focusable. 62 | // TODO: evaluate 63 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/onclick-has-focus.md 64 | 'jsx-a11y/onclick-has-focus': 0, 65 | 66 | // require things with onClick to have an aria role 67 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/onclick-has-role.md 68 | 'jsx-a11y/onclick-has-role': 0, 69 | 70 | // Enforce that elements with ARIA roles must have all required attributes 71 | // for that role. 72 | // TODO: enable 73 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-has-required-aria-props.md 74 | 'jsx-a11y/role-has-required-aria-props': 0, 75 | 76 | // Enforce that elements with explicit or implicit roles defined contain 77 | // only aria-* properties supported by that role. 78 | // TODO: enable 79 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-supports-aria-props.md 80 | 'jsx-a11y/role-supports-aria-props': 0, 81 | 82 | // Enforce tabIndex value is not greater than zero. 83 | // TODO: evaluate 84 | // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/tabindex-no-positive.md 85 | 'jsx-a11y/tabindex-no-positive': 0, 86 | }, 87 | }; 88 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/es6.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | es6: true 4 | }, 5 | parserOptions: { 6 | ecmaVersion: 6, 7 | sourceType: 'module', 8 | ecmaFeatures: { 9 | generators: false, 10 | objectLiteralDuplicateProperties: false 11 | } 12 | }, 13 | 14 | rules: { 15 | // enforces no braces where they can be omitted 16 | // http://eslint.org/docs/rules/arrow-body-style 17 | 'arrow-body-style': [2, 'as-needed'], 18 | 19 | // require parens in arrow function arguments 20 | 'arrow-parens': 0, 21 | 22 | // require space before/after arrow function's arrow 23 | // http://eslint.org/docs/rules/arrow-spacing 24 | 'arrow-spacing': [2, { before: true, after: true }], 25 | 26 | // verify super() callings in constructors 27 | 'constructor-super': 0, 28 | 29 | // enforce the spacing around the * in generator functions 30 | // http://eslint.org/docs/rules/generator-star-spacing 31 | 'generator-star-spacing': [2, { before: false, after: true }], 32 | 33 | // disallow modifying variables of class declarations 34 | // http://eslint.org/docs/rules/no-class-assign 35 | 'no-class-assign': 2, 36 | 37 | // disallow arrow functions where they could be confused with comparisons 38 | // http://eslint.org/docs/rules/no-confusing-arrow 39 | 'no-confusing-arrow': [2, { 40 | allowParens: true, 41 | }], 42 | 43 | // disallow modifying variables that are declared using const 44 | 'no-const-assign': 2, 45 | 46 | // disallow duplicate class members 47 | // http://eslint.org/docs/rules/no-dupe-class-members 48 | 'no-dupe-class-members': 2, 49 | 50 | // disallow importing from the same path more than once 51 | // http://eslint.org/docs/rules/no-duplicate-imports 52 | 'no-duplicate-imports': 2, 53 | 54 | // disallow symbol constructor 55 | // http://eslint.org/docs/rules/no-new-symbol 56 | 'no-new-symbol': 2, 57 | 58 | // disallow specific imports 59 | // http://eslint.org/docs/rules/no-restricted-imports 60 | 'no-restricted-imports': 0, 61 | 62 | // disallow to use this/super before super() calling in constructors. 63 | 'no-this-before-super': 0, 64 | 65 | // disallow useless computed property keys 66 | // http://eslint.org/docs/rules/no-useless-computed-key 67 | 'no-useless-computed-key': 2, 68 | 69 | // disallow unnecessary constructor 70 | // http://eslint.org/docs/rules/no-useless-constructor 71 | 'no-useless-constructor': 2, 72 | 73 | // disallow renaming import, export, and destructured assignments to the same name 74 | // http://eslint.org/docs/rules/no-useless-rename 75 | 'no-useless-rename': [2, { 76 | ignoreDestructuring: false, 77 | ignoreImport: false, 78 | ignoreExport: false, 79 | }], 80 | 81 | // require let or const instead of var 82 | 'no-var': 2, 83 | 84 | // require method and property shorthand syntax for object literals 85 | // http://eslint.org/docs/rules/object-shorthand 86 | 'object-shorthand': [2, 'always', { 87 | ignoreConstructors: false, 88 | avoidQuotes: true, 89 | }], 90 | 91 | // suggest using arrow functions as callbacks 92 | 'prefer-arrow-callback': [2, { 93 | allowNamedFunctions: false, 94 | allowUnboundThis: true, 95 | }], 96 | 97 | // suggest using of const declaration for variables that are never modified after declared 98 | 'prefer-const': [2, { 99 | destructuring: 'any', 100 | ignoreReadBeforeAssign: true, 101 | }], 102 | 103 | // suggest using Reflect methods where applicable 104 | 'prefer-reflect': 0, 105 | 106 | // use rest parameters instead of arguments 107 | // http://eslint.org/docs/rules/prefer-rest-params 108 | 'prefer-rest-params': 2, 109 | 110 | // suggest using the spread operator instead of .apply() 111 | 'prefer-spread': 0, 112 | 113 | // suggest using template literals instead of string concatenation 114 | // http://eslint.org/docs/rules/prefer-template 115 | 'prefer-template': 2, 116 | 117 | // disallow generator functions that do not have yield 118 | 'require-yield': 0, 119 | 120 | // import sorting 121 | // http://eslint.org/docs/rules/sort-imports 122 | 'sort-imports': 0, 123 | 124 | // enforce usage of spacing in template strings 125 | // http://eslint.org/docs/rules/template-curly-spacing 126 | 'template-curly-spacing': 2, 127 | 128 | // enforce spacing around the * in yield* expressions 129 | // http://eslint.org/docs/rules/yield-star-spacing 130 | 'yield-star-spacing': [2, 'after'] 131 | } 132 | }; 133 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/imports.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | es6: true 4 | }, 5 | parserOptions: { 6 | ecmaVersion: 6, 7 | sourceType: 'module' 8 | }, 9 | plugins: [ 10 | 'import' 11 | ], 12 | 13 | settings: { 14 | 'import/resolver': { 15 | node: { 16 | extensions: ['.js', '.json'] 17 | } 18 | } 19 | }, 20 | 21 | rules: { 22 | // Static analysis: 23 | 24 | // ensure imports point to files/modules that can be resolved 25 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md 26 | 'import/no-unresolved': [2, { commonjs: true }], 27 | 28 | // ensure named imports coupled with named exports 29 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it 30 | 'import/named': 0, 31 | 32 | // ensure default import coupled with default export 33 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it 34 | 'import/default': 0, 35 | 36 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/namespace.md 37 | 'import/namespace': 0, 38 | 39 | // Helpful warnings: 40 | 41 | // disallow invalid exports, e.g. multiple defaults 42 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md 43 | 'import/export': 2, 44 | 45 | // do not allow a default import name to match a named export 46 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md 47 | // TODO: enable 48 | 'import/no-named-as-default': 0, 49 | 50 | // warn on accessing default export property names that are also named exports 51 | // TODO: enable? 52 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md 53 | 'import/no-named-as-default-member': 0, 54 | 55 | // disallow use of jsdoc-marked-deprecated imports 56 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md 57 | 'import/no-deprecated': 0, 58 | 59 | // Forbid the use of extraneous packages 60 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md 61 | // TODO: enable 62 | 'import/no-extraneous-dependencies': [0, { 63 | devDependencies: false, 64 | optionalDependencies: false, 65 | }], 66 | 67 | // Forbid mutable exports 68 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md 69 | 'import/no-mutable-exports': 2, 70 | 71 | // Module systems: 72 | 73 | // disallow require() 74 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md 75 | 'import/no-commonjs': 0, 76 | 77 | // disallow AMD require/define 78 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-amd.md 79 | 'import/no-amd': 2, 80 | 81 | // No Node.js builtin modules 82 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md 83 | 'import/no-nodejs-modules': 0, 84 | 85 | // Style guide: 86 | 87 | // disallow non-import statements appearing before import statements 88 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md 89 | 'import/imports-first': [2, 'absolute-first'], 90 | 91 | // disallow duplicate imports 92 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md 93 | 'import/no-duplicates': 2, 94 | 95 | // disallow namespace imports 96 | // TODO: enable? 97 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md 98 | 'import/no-namespace': 0, 99 | 100 | // Ensure consistent use of file extension within the import path 101 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md 102 | // TODO: enable 103 | 'import/extensions': [0, 'never'], 104 | 105 | // Enforce a convention in module import order 106 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md 107 | // TODO: enable? 108 | 'import/order': [0, { 109 | groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'], 110 | 'newlines-between': 'never', 111 | }], 112 | 113 | // Require a newline after the last import/require in a group 114 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md 115 | // TODO: enable 116 | 'import/newline-after-import': 0, 117 | 118 | // Require modules with a single export to use a default export 119 | // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md 120 | // TODO: enable 121 | 'import/prefer-default-export': 0 122 | } 123 | }; 124 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/best-practices.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // enforces getter/setter pairs in objects 4 | 'accessor-pairs': 0, 5 | 6 | // enforces return statements in callbacks of array's methods 7 | // http://eslint.org/docs/rules/array-callback-return 8 | 'array-callback-return': 2, 9 | 10 | // treat var statements as if they were block scoped 11 | 'block-scoped-var': 2, 12 | 13 | // specify the maximum cyclomatic complexity allowed in a program 14 | complexity: [0, 11], 15 | 16 | // require return statements to either always or never specify values 17 | 'consistent-return': 2, 18 | 19 | // specify curly brace conventions for all control statements 20 | curly: [2, 'multi-line'], 21 | 22 | // require default case in switch statements 23 | 'default-case': [2, { commentPattern: '^no default$' }], 24 | 25 | // encourages use of dot notation whenever possible 26 | 'dot-notation': [2, { allowKeywords: true }], 27 | 28 | // enforces consistent newlines before or after dots 29 | 'dot-location': 0, 30 | 31 | // require the use of === and !== 32 | // http://eslint.org/docs/rules/eqeqeq 33 | eqeqeq: [2, 'allow-null'], 34 | 35 | // make sure for-in loops have an if statement 36 | 'guard-for-in': 2, 37 | 38 | // disallow the use of alert, confirm, and prompt 39 | 'no-alert': 1, 40 | 41 | // disallow use of arguments.caller or arguments.callee 42 | 'no-caller': 2, 43 | 44 | // disallow lexical declarations in case/default clauses 45 | // http://eslint.org/docs/rules/no-case-declarations.html 46 | 'no-case-declarations': 2, 47 | 48 | // disallow division operators explicitly at beginning of regular expression 49 | 'no-div-regex': 0, 50 | 51 | // disallow else after a return in an if 52 | 'no-else-return': 2, 53 | 54 | // disallow empty functions, except for standalone funcs/arrows 55 | // http://eslint.org/docs/rules/no-empty-function 56 | 'no-empty-function': [2, { 57 | allow: [ 58 | 'arrowFunctions', 59 | 'functions', 60 | 'methods', 61 | ] 62 | }], 63 | 64 | // disallow empty destructuring patterns 65 | // http://eslint.org/docs/rules/no-empty-pattern 66 | 'no-empty-pattern': 2, 67 | 68 | // disallow comparisons to null without a type-checking operator 69 | 'no-eq-null': 0, 70 | 71 | // disallow use of eval() 72 | 'no-eval': 2, 73 | 74 | // disallow adding to native types 75 | 'no-extend-native': 2, 76 | 77 | // disallow unnecessary function binding 78 | 'no-extra-bind': 2, 79 | 80 | // disallow Unnecessary Labels 81 | // http://eslint.org/docs/rules/no-extra-label 82 | 'no-extra-label': 2, 83 | 84 | // disallow fallthrough of case statements 85 | 'no-fallthrough': 2, 86 | 87 | // disallow the use of leading or trailing decimal points in numeric literals 88 | 'no-floating-decimal': 2, 89 | 90 | // disallow the type conversions with shorter notations 91 | 'no-implicit-coercion': 0, 92 | 93 | // disallow var and named functions in global scope 94 | // http://eslint.org/docs/rules/no-implicit-globals 95 | 'no-implicit-globals': 0, 96 | 97 | // disallow use of eval()-like methods 98 | 'no-implied-eval': 2, 99 | 100 | // disallow this keywords outside of classes or class-like objects 101 | 'no-invalid-this': 0, 102 | 103 | // disallow usage of __iterator__ property 104 | 'no-iterator': 2, 105 | 106 | // disallow use of labels for anything other then loops and switches 107 | 'no-labels': [2, { allowLoop: false, allowSwitch: false }], 108 | 109 | // disallow unnecessary nested blocks 110 | 'no-lone-blocks': 2, 111 | 112 | // disallow creation of functions within loops 113 | 'no-loop-func': 2, 114 | 115 | // disallow magic numbers 116 | // http://eslint.org/docs/rules/no-magic-numbers 117 | 'no-magic-numbers': [0, { 118 | ignore: [], 119 | ignoreArrayIndexes: true, 120 | enforceConst: true, 121 | detectObjects: false, 122 | }], 123 | 124 | // disallow use of multiple spaces 125 | 'no-multi-spaces': 2, 126 | 127 | // disallow use of multiline strings 128 | 'no-multi-str': 2, 129 | 130 | // disallow reassignments of native objects 131 | 'no-native-reassign': 2, 132 | 133 | // disallow use of new operator when not part of the assignment or comparison 134 | 'no-new': 2, 135 | 136 | // disallow use of new operator for Function object 137 | 'no-new-func': 2, 138 | 139 | // disallows creating new instances of String, Number, and Boolean 140 | 'no-new-wrappers': 2, 141 | 142 | // disallow use of (old style) octal literals 143 | 'no-octal': 2, 144 | 145 | // disallow use of octal escape sequences in string literals, such as 146 | // var foo = 'Copyright \251'; 147 | 'no-octal-escape': 2, 148 | 149 | // disallow reassignment of function parameters 150 | // disallow parameter object manipulation 151 | // rule: http://eslint.org/docs/rules/no-param-reassign.html 152 | 'no-param-reassign': [2, { props: true }], 153 | 154 | // disallow usage of __proto__ property 155 | 'no-proto': 2, 156 | 157 | // disallow declaring the same variable more then once 158 | 'no-redeclare': 2, 159 | 160 | // disallow use of assignment in return statement 161 | 'no-return-assign': 2, 162 | 163 | // disallow use of `javascript:` urls. 164 | 'no-script-url': 2, 165 | 166 | // disallow self assignment 167 | // http://eslint.org/docs/rules/no-self-assign 168 | 'no-self-assign': 2, 169 | 170 | // disallow comparisons where both sides are exactly the same 171 | 'no-self-compare': 2, 172 | 173 | // disallow use of comma operator 174 | 'no-sequences': 2, 175 | 176 | // restrict what can be thrown as an exception 177 | 'no-throw-literal': 2, 178 | 179 | // disallow unmodified conditions of loops 180 | // http://eslint.org/docs/rules/no-unmodified-loop-condition 181 | 'no-unmodified-loop-condition': 0, 182 | 183 | // disallow usage of expressions in statement position 184 | 'no-unused-expressions': 2, 185 | 186 | // disallow unused labels 187 | // http://eslint.org/docs/rules/no-unused-labels 188 | 'no-unused-labels': 2, 189 | 190 | // disallow unnecessary .call() and .apply() 191 | 'no-useless-call': 0, 192 | 193 | // disallow useless string concatenation 194 | // http://eslint.org/docs/rules/no-useless-concat 195 | 'no-useless-concat': 2, 196 | 197 | // disallow unnecessary string escaping 198 | // http://eslint.org/docs/rules/no-useless-escape 199 | 'no-useless-escape': 2, 200 | 201 | // disallow use of void operator 202 | 'no-void': 0, 203 | 204 | // disallow usage of configurable warning terms in comments: e.g. todo 205 | 'no-warning-comments': [0, { terms: ['todo', 'fixme', 'xxx'], location: 'start' }], 206 | 207 | // disallow use of the with statement 208 | 'no-with': 2, 209 | 210 | // require use of the second argument for parseInt() 211 | radix: 2, 212 | 213 | // requires to declare all vars on top of their containing scope 214 | 'vars-on-top': 2, 215 | 216 | // require immediate function invocation to be wrapped in parentheses 217 | // http://eslint.org/docs/rules/wrap-iife.html 218 | 'wrap-iife': [2, 'outside'], 219 | 220 | // require or disallow Yoda conditions 221 | yoda: 2 222 | } 223 | }; 224 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/style.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // enforce spacing inside array brackets 4 | 'array-bracket-spacing': [2, 'never'], 5 | 6 | // enforce spacing inside single-line blocks 7 | // http://eslint.org/docs/rules/block-spacing 8 | 'block-spacing': [2, 'always'], 9 | 10 | // enforce one true brace style 11 | 'brace-style': [2, '1tbs', { allowSingleLine: true }], 12 | 13 | // require camel case names 14 | camelcase: [2, { properties: 'never' }], 15 | 16 | // enforce spacing before and after comma 17 | 'comma-spacing': [2, { before: false, after: true }], 18 | 19 | // enforce one true comma style 20 | 'comma-style': [2, 'last'], 21 | 22 | // disallow padding inside computed properties 23 | 'computed-property-spacing': [2, 'never'], 24 | 25 | // enforces consistent naming when capturing the current execution context 26 | 'consistent-this': 0, 27 | 28 | // enforce newline at the end of file, with no multiple empty lines 29 | 'eol-last': 2, 30 | 31 | // require function expressions to have a name 32 | 'func-names': 1, 33 | 34 | // enforces use of function declarations or expressions 35 | 'func-style': 0, 36 | 37 | // Blacklist certain identifiers to prevent them being used 38 | // http://eslint.org/docs/rules/id-blacklist 39 | 'id-blacklist': 0, 40 | 41 | // this option enforces minimum and maximum identifier lengths 42 | // (variable names, property names etc.) 43 | 'id-length': 0, 44 | 45 | // require identifiers to match the provided regular expression 46 | 'id-match': 0, 47 | 48 | // this option sets a specific tab width for your code 49 | // http://eslint.org/docs/rules/indent 50 | indent: [2, 2, { SwitchCase: 1, VariableDeclarator: 1 }], 51 | 52 | // specify whether double or single quotes should be used in JSX attributes 53 | // http://eslint.org/docs/rules/jsx-quotes 54 | 'jsx-quotes': 0, 55 | 56 | // enforces spacing between keys and values in object literal properties 57 | 'key-spacing': [2, { beforeColon: false, afterColon: true }], 58 | 59 | // require a space before & after certain keywords 60 | 'keyword-spacing': [2, { 61 | before: true, 62 | after: true, 63 | overrides: { 64 | return: { after: true }, 65 | throw: { after: true }, 66 | case: { after: true } 67 | } 68 | }], 69 | 70 | // disallow mixed 'LF' and 'CRLF' as linebreaks 71 | 'linebreak-style': 0, 72 | 73 | // enforces empty lines around comments 74 | 'lines-around-comment': 0, 75 | 76 | // specify the maximum depth that blocks can be nested 77 | 'max-depth': [0, 4], 78 | 79 | // specify the maximum length of a line in your program 80 | // http://eslint.org/docs/rules/max-len 81 | 'max-len': [2, 100, 2, { 82 | ignoreUrls: true, 83 | ignoreComments: false 84 | }], 85 | 86 | // specify the maximum depth callbacks can be nested 87 | 'max-nested-callbacks': 0, 88 | 89 | // limits the number of parameters that can be used in the function declaration. 90 | 'max-params': [0, 3], 91 | 92 | // specify the maximum number of statement allowed in a function 93 | 'max-statements': [0, 10], 94 | 95 | // restrict the number of statements per line 96 | // http://eslint.org/docs/rules/max-statements-per-line 97 | 'max-statements-per-line': [0, { max: 1 }], 98 | 99 | // require a capital letter for constructors 100 | 'new-cap': [2, { newIsCap: true }], 101 | 102 | // disallow the omission of parentheses when invoking a constructor with no arguments 103 | 'new-parens': 0, 104 | 105 | // allow/disallow an empty newline after var statement 106 | 'newline-after-var': 0, 107 | 108 | // http://eslint.org/docs/rules/newline-before-return 109 | 'newline-before-return': 0, 110 | 111 | // enforces new line after each method call in the chain to make it 112 | // more readable and easy to maintain 113 | // http://eslint.org/docs/rules/newline-per-chained-call 114 | 'newline-per-chained-call': [2, { ignoreChainWithDepth: 3 }], 115 | 116 | // disallow use of the Array constructor 117 | 'no-array-constructor': 2, 118 | 119 | // disallow use of bitwise operators 120 | 'no-bitwise': 0, 121 | 122 | // disallow use of the continue statement 123 | 'no-continue': 0, 124 | 125 | // disallow comments inline after code 126 | 'no-inline-comments': 0, 127 | 128 | // disallow if as the only statement in an else block 129 | 'no-lonely-if': 0, 130 | 131 | // disallow mixed spaces and tabs for indentation 132 | 'no-mixed-spaces-and-tabs': 2, 133 | 134 | // disallow multiple empty lines and only one newline at the end 135 | 'no-multiple-empty-lines': [2, { max: 2, maxEOF: 1 }], 136 | 137 | // disallow negated conditions 138 | // http://eslint.org/docs/rules/no-negated-condition 139 | 'no-negated-condition': 0, 140 | 141 | // disallow nested ternary expressions 142 | 'no-nested-ternary': 2, 143 | 144 | // disallow use of the Object constructor 145 | 'no-new-object': 2, 146 | 147 | // disallow use of unary operators, ++ and -- 148 | 'no-plusplus': 0, 149 | 150 | // disallow certain syntax forms 151 | // http://eslint.org/docs/rules/no-restricted-syntax 152 | 'no-restricted-syntax': [ 153 | 2, 154 | 'DebuggerStatement', 155 | 'ForInStatement', 156 | 'LabeledStatement', 157 | 'WithStatement', 158 | ], 159 | 160 | // disallow space between function identifier and application 161 | 'no-spaced-func': 2, 162 | 163 | // disallow the use of ternary operators 164 | 'no-ternary': 0, 165 | 166 | // disallow trailing whitespace at the end of lines 167 | 'no-trailing-spaces': 2, 168 | 169 | // disallow dangling underscores in identifiers 170 | 'no-underscore-dangle': [2, { allowAfterThis: false }], 171 | 172 | // disallow the use of Boolean literals in conditional expressions 173 | // also, prefer `a || b` over `a ? a : b` 174 | // http://eslint.org/docs/rules/no-unneeded-ternary 175 | 'no-unneeded-ternary': [2, { defaultAssignment: false }], 176 | 177 | // disallow whitespace before properties 178 | // http://eslint.org/docs/rules/no-whitespace-before-property 179 | 'no-whitespace-before-property': 2, 180 | 181 | // require padding inside curly braces 182 | 'object-curly-spacing': [2, 'always'], 183 | 184 | // enforce "same line" or "multiple line" on object properties. 185 | // http://eslint.org/docs/rules/object-property-newline 186 | // TODO: enable when https://github.com/eslint/eslint/issues/5667#issuecomment-219334864 is resolved 187 | 'object-property-newline': [0, { 188 | allowMultiplePropertiesPerLine: true, 189 | }], 190 | 191 | // allow just one var statement per function 192 | 'one-var': [2, 'never'], 193 | 194 | // require a newline around variable declaration 195 | // http://eslint.org/docs/rules/one-var-declaration-per-line 196 | 'one-var-declaration-per-line': [2, 'always'], 197 | 198 | // require assignment operator shorthand where possible or prohibit it entirely 199 | 'operator-assignment': 0, 200 | 201 | // enforce operators to be placed before or after line breaks 202 | 'operator-linebreak': 0, 203 | 204 | // enforce padding within blocks 205 | 'padded-blocks': [2, 'never'], 206 | 207 | // require quotes around object literal property names 208 | // http://eslint.org/docs/rules/quote-props.html 209 | 'quote-props': [2, 'as-needed', { keywords: false, unnecessary: true, numbers: false }], 210 | 211 | // specify whether double or single quotes should be used 212 | quotes: [2, 'single', { avoidEscape: true }], 213 | 214 | // do not require jsdoc 215 | // http://eslint.org/docs/rules/require-jsdoc 216 | 'require-jsdoc': 0, 217 | 218 | // require or disallow use of semicolons instead of ASI 219 | semi: [2, 'always'], 220 | 221 | // enforce spacing before and after semicolons 222 | 'semi-spacing': [2, { before: false, after: true }], 223 | 224 | // sort variables within the same declaration block 225 | 'sort-vars': 0, 226 | 227 | // require or disallow space before blocks 228 | 'space-before-blocks': 2, 229 | 230 | // require or disallow space before function opening parenthesis 231 | // http://eslint.org/docs/rules/space-before-function-paren 232 | 'space-before-function-paren': [2, { anonymous: 'always', named: 'never' }], 233 | 234 | // require or disallow spaces inside parentheses 235 | 'space-in-parens': [2, 'never'], 236 | 237 | // require spaces around operators 238 | 'space-infix-ops': 2, 239 | 240 | // Require or disallow spaces before/after unary operators 241 | 'space-unary-ops': 0, 242 | 243 | // require or disallow a space immediately following the // or /* in a comment 244 | 'spaced-comment': [2, 'always', { 245 | exceptions: ['-', '+'], 246 | markers: ['=', '!'] // space here to support sprockets directives 247 | }], 248 | 249 | // require or disallow the Unicode Byte Order Mark 250 | // http://eslint.org/docs/rules/unicode-bom 251 | 'unicode-bom': [2, 'never'], 252 | 253 | // require regex literals to be wrapped in parentheses 254 | 'wrap-regex': 0 255 | } 256 | }; 257 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/rules/react.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | 'react' 4 | ], 5 | parserOptions: { 6 | ecmaFeatures: { 7 | jsx: true, 8 | }, 9 | }, 10 | ecmaFeatures: { 11 | jsx: true 12 | }, 13 | 14 | // View link below for react rules documentation 15 | // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules 16 | rules: { 17 | // specify whether double or single quotes should be used in JSX attributes 18 | // http://eslint.org/docs/rules/jsx-quotes 19 | 'jsx-quotes': [2, 'prefer-double'], 20 | 21 | // Prevent missing displayName in a React component definition 22 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 23 | 'react/display-name': [0, { ignoreTranspilerName: false }], 24 | 25 | // Forbid certain propTypes (any, array, object) 26 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md 27 | 'react/forbid-prop-types': [0, { forbid: ['any', 'array', 'object'] }], 28 | 29 | // Enforce boolean attributes notation in JSX 30 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md 31 | 'react/jsx-boolean-value': [2, 'never'], 32 | 33 | // Validate closing bracket location in JSX 34 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md 35 | 'react/jsx-closing-bracket-location': [2, 'line-aligned'], 36 | 37 | // Enforce or disallow spaces inside of curly braces in JSX attributes 38 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md 39 | 'react/jsx-curly-spacing': [2, 'never', { allowMultiline: true }], 40 | 41 | // Enforce event handler naming conventions in JSX 42 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md 43 | 'react/jsx-handler-names': [0, { 44 | eventHandlerPrefix: 'handle', 45 | eventHandlerPropPrefix: 'on', 46 | }], 47 | 48 | // Validate props indentation in JSX 49 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md 50 | 'react/jsx-indent-props': [2, 2], 51 | 52 | // Validate JSX has key prop when in array or iterator 53 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md 54 | 'react/jsx-key': 0, 55 | 56 | // Limit maximum of props on a single line in JSX 57 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md 58 | 'react/jsx-max-props-per-line': [0, { maximum: 1 }], 59 | 60 | // Prevent usage of .bind() in JSX props 61 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md 62 | 'react/jsx-no-bind': [2, { 63 | ignoreRefs: true, 64 | allowArrowFunctions: true, 65 | allowBind: false, 66 | }], 67 | 68 | // Prevent duplicate props in JSX 69 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md 70 | 'react/jsx-no-duplicate-props': [0, { ignoreCase: false }], 71 | 72 | // Prevent usage of unwrapped JSX strings 73 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md 74 | 'react/jsx-no-literals': 0, 75 | 76 | // Disallow undeclared variables in JSX 77 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md 78 | 'react/jsx-no-undef': 2, 79 | 80 | // Enforce PascalCase for user-defined JSX components 81 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md 82 | 'react/jsx-pascal-case': [2, { 83 | allowAllCaps: true, 84 | ignore: [], 85 | }], 86 | 87 | // Enforce propTypes declarations alphabetical sorting 88 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md 89 | 'react/sort-prop-types': [0, { 90 | ignoreCase: false, 91 | callbacksLast: false, 92 | }], 93 | 94 | // deprecated in favor of react/jsx-sort-props 95 | 'react/jsx-sort-prop-types': 0, 96 | 97 | // Enforce props alphabetical sorting 98 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md 99 | 'react/jsx-sort-props': [0, { 100 | ignoreCase: false, 101 | callbacksLast: false, 102 | }], 103 | 104 | // Prevent React to be incorrectly marked as unused 105 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md 106 | 'react/jsx-uses-react': [2, { pragma: 'React' }], 107 | 108 | // Prevent variables used in JSX to be incorrectly marked as unused 109 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md 110 | 'react/jsx-uses-vars': 2, 111 | 112 | // Prevent usage of dangerous JSX properties 113 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md 114 | 'react/no-danger': 0, 115 | 116 | // Prevent usage of deprecated methods 117 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md 118 | 'react/no-deprecated': [1, { react: '0.14.0' }], 119 | 120 | // Prevent usage of setState in componentDidMount 121 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md 122 | 'react/no-did-mount-set-state': [2, 'allow-in-func'], 123 | 124 | // Prevent usage of setState in componentDidUpdate 125 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md 126 | 'react/no-did-update-set-state': [2, 'allow-in-func'], 127 | 128 | // Prevent direct mutation of this.state 129 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md 130 | 'react/no-direct-mutation-state': 0, 131 | 132 | // Prevent usage of isMounted 133 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md 134 | 'react/no-is-mounted': 2, 135 | 136 | // Prevent multiple component definition per file 137 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md 138 | 'react/no-multi-comp': [2, { ignoreStateless: true }], 139 | 140 | // Prevent usage of setState 141 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md 142 | 'react/no-set-state': 0, 143 | 144 | // Prevent using string references 145 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md 146 | 'react/no-string-refs': 0, 147 | 148 | // Prevent usage of unknown DOM property 149 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md 150 | 'react/no-unknown-property': 2, 151 | 152 | // Require ES6 class declarations over React.createClass 153 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md 154 | 'react/prefer-es6-class': [2, 'always'], 155 | 156 | // Require stateless functions when not using lifecycle methods, setState or ref 157 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md 158 | 'react/prefer-stateless-function': 2, 159 | 160 | // Prevent missing props validation in a React component definition 161 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md 162 | 'react/prop-types': [2, { ignore: [], customValidators: [] }], 163 | 164 | // Prevent missing React when using JSX 165 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md 166 | 'react/react-in-jsx-scope': 2, 167 | 168 | // Restrict file extensions that may be required 169 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-extension.md 170 | 'react/require-extension': [0, { extensions: ['.jsx'] }], 171 | 172 | // Require render() methods to return something 173 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md 174 | 'react/require-render-return': 2, 175 | 176 | // Prevent extra closing tags for components without children 177 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md 178 | 'react/self-closing-comp': 2, 179 | 180 | // Enforce spaces before the closing bracket of self-closing JSX elements 181 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md 182 | 'react/jsx-space-before-closing': [2, 'always'], 183 | 184 | // Enforce component methods order 185 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 186 | 'react/sort-comp': [2, { 187 | order: [ 188 | 'static-methods', 189 | 'lifecycle', 190 | '/^on.+$/', 191 | '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', 192 | 'everything-else', 193 | '/^render.+$/', 194 | 'render' 195 | ], 196 | }], 197 | 198 | // Prevent missing parentheses around multilines JSX 199 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md 200 | 'react/wrap-multilines': [2, { 201 | declaration: true, 202 | assignment: true, 203 | return: true 204 | }], 205 | 206 | // Require that the first prop in a JSX element be on a new line when the element is multiline 207 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md 208 | 'react/jsx-first-prop-new-line': [2, 'multiline'], 209 | 210 | // enforce spacing around jsx equals signs 211 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md 212 | 'react/jsx-equals-spacing': [2, 'never'], 213 | 214 | // enforce JSX indentation 215 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md 216 | 'react/jsx-indent': [2, 2], 217 | 218 | // disallow target="_blank" on links 219 | // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md 220 | // TODO: enable 221 | 'react/jsx-no-target-blank': 0 222 | }, 223 | 224 | settings: { 225 | 'import/resolver': { 226 | node: { 227 | extensions: ['.js', '.jsx', '.json'] 228 | } 229 | }, 230 | react: { 231 | pragma: 'React', 232 | version: '0.14' 233 | }, 234 | } 235 | }; 236 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 9.0.1 / 2016-05-08 2 | ================== 3 | - [patch] update `eslint-config-airbnb-base` to v3.0.1 4 | 5 | 9.0.0 / 2016-05-07 6 | ================== 7 | - [breaking] update `eslint-config-airbnb-base` to v3 8 | - [deps] update `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y` 9 | 10 | 8.0.0 / 2016-04-21 11 | ================== 12 | - [breaking] Migrate non-React rules to a separate linter config (`eslint-config-airbnb-base`) 13 | - [breaking] disallow empty methods 14 | - [breaking] disallow empty restructuring patterns 15 | - [breaking] enable `no-restricted-syntax` rule 16 | - [breaking] enable `global-require` rule 17 | - [breaking] [react] enable `react/jsx-curly-spacing` rule ([#693](https://github.com/airbnb/javascript/issues/693)) 18 | - [semver-minor] [react] Add `react/jsx-first-prop-new-line` rule 19 | - [semver-minor] [react] enable `jsx-equals-spacing` rule 20 | - [semver-minor] [react] enable `jsx-indent` rule 21 | - [semver-minor] enforce spacing inside single-line blocks 22 | - [semver-minor] enforce `no-underscore-dangle` 23 | - [semver-minor] Enable import/no-unresolved and import/export rules ([#825](https://github.com/airbnb/javascript/issues/825)) 24 | - [semver-patch] Enable `no-useless-concat` rule which `prefer-template` already covers 25 | - [semver-patch] Allow `== null` ([#542](https://github.com/airbnb/javascript/issues/542)) 26 | - [dev deps / peer deps] update `eslint`, `eslint-plugin-react`, `eslint-plugin-import` 27 | - [dev deps / peer deps] update `eslint-plugin-jsx-a11y` and rename rules ([#838](https://github.com/airbnb/javascript/issues/838)) 28 | - [refactor] [react] separate a11y rules to their own file 29 | - [refactor] Add missing disabled rules. 30 | - [tests] Add `eslint-find-rules` to prevent missing rules 31 | 32 | 7.0.0 / 2016-04-11 33 | ================== 34 | - [react] [breaking] Add accessibility rules to the React style guide + `eslint-plugin-a11y` 35 | - [breaking] enable `react/require-render-return` 36 | - [breaking] Add `no-dupe-class-members` rule + section ([#785](https://github.com/airbnb/javascript/issues/785)) 37 | - [breaking] error on debugger statements 38 | - [breaking] add `no-useless-escape` rule 39 | - [breaking] add `no-duplicate-imports` rule 40 | - [semver-minor] enable `jsx-pascal-case` rule 41 | - [deps] update `eslint`, `react` 42 | - [dev deps] update `eslint`, `eslint-plugin-react` 43 | 44 | 6.2.0 / 2016-03-22 45 | ================== 46 | - [new] Allow arrow functions in JSX props 47 | - [fix] re-enable `no-confusing-arrow` rule, with `allowParens` option enabled ([#752](https://github.com/airbnb/javascript/issues/752), [#791](https://github.com/airbnb/javascript/issues/791)) 48 | - [dev deps] update `tape`, `eslint`, `eslint-plugin-react` 49 | - [peer deps] update `eslint`, `eslint-plugin-react` 50 | 51 | 6.1.0 / 2016-02-22 52 | ================== 53 | - [new] enable [`react/prefer-stateless-function`][react/prefer-stateless-function] 54 | - [dev deps] update `react-plugin-eslint`, `eslint`, `tape` 55 | 56 | 6.0.2 / 2016-02-22 57 | ================== 58 | - [fix] disable [`no-confusing-arrow`][no-confusing-arrow] due to an `eslint` bug ([#752](https://github.com/airbnb/javascript/issues/752)) 59 | 60 | 6.0.1 / 2016-02-21 61 | ================== 62 | - [fix] disable [`newline-per-chained-call`][newline-per-chained-call] due to an `eslint` bug ([#748](https://github.com/airbnb/javascript/issues/748)) 63 | 64 | 6.0.0 / 2016-02-21 65 | ================== 66 | - [breaking] enable [`array-callback-return`][array-callback-return] 67 | - [breaking] enable [`no-confusing-arrow`][no-confusing-arrow] 68 | - [breaking] enable [`no-new-symbol`][no-new-symbol] 69 | - [breaking] enable [`no-restricted-imports`][no-restricted-imports] 70 | - [breaking] enable [`no-useless-constructor`][no-useless-constructor] 71 | - [breaking] enable [`prefer-rest-params`][prefer-rest-params] 72 | - [breaking] enable [`template-curly-spacing`][template-curly-spacing] 73 | - [breaking] enable [`newline-per-chained-call`][newline-per-chained-call] 74 | - [breaking] enable [`one-var-declaration-per-line`][one-var-declaration-per-line] 75 | - [breaking] enable [`no-self-assign`][no-self-assign] 76 | - [breaking] enable [`no-whitespace-before-property`][no-whitespace-before-property] 77 | - [breaking] [react] enable [`react/jsx-space-before-closing`][react/jsx-space-before-closing] 78 | - [breaking] [react] enable `static-methods` at top of [`react/sort-comp`][react/sort-comp] 79 | - [breaking] [react] don't `ignoreTranspilerName` for [`react/display-name`][react/display-name] 80 | - [peer+dev deps] update `eslint`, `eslint-plugin-react` ([#730](https://github.com/airbnb/javascript/issues/730)) 81 | 82 | 5.0.1 / 2016-02-13 83 | ================== 84 | - [fix] `eslint` peerDep should not include breaking changes 85 | 86 | 5.0.0 / 2016-02-03 87 | ================== 88 | - [breaking] disallow unneeded ternary expressions 89 | - [breaking] Avoid lexical declarations in case/default clauses 90 | - [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` 91 | 92 | 4.0.0 / 2016-01-22 93 | ================== 94 | - [breaking] require outer IIFE wrapping; flesh out guide section 95 | - [minor] Add missing [`arrow-body-style`][arrow-body-style], [`prefer-template`][prefer-template] rules ([#678](https://github.com/airbnb/javascript/issues/678)) 96 | - [minor] Add [`prefer-arrow-callback`][prefer-arrow-callback] to ES6 rules (to match the guide) ([#677](https://github.com/airbnb/javascript/issues/677)) 97 | - [Tests] run `npm run lint` as part of tests; fix errors 98 | - [Tests] use `parallelshell` to parallelize npm run-scripts 99 | 100 | 3.1.0 / 2016-01-07 101 | ================== 102 | - [minor] Allow multiple stateless components in a single file 103 | 104 | 3.0.2 / 2016-01-06 105 | ================== 106 | - [fix] Ignore URLs in [`max-len`][max-len] ([#664](https://github.com/airbnb/javascript/issues/664)) 107 | 108 | 3.0.1 / 2016-01-06 109 | ================== 110 | - [fix] because we use babel, keywords should not be quoted 111 | 112 | 3.0.0 / 2016-01-04 113 | ================== 114 | - [breaking] enable [`quote-props`][quote-props] rule ([#632](https://github.com/airbnb/javascript/issues/632)) 115 | - [breaking] Define a max line length of 100 characters ([#639](https://github.com/airbnb/javascript/issues/639)) 116 | - [breaking] [react] Minor cleanup for the React styleguide, add [`react/jsx-no-bind`][react/jsx-no-bind] ([#619](https://github.com/airbnb/javascript/issues/619)) 117 | - [breaking] update best-practices config to prevent parameter object manipulation ([#627](https://github.com/airbnb/javascript/issues/627)) 118 | - [minor] Enable [`react/no-is-mounted`][react/no-is-mounted] rule (#635, #633) 119 | - [minor] Sort [`react/prefer-es6-class`][react/prefer-es6-class] alphabetically ([#634](https://github.com/airbnb/javascript/issues/634)) 120 | - [minor] enable [`react/prefer-es6-class`][react/prefer-es6-class] rule 121 | - Permit strict mode in "legacy" config 122 | - [react] add missing rules from `eslint-plugin-react` (enforcing where necessary) ([#581](https://github.com/airbnb/javascript/issues/581)) 123 | - [dev deps] update `eslint-plugin-react` 124 | 125 | 2.1.1 / 2015-12-15 126 | ================== 127 | - [fix] Remove deprecated [`react/jsx-quotes`][react/jsx-quotes] ([#622](https://github.com/airbnb/javascript/issues/622)) 128 | 129 | 2.1.0 / 2015-12-15 130 | ================== 131 | - [fix] use `require.resolve` to allow nested `extend`s ([#582](https://github.com/airbnb/javascript/issues/582)) 132 | - [new] enable [`object-shorthand`][object-shorthand] rule ([#621](https://github.com/airbnb/javascript/issues/621)) 133 | - [new] enable [`arrow-spacing`][arrow-spacing] rule ([#517](https://github.com/airbnb/javascript/issues/517)) 134 | - [docs] flesh out react rule defaults ([#618](https://github.com/airbnb/javascript/issues/618)) 135 | 136 | 2.0.0 / 2015-12-03 137 | ================== 138 | - [breaking] [`space-before-function-paren`][space-before-function-paren]: require function spacing: `function (` ([#605](https://github.com/airbnb/javascript/issues/605)) 139 | - [breaking] [`indent`][indent]: Fix switch statement indentation rule ([#606](https://github.com/airbnb/javascript/issues/606)) 140 | - [breaking] [`array-bracket-spacing`][array-bracket-spacing], [`computed-property-spacing`][computed-property-spacing]: disallow spacing inside brackets ([#594](https://github.com/airbnb/javascript/issues/594)) 141 | - [breaking] [`object-curly-spacing`][object-curly-spacing]: require padding inside curly braces ([#594](https://github.com/airbnb/javascript/issues/594)) 142 | - [breaking] [`space-in-parens`][space-in-parens]: disallow spaces in parens ([#594](https://github.com/airbnb/javascript/issues/594)) 143 | 144 | 1.0.2 / 2015-11-25 145 | ================== 146 | - [breaking] [`no-multiple-empty-lines`][no-multiple-empty-lines]: only allow 1 blank line at EOF ([#578](https://github.com/airbnb/javascript/issues/578)) 147 | - [new] `restParams`: enable rest params ([#592](https://github.com/airbnb/javascript/issues/592)) 148 | 149 | 1.0.1 / 2015-11-25 150 | ================== 151 | - *erroneous publish* 152 | 153 | 1.0.0 / 2015-11-08 154 | ================== 155 | - require `eslint` `v1.0.0` or higher 156 | - remove `babel-eslint` dependency 157 | 158 | 0.1.1 / 2015-11-05 159 | ================== 160 | - remove [`id-length`][id-length] rule ([#569](https://github.com/airbnb/javascript/issues/569)) 161 | - enable [`no-mixed-spaces-and-tabs`][no-mixed-spaces-and-tabs] ([#539](https://github.com/airbnb/javascript/issues/539)) 162 | - enable [`no-const-assign`][no-const-assign] ([#560](https://github.com/airbnb/javascript/issues/560)) 163 | - enable [`space-before-keywords`][space-before-keywords] ([#554](https://github.com/airbnb/javascript/issues/554)) 164 | 165 | 0.1.0 / 2015-11-05 166 | ================== 167 | - switch to modular rules files courtesy the [eslint-config-default][ecd] project and [@taion][taion]. [PR][pr-modular] 168 | - export `eslint-config-airbnb/legacy` for ES5-only users. `eslint-config-airbnb/legacy` does not require the `babel-eslint` parser. [PR][pr-legacy] 169 | 170 | 0.0.9 / 2015-09-24 171 | ================== 172 | - add rule [`no-undef`][no-undef] 173 | - add rule [`id-length`][id-length] 174 | 175 | 0.0.8 / 2015-08-21 176 | ================== 177 | - now has a changelog 178 | - now is modular (see instructions above for with react and without react versions) 179 | 180 | 0.0.7 / 2015-07-30 181 | ================== 182 | - TODO: fill in 183 | 184 | 185 | [ecd]: https://github.com/walmartlabs/eslint-config-defaults 186 | [taion]: https://github.com/taion 187 | [pr-modular]: https://github.com/airbnb/javascript/pull/526 188 | [pr-legacy]: https://github.com/airbnb/javascript/pull/527 189 | 190 | [array-bracket-spacing]: http://eslint.org/docs/rules/array-bracket-spacing 191 | [array-callback-return]: http://eslint.org/docs/rules/array-callback-return 192 | [arrow-body-style]: http://eslint.org/docs/rules/arrow-body-style 193 | [arrow-spacing]: http://eslint.org/docs/rules/arrow-spacing 194 | [computed-property-spacing]: http://eslint.org/docs/rules/computed-property-spacing 195 | [id-length]: http://eslint.org/docs/rules/id-length 196 | [indent]: http://eslint.org/docs/rules/indent 197 | [max-len]: http://eslint.org/docs/rules/max-len 198 | [newline-per-chained-call]: http://eslint.org/docs/rules/newline-per-chained-call 199 | [no-confusing-arrow]: http://eslint.org/docs/rules/no-confusing-arrow 200 | [no-const-assign]: http://eslint.org/docs/rules/no-const-assign 201 | [no-mixed-spaces-and-tabs]: http://eslint.org/docs/rules/no-mixed-spaces-and-tabs 202 | [no-multiple-empty-lines]: http://eslint.org/docs/rules/no-multiple-empty-lines 203 | [no-new-symbol]: http://eslint.org/docs/rules/no-new-symbol 204 | [no-restricted-imports]: http://eslint.org/docs/rules/no-restricted-imports 205 | [no-self-assign]: http://eslint.org/docs/rules/no-self-assign 206 | [no-undef]: http://eslint.org/docs/rules/no-undef 207 | [no-useless-constructor]: http://eslint.org/docs/rules/no-useless-constructor 208 | [no-whitespace-before-property]: http://eslint.org/docs/rules/no-whitespace-before-property 209 | [object-curly-spacing]: http://eslint.org/docs/rules/object-curly-spacing 210 | [object-shorthand]: http://eslint.org/docs/rules/object-shorthand 211 | [one-var-declaration-per-line]: http://eslint.org/docs/rules/one-var-declaration-per-line 212 | [prefer-arrow-callback]: http://eslint.org/docs/rules/prefer-arrow-callback 213 | [prefer-rest-params]: http://eslint.org/docs/rules/prefer-rest-params 214 | [prefer-template]: http://eslint.org/docs/rules/prefer-template 215 | [quote-props]: http://eslint.org/docs/rules/quote-props 216 | [space-before-function-paren]: http://eslint.org/docs/rules/space-before-function-paren 217 | [space-before-keywords]: http://eslint.org/docs/rules/space-before-keywords 218 | [space-in-parens]: http://eslint.org/docs/rules/space-in-parens 219 | [template-curly-spacing]: http://eslint.org/docs/rules/template-curly-spacing 220 | 221 | [react/jsx-space-before-closing]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md 222 | [react/sort-comp]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 223 | [react/display-name]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 224 | [react/jsx-no-bind]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md 225 | [react/no-is-mounted]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md 226 | [react/prefer-es6-class]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md 227 | [react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md 228 | [react/prefer-stateless-function]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md 229 | -------------------------------------------------------------------------------- /react/README.md: -------------------------------------------------------------------------------- 1 | # Przewodnik stylistyczny React/JSX od Airbnb 2 | 3 | *Przeważnie rozsądne podejście do React i JSX* 4 | 5 | ## Spis treści 6 | 7 | 1. [Podstawowe zasady](#basic-rules) 8 | 1. [Class kontra `React.createClass` kontra bezklasowe](#class-vs-reactcreateclass-vs-stateless) 9 | 1. [Nazewnictwo](#naming) 10 | 1. [Deklaracje](#declaration) 11 | 1. [Wyrównanie](#alignment) 12 | 1. [Cudzysłowy](#quotes) 13 | 1. [Spacjonowanie](#spacing) 14 | 1. [Właściwości - Props](#props) 15 | 1. [Nawiasy](#parentheses) 16 | 1. [Znaczniki](#tags) 17 | 1. [Metody](#methods) 18 | 1. [Porządkowanie](#ordering) 19 | 1. [`isMounted`](#ismounted) 20 | 21 | ## Podstawowe zasady 22 | 23 | Plik powinien zawierć tylko jeden komponent. 24 | - Jednak dopuszcza się liczne komponenty w pojedynczym pliku gdy są [komponentami bezstanowymi lub czystymi, ](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions). eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless). 25 | - Zawsze używaj skaładni JSX. 26 | - Nie używaj `React.createElement`, chyba że inicjujesz aplikację z pliku, który nie jest JSX. 27 | 28 | ## Class kontra `React.createClass` kontra bezstanowe 29 | 30 | - Jeżeli masz wewnętrzny stan i/albo odnośniki (refs), wtedy skłaniaj się ku wykorzystaniu `class extends React.Component` zamiast `React.createClass`, chyba że posiadasz dobry powód żeby użyć wstawek (mixins). eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) 31 | 32 | ```jsx 33 | // źle 34 | const Listing = React.createClass({ 35 | // ... 36 | render() { 37 | return
{this.state.hello}
; 38 | } 39 | }); 40 | 41 | // dobrze 42 | class Listing extends React.Component { 43 | // ... 44 | render() { 45 | return
{this.state.hello}
; 46 | } 47 | } 48 | ``` 49 | 50 | Jeśli nie masz stanu (state) lub odwołań (refs), wtedy zamiast klas wybierz normalną funkcję (funkcję anonimową ): 51 | 52 | ```jsx 53 | // źle 54 | class Listing extends React.Component { 55 | render() { 56 | return
{this.props.hello}
; 57 | } 58 | } 59 | 60 | // źle (poleganie na inferencji (wnioskowaniu?) nazwy funkcji jest odradzane ) 61 | const Listing = ({ hello }) => ( 62 |
{hello}
63 | ); 64 | 65 | // dobrze 66 | function Listing({ hello }) { 67 | return
{hello}
; 68 | } 69 | ``` 70 | 71 | ## Nazewnictwo 72 | 73 | - **Rozszrzenia**: Dla komponentów React używaj rozszerzenia `.jsx`. 74 | - **Nazwy plików**: Dla nazw plików używaj PascalCase np.: `ReservationCard.jsx`. 75 | - **Nazywanie struktur**: Używaj PascalCase dla komponentów React i camelCase dla ich instancji. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) 76 | 77 | ```jsx 78 | // źle 79 | import reservationCard from './ReservationCard'; 80 | 81 | // dobrze 82 | import ReservationCard from './ReservationCard'; 83 | 84 | // źle 85 | const ReservationItem = ; 86 | 87 | // dobrze 88 | const reservationItem = ; 89 | ``` 90 | 91 | - **Nazywanie komponentów**: Używaj nazw plików tak jak nazw komponentów. Na przykład odnośnik dla pliku `ReservationCard.jsx` powinien nazywać się `ReservationCard`. Jakkolwiek, dla komponentów podstawowych (root components) w katalogu, używaj `index.jsx` jako nazwy pliku i nazwy katalogu jako nazwy komponentu: 92 | 93 | ```jsx 94 | // źle 95 | import Footer from './Footer/Footer'; 96 | 97 | // źle 98 | import Footer from './Footer/index'; 99 | 100 | // dobrze 101 | import Footer from './Footer'; 102 | ``` 103 | 104 | ## Deklaracje 105 | 106 | - Nie używaj `displayName` dla nazw komponentów. W zamian nazwij komponent po jego odnośniku. 107 | 108 | ```jsx 109 | // źle 110 | export default React.createClass({ 111 | displayName: 'ReservationCard', 112 | // kod 113 | }); 114 | 115 | // dobrze 116 | export default class ReservationCard extends React.Component { 117 | } 118 | ``` 119 | 120 | ## Wyrównanie 121 | 122 | - Podążaj za tymi stylami wyrównań dla składni JSX. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) 123 | 124 | ```jsx 125 | // źle 126 | 128 | 129 | // dobrze 130 | 134 | // jeśli właściwości (props) mieszczą się w jednej lini wtedy utrzymaj je w jednej lini 135 | 136 | 137 | // dzieci wyrównane są normalnie 138 | 142 | 143 | 144 | ``` 145 | 146 | ## Cudzysłowy 147 | 148 | - Zawsze używaj podwójnych cudzysłowów (`"`) dla atrybutów JSX i apostrofów (`'`) dla pozostałego kodu JS. eslint: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes) 149 | 150 | > Dlaczego? Atrybuty JSX [nie mogą zawierać znaku modyfikacji przed apostrofami](http://eslint.org/docs/rules/jsx-quotes), węc cudzysłowy sprawiają że pisownia wyrazów takich `"don't"` jest łatwiesza w zapisie. 151 | > Typowe atrybuty HTML także używają cudzysłowów zamiast apostofów, więc atrybuty JSX odzwierciedlają niniejszą konwencję. 152 | 153 | ```jsx 154 | // źle 155 | 156 | 157 | // dobrze 158 | 159 | 160 | // źle 161 | 162 | 163 | // dobrze 164 | 165 | ``` 166 | 167 | ## Spacjonowanie 168 | 169 | - Zawsze dodawaj pojedynczą spacje w samo-zamykanych tagach. 170 | 171 | ```jsx 172 | // źle 173 | 174 | 175 | // bardzo źle 176 | 177 | 178 | // źle 179 | 181 | 182 | // dobrze 183 | 184 | ``` 185 | 186 | - Nie okładaj nawiasów klamrowych JSX (`{}`) spacjami. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md) 187 | 188 | ```jsx 189 | // źle 190 | 191 | 192 | // dobrze 193 | 194 | ``` 195 | 196 | ## Właściwości - Props 197 | 198 | - Zawsze używaj camelCase for nazw własciwości. 199 | 200 | ```jsx 201 | // źle 202 | 206 | 207 | // dobrze 208 | 212 | ``` 213 | 214 | - Unikaj ustawaienia wartości właściwości gdy wyraźnie przypisane jest jej `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md) 215 | 216 | ```jsx 217 | // źle 218 |