├── .editorconfig ├── .github └── workflows │ ├── node-pretest.yml │ ├── node.yml │ ├── rebase.yml │ └── require-allow-edits.yml ├── .gitignore ├── .npmrc ├── LICENSE.md ├── README.md ├── css-in-javascript └── README.md ├── linters ├── .eslintrc ├── .jshintrc ├── .markdownlint.json └── SublimeLinter │ └── SublimeLinter.sublime-settings ├── package.json ├── packages ├── eslint-config-airbnb-base │ ├── .babelrc │ ├── .editorconfig │ ├── .eslintrc │ ├── .npmrc │ ├── CHANGELOG.md │ ├── LICENSE.md │ ├── README.md │ ├── index.js │ ├── legacy.js │ ├── package.json │ ├── rules │ │ ├── best-practices.js │ │ ├── errors.js │ │ ├── es6.js │ │ ├── imports.js │ │ ├── node.js │ │ ├── strict.js │ │ ├── style.js │ │ └── variables.js │ ├── test │ │ ├── .eslintrc │ │ ├── requires.js │ │ └── test-base.js │ ├── whitespace-async.js │ ├── whitespace.js │ └── whitespaceRules.js └── eslint-config-airbnb │ ├── .babelrc │ ├── .editorconfig │ ├── .eslintrc │ ├── .npmrc │ ├── CHANGELOG.md │ ├── LICENSE.md │ ├── README.md │ ├── base.js │ ├── hooks.js │ ├── index.js │ ├── legacy.js │ ├── package.json │ ├── rules │ ├── react-a11y.js │ ├── react-hooks.js │ └── react.js │ ├── test │ ├── .eslintrc │ ├── requires.js │ ├── test-base.js │ └── test-react-order.js │ ├── whitespace-async.js │ ├── whitespace.js │ └── whitespaceRules.js └── react └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | end_of_line = lf 10 | # editorconfig-tools is unable to ignore longs strings or urls 11 | max_line_length = off 12 | 13 | [CHANGELOG.md] 14 | indent_size = false 15 | -------------------------------------------------------------------------------- /.github/workflows/node-pretest.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: pretest/posttest' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | pretest: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | package: 12 | - '..' 13 | - eslint-config-airbnb 14 | - eslint-config-airbnb-base 15 | 16 | defaults: 17 | run: 18 | working-directory: "packages/${{ matrix.package }}" 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - uses: ljharb/actions/node/install@main 23 | name: 'nvm install lts/* && npm install' 24 | with: 25 | node-version: 'lts/*' 26 | - run: npm run pretest 27 | -------------------------------------------------------------------------------- /.github/workflows/node.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | matrix: 7 | runs-on: ubuntu-latest 8 | outputs: 9 | latest: ${{ steps.set-matrix.outputs.requireds }} 10 | steps: 11 | - uses: ljharb/actions/node/matrix@main 12 | id: set-matrix 13 | with: 14 | versionsAsRoot: true 15 | type: 'majors' 16 | preset: '^12 || ^14 || ^16 || >= 17' 17 | 18 | base: 19 | needs: [matrix] 20 | name: 'base config' 21 | runs-on: ubuntu-latest 22 | 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | node-version: ${{ fromJson(needs.matrix.outputs.latest) }} 27 | eslint: 28 | - 8 29 | - 7 30 | package: 31 | - eslint-config-airbnb-base 32 | exclude: 33 | - node-version: 10 34 | eslint: 8 35 | package: eslint-config-airbnb-base 36 | 37 | defaults: 38 | run: 39 | working-directory: "packages/${{ matrix.package }}" 40 | 41 | steps: 42 | - uses: actions/checkout@v2 43 | - uses: ljharb/actions/node/install@main 44 | name: 'nvm install ${{ matrix.node-version }} && npm install' 45 | with: 46 | before_install: cd "packages/${{ matrix.package }}" 47 | node-version: ${{ matrix.node-version }} 48 | after_install: | 49 | npm install --no-save "eslint@${{ matrix.eslint }}" 50 | - run: node -pe "require('eslint/package.json').version" 51 | name: 'eslint version' 52 | - run: npm run travis 53 | - uses: codecov/codecov-action@v2 54 | 55 | react: 56 | needs: [matrix] 57 | name: 'react config' 58 | runs-on: ubuntu-latest 59 | 60 | strategy: 61 | fail-fast: false 62 | matrix: 63 | node-version: ${{ fromJson(needs.matrix.outputs.latest) }} 64 | eslint: 65 | - 8 66 | - 7 67 | package: 68 | - eslint-config-airbnb 69 | react-hooks: 70 | - 4 71 | 72 | defaults: 73 | run: 74 | working-directory: "packages/${{ matrix.package }}" 75 | 76 | steps: 77 | - uses: actions/checkout@v2 78 | - uses: ljharb/actions/node/install@main 79 | name: 'nvm install ${{ matrix.node-version }} && npm install' 80 | with: 81 | before_install: cd "packages/${{ matrix.package }}" 82 | node-version: ${{ matrix.node-version }} 83 | after_install: | 84 | npm install --no-save "eslint@${{ matrix.eslint }}" 85 | - run: node -pe "require('eslint/package.json').version" 86 | name: 'eslint version' 87 | - run: npm install --no-save "eslint-plugin-react-hooks@${{ matrix.react-hooks }}" 88 | if: ${{ matrix.react-hooks > 0}} 89 | - run: npm run travis 90 | - uses: codecov/codecov-action@v2 91 | 92 | prepublish-base: 93 | name: 'prepublish tests (base config)' 94 | runs-on: ubuntu-latest 95 | strategy: 96 | fail-fast: false 97 | matrix: 98 | eslint: 99 | - 8 100 | - 7 101 | package: 102 | - eslint-config-airbnb-base 103 | 104 | defaults: 105 | run: 106 | working-directory: "packages/${{ matrix.package }}" 107 | 108 | steps: 109 | - uses: actions/checkout@v2 110 | - uses: ljharb/actions/node/install@main 111 | name: 'nvm install lts/* && npm install' 112 | with: 113 | before_install: cd "packages/${{ matrix.package }}" 114 | node-version: lts/* 115 | after_install: | 116 | npm install --no-save "eslint@${{ matrix.eslint }}" 117 | - run: node -pe "require('eslint/package.json').version" 118 | name: 'eslint version' 119 | - run: npm run pretravis 120 | - run: npm run prepublishOnly 121 | - run: npm run posttravis 122 | 123 | prepublish-react: 124 | name: 'prepublish tests (react config)' 125 | runs-on: ubuntu-latest 126 | strategy: 127 | fail-fast: false 128 | matrix: 129 | eslint: 130 | - 8 131 | - 7 132 | package: 133 | - eslint-config-airbnb 134 | react-hooks: 135 | - 4 136 | 137 | defaults: 138 | run: 139 | working-directory: "packages/${{ matrix.package }}" 140 | 141 | steps: 142 | - uses: actions/checkout@v2 143 | - uses: ljharb/actions/node/install@main 144 | name: 'nvm install lts/* && npm install' 145 | with: 146 | before_install: cd "packages/${{ matrix.package }}" 147 | node-version: lts/* 148 | after_install: | 149 | npm install --no-save "eslint@${{ matrix.eslint }}" 150 | - run: npm install --no-save "eslint-plugin-react-hooks@${{ matrix.react-hooks }}" 151 | if: ${{ matrix.react-hooks > 0}} 152 | - run: node -pe "require('eslint/package.json').version" 153 | name: 'eslint version' 154 | - run: npm run pretravis 155 | - run: npm run prepublishOnly 156 | - run: npm run posttravis 157 | 158 | node: 159 | name: 'node 10+' 160 | needs: [base, prepublish-base, react, prepublish-react] 161 | runs-on: ubuntu-latest 162 | steps: 163 | - run: 'echo tests completed' 164 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | name: Automatic Rebase 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | name: "Automatic Rebase" 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: ljharb/rebase@master 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | -------------------------------------------------------------------------------- /.github/workflows/require-allow-edits.yml: -------------------------------------------------------------------------------- 1 | name: Require “Allow Edits” 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | name: "Require “Allow Edits”" 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: ljharb/require-allow-edits@main 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gitignore 2 | 3 | node_modules 4 | 5 | # Only apps should have lockfiles 6 | yarn.lock 7 | package-lock.json 8 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012 Airbnb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /css-in-javascript/README.md: -------------------------------------------------------------------------------- 1 | # Airbnb CSS-in-JavaScript Style Guide 2 | 3 | *A mostly reasonable approach to CSS-in-JavaScript* 4 | 5 | ## Table of Contents 6 | 7 | 1. [Naming](#naming) 8 | 1. [Ordering](#ordering) 9 | 1. [Nesting](#nesting) 10 | 1. [Inline](#inline) 11 | 1. [Themes](#themes) 12 | 13 | ## Naming 14 | 15 | - Use camelCase for object keys (i.e. "selectors"). 16 | 17 | > Why? We access these keys as properties on the `styles` object in the component, so it is most convenient to use camelCase. 18 | 19 | ```js 20 | // bad 21 | { 22 | 'bermuda-triangle': { 23 | display: 'none', 24 | }, 25 | } 26 | 27 | // good 28 | { 29 | bermudaTriangle: { 30 | display: 'none', 31 | }, 32 | } 33 | ``` 34 | 35 | - Use an underscore for modifiers to other styles. 36 | 37 | > Why? Similar to [BEM](https://getbem.com/introduction/), this naming convention makes it clear that the styles are intended to modify the element preceded by the underscore. Underscores do not need to be quoted, so they are preferred over other characters, such as dashes. 38 | 39 | ```js 40 | // bad 41 | { 42 | bruceBanner: { 43 | color: 'pink', 44 | transition: 'color 10s', 45 | }, 46 | 47 | bruceBannerTheHulk: { 48 | color: 'green', 49 | }, 50 | } 51 | 52 | // good 53 | { 54 | bruceBanner: { 55 | color: 'pink', 56 | transition: 'color 10s', 57 | }, 58 | 59 | bruceBanner_theHulk: { 60 | color: 'green', 61 | }, 62 | } 63 | ``` 64 | 65 | - Use `selectorName_fallback` for sets of fallback styles. 66 | 67 | > Why? Similar to modifiers, keeping the naming consistent helps reveal the relationship of these styles to the styles that override them in more adequate browsers. 68 | 69 | ```js 70 | // bad 71 | { 72 | muscles: { 73 | display: 'flex', 74 | }, 75 | 76 | muscles_sadBears: { 77 | width: '100%', 78 | }, 79 | } 80 | 81 | // good 82 | { 83 | muscles: { 84 | display: 'flex', 85 | }, 86 | 87 | muscles_fallback: { 88 | width: '100%', 89 | }, 90 | } 91 | ``` 92 | 93 | - Use a separate selector for sets of fallback styles. 94 | 95 | > Why? Keeping fallback styles contained in a separate object clarifies their purpose, which improves readability. 96 | 97 | ```js 98 | // bad 99 | { 100 | muscles: { 101 | display: 'flex', 102 | }, 103 | 104 | left: { 105 | flexGrow: 1, 106 | display: 'inline-block', 107 | }, 108 | 109 | right: { 110 | display: 'inline-block', 111 | }, 112 | } 113 | 114 | // good 115 | { 116 | muscles: { 117 | display: 'flex', 118 | }, 119 | 120 | left: { 121 | flexGrow: 1, 122 | }, 123 | 124 | left_fallback: { 125 | display: 'inline-block', 126 | }, 127 | 128 | right_fallback: { 129 | display: 'inline-block', 130 | }, 131 | } 132 | ``` 133 | 134 | - Use device-agnostic names (e.g. "small", "medium", and "large") to name media query breakpoints. 135 | 136 | > Why? Commonly used names like "phone", "tablet", and "desktop" do not match the characteristics of the devices in the real world. Using these names sets the wrong expectations. 137 | 138 | ```js 139 | // bad 140 | const breakpoints = { 141 | mobile: '@media (max-width: 639px)', 142 | tablet: '@media (max-width: 1047px)', 143 | desktop: '@media (min-width: 1048px)', 144 | }; 145 | 146 | // good 147 | const breakpoints = { 148 | small: '@media (max-width: 639px)', 149 | medium: '@media (max-width: 1047px)', 150 | large: '@media (min-width: 1048px)', 151 | }; 152 | ``` 153 | 154 | ## Ordering 155 | 156 | - Define styles after the component. 157 | 158 | > Why? We use a higher-order component to theme our styles, which is naturally used after the component definition. Passing the styles object directly to this function reduces indirection. 159 | 160 | ```jsx 161 | // bad 162 | const styles = { 163 | container: { 164 | display: 'inline-block', 165 | }, 166 | }; 167 | 168 | function MyComponent({ styles }) { 169 | return ( 170 |
171 | Never doubt that a small group of thoughtful, committed citizens can 172 | change the world. Indeed, it’s the only thing that ever has. 173 |
174 | ); 175 | } 176 | 177 | export default withStyles(() => styles)(MyComponent); 178 | 179 | // good 180 | function MyComponent({ styles }) { 181 | return ( 182 |
183 | Never doubt that a small group of thoughtful, committed citizens can 184 | change the world. Indeed, it’s the only thing that ever has. 185 |
186 | ); 187 | } 188 | 189 | export default withStyles(() => ({ 190 | container: { 191 | display: 'inline-block', 192 | }, 193 | }))(MyComponent); 194 | ``` 195 | 196 | ## Nesting 197 | 198 | - Leave a blank line between adjacent blocks at the same indentation level. 199 | 200 | > Why? The whitespace improves readability and reduces the likelihood of merge conflicts. 201 | 202 | ```js 203 | // bad 204 | { 205 | bigBang: { 206 | display: 'inline-block', 207 | '::before': { 208 | content: "''", 209 | }, 210 | }, 211 | universe: { 212 | border: 'none', 213 | }, 214 | } 215 | 216 | // good 217 | { 218 | bigBang: { 219 | display: 'inline-block', 220 | 221 | '::before': { 222 | content: "''", 223 | }, 224 | }, 225 | 226 | universe: { 227 | border: 'none', 228 | }, 229 | } 230 | ``` 231 | 232 | ## Inline 233 | 234 | - Use inline styles for styles that have a high cardinality (e.g. uses the value of a prop) and not for styles that have a low cardinality. 235 | 236 | > Why? Generating themed stylesheets can be expensive, so they are best for discrete sets of styles. 237 | 238 | ```jsx 239 | // bad 240 | export default function MyComponent({ spacing }) { 241 | return ( 242 |
243 | ); 244 | } 245 | 246 | // good 247 | function MyComponent({ styles, spacing }) { 248 | return ( 249 |
250 | ); 251 | } 252 | export default withStyles(() => ({ 253 | periodic: { 254 | display: 'table', 255 | }, 256 | }))(MyComponent); 257 | ``` 258 | 259 | ## Themes 260 | 261 | - Use an abstraction layer such as [react-with-styles](https://github.com/airbnb/react-with-styles) that enables theming. *react-with-styles gives us things like `withStyles()`, `ThemedStyleSheet`, and `css()` which are used in some of the examples in this document.* 262 | 263 | > Why? It is useful to have a set of shared variables for styling your components. Using an abstraction layer makes this more convenient. Additionally, this can help prevent your components from being tightly coupled to any particular underlying implementation, which gives you more freedom. 264 | 265 | - Define colors only in themes. 266 | 267 | ```js 268 | // bad 269 | export default withStyles(() => ({ 270 | chuckNorris: { 271 | color: '#bada55', 272 | }, 273 | }))(MyComponent); 274 | 275 | // good 276 | export default withStyles(({ color }) => ({ 277 | chuckNorris: { 278 | color: color.badass, 279 | }, 280 | }))(MyComponent); 281 | ``` 282 | 283 | - Define fonts only in themes. 284 | 285 | ```js 286 | // bad 287 | export default withStyles(() => ({ 288 | towerOfPisa: { 289 | fontStyle: 'italic', 290 | }, 291 | }))(MyComponent); 292 | 293 | // good 294 | export default withStyles(({ font }) => ({ 295 | towerOfPisa: { 296 | fontStyle: font.italic, 297 | }, 298 | }))(MyComponent); 299 | ``` 300 | 301 | - Define fonts as sets of related styles. 302 | 303 | ```js 304 | // bad 305 | export default withStyles(() => ({ 306 | towerOfPisa: { 307 | fontFamily: 'Italiana, "Times New Roman", serif', 308 | fontSize: '2em', 309 | fontStyle: 'italic', 310 | lineHeight: 1.5, 311 | }, 312 | }))(MyComponent); 313 | 314 | // good 315 | export default withStyles(({ font }) => ({ 316 | towerOfPisa: { 317 | ...font.italian, 318 | }, 319 | }))(MyComponent); 320 | ``` 321 | 322 | - Define base grid units in theme (either as a value or a function that takes a multiplier). 323 | 324 | ```js 325 | // bad 326 | export default withStyles(() => ({ 327 | rip: { 328 | bottom: '-6912px', // 6 feet 329 | }, 330 | }))(MyComponent); 331 | 332 | // good 333 | export default withStyles(({ units }) => ({ 334 | rip: { 335 | bottom: units(864), // 6 feet, assuming our unit is 8px 336 | }, 337 | }))(MyComponent); 338 | 339 | // good 340 | export default withStyles(({ unit }) => ({ 341 | rip: { 342 | bottom: 864 * unit, // 6 feet, assuming our unit is 8px 343 | }, 344 | }))(MyComponent); 345 | ``` 346 | 347 | - Define media queries only in themes. 348 | 349 | ```js 350 | // bad 351 | export default withStyles(() => ({ 352 | container: { 353 | width: '100%', 354 | 355 | '@media (max-width: 1047px)': { 356 | width: '50%', 357 | }, 358 | }, 359 | }))(MyComponent); 360 | 361 | // good 362 | export default withStyles(({ breakpoint }) => ({ 363 | container: { 364 | width: '100%', 365 | 366 | [breakpoint.medium]: { 367 | width: '50%', 368 | }, 369 | }, 370 | }))(MyComponent); 371 | ``` 372 | 373 | - Define tricky fallback properties in themes. 374 | 375 | > Why? Many CSS-in-JavaScript implementations merge style objects together which makes specifying fallbacks for the same property (e.g. `display`) a little tricky. To keep the approach unified, put these fallbacks in the theme. 376 | 377 | ```js 378 | // bad 379 | export default withStyles(() => ({ 380 | .muscles { 381 | display: 'flex', 382 | }, 383 | 384 | .muscles_fallback { 385 | 'display ': 'table', 386 | }, 387 | }))(MyComponent); 388 | 389 | // good 390 | export default withStyles(({ fallbacks }) => ({ 391 | .muscles { 392 | display: 'flex', 393 | }, 394 | 395 | .muscles_fallback { 396 | [fallbacks.display]: 'table', 397 | }, 398 | }))(MyComponent); 399 | 400 | // good 401 | export default withStyles(({ fallback }) => ({ 402 | .muscles { 403 | display: 'flex', 404 | }, 405 | 406 | .muscles_fallback { 407 | [fallback('display')]: 'table', 408 | }, 409 | }))(MyComponent); 410 | ``` 411 | 412 | - Create as few custom themes as possible. Many applications may only have one theme. 413 | 414 | - Namespace custom theme settings under a nested object with a unique and descriptive key. 415 | 416 | ```js 417 | // bad 418 | ThemedStyleSheet.registerTheme('mySection', { 419 | mySectionPrimaryColor: 'green', 420 | }); 421 | 422 | // good 423 | ThemedStyleSheet.registerTheme('mySection', { 424 | mySection: { 425 | primaryColor: 'green', 426 | }, 427 | }); 428 | ``` 429 | 430 | --- 431 | 432 | CSS puns adapted from [Saijo George](https://saijogeorge.com/css-puns/). 433 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /linters/.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "Be explicit by listing every available rule. https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md", 3 | "comment": "Note that there will be numeric gaps, not every MD number is implemented in markdownlint.", 4 | 5 | "comment": "MD001: Header levels should only increment by one level at a time.", 6 | "header-increment": true, 7 | 8 | "comment": "MD002: First header should be a top level header.", 9 | "first-header-h1": true, 10 | 11 | "comment": "MD003: Header style: start with hashes.", 12 | "header-style": { 13 | "style": "atx" 14 | }, 15 | 16 | "comment": "MD004: Unordered list style", 17 | "ul-style": { 18 | "style": "dash" 19 | }, 20 | 21 | "comment": "MD005: Consistent indentation for list items at the same level.", 22 | "list-indent": true, 23 | 24 | "comment": "MD006: Consider starting bulleted lists at the beginning of the line.", 25 | "ul-start-left": false, 26 | 27 | "comment": "MD007: Unordered list indentation: 2 spaces.", 28 | "ul-indent": { 29 | "indent": 2, 30 | "start_indented": true 31 | }, 32 | 33 | "comment": "MD009: Disallow trailing spaces!", 34 | "no-trailing-spaces": { 35 | "br_spaces": 0, 36 | "comment": "Empty lines inside list items should not be indented.", 37 | "list_item_empty_lines": false 38 | }, 39 | 40 | "comment": "MD010: No hard tabs, not even in code blocks.", 41 | "no-hard-tabs": { 42 | "code_blocks": true 43 | }, 44 | 45 | "comment": "MD011: Prevent reversed link syntax", 46 | "no-reversed-links": true, 47 | 48 | "comment": "MD012: Disallow multiple consecutive blank lines.", 49 | "no-multiple-blanks": { 50 | "maximum": 1 51 | }, 52 | 53 | "comment": "MD013: Line length", 54 | "line-length": false, 55 | 56 | "comment": "MD014: Disallow use of dollar signs($) before commands without showing output.", 57 | "commands-show-output": true, 58 | 59 | "comment": "MD018: Disallow space after hash on atx style header.", 60 | "no-missing-space-atx": true, 61 | 62 | "comment": "MD019: Disallow multiple spaces after hash on atx style header.", 63 | "no-multiple-space-atx": true, 64 | 65 | "comment": "MD020: No space should be inside hashes on closed atx style header.", 66 | "no-missing-space-closed-atx": true, 67 | 68 | "comment": "MD021: Disallow multiple spaces inside hashes on closed atx style header.", 69 | "no-multiple-space-closed-atx": true, 70 | 71 | "comment": "MD022: Headers should be surrounded by blank lines.", 72 | "comment": "Some headers have preceding HTML anchors. Unfortunate that we have to disable this, as it otherwise catches a real problem that trips up some Markdown renderers", 73 | "blanks-around-headers": false, 74 | 75 | "comment": "MD023: Headers must start at the beginning of the line.", 76 | "header-start-left": true, 77 | 78 | "comment": "MD024: Disallow multiple headers with the same content.", 79 | "no-duplicate-header": true, 80 | 81 | "comment": "MD025: Disallow multiple top level headers in the same document.", 82 | "comment": "Gotta have a matching closing brace at the end.", 83 | "single-h1": false, 84 | 85 | "comment": "MD026: Disallow trailing punctuation in header.", 86 | "comment": "You must have a semicolon after the ending closing brace.", 87 | "no-trailing-punctuation": { 88 | "punctuation" : ".,:!?" 89 | }, 90 | "comment": "MD027: Dissalow multiple spaces after blockquote symbol", 91 | "no-multiple-space-blockquote": true, 92 | 93 | "comment": "MD028: Blank line inside blockquote", 94 | "comment": "Some 'Why?' and 'Why not?' blocks are separated by a blank line", 95 | "no-blanks-blockquote": false, 96 | 97 | "comment": "MD029: Ordered list item prefix", 98 | "ol-prefix": { 99 | "style": "one" 100 | }, 101 | 102 | "comment": "MD030: Spaces after list markers", 103 | "list-marker-space": { 104 | "ul_single": 1, 105 | "ol_single": 1, 106 | "ul_multi": 1, 107 | "ol_multi": 1 108 | }, 109 | 110 | "comment": "MD031: Fenced code blocks should be surrounded by blank lines", 111 | "blanks-around-fences": true, 112 | 113 | "comment": "MD032: Lists should be surrounded by blank lines", 114 | "comment": "Some lists have preceding HTML anchors. Unfortunate that we have to disable this, as it otherwise catches a real problem that trips up some Markdown renderers", 115 | "blanks-around-lists": false, 116 | 117 | "comment": "MD033: Disallow inline HTML", 118 | "comment": "HTML is needed for explicit anchors", 119 | "no-inline-html": false, 120 | 121 | "comment": "MD034: No bare URLs should be used", 122 | "no-bare-urls": true, 123 | 124 | "comment": "MD035: Horizontal rule style", 125 | "hr-style": { 126 | "style": "consistent" 127 | }, 128 | 129 | "comment": "MD036: Do not use emphasis instead of a header.", 130 | "no-emphasis-as-header": false, 131 | 132 | "comment": "MD037: Disallow spaces inside emphasis markers.", 133 | "no-space-in-emphasis": true, 134 | 135 | "comment": "MD038: Disallow spaces inside code span elements.", 136 | "no-space-in-code": true, 137 | 138 | "comment": "MD039: Disallow spaces inside link text.", 139 | "no-space-in-links": true, 140 | 141 | "comment": "MD040: Fenced code blocks should have a language specified.", 142 | "fenced-code-language": true, 143 | 144 | "comment": "MD041: First line in file should be a top level header.", 145 | "first-line-h1": true, 146 | 147 | "comment": "MD042: No empty links", 148 | "no-empty-links": true, 149 | 150 | "comment": "MD043: Required header structure.", 151 | "required-headers": false, 152 | 153 | "comment": "MD044: Proper names should have the correct capitalization.", 154 | "proper-names": false 155 | } 156 | -------------------------------------------------------------------------------- /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 https://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 | -------------------------------------------------------------------------------- /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 | "postinstall": "rm -rf node_modules/markdownlint-cli/node_modules/markdownlint", 8 | "install:config": "cd packages/eslint-config-airbnb && npm prune && npm install", 9 | "install:config:base": "cd packages/eslint-config-airbnb-base && npm prune && npm install", 10 | "lint": "markdownlint --config linters/.markdownlint.json README.md */README.md", 11 | "pretest": "npm run --silent lint", 12 | "test": "npm run --silent test:config && npm run --silent test:config:base", 13 | "test:config": "cd packages/eslint-config-airbnb; npm test", 14 | "test:config:base": "cd packages/eslint-config-airbnb-base; npm test", 15 | "pretravis": "npm run --silent lint", 16 | "travis": "npm run --silent travis:config && npm run --silent travis:config:base", 17 | "travis:config": "cd packages/eslint-config-airbnb; npm run travis", 18 | "travis:config:base": "cd packages/eslint-config-airbnb-base; npm run travis" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/airbnb/javascript.git" 23 | }, 24 | "keywords": [ 25 | "style guide", 26 | "lint", 27 | "airbnb", 28 | "es6", 29 | "es2015", 30 | "es2016", 31 | "es2017", 32 | "es2018", 33 | "react", 34 | "jsx" 35 | ], 36 | "author": "Harrison Shoff (https://twitter.com/hshoff)", 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/airbnb/javascript/issues" 40 | }, 41 | "homepage": "https://github.com/airbnb/javascript", 42 | "devDependencies": { 43 | "markdownlint": "^0.29.0", 44 | "markdownlint-cli": "^0.35.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["airbnb"] 3 | } 4 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/.editorconfig: -------------------------------------------------------------------------------- 1 | ../../.editorconfig -------------------------------------------------------------------------------- /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 | "max-len": 0, 9 | }, 10 | } 11 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/.npmrc: -------------------------------------------------------------------------------- 1 | ../../.npmrc -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 15.0.0 / 2021-11-08 2 | ================== 3 | - [breaking] drop eslint < 7, add eslint 8 (#2495) 4 | - [breaking] add `exports` 5 | - [patch] Improve `function-paren-newline` with `multiline-arguments` option (#2471) 6 | - [patch] update default value for complexity (#2420) 7 | - [patch] add disabled `no-unsafe-optional-chaining` rule 8 | - [patch] arthmetic -> arithmetic (#2341) 9 | - [patch] fix spelling of "than" (#2333) 10 | - [patch] add `no-nonoctal-decimal-escape` rule 11 | - [patch] `import/no-extraneous-dependencies`: Add .eslintrc.js to devDeps (#2329) 12 | - [guide] Spread operator => Spread syntax (#2423) 13 | - [guide] add references for eslint rules (#2419) 14 | - [Docs] HTTP => HTTPS (#2489) 15 | - [readme] some updates 16 | - [meta] use `prepublishOnly` script for npm 7+ 17 | - [deps] update `eslint-plugin-import`, `eslint-plugin-react`, `object.entries` 18 | - [dev deps] update `@babel/runtime`, `tape` 19 | 20 | 14.2.1 / 2020-11-06 21 | ================== 22 | - [base] `no-restricted-globals`: add better messages (#2320) 23 | - [base] add new core eslint rules, set to off 24 | - [deps] update `confusing-browser-globals`, `object.assign` 25 | - [deps] update `eslint-plugin-import`, use valid `import/no-cycle` `maxDepth` option (#2250, #2249) 26 | - [dev deps] update `@babel/runtime`, `eslint-find-rules`, `eslint-plugin-import` 27 | 28 | 14.2.0 / 2020-06-10 29 | ================== 30 | - [new] add `eslint` `v7` 31 | - [minor] Disallow multiple empty lines (#2238) 32 | - [minor] Fix typo in no-multiple-empty-lines rule (#2168) 33 | - [patch] Include 'context' exception for `no-param-reassign` (#2230) 34 | - [patch] Allow triple-slash (///) comments (#2197) 35 | - [patch] Disable `prefer-object-spread` for `airbnb-base/legacy` (#2198) 36 | - [deps] update `eslint-plugin-import`, `eslint-plugin-react`, `babel-preset-airbnb`, `eslint-find-rules`, `in-publish`, `tape`, `object.entries` 37 | 38 | 14.1.0 / 2020-03-12 39 | ================== 40 | - [minor] add new disabled rules, update eslint 41 | - [minor] enable `import/no-useless-path-segments` for commonjs (#2113) 42 | - [fix] `whitespace`: only set erroring rules to "warn" 43 | - Fix indentation with JSX Fragments (#2157) 44 | - [patch] `import/no-extraneous-dependencies`: Support karma config files (#2121) 45 | - [readme] normalize multiline word according to merriam-webster (#2138) 46 | - [deps] update `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, `object.entries`, `confusing-browser-globals` 47 | - [dev deps] update `@babel/runtime`, `babel-preset-airbnb`, `safe-publish-latest`, `tape` 48 | - [tests] re-enable eslint rule `prefer-destructuring` internally (#2110) 49 | 50 | 14.0.0 / 2019-08-09 51 | ================== 52 | - [breaking] `no-self-assign`: enable `props` option 53 | - [breaking] enable `no-useless-catch` 54 | - [breaking] enable `max-classes-per-file` 55 | - [breaking] enable `no-misleading-character-class` 56 | - [breaking] enable `no-async-promise-executor` 57 | - [breaking] enable `prefer-object-spread` 58 | - [breaking] `func-name-matching`: enable `considerPropertyDescriptor` option 59 | - [breaking] `padded-blocks`: enable `allowSingleLineBlocks` option (#1255) 60 | - [breaking] `no-multiple-empty-lines`: Restrict empty lines at beginning of file (#2042) 61 | - [breaking] Set 'strict' to 'never' (#1962) 62 | - [breaking] legacy: Enable 'strict' (#1962) 63 | - [breaking] Simplifies `no-mixed-operators` (#1864) 64 | - [breaking] Require parens for arrow function args (#1863) 65 | - [breaking] add eslint v6, drop eslint v4 66 | - [patch] `camelcase`: enable ignoreDestructuring 67 | - [patch] Add markers to spaced-comment block for Flow types (#1966) 68 | - [patch] Do not prefer destructuring for object assignment expression (#1583) 69 | - [deps] update `confusing-browser-globals`, `eslint-plugin-import`, `tape`, `babel-preset-airbnb` 70 | - [dev deps] update babel-related deps to latest 71 | - [dev deps] update `eslint-find-rules`, `eslint-plugin-import` 72 | - [tests] only run tests in non-lint per-package travis job 73 | - [tests] use `eclint` instead of `editorconfig-tools` 74 | 75 | 13.2.0 / 2019-07-01 76 | ================== 77 | - [minor] Enforce dangling underscores in method names (#1907) 78 | - [fix] disable `no-var` in legacy entry point 79 | - [patch] Ignore property modifications of `staticContext` params (#2029) 80 | - [patch] `no-extraneous-dependencies`: Add jest.setup.js to devDeps (#1998) 81 | - [meta] add disabled `prefer-named-capture-group` rule 82 | - [meta] add disabled `no-useless-catch` config 83 | - [deps] Switch to confusing-browser-globals (#1961) 84 | - [deps] update `object.entries`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `tape` 85 | - [docs] correct JavaScript capitalization (#2046) 86 | - [readme] Improve eslint config setup instructions for yarn (#2001) 87 | - [docs] fix docs for whitespace config (#1914, #1871) 88 | 89 | 13.1.0 / 2018-08-13 90 | ================== 91 | - [new] add eslint v5 support (#1834) 92 | - [deps] update `eslint-plugin-import`, `eslint`, `babel-preset-airbnb`, `safe-publish-latest`, `eslint-find-rules` 93 | - [docs] fix typo in readme (#1855) 94 | - [new] update base ecmaVersion to 2018; remove deprecated experimentalObjectRestSpread option 95 | 96 | 13.0.0 / 2018-06-21 97 | ================== 98 | - [breaking] order of import statements is ignored for unassigned imports (#1782) 99 | - [breaking] enable `import/no-cycle`: warn on cyclical dependencies (#1779) 100 | - [breaking] Change import/no-self-import from "off" to "error" (#1770) 101 | - [breaking] Update `object-curly-newline` to match eslint 4.18.0 (#1761) 102 | - [breaking] enable `no-useless-path-segments` (#1743) 103 | - [breaking] Prevent line breaks before and after `=` (#1710) 104 | - [breaking] Add .mjs extension support (#1634) 105 | - [breaking] enable `implicit-arrow-linebreak` 106 | - [breaking] Enables `nonblock-statement-body-position` rule and adds link to guide (#1618) 107 | - [breaking] `no-mixed-operators`: only warn on `**` and `%` mixed with arithmetic operators; removes violation against mixing common math operators. (#1611) 108 | - [breaking] `import/named`: enable 109 | - [breaking] `lines-between-class-members`: set to “always” 110 | - [breaking] `no-else-return`: disallow else-if (#1595) 111 | - [breaking] Enables eslint rule for operator-linebreak 112 | - [new] Adds config entry point with only whitespace rules enabled (#1749, #1751) 113 | - [minor] only allow one newline at the end (#1794) 114 | - [patch] Adjust imports for vue-cli (#1809) 115 | - [patch] Allow devDependencies for `foo_spec.js` naming style (#1732) 116 | - [patch] `function-paren-newline`: change to "consistent" 117 | - [patch] avoid `__mocks__` `no-extraneous-dependencies` check (#1772) 118 | - [patch] Include 'accumulator' exception for `no-param-reassign` (#1768) 119 | - [patch] Set import/extensions to ignorePackages (#1652) 120 | - [patch] properly ignore indentation on jsx 121 | - [patch] `array-callback-return`: enable `allowImplicit` option (#1668) 122 | - [deps] update `eslint`, `eslint-plugin-import` 123 | - [dev deps] update `babel-preset-airbnb`, `tape`, `eslint-find-rules` 124 | - [meta] add ES2015-2018 in npm package keywords (#1587) 125 | - [meta] Add licenses to sub packages (#1746) 126 | - [docs] add `npx` shortcut (#1694) 127 | - [docs] Use HTTPS for links to ESLint documentation (#1628) 128 | - [tests] ensure all entry points parse 129 | 130 | 12.1.0 / 2017-10-16 131 | ================== 132 | - [deps] update `eslint` to `v4.9` 133 | 134 | 12.0.2 / 2017-10-05 135 | ================== 136 | - [deps] update `eslint` 137 | 138 | 12.0.1 / 2017-09-27 139 | ================== 140 | - [fix] ensure all JSX elements are ignored by `indent` (#1569) 141 | - [deps] update `eslint` 142 | 143 | 12.0.0 / 2017-09-02 144 | ================== 145 | - [deps] [breaking] require `eslint` v4 146 | - enable `function-paren-newline`, `for-direction`, `getter-return`, `no-compare-neg-zero`, `semi-style`, `object-curly-newline`, `no-buffer-constructor`, `no-restricted-globals`, `switch-colon-spacing`, `template-tag-spacing`, `prefer-promise-reject-errors`, `prefer-destructuring` 147 | - improve `indent`, `no-multi-spaces`, `no-trailing-spaces`, `no-underscore-dangle` 148 | - [breaking] move `comma-dangle` to Stylistic Issues (#1514) 149 | - [breaking] Rules prohibiting global isNaN, isFinite (#1477) 150 | - [patch] also disallow padding in classes and switches (#1403) 151 | - [patch] support Protractor config files in import/no-extraneous-dependencies (#1543) 152 | 153 | 11.3.2 / 2017-08-22 154 | ================== 155 | - [patch] Add jest.config.js to import/no-extraneous-dependencies devDeps (#1522) 156 | - [patch] Improve Gruntfile glob pattern (#1503) 157 | - [deps] update `eslint` v4, `tape` 158 | - [docs] Specify yarn-specific install instructions (#1511) 159 | 160 | 11.3.1 / 2017-07-24 161 | ================== 162 | - [fix] `legacy`: remove top-level `ecmaFeatures` 163 | 164 | 11.3.0 / 2017-07-23 165 | ================== 166 | - [deps] allow eslint v3 or v4 (#1447) 167 | - [deps] update `eslint-plugin-import` 168 | - [minor] Balanced spacing for inline block comments (#1440) 169 | - [minor] `no-return-assign`: strengthen linting against returning assignments 170 | - [patch] Allow jsx extensions for test files (#1427) 171 | - [patch] `no-restricted-globals`: add confusing globals; leave disabled for now (#1420) 172 | - [patch] Support Protractor config files in import/no-extraneous-dependencies (#1456) 173 | - [docs] Remove TODO in prefer-reflect as it's deprecated (#1452) 174 | - [docs] add yarn instructions (#1463, #1464) 175 | 176 | 11.2.0 / 2017-05-14 177 | ================== 178 | - [minor] Disallow unused global variables 179 | 180 | 11.1.3 / 2017-04-03 181 | ================== 182 | - [patch] add error messages to `no-restricted-syntax` (#1353) 183 | - [deps] update `eslint` 184 | 185 | 11.1.2 / 2017-03-25 186 | ================== 187 | - [patch] `no-param-reassign`: add ignorePropertyModificationsFor (#1325) 188 | - [deps] update `eslint` 189 | 190 | 11.1.1 / 2017-03-03 191 | ================== 192 | - [deps] update `eslint` 193 | - [patch] enable `ignoreRestSiblings` in `no-unused-vars` 194 | 195 | 11.1.0 / 2017-01-08 196 | ================== 197 | - [minor] enable `no-multi-assign` 198 | - [deps] update `eslint`, `babel-preset-airbnb` 199 | - Update a deprecated option (`eqeqeq`) (#1244) 200 | 201 | 11.0.1 / 2017-01-08 202 | ================== 203 | - [deps] update `eslint` 204 | - [docs] add note about `install-peerdeps` (#1234) 205 | - [docs] Updated instructions to support non-bash users (#1214) 206 | 207 | 11.0.0 / 2016-12-11 208 | ================== 209 | - [breaking] enable `no-await-in-loop` 210 | - [patch] disable `no-duplicate-imports` rule (#1188, #1195, #1054) 211 | - [patch] `import/no-extraneous-dependencies`: add some comments to ignore patterns 212 | - [patch] add `import/no-extraneous-dependencies` ignore patterns for test files (#1174) 213 | - [patch] `import/no-extraneous-dependencies`: added ignore patterns for config files (#1168) 214 | - [deps] update `eslint`, `eslint-plugin-import`, `tape` 215 | 216 | 10.0.1 / 2016-11-07 217 | ================== 218 | - [fix] legacy config should not require `**` 219 | 220 | 10.0.0 / 2016-11-06 221 | ================== 222 | - [breaking] prefer `**` over `Math.pow` 223 | - [breaking] `comma-dangle`: require trailing commas for functions 224 | - [breaking] enable `no-useless-return` 225 | - [breaking] tighten up `indent` 226 | - [breaking] tighten up `spaced-comment` 227 | - [breaking] enable `import/no-named-default` 228 | - [patch] loosen `max-len` with `ignoreRegExpLiterals` option 229 | - [patch] loosen `no-extraneous-dependencies` for test files (#959, #1089) 230 | - [deps] update `eslint`, `eslint-plugin-import` 231 | - [dev deps] update `eslint-find-rules` 232 | - [Tests] on `node` `v7` 233 | 234 | 9.0.0 / 2016-10-16 235 | ================== 236 | - [breaking] Add `ForOfStatement` to `no-restricted-syntax` (#1122, #1134) 237 | - [breaking] enable `import/no-webpack-loader-syntax` (#1123) 238 | - [breaking] [deps] update `eslint` to `v3.8.0` (#1132) 239 | - [breaking] [deps] update `eslint-plugin-import` to v2 (#1101) 240 | - [patch] `new-cap`: add immutable.js exceptions 241 | - [docs] ensure latest version of config is installed 242 | - [dev deps] update `babel-preset-airbnb`, `eslint`, `eslint-find-rules`, `tape`, `safe-publish-latest` 243 | 244 | 8.0.0 / 2016-09-24 245 | ================== 246 | - [breaking] enable rules: `no-restricted-properties`, `prefer-numeric-literals`, `lines-around-directive`, `import/extensions`, `import/no-absolute-path`, `import/no-dynamic-require` 247 | 248 | 7.2.0 / 2016-09-23 249 | ================== 250 | - [new] set `ecmaVersion` to 2017; enable object rest/spread; update `babel-preset-airbnb` 251 | - [patch] fix category of `no-restricted-properties` 252 | - [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules`, `safe-publish-latest` 253 | 254 | 7.1.0 / 2016-09-11 255 | ================== 256 | - [minor] enable `arrow-parens` rule 257 | 258 | 7.0.1 / 2016-09-10 259 | ================== 260 | - [patch] loosen `max-len` by ignoring strings 261 | - [deps] update to `eslint` `v3.5.0` 262 | 263 | 7.0.0 / 2016-09-06 264 | ================== 265 | - [breaking] Add no-plusplus in style.js and added explanation in README (#1012) 266 | 267 | 6.0.0 / 2016-09-06 268 | ================== 269 | - [breaking] `valid-typeof`: enable `requireStringLiterals` option 270 | - [breaking] enable `class-methods-use-this` 271 | - [breaking] enable `symbol-description` 272 | - [breaking] enable `no-bitwise` 273 | - [breaking] enable `no-tabs` 274 | - [breaking] enable `func-call-spacing` 275 | - [breaking] enable `no-template-curly-in-string` 276 | - [patch] remove redundant `DebuggerStatement` from `no-restricted-syntax` (#1031) 277 | - [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-import` 278 | - Update `ecmaVersion` to `2016` 279 | 280 | 5.0.3 / 2016-08-21 281 | ================== 282 | - [fix] correct `import/extensions` list (#1013) 283 | - [refactor] Changed ESLint rule configs to use 'off', 'warn', and 'error' instead of numbers for better readability (#946) 284 | - [deps] update `eslint`, `eslint-plugin-react` 285 | 286 | 5.0.2 / 2016-08-12 287 | ================== 288 | - [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-import` 289 | - [tests] add `safe-publish-latest` to `prepublish` 290 | 291 | 5.0.1 / 2016-07-29 292 | ================== 293 | - [patch] `no-unused-expressions`: flesh out options 294 | - [deps] update `eslint` to `v3.2`, `eslint-plugin-import` to `v1.12` 295 | - [tests] improve prepublish script 296 | 297 | 5.0.0 / 2016-07-24 298 | ================== 299 | - [breaking] enable `import/newline-after-import` 300 | - [breaking] enable overlooked rules: `linebreak-style`, `new-parens`, `no-continue`, `no-lonely-if`, `operator-assignment`, `space-unary-ops`, `dot-location`, `no-extra-boolean-cast`, `no-this-before-super`, `require-yield`, `no-path-concat`, `no-label-var`, `no-void`, `constructor-super`, `prefer-spread`, `no-new-require`, `no-undef-init`, `no-unexpected-multiline` 301 | - [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-import`, `babel-tape-runner`; add `babel-preset-airbnb` 302 | - [patch] flesh out defaults: `jsx-quotes` 303 | - [docs] update the peer dep install command to dynamically look up the right version numbers when installing peer deps 304 | - [tests] fix prepublish scripts 305 | 306 | 4.0.2 / 2016-07-14 307 | ================== 308 | - [fix] repair accidental comma-dangle change 309 | 310 | 4.0.1 / 2016-07-14 (unpublished) 311 | ================== 312 | - [fix] Prevent trailing commas in the legacy config (#950) 313 | - [deps] update `eslint-plugin-import` 314 | 315 | 4.0.0 / 2016-07-02 316 | ================== 317 | - [breaking] [deps] update `eslint` to v3; drop support for < node 4 318 | - [breaking] enable `rest-spread-spacing` rule 319 | - [breaking] enable `no-mixed-operators` rule 320 | - [breaking] enable `import` rules: `no-named-as-default`, `no-named-as-default-member`, `no-extraneous-dependencies` 321 | - [breaking] enable `object-property-newline` rule 322 | - [breaking] enable `no-prototype-builtins` rule 323 | - [breaking] enable `no-useless-rename` rule 324 | - [breaking] enable `unicode-bom` rule 325 | - [breaking] Enforce proper generator star spacing (#887) 326 | - [breaking] Enable imports/imports-first rule (#882) 327 | - [breaking] re-order rules; put import rules in separate file (#881) 328 | - [patch] `newline-per-chained-call`: bump the limit to 4 329 | - [patch] `object-shorthand`: do not warn when the concise form would have a string literal as a name 330 | - [patch] Loosen `prefer-const` to not warn when the variable is “read” before being assigned to 331 | - [refactor] fix quoting of rule properties (#885) 332 | - [refactor] `quotes`: Use object option form rather than deprecated string form. 333 | - [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules`, `tape` 334 | - [tests] Only run `eslint-find-rules` on prepublish, not in tests 335 | 336 | 3.0.1 / 2016-05-08 337 | ================== 338 | - [patch] re-disable `no-extra-parens` (#869, #867) 339 | 340 | 3.0.0 / 2016-05-07 341 | ================== 342 | - [breaking] enable `import/no-mutable-exports` 343 | - [breaking] enable `no-class-assign` rule, to pair with `no-func-assign` 344 | - [breaking] widen `no-extra-parens` to include everything, except `nestedBinaryExpressions` 345 | - [breaking] Re-enabling `newline-per-chained-call` (#748) 346 | - [minor] enable `import/no-amd` 347 | - [patch] enable `import/no-duplicates` 348 | - [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules` 349 | 350 | 2.0.0 / 2016-04-29 351 | ================== 352 | - [breaking] enable `no-unsafe-finally` rule 353 | - [semver-minor] enable `no-useless-computed-key` rule 354 | - [deps] update `eslint`, `eslint-plugin-import` 355 | 356 | 1.0.4 / 2016-04-26 357 | ================== 358 | - [deps] update `eslint-find-rules`, `eslint-plugin-import` 359 | 360 | 1.0.3 / 2016-04-21 361 | ================== 362 | - [patch: loosen rules] Allow empty class/object methods 363 | 364 | 1.0.2 / 2016-04-20 365 | ================== 366 | - [patch: loosen rules] Allow `break` (#840) 367 | 368 | 1.0.1 / 2016-04-19 369 | ================== 370 | - [patch: loosen rules] Allow `== null` (#542) 371 | 372 | 1.0.0 / 2016-04-19 373 | ================== 374 | - Initial commmit; moved content over from `eslint-config-airbnb` package. 375 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012 Airbnb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-airbnb-base [![Version Badge][npm-version-svg]][package-url] 2 | 3 | [![npm version](https://badge.fury.io/js/eslint-config-airbnb-base.svg)][package-url] 4 | 5 | [![github actions][actions-image]][actions-url] 6 | [![License][license-image]][license-url] 7 | [![Downloads][downloads-image]][downloads-url] 8 | 9 | This package provides Airbnb's base JS .eslintrc (without React plugins) as an extensible shared config. 10 | 11 | ## Usage 12 | 13 | We export two ESLint configurations for your usage. 14 | 15 | ### eslint-config-airbnb-base 16 | 17 | Our default export contains all of our ESLint rules, including ECMAScript 6+. It requires `eslint` and `eslint-plugin-import`. 18 | 19 | 1. Install the correct versions of each package, which are listed by the command: 20 | 21 | ```sh 22 | npm info "eslint-config-airbnb-base@latest" peerDependencies 23 | ``` 24 | 25 | If using **npm 5+**, use this shortcut 26 | 27 | ```sh 28 | npx install-peerdeps --dev eslint-config-airbnb-base 29 | ``` 30 | 31 | If using **yarn**, you can also use the shortcut described above if you have npm 5+ installed on your machine, as the command will detect that you are using yarn and will act accordingly. 32 | Otherwise, run `npm info "eslint-config-airbnb-base@latest" peerDependencies` to list the peer dependencies and versions, then run `yarn add --dev @` for each listed peer dependency. 33 | 34 | 35 | If using **npm < 5**, Linux/OSX users can run 36 | 37 | ```sh 38 | ( 39 | export PKG=eslint-config-airbnb-base; 40 | npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest" 41 | ) 42 | ``` 43 | 44 | Which produces and runs a command like: 45 | 46 | ```sh 47 | npm install --save-dev eslint-config-airbnb-base eslint@^#.#.# eslint-plugin-import@^#.#.# 48 | ``` 49 | 50 | If using **npm < 5**, Windows users can either install all the peer dependencies manually, or use the [install-peerdeps](https://github.com/nathanhleung/install-peerdeps) cli tool. 51 | 52 | ```sh 53 | npm install -g install-peerdeps 54 | install-peerdeps --dev eslint-config-airbnb-base 55 | ``` 56 | 57 | The cli will produce and run a command like: 58 | 59 | ```sh 60 | npm install --save-dev eslint-config-airbnb-base eslint@^#.#.# eslint-plugin-import@^#.#.# 61 | ``` 62 | 63 | 2. Add `"extends": "airbnb-base"` to your .eslintrc. 64 | 65 | ### eslint-config-airbnb-base/legacy 66 | 67 | Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`. 68 | 69 | 1. Install the correct versions of each package, which are listed by the command: 70 | 71 | ```sh 72 | npm info "eslint-config-airbnb-base@latest" peerDependencies 73 | ``` 74 | 75 | Linux/OSX users can run 76 | ```sh 77 | ( 78 | export PKG=eslint-config-airbnb-base; 79 | npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG" 80 | ) 81 | ``` 82 | 83 | Which produces and runs a command like: 84 | 85 | ```sh 86 | npm install --save-dev eslint-config-airbnb-base eslint@^#.#.# eslint-plugin-import@^#.#.# 87 | ``` 88 | 89 | 2. Add `"extends": "airbnb-base/legacy"` to your .eslintrc 90 | 91 | 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](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information. 92 | 93 | ### eslint-config-airbnb-base/whitespace 94 | 95 | This entry point only errors on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/whitespace.js). 96 | 97 | ## Improving this config 98 | 99 | 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? 100 | 101 | You can run tests with `npm test`. 102 | 103 | You can make sure this module lints with itself using `npm run lint`. 104 | 105 | [package-url]: https://npmjs.org/package/eslint-config-airbnb-base 106 | [npm-version-svg]: https://versionbadg.es/airbnb/javascript.svg 107 | [license-image]: https://img.shields.io/npm/l/eslint-config-airbnb-base.svg 108 | [license-url]: LICENSE.md 109 | [downloads-image]: https://img.shields.io/npm/dm/eslint-config-airbnb-base.svg 110 | [downloads-url]: https://npm-stat.com/charts.html?package=eslint-config-airbnb-base 111 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/airbnb/javascript 112 | [actions-url]: https://github.com/airbnb/javascript/actions 113 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | './rules/best-practices', 4 | './rules/errors', 5 | './rules/node', 6 | './rules/style', 7 | './rules/variables', 8 | './rules/es6', 9 | './rules/imports', 10 | './rules/strict', 11 | ].map(require.resolve), 12 | parserOptions: { 13 | ecmaVersion: 2018, 14 | sourceType: 'module', 15 | }, 16 | rules: {}, 17 | }; 18 | -------------------------------------------------------------------------------- /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 | rules: { 17 | 'comma-dangle': ['error', 'never'], 18 | 'prefer-numeric-literals': 'off', 19 | 'no-restricted-properties': ['error', { 20 | object: 'arguments', 21 | property: 'callee', 22 | message: 'arguments.callee is deprecated', 23 | }, { 24 | property: '__defineGetter__', 25 | message: 'Please use Object.defineProperty instead.', 26 | }, { 27 | property: '__defineSetter__', 28 | message: 'Please use Object.defineProperty instead.', 29 | }], 30 | 'no-var': 'off', 31 | 'prefer-object-spread': 'off', 32 | strict: ['error', 'safe'], 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-airbnb-base", 3 | "version": "15.0.0", 4 | "description": "Airbnb's base JS ESLint config, following our styleguide", 5 | "main": "index.js", 6 | "exports": { 7 | ".": "./index.js", 8 | "./legacy": "./legacy.js", 9 | "./whitespace": "./whitespace.js", 10 | "./rules/best-practices": "./rules/best-practices.js", 11 | "./rules/es6": "./rules/es6.js", 12 | "./rules/node": "./rules/node.js", 13 | "./rules/style": "./rules/style.js", 14 | "./rules/errors": "./rules/errors.js", 15 | "./rules/imports": "./rules/imports.js", 16 | "./rules/strict": "./rules/strict.js", 17 | "./rules/variables": "./rules/variables.js", 18 | "./package.json": "./package.json" 19 | }, 20 | "scripts": { 21 | "prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", 22 | "lint": "eslint --report-unused-disable-directives .", 23 | "pretests-only": "node ./test/requires", 24 | "tests-only": "babel-tape-runner ./test/test-*.js", 25 | "prepublishOnly": "eslint-find-rules --unused && npm test && safe-publish-latest", 26 | "prepublish": "not-in-publish || npm run prepublishOnly", 27 | "pretest": "npm run --silent lint", 28 | "test": "npm run --silent tests-only", 29 | "pretravis": ":", 30 | "travis": "npm run --silent tests-only", 31 | "posttravis": ":" 32 | }, 33 | "repository": { 34 | "type": "git", 35 | "url": "https://github.com/airbnb/javascript" 36 | }, 37 | "keywords": [ 38 | "eslint", 39 | "eslintconfig", 40 | "config", 41 | "airbnb", 42 | "javascript", 43 | "styleguide", 44 | "es2015", 45 | "es2016", 46 | "es2017", 47 | "es2018" 48 | ], 49 | "author": "Jake Teton-Landis (https://twitter.com/@jitl)", 50 | "contributors": [ 51 | { 52 | "name": "Jake Teton-Landis", 53 | "url": "https://twitter.com/jitl" 54 | }, 55 | { 56 | "name": "Jordan Harband", 57 | "email": "ljharb@gmail.com", 58 | "url": "http://ljharb.codes" 59 | }, 60 | { 61 | "name": "Harrison Shoff", 62 | "url": "https://twitter.com/hshoff" 63 | } 64 | ], 65 | "license": "MIT", 66 | "bugs": { 67 | "url": "https://github.com/airbnb/javascript/issues" 68 | }, 69 | "homepage": "https://github.com/airbnb/javascript", 70 | "devDependencies": { 71 | "@babel/runtime": "^7.25.6", 72 | "babel-preset-airbnb": "^4.5.0", 73 | "babel-tape-runner": "^3.0.0", 74 | "eclint": "^2.8.1", 75 | "eslint": "^7.32.0 || ^8.2.0", 76 | "eslint-find-rules": "^4.1.0", 77 | "eslint-plugin-import": "^2.30.0", 78 | "in-publish": "^2.0.1", 79 | "safe-publish-latest": "^2.0.0", 80 | "tape": "^5.9.0" 81 | }, 82 | "peerDependencies": { 83 | "eslint": "^7.32.0 || ^8.2.0", 84 | "eslint-plugin-import": "^2.30.0" 85 | }, 86 | "engines": { 87 | "node": "^10.12.0 || >=12.0.0" 88 | }, 89 | "dependencies": { 90 | "confusing-browser-globals": "^1.0.11" 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/best-practices.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // enforces getter/setter pairs in objects 4 | // https://eslint.org/docs/rules/accessor-pairs 5 | 'accessor-pairs': 'off', 6 | 7 | // enforces return statements in callbacks of array's methods 8 | // https://eslint.org/docs/rules/array-callback-return 9 | 'array-callback-return': ['error', { allowImplicit: true }], 10 | 11 | // treat var statements as if they were block scoped 12 | // https://eslint.org/docs/rules/block-scoped-var 13 | 'block-scoped-var': 'error', 14 | 15 | // specify the maximum cyclomatic complexity allowed in a program 16 | // https://eslint.org/docs/rules/complexity 17 | complexity: ['off', 20], 18 | 19 | // enforce that class methods use "this" 20 | // https://eslint.org/docs/rules/class-methods-use-this 21 | 'class-methods-use-this': ['error', { 22 | exceptMethods: [], 23 | }], 24 | 25 | // require return statements to either always or never specify values 26 | // https://eslint.org/docs/rules/consistent-return 27 | 'consistent-return': 'error', 28 | 29 | // specify curly brace conventions for all control statements 30 | // https://eslint.org/docs/rules/curly 31 | curly: ['error', 'multi-line'], // multiline 32 | 33 | // require default case in switch statements 34 | // https://eslint.org/docs/rules/default-case 35 | 'default-case': ['error', { commentPattern: '^no default$' }], 36 | 37 | // Enforce default clauses in switch statements to be last 38 | // https://eslint.org/docs/rules/default-case-last 39 | 'default-case-last': 'error', 40 | 41 | // https://eslint.org/docs/rules/default-param-last 42 | 'default-param-last': 'error', 43 | 44 | // encourages use of dot notation whenever possible 45 | // https://eslint.org/docs/rules/dot-notation 46 | 'dot-notation': ['error', { allowKeywords: true }], 47 | 48 | // enforces consistent newlines before or after dots 49 | // https://eslint.org/docs/rules/dot-location 50 | 'dot-location': ['error', 'property'], 51 | 52 | // require the use of === and !== 53 | // https://eslint.org/docs/rules/eqeqeq 54 | eqeqeq: ['error', 'always', { null: 'ignore' }], 55 | 56 | // Require grouped accessor pairs in object literals and classes 57 | // https://eslint.org/docs/rules/grouped-accessor-pairs 58 | 'grouped-accessor-pairs': 'error', 59 | 60 | // make sure for-in loops have an if statement 61 | // https://eslint.org/docs/rules/guard-for-in 62 | 'guard-for-in': 'error', 63 | 64 | // enforce a maximum number of classes per file 65 | // https://eslint.org/docs/rules/max-classes-per-file 66 | 'max-classes-per-file': ['error', 1], 67 | 68 | // disallow the use of alert, confirm, and prompt 69 | // https://eslint.org/docs/rules/no-alert 70 | // TODO: enable, semver-major 71 | 'no-alert': 'warn', 72 | 73 | // disallow use of arguments.caller or arguments.callee 74 | // https://eslint.org/docs/rules/no-caller 75 | 'no-caller': 'error', 76 | 77 | // disallow lexical declarations in case/default clauses 78 | // https://eslint.org/docs/rules/no-case-declarations 79 | 'no-case-declarations': 'error', 80 | 81 | // Disallow returning value in constructor 82 | // https://eslint.org/docs/rules/no-constructor-return 83 | 'no-constructor-return': 'error', 84 | 85 | // disallow division operators explicitly at beginning of regular expression 86 | // https://eslint.org/docs/rules/no-div-regex 87 | 'no-div-regex': 'off', 88 | 89 | // disallow else after a return in an if 90 | // https://eslint.org/docs/rules/no-else-return 91 | 'no-else-return': ['error', { allowElseIf: false }], 92 | 93 | // disallow empty functions, except for standalone funcs/arrows 94 | // https://eslint.org/docs/rules/no-empty-function 95 | 'no-empty-function': ['error', { 96 | allow: [ 97 | 'arrowFunctions', 98 | 'functions', 99 | 'methods', 100 | ] 101 | }], 102 | 103 | // disallow empty destructuring patterns 104 | // https://eslint.org/docs/rules/no-empty-pattern 105 | 'no-empty-pattern': 'error', 106 | 107 | // Disallow empty static blocks 108 | // https://eslint.org/docs/latest/rules/no-empty-static-block 109 | // TODO: semver-major, enable 110 | 'no-empty-static-block': 'off', 111 | 112 | // disallow comparisons to null without a type-checking operator 113 | // https://eslint.org/docs/rules/no-eq-null 114 | 'no-eq-null': 'off', 115 | 116 | // disallow use of eval() 117 | // https://eslint.org/docs/rules/no-eval 118 | 'no-eval': 'error', 119 | 120 | // disallow adding to native types 121 | // https://eslint.org/docs/rules/no-extend-native 122 | 'no-extend-native': 'error', 123 | 124 | // disallow unnecessary function binding 125 | // https://eslint.org/docs/rules/no-extra-bind 126 | 'no-extra-bind': 'error', 127 | 128 | // disallow Unnecessary Labels 129 | // https://eslint.org/docs/rules/no-extra-label 130 | 'no-extra-label': 'error', 131 | 132 | // disallow fallthrough of case statements 133 | // https://eslint.org/docs/rules/no-fallthrough 134 | 'no-fallthrough': 'error', 135 | 136 | // disallow the use of leading or trailing decimal points in numeric literals 137 | // https://eslint.org/docs/rules/no-floating-decimal 138 | 'no-floating-decimal': 'error', 139 | 140 | // disallow reassignments of native objects or read-only globals 141 | // https://eslint.org/docs/rules/no-global-assign 142 | 'no-global-assign': ['error', { exceptions: [] }], 143 | 144 | // deprecated in favor of no-global-assign 145 | // https://eslint.org/docs/rules/no-native-reassign 146 | 'no-native-reassign': 'off', 147 | 148 | // disallow implicit type conversions 149 | // https://eslint.org/docs/rules/no-implicit-coercion 150 | 'no-implicit-coercion': ['off', { 151 | boolean: false, 152 | number: true, 153 | string: true, 154 | allow: [], 155 | }], 156 | 157 | // disallow var and named functions in global scope 158 | // https://eslint.org/docs/rules/no-implicit-globals 159 | 'no-implicit-globals': 'off', 160 | 161 | // disallow use of eval()-like methods 162 | // https://eslint.org/docs/rules/no-implied-eval 163 | 'no-implied-eval': 'error', 164 | 165 | // disallow this keywords outside of classes or class-like objects 166 | // https://eslint.org/docs/rules/no-invalid-this 167 | 'no-invalid-this': 'off', 168 | 169 | // disallow usage of __iterator__ property 170 | // https://eslint.org/docs/rules/no-iterator 171 | 'no-iterator': 'error', 172 | 173 | // disallow use of labels for anything other than loops and switches 174 | // https://eslint.org/docs/rules/no-labels 175 | 'no-labels': ['error', { allowLoop: false, allowSwitch: false }], 176 | 177 | // disallow unnecessary nested blocks 178 | // https://eslint.org/docs/rules/no-lone-blocks 179 | 'no-lone-blocks': 'error', 180 | 181 | // disallow creation of functions within loops 182 | // https://eslint.org/docs/rules/no-loop-func 183 | 'no-loop-func': 'error', 184 | 185 | // disallow magic numbers 186 | // https://eslint.org/docs/rules/no-magic-numbers 187 | 'no-magic-numbers': ['off', { 188 | ignore: [], 189 | ignoreArrayIndexes: true, 190 | enforceConst: true, 191 | detectObjects: false, 192 | }], 193 | 194 | // disallow use of multiple spaces 195 | // https://eslint.org/docs/rules/no-multi-spaces 196 | 'no-multi-spaces': ['error', { 197 | ignoreEOLComments: false, 198 | }], 199 | 200 | // disallow use of multiline strings 201 | // https://eslint.org/docs/rules/no-multi-str 202 | 'no-multi-str': 'error', 203 | 204 | // disallow use of new operator when not part of the assignment or comparison 205 | // https://eslint.org/docs/rules/no-new 206 | 'no-new': 'error', 207 | 208 | // disallow use of new operator for Function object 209 | // https://eslint.org/docs/rules/no-new-func 210 | 'no-new-func': 'error', 211 | 212 | // disallows creating new instances of String, Number, and Boolean 213 | // https://eslint.org/docs/rules/no-new-wrappers 214 | 'no-new-wrappers': 'error', 215 | 216 | // Disallow \8 and \9 escape sequences in string literals 217 | // https://eslint.org/docs/rules/no-nonoctal-decimal-escape 218 | 'no-nonoctal-decimal-escape': 'error', 219 | 220 | // Disallow calls to the Object constructor without an argument 221 | // https://eslint.org/docs/latest/rules/no-object-constructor 222 | // TODO: enable, semver-major 223 | 'no-object-constructor': 'off', 224 | 225 | // disallow use of (old style) octal literals 226 | // https://eslint.org/docs/rules/no-octal 227 | 'no-octal': 'error', 228 | 229 | // disallow use of octal escape sequences in string literals, such as 230 | // var foo = 'Copyright \251'; 231 | // https://eslint.org/docs/rules/no-octal-escape 232 | 'no-octal-escape': 'error', 233 | 234 | // disallow reassignment of function parameters 235 | // disallow parameter object manipulation except for specific exclusions 236 | // rule: https://eslint.org/docs/rules/no-param-reassign.html 237 | 'no-param-reassign': ['error', { 238 | props: true, 239 | ignorePropertyModificationsFor: [ 240 | 'acc', // for reduce accumulators 241 | 'accumulator', // for reduce accumulators 242 | 'e', // for e.returnvalue 243 | 'ctx', // for Koa routing 244 | 'context', // for Koa routing 245 | 'req', // for Express requests 246 | 'request', // for Express requests 247 | 'res', // for Express responses 248 | 'response', // for Express responses 249 | '$scope', // for Angular 1 scopes 250 | 'staticContext', // for ReactRouter context 251 | ] 252 | }], 253 | 254 | // disallow usage of __proto__ property 255 | // https://eslint.org/docs/rules/no-proto 256 | 'no-proto': 'error', 257 | 258 | // disallow declaring the same variable more than once 259 | // https://eslint.org/docs/rules/no-redeclare 260 | 'no-redeclare': 'error', 261 | 262 | // disallow certain object properties 263 | // https://eslint.org/docs/rules/no-restricted-properties 264 | 'no-restricted-properties': ['error', { 265 | object: 'arguments', 266 | property: 'callee', 267 | message: 'arguments.callee is deprecated', 268 | }, { 269 | object: 'global', 270 | property: 'isFinite', 271 | message: 'Please use Number.isFinite instead', 272 | }, { 273 | object: 'self', 274 | property: 'isFinite', 275 | message: 'Please use Number.isFinite instead', 276 | }, { 277 | object: 'window', 278 | property: 'isFinite', 279 | message: 'Please use Number.isFinite instead', 280 | }, { 281 | object: 'global', 282 | property: 'isNaN', 283 | message: 'Please use Number.isNaN instead', 284 | }, { 285 | object: 'self', 286 | property: 'isNaN', 287 | message: 'Please use Number.isNaN instead', 288 | }, { 289 | object: 'window', 290 | property: 'isNaN', 291 | message: 'Please use Number.isNaN instead', 292 | }, { 293 | property: '__defineGetter__', 294 | message: 'Please use Object.defineProperty instead.', 295 | }, { 296 | property: '__defineSetter__', 297 | message: 'Please use Object.defineProperty instead.', 298 | }, { 299 | object: 'Math', 300 | property: 'pow', 301 | message: 'Use the exponentiation operator (**) instead.', 302 | }], 303 | 304 | // disallow use of assignment in return statement 305 | // https://eslint.org/docs/rules/no-return-assign 306 | 'no-return-assign': ['error', 'always'], 307 | 308 | // disallow redundant `return await` 309 | // https://eslint.org/docs/rules/no-return-await 310 | 'no-return-await': 'error', 311 | 312 | // disallow use of `javascript:` urls. 313 | // https://eslint.org/docs/rules/no-script-url 314 | 'no-script-url': 'error', 315 | 316 | // disallow self assignment 317 | // https://eslint.org/docs/rules/no-self-assign 318 | 'no-self-assign': ['error', { 319 | props: true, 320 | }], 321 | 322 | // disallow comparisons where both sides are exactly the same 323 | // https://eslint.org/docs/rules/no-self-compare 324 | 'no-self-compare': 'error', 325 | 326 | // disallow use of comma operator 327 | // https://eslint.org/docs/rules/no-sequences 328 | 'no-sequences': 'error', 329 | 330 | // restrict what can be thrown as an exception 331 | // https://eslint.org/docs/rules/no-throw-literal 332 | 'no-throw-literal': 'error', 333 | 334 | // disallow unmodified conditions of loops 335 | // https://eslint.org/docs/rules/no-unmodified-loop-condition 336 | 'no-unmodified-loop-condition': 'off', 337 | 338 | // disallow usage of expressions in statement position 339 | // https://eslint.org/docs/rules/no-unused-expressions 340 | 'no-unused-expressions': ['error', { 341 | allowShortCircuit: false, 342 | allowTernary: false, 343 | allowTaggedTemplates: false, 344 | }], 345 | 346 | // disallow unused labels 347 | // https://eslint.org/docs/rules/no-unused-labels 348 | 'no-unused-labels': 'error', 349 | 350 | // disallow unnecessary .call() and .apply() 351 | // https://eslint.org/docs/rules/no-useless-call 352 | 'no-useless-call': 'off', 353 | 354 | // Disallow unnecessary catch clauses 355 | // https://eslint.org/docs/rules/no-useless-catch 356 | 'no-useless-catch': 'error', 357 | 358 | // disallow useless string concatenation 359 | // https://eslint.org/docs/rules/no-useless-concat 360 | 'no-useless-concat': 'error', 361 | 362 | // disallow unnecessary string escaping 363 | // https://eslint.org/docs/rules/no-useless-escape 364 | 'no-useless-escape': 'error', 365 | 366 | // disallow redundant return; keywords 367 | // https://eslint.org/docs/rules/no-useless-return 368 | 'no-useless-return': 'error', 369 | 370 | // disallow use of void operator 371 | // https://eslint.org/docs/rules/no-void 372 | 'no-void': 'error', 373 | 374 | // disallow usage of configurable warning terms in comments: e.g. todo 375 | // https://eslint.org/docs/rules/no-warning-comments 376 | 'no-warning-comments': ['off', { terms: ['todo', 'fixme', 'xxx'], location: 'start' }], 377 | 378 | // disallow use of the with statement 379 | // https://eslint.org/docs/rules/no-with 380 | 'no-with': 'error', 381 | 382 | // require using Error objects as Promise rejection reasons 383 | // https://eslint.org/docs/rules/prefer-promise-reject-errors 384 | 'prefer-promise-reject-errors': ['error', { allowEmptyReject: true }], 385 | 386 | // Suggest using named capture group in regular expression 387 | // https://eslint.org/docs/rules/prefer-named-capture-group 388 | 'prefer-named-capture-group': 'off', 389 | 390 | // Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() 391 | // https://eslint.org/docs/rules/prefer-object-has-own 392 | // TODO: semver-major: enable thus rule, once eslint v8.5.0 is required 393 | 'prefer-object-has-own': 'off', 394 | 395 | // https://eslint.org/docs/rules/prefer-regex-literals 396 | 'prefer-regex-literals': ['error', { 397 | disallowRedundantWrapping: true, 398 | }], 399 | 400 | // require use of the second argument for parseInt() 401 | // https://eslint.org/docs/rules/radix 402 | radix: 'error', 403 | 404 | // require `await` in `async function` (note: this is a horrible rule that should never be used) 405 | // https://eslint.org/docs/rules/require-await 406 | 'require-await': 'off', 407 | 408 | // Enforce the use of u flag on RegExp 409 | // https://eslint.org/docs/rules/require-unicode-regexp 410 | 'require-unicode-regexp': 'off', 411 | 412 | // requires to declare all vars on top of their containing scope 413 | // https://eslint.org/docs/rules/vars-on-top 414 | 'vars-on-top': 'error', 415 | 416 | // require immediate function invocation to be wrapped in parentheses 417 | // https://eslint.org/docs/rules/wrap-iife.html 418 | 'wrap-iife': ['error', 'outside', { functionPrototypeMethods: false }], 419 | 420 | // require or disallow Yoda conditions 421 | // https://eslint.org/docs/rules/yoda 422 | yoda: 'error' 423 | } 424 | }; 425 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/errors.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // Enforce “for” loop update clause moving the counter in the right direction 4 | // https://eslint.org/docs/rules/for-direction 5 | 'for-direction': 'error', 6 | 7 | // Enforces that a return statement is present in property getters 8 | // https://eslint.org/docs/rules/getter-return 9 | 'getter-return': ['error', { allowImplicit: true }], 10 | 11 | // disallow using an async function as a Promise executor 12 | // https://eslint.org/docs/rules/no-async-promise-executor 13 | 'no-async-promise-executor': 'error', 14 | 15 | // Disallow await inside of loops 16 | // https://eslint.org/docs/rules/no-await-in-loop 17 | 'no-await-in-loop': 'error', 18 | 19 | // Disallow comparisons to negative zero 20 | // https://eslint.org/docs/rules/no-compare-neg-zero 21 | 'no-compare-neg-zero': 'error', 22 | 23 | // disallow assignment in conditional expressions 24 | 'no-cond-assign': ['error', 'always'], 25 | 26 | // disallow use of console 27 | 'no-console': 'warn', 28 | 29 | // Disallows expressions where the operation doesn't affect the value 30 | // https://eslint.org/docs/rules/no-constant-binary-expression 31 | // TODO: semver-major, enable 32 | 'no-constant-binary-expression': 'off', 33 | 34 | // disallow use of constant expressions in conditions 35 | 'no-constant-condition': 'warn', 36 | 37 | // disallow control characters in regular expressions 38 | 'no-control-regex': 'error', 39 | 40 | // disallow use of debugger 41 | 'no-debugger': 'error', 42 | 43 | // disallow duplicate arguments in functions 44 | 'no-dupe-args': 'error', 45 | 46 | // Disallow duplicate conditions in if-else-if chains 47 | // https://eslint.org/docs/rules/no-dupe-else-if 48 | 'no-dupe-else-if': 'error', 49 | 50 | // disallow duplicate keys when creating object literals 51 | 'no-dupe-keys': 'error', 52 | 53 | // disallow a duplicate case label. 54 | 'no-duplicate-case': 'error', 55 | 56 | // disallow empty statements 57 | 'no-empty': 'error', 58 | 59 | // disallow the use of empty character classes in regular expressions 60 | 'no-empty-character-class': 'error', 61 | 62 | // disallow assigning to the exception in a catch block 63 | 'no-ex-assign': 'error', 64 | 65 | // disallow double-negation boolean casts in a boolean context 66 | // https://eslint.org/docs/rules/no-extra-boolean-cast 67 | 'no-extra-boolean-cast': 'error', 68 | 69 | // disallow unnecessary parentheses 70 | // https://eslint.org/docs/rules/no-extra-parens 71 | 'no-extra-parens': ['off', 'all', { 72 | conditionalAssign: true, 73 | nestedBinaryExpressions: false, 74 | returnAssign: false, 75 | ignoreJSX: 'all', // delegate to eslint-plugin-react 76 | enforceForArrowConditionals: false, 77 | }], 78 | 79 | // disallow unnecessary semicolons 80 | 'no-extra-semi': 'error', 81 | 82 | // disallow overwriting functions written as function declarations 83 | 'no-func-assign': 'error', 84 | 85 | // https://eslint.org/docs/rules/no-import-assign 86 | 'no-import-assign': 'error', 87 | 88 | // disallow function or variable declarations in nested blocks 89 | 'no-inner-declarations': 'error', 90 | 91 | // disallow invalid regular expression strings in the RegExp constructor 92 | 'no-invalid-regexp': 'error', 93 | 94 | // disallow irregular whitespace outside of strings and comments 95 | 'no-irregular-whitespace': 'error', 96 | 97 | // Disallow Number Literals That Lose Precision 98 | // https://eslint.org/docs/rules/no-loss-of-precision 99 | 'no-loss-of-precision': 'error', 100 | 101 | // Disallow characters which are made with multiple code points in character class syntax 102 | // https://eslint.org/docs/rules/no-misleading-character-class 103 | 'no-misleading-character-class': 'error', 104 | 105 | // disallow the use of object properties of the global object (Math and JSON) as functions 106 | 'no-obj-calls': 'error', 107 | 108 | // Disallow new operators with global non-constructor functions 109 | // https://eslint.org/docs/latest/rules/no-new-native-nonconstructor 110 | // TODO: semver-major, enable 111 | 'no-new-native-nonconstructor': 'off', 112 | 113 | // Disallow returning values from Promise executor functions 114 | // https://eslint.org/docs/rules/no-promise-executor-return 115 | 'no-promise-executor-return': 'error', 116 | 117 | // disallow use of Object.prototypes builtins directly 118 | // https://eslint.org/docs/rules/no-prototype-builtins 119 | 'no-prototype-builtins': 'error', 120 | 121 | // disallow multiple spaces in a regular expression literal 122 | 'no-regex-spaces': 'error', 123 | 124 | // Disallow returning values from setters 125 | // https://eslint.org/docs/rules/no-setter-return 126 | 'no-setter-return': 'error', 127 | 128 | // disallow sparse arrays 129 | 'no-sparse-arrays': 'error', 130 | 131 | // Disallow template literal placeholder syntax in regular strings 132 | // https://eslint.org/docs/rules/no-template-curly-in-string 133 | 'no-template-curly-in-string': 'error', 134 | 135 | // Avoid code that looks like two expressions but is actually one 136 | // https://eslint.org/docs/rules/no-unexpected-multiline 137 | 'no-unexpected-multiline': 'error', 138 | 139 | // disallow unreachable statements after a return, throw, continue, or break statement 140 | 'no-unreachable': 'error', 141 | 142 | // Disallow loops with a body that allows only one iteration 143 | // https://eslint.org/docs/rules/no-unreachable-loop 144 | 'no-unreachable-loop': ['error', { 145 | ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement 146 | }], 147 | 148 | // disallow return/throw/break/continue inside finally blocks 149 | // https://eslint.org/docs/rules/no-unsafe-finally 150 | 'no-unsafe-finally': 'error', 151 | 152 | // disallow negating the left operand of relational operators 153 | // https://eslint.org/docs/rules/no-unsafe-negation 154 | 'no-unsafe-negation': 'error', 155 | 156 | // disallow use of optional chaining in contexts where the undefined value is not allowed 157 | // https://eslint.org/docs/rules/no-unsafe-optional-chaining 158 | 'no-unsafe-optional-chaining': ['error', { disallowArithmeticOperators: true }], 159 | 160 | // Disallow Unused Private Class Members 161 | // https://eslint.org/docs/rules/no-unused-private-class-members 162 | // TODO: enable once eslint 7 is dropped (which is semver-major) 163 | 'no-unused-private-class-members': 'off', 164 | 165 | // Disallow useless backreferences in regular expressions 166 | // https://eslint.org/docs/rules/no-useless-backreference 167 | 'no-useless-backreference': 'error', 168 | 169 | // disallow negation of the left operand of an in expression 170 | // deprecated in favor of no-unsafe-negation 171 | 'no-negated-in-lhs': 'off', 172 | 173 | // Disallow assignments that can lead to race conditions due to usage of await or yield 174 | // https://eslint.org/docs/rules/require-atomic-updates 175 | // note: not enabled because it is very buggy 176 | 'require-atomic-updates': 'off', 177 | 178 | // disallow comparisons with the value NaN 179 | 'use-isnan': 'error', 180 | 181 | // ensure JSDoc comments are valid 182 | // https://eslint.org/docs/rules/valid-jsdoc 183 | 'valid-jsdoc': 'off', 184 | 185 | // ensure that the results of typeof are compared against a valid string 186 | // https://eslint.org/docs/rules/valid-typeof 187 | 'valid-typeof': ['error', { requireStringLiterals: true }], 188 | } 189 | }; 190 | -------------------------------------------------------------------------------- /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 | // https://eslint.org/docs/rules/arrow-body-style 17 | // TODO: enable requireReturnForObjectLiteral? 18 | 'arrow-body-style': ['error', 'as-needed', { 19 | requireReturnForObjectLiteral: false, 20 | }], 21 | 22 | // require parens in arrow function arguments 23 | // https://eslint.org/docs/rules/arrow-parens 24 | 'arrow-parens': ['error', 'always'], 25 | 26 | // require space before/after arrow function's arrow 27 | // https://eslint.org/docs/rules/arrow-spacing 28 | 'arrow-spacing': ['error', { before: true, after: true }], 29 | 30 | // verify super() callings in constructors 31 | 'constructor-super': 'error', 32 | 33 | // enforce the spacing around the * in generator functions 34 | // https://eslint.org/docs/rules/generator-star-spacing 35 | 'generator-star-spacing': ['error', { before: false, after: true }], 36 | 37 | // disallow modifying variables of class declarations 38 | // https://eslint.org/docs/rules/no-class-assign 39 | 'no-class-assign': 'error', 40 | 41 | // disallow arrow functions where they could be confused with comparisons 42 | // https://eslint.org/docs/rules/no-confusing-arrow 43 | 'no-confusing-arrow': ['error', { 44 | allowParens: true, 45 | }], 46 | 47 | // disallow modifying variables that are declared using const 48 | 'no-const-assign': 'error', 49 | 50 | // disallow duplicate class members 51 | // https://eslint.org/docs/rules/no-dupe-class-members 52 | 'no-dupe-class-members': 'error', 53 | 54 | // disallow importing from the same path more than once 55 | // https://eslint.org/docs/rules/no-duplicate-imports 56 | // replaced by https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md 57 | 'no-duplicate-imports': 'off', 58 | 59 | // disallow symbol constructor 60 | // https://eslint.org/docs/rules/no-new-symbol 61 | 'no-new-symbol': 'error', 62 | 63 | // Disallow specified names in exports 64 | // https://eslint.org/docs/rules/no-restricted-exports 65 | 'no-restricted-exports': ['error', { 66 | restrictedNamedExports: [ 67 | 'default', // use `export default` to provide a default export 68 | 'then', // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions 69 | ], 70 | }], 71 | 72 | // disallow specific imports 73 | // https://eslint.org/docs/rules/no-restricted-imports 74 | 'no-restricted-imports': ['off', { 75 | paths: [], 76 | patterns: [] 77 | }], 78 | 79 | // disallow to use this/super before super() calling in constructors. 80 | // https://eslint.org/docs/rules/no-this-before-super 81 | 'no-this-before-super': 'error', 82 | 83 | // disallow useless computed property keys 84 | // https://eslint.org/docs/rules/no-useless-computed-key 85 | 'no-useless-computed-key': 'error', 86 | 87 | // disallow unnecessary constructor 88 | // https://eslint.org/docs/rules/no-useless-constructor 89 | 'no-useless-constructor': 'error', 90 | 91 | // disallow renaming import, export, and destructured assignments to the same name 92 | // https://eslint.org/docs/rules/no-useless-rename 93 | 'no-useless-rename': ['error', { 94 | ignoreDestructuring: false, 95 | ignoreImport: false, 96 | ignoreExport: false, 97 | }], 98 | 99 | // require let or const instead of var 100 | 'no-var': 'error', 101 | 102 | // require method and property shorthand syntax for object literals 103 | // https://eslint.org/docs/rules/object-shorthand 104 | 'object-shorthand': ['error', 'always', { 105 | ignoreConstructors: false, 106 | avoidQuotes: true, 107 | }], 108 | 109 | // suggest using arrow functions as callbacks 110 | 'prefer-arrow-callback': ['error', { 111 | allowNamedFunctions: false, 112 | allowUnboundThis: true, 113 | }], 114 | 115 | // suggest using of const declaration for variables that are never modified after declared 116 | 'prefer-const': ['error', { 117 | destructuring: 'any', 118 | ignoreReadBeforeAssign: true, 119 | }], 120 | 121 | // Prefer destructuring from arrays and objects 122 | // https://eslint.org/docs/rules/prefer-destructuring 123 | 'prefer-destructuring': ['error', { 124 | VariableDeclarator: { 125 | array: false, 126 | object: true, 127 | }, 128 | AssignmentExpression: { 129 | array: true, 130 | object: false, 131 | }, 132 | }, { 133 | enforceForRenamedProperties: false, 134 | }], 135 | 136 | // disallow parseInt() in favor of binary, octal, and hexadecimal literals 137 | // https://eslint.org/docs/rules/prefer-numeric-literals 138 | 'prefer-numeric-literals': 'error', 139 | 140 | // suggest using Reflect methods where applicable 141 | // https://eslint.org/docs/rules/prefer-reflect 142 | 'prefer-reflect': 'off', 143 | 144 | // use rest parameters instead of arguments 145 | // https://eslint.org/docs/rules/prefer-rest-params 146 | 'prefer-rest-params': 'error', 147 | 148 | // suggest using the spread syntax instead of .apply() 149 | // https://eslint.org/docs/rules/prefer-spread 150 | 'prefer-spread': 'error', 151 | 152 | // suggest using template literals instead of string concatenation 153 | // https://eslint.org/docs/rules/prefer-template 154 | 'prefer-template': 'error', 155 | 156 | // disallow generator functions that do not have yield 157 | // https://eslint.org/docs/rules/require-yield 158 | 'require-yield': 'error', 159 | 160 | // enforce spacing between object rest-spread 161 | // https://eslint.org/docs/rules/rest-spread-spacing 162 | 'rest-spread-spacing': ['error', 'never'], 163 | 164 | // import sorting 165 | // https://eslint.org/docs/rules/sort-imports 166 | 'sort-imports': ['off', { 167 | ignoreCase: false, 168 | ignoreDeclarationSort: false, 169 | ignoreMemberSort: false, 170 | memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], 171 | }], 172 | 173 | // require a Symbol description 174 | // https://eslint.org/docs/rules/symbol-description 175 | 'symbol-description': 'error', 176 | 177 | // enforce usage of spacing in template strings 178 | // https://eslint.org/docs/rules/template-curly-spacing 179 | 'template-curly-spacing': 'error', 180 | 181 | // enforce spacing around the * in yield* expressions 182 | // https://eslint.org/docs/rules/yield-star-spacing 183 | 'yield-star-spacing': ['error', 'after'] 184 | } 185 | }; 186 | -------------------------------------------------------------------------------- /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: ['.mjs', '.js', '.json'] 17 | } 18 | }, 19 | 'import/extensions': [ 20 | '.js', 21 | '.mjs', 22 | '.jsx', 23 | ], 24 | 'import/core-modules': [ 25 | ], 26 | 'import/ignore': [ 27 | 'node_modules', 28 | '\\.(coffee|scss|css|less|hbs|svg|json)$', 29 | ], 30 | }, 31 | 32 | rules: { 33 | // Static analysis: 34 | 35 | // ensure imports point to files/modules that can be resolved 36 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md 37 | 'import/no-unresolved': ['error', { commonjs: true, caseSensitive: true }], 38 | 39 | // ensure named imports coupled with named exports 40 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it 41 | 'import/named': 'error', 42 | 43 | // ensure default import coupled with default export 44 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it 45 | 'import/default': 'off', 46 | 47 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/namespace.md 48 | 'import/namespace': 'off', 49 | 50 | // Helpful warnings: 51 | 52 | // disallow invalid exports, e.g. multiple defaults 53 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/export.md 54 | 'import/export': 'error', 55 | 56 | // do not allow a default import name to match a named export 57 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md 58 | 'import/no-named-as-default': 'error', 59 | 60 | // warn on accessing default export property names that are also named exports 61 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md 62 | 'import/no-named-as-default-member': 'error', 63 | 64 | // disallow use of jsdoc-marked-deprecated imports 65 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md 66 | 'import/no-deprecated': 'off', 67 | 68 | // Forbid the use of extraneous packages 69 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md 70 | // paths are treated both as absolute paths, and relative to process.cwd() 71 | 'import/no-extraneous-dependencies': ['error', { 72 | devDependencies: [ 73 | 'test/**', // tape, common npm pattern 74 | 'tests/**', // also common npm pattern 75 | 'spec/**', // mocha, rspec-like pattern 76 | '**/__tests__/**', // jest pattern 77 | '**/__mocks__/**', // jest pattern 78 | 'test.{js,jsx}', // repos with a single test file 79 | 'test-*.{js,jsx}', // repos with multiple top-level test files 80 | '**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test 81 | '**/jest.config.js', // jest config 82 | '**/jest.setup.js', // jest setup 83 | '**/vue.config.js', // vue-cli config 84 | '**/webpack.config.js', // webpack config 85 | '**/webpack.config.*.js', // webpack config 86 | '**/rollup.config.js', // rollup config 87 | '**/rollup.config.*.js', // rollup config 88 | '**/gulpfile.js', // gulp config 89 | '**/gulpfile.*.js', // gulp config 90 | '**/Gruntfile{,.js}', // grunt config 91 | '**/protractor.conf.js', // protractor config 92 | '**/protractor.conf.*.js', // protractor config 93 | '**/karma.conf.js', // karma config 94 | '**/.eslintrc.js' // eslint config 95 | ], 96 | optionalDependencies: false, 97 | }], 98 | 99 | // Forbid mutable exports 100 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md 101 | 'import/no-mutable-exports': 'error', 102 | 103 | // Module systems: 104 | 105 | // disallow require() 106 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md 107 | 'import/no-commonjs': 'off', 108 | 109 | // disallow AMD require/define 110 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-amd.md 111 | 'import/no-amd': 'error', 112 | 113 | // No Node.js builtin modules 114 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md 115 | // TODO: enable? 116 | 'import/no-nodejs-modules': 'off', 117 | 118 | // Style guide: 119 | 120 | // disallow non-import statements appearing before import statements 121 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/first.md 122 | 'import/first': 'error', 123 | 124 | // disallow non-import statements appearing before import statements 125 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/imports-first.md 126 | // deprecated: use `import/first` 127 | 'import/imports-first': 'off', 128 | 129 | // disallow duplicate imports 130 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md 131 | 'import/no-duplicates': 'error', 132 | 133 | // disallow namespace imports 134 | // TODO: enable? 135 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-namespace.md 136 | 'import/no-namespace': 'off', 137 | 138 | // Ensure consistent use of file extension within the import path 139 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/extensions.md 140 | 'import/extensions': ['error', 'ignorePackages', { 141 | js: 'never', 142 | mjs: 'never', 143 | jsx: 'never', 144 | }], 145 | 146 | // ensure absolute imports are above relative imports and that unassigned imports are ignored 147 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md 148 | // TODO: enforce a stricter convention in module import order? 149 | 'import/order': ['error', { groups: [['builtin', 'external', 'internal']] }], 150 | 151 | // Require a newline after the last import/require in a group 152 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md 153 | 'import/newline-after-import': 'error', 154 | 155 | // Require modules with a single export to use a default export 156 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md 157 | 'import/prefer-default-export': 'error', 158 | 159 | // Restrict which files can be imported in a given folder 160 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md 161 | 'import/no-restricted-paths': 'off', 162 | 163 | // Forbid modules to have too many dependencies 164 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/max-dependencies.md 165 | 'import/max-dependencies': ['off', { max: 10 }], 166 | 167 | // Forbid import of modules using absolute paths 168 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md 169 | 'import/no-absolute-path': 'error', 170 | 171 | // Forbid require() calls with expressions 172 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md 173 | 'import/no-dynamic-require': 'error', 174 | 175 | // prevent importing the submodules of other modules 176 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md 177 | 'import/no-internal-modules': ['off', { 178 | allow: [], 179 | }], 180 | 181 | // Warn if a module could be mistakenly parsed as a script by a consumer 182 | // leveraging Unambiguous JavaScript Grammar 183 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/unambiguous.md 184 | // this should not be enabled until this proposal has at least been *presented* to TC39. 185 | // At the moment, it's not a thing. 186 | 'import/unambiguous': 'off', 187 | 188 | // Forbid Webpack loader syntax in imports 189 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md 190 | 'import/no-webpack-loader-syntax': 'error', 191 | 192 | // Prevent unassigned imports 193 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md 194 | // importing for side effects is perfectly acceptable, if you need side effects. 195 | 'import/no-unassigned-import': 'off', 196 | 197 | // Prevent importing the default as if it were named 198 | // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-default.md 199 | 'import/no-named-default': 'error', 200 | 201 | // Reports if a module's default export is unnamed 202 | // https://github.com/import-js/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md 203 | 'import/no-anonymous-default-export': ['off', { 204 | allowArray: false, 205 | allowArrowFunction: false, 206 | allowAnonymousClass: false, 207 | allowAnonymousFunction: false, 208 | allowLiteral: false, 209 | allowObject: false, 210 | }], 211 | 212 | // This rule enforces that all exports are declared at the bottom of the file. 213 | // https://github.com/import-js/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md 214 | // TODO: enable? 215 | 'import/exports-last': 'off', 216 | 217 | // Reports when named exports are not grouped together in a single export declaration 218 | // or when multiple assignments to CommonJS module.exports or exports object are present 219 | // in a single file. 220 | // https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md 221 | 'import/group-exports': 'off', 222 | 223 | // forbid default exports. this is a terrible rule, do not use it. 224 | // https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md 225 | 'import/no-default-export': 'off', 226 | 227 | // Prohibit named exports. this is a terrible rule, do not use it. 228 | // https://github.com/import-js/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md 229 | 'import/no-named-export': 'off', 230 | 231 | // Forbid a module from importing itself 232 | // https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md 233 | 'import/no-self-import': 'error', 234 | 235 | // Forbid cyclical dependencies between modules 236 | // https://github.com/import-js/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md 237 | 'import/no-cycle': ['error', { maxDepth: '∞' }], 238 | 239 | // Ensures that there are no useless path segments 240 | // https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md 241 | 'import/no-useless-path-segments': ['error', { commonjs: true }], 242 | 243 | // dynamic imports require a leading comment with a webpackChunkName 244 | // https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md 245 | 'import/dynamic-import-chunkname': ['off', { 246 | importFunctions: [], 247 | webpackChunknameFormat: '[0-9a-zA-Z-_/.]+', 248 | }], 249 | 250 | // Use this rule to prevent imports to folders in relative parent paths. 251 | // https://github.com/import-js/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md 252 | 'import/no-relative-parent-imports': 'off', 253 | 254 | // Reports modules without any exports, or with unused exports 255 | // https://github.com/import-js/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md 256 | // TODO: enable once it supports CJS 257 | 'import/no-unused-modules': ['off', { 258 | ignoreExports: [], 259 | missingExports: true, 260 | unusedExports: true, 261 | }], 262 | 263 | // Reports the use of import declarations with CommonJS exports in any module except for the main module. 264 | // https://github.com/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-import-module-exports.md 265 | 'import/no-import-module-exports': ['error', { 266 | exceptions: [], 267 | }], 268 | 269 | // Use this rule to prevent importing packages through relative paths. 270 | // https://github.com/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md 271 | 'import/no-relative-packages': 'error', 272 | 273 | // enforce a consistent style for type specifiers (inline or top-level) 274 | // https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/consistent-type-specifier-style.md 275 | // TODO, semver-major: enable (just in case) 276 | 'import/consistent-type-specifier-style': ['off', 'prefer-inline'], 277 | 278 | // Reports the use of empty named import blocks. 279 | // https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/no-empty-named-blocks.md 280 | // TODO, semver-minor: enable 281 | 'import/no-empty-named-blocks': 'off', 282 | }, 283 | }; 284 | -------------------------------------------------------------------------------- /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': 'off', 9 | 10 | // require all requires be top-level 11 | // https://eslint.org/docs/rules/global-require 12 | 'global-require': 'error', 13 | 14 | // enforces error handling in callbacks (node environment) 15 | 'handle-callback-err': 'off', 16 | 17 | // disallow use of the Buffer() constructor 18 | // https://eslint.org/docs/rules/no-buffer-constructor 19 | 'no-buffer-constructor': 'error', 20 | 21 | // disallow mixing regular variable and require declarations 22 | 'no-mixed-requires': ['off', false], 23 | 24 | // disallow use of new operator with the require function 25 | 'no-new-require': 'error', 26 | 27 | // disallow string concatenation with __dirname and __filename 28 | // https://eslint.org/docs/rules/no-path-concat 29 | 'no-path-concat': 'error', 30 | 31 | // disallow use of process.env 32 | 'no-process-env': 'off', 33 | 34 | // disallow process.exit() 35 | 'no-process-exit': 'off', 36 | 37 | // restrict usage of specified node modules 38 | 'no-restricted-modules': 'off', 39 | 40 | // disallow use of synchronous methods (off by default) 41 | 'no-sync': 'off', 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/strict.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // babel inserts `'use strict';` for us 4 | strict: ['error', 'never'] 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/style.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | // enforce line breaks after opening and before closing array brackets 4 | // https://eslint.org/docs/rules/array-bracket-newline 5 | // TODO: enable? semver-major 6 | 'array-bracket-newline': ['off', 'consistent'], // object option alternative: { multiline: true, minItems: 3 } 7 | 8 | // enforce line breaks between array elements 9 | // https://eslint.org/docs/rules/array-element-newline 10 | // TODO: enable? semver-major 11 | 'array-element-newline': ['off', { multiline: true, minItems: 3 }], 12 | 13 | // enforce spacing inside array brackets 14 | 'array-bracket-spacing': ['error', 'never'], 15 | 16 | // enforce spacing inside single-line blocks 17 | // https://eslint.org/docs/rules/block-spacing 18 | 'block-spacing': ['error', 'always'], 19 | 20 | // enforce one true brace style 21 | 'brace-style': ['error', '1tbs', { allowSingleLine: true }], 22 | 23 | // require camel case names 24 | camelcase: ['error', { properties: 'never', ignoreDestructuring: false }], 25 | 26 | // enforce or disallow capitalization of the first letter of a comment 27 | // https://eslint.org/docs/rules/capitalized-comments 28 | 'capitalized-comments': ['off', 'never', { 29 | line: { 30 | ignorePattern: '.*', 31 | ignoreInlineComments: true, 32 | ignoreConsecutiveComments: true, 33 | }, 34 | block: { 35 | ignorePattern: '.*', 36 | ignoreInlineComments: true, 37 | ignoreConsecutiveComments: true, 38 | }, 39 | }], 40 | 41 | // require trailing commas in multiline object literals 42 | 'comma-dangle': ['error', { 43 | arrays: 'always-multiline', 44 | objects: 'always-multiline', 45 | imports: 'always-multiline', 46 | exports: 'always-multiline', 47 | functions: 'always-multiline', 48 | }], 49 | 50 | // enforce spacing before and after comma 51 | 'comma-spacing': ['error', { before: false, after: true }], 52 | 53 | // enforce one true comma style 54 | 'comma-style': ['error', 'last', { 55 | exceptions: { 56 | ArrayExpression: false, 57 | ArrayPattern: false, 58 | ArrowFunctionExpression: false, 59 | CallExpression: false, 60 | FunctionDeclaration: false, 61 | FunctionExpression: false, 62 | ImportDeclaration: false, 63 | ObjectExpression: false, 64 | ObjectPattern: false, 65 | VariableDeclaration: false, 66 | NewExpression: false, 67 | } 68 | }], 69 | 70 | // disallow padding inside computed properties 71 | 'computed-property-spacing': ['error', 'never'], 72 | 73 | // enforces consistent naming when capturing the current execution context 74 | 'consistent-this': 'off', 75 | 76 | // enforce newline at the end of file, with no multiple empty lines 77 | 'eol-last': ['error', 'always'], 78 | 79 | // https://eslint.org/docs/rules/function-call-argument-newline 80 | 'function-call-argument-newline': ['error', 'consistent'], 81 | 82 | // enforce spacing between functions and their invocations 83 | // https://eslint.org/docs/rules/func-call-spacing 84 | 'func-call-spacing': ['error', 'never'], 85 | 86 | // requires function names to match the name of the variable or property to which they are 87 | // assigned 88 | // https://eslint.org/docs/rules/func-name-matching 89 | 'func-name-matching': ['off', 'always', { 90 | includeCommonJSModuleExports: false, 91 | considerPropertyDescriptor: true, 92 | }], 93 | 94 | // require function expressions to have a name 95 | // https://eslint.org/docs/rules/func-names 96 | 'func-names': 'warn', 97 | 98 | // enforces use of function declarations or expressions 99 | // https://eslint.org/docs/rules/func-style 100 | // TODO: enable 101 | 'func-style': ['off', 'expression'], 102 | 103 | // require line breaks inside function parentheses if there are line breaks between parameters 104 | // https://eslint.org/docs/rules/function-paren-newline 105 | 'function-paren-newline': ['error', 'multiline-arguments'], 106 | 107 | // disallow specified identifiers 108 | // https://eslint.org/docs/rules/id-denylist 109 | 'id-denylist': 'off', 110 | 111 | // this option enforces minimum and maximum identifier lengths 112 | // (variable names, property names etc.) 113 | 'id-length': 'off', 114 | 115 | // require identifiers to match the provided regular expression 116 | 'id-match': 'off', 117 | 118 | // Enforce the location of arrow function bodies with implicit returns 119 | // https://eslint.org/docs/rules/implicit-arrow-linebreak 120 | 'implicit-arrow-linebreak': ['error', 'beside'], 121 | 122 | // this option sets a specific tab width for your code 123 | // https://eslint.org/docs/rules/indent 124 | indent: ['error', 2, { 125 | SwitchCase: 1, 126 | VariableDeclarator: 1, 127 | outerIIFEBody: 1, 128 | // MemberExpression: null, 129 | FunctionDeclaration: { 130 | parameters: 1, 131 | body: 1 132 | }, 133 | FunctionExpression: { 134 | parameters: 1, 135 | body: 1 136 | }, 137 | CallExpression: { 138 | arguments: 1 139 | }, 140 | ArrayExpression: 1, 141 | ObjectExpression: 1, 142 | ImportDeclaration: 1, 143 | flatTernaryExpressions: false, 144 | // list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js 145 | ignoredNodes: ['JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXFragment', 'JSXOpeningFragment', 'JSXClosingFragment', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'], 146 | ignoreComments: false 147 | }], 148 | 149 | // specify whether double or single quotes should be used in JSX attributes 150 | // https://eslint.org/docs/rules/jsx-quotes 151 | 'jsx-quotes': ['off', 'prefer-double'], 152 | 153 | // enforces spacing between keys and values in object literal properties 154 | 'key-spacing': ['error', { beforeColon: false, afterColon: true }], 155 | 156 | // require a space before & after certain keywords 157 | 'keyword-spacing': ['error', { 158 | before: true, 159 | after: true, 160 | overrides: { 161 | return: { after: true }, 162 | throw: { after: true }, 163 | case: { after: true } 164 | } 165 | }], 166 | 167 | // enforce position of line comments 168 | // https://eslint.org/docs/rules/line-comment-position 169 | // TODO: enable? 170 | 'line-comment-position': ['off', { 171 | position: 'above', 172 | ignorePattern: '', 173 | applyDefaultPatterns: true, 174 | }], 175 | 176 | // disallow mixed 'LF' and 'CRLF' as linebreaks 177 | // https://eslint.org/docs/rules/linebreak-style 178 | 'linebreak-style': ['error', 'unix'], 179 | 180 | // require or disallow an empty line between class members 181 | // https://eslint.org/docs/rules/lines-between-class-members 182 | 'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: false }], 183 | 184 | // enforces empty lines around comments 185 | 'lines-around-comment': 'off', 186 | 187 | // require or disallow newlines around directives 188 | // https://eslint.org/docs/rules/lines-around-directive 189 | 'lines-around-directive': ['error', { 190 | before: 'always', 191 | after: 'always', 192 | }], 193 | 194 | // Require or disallow logical assignment logical operator shorthand 195 | // https://eslint.org/docs/latest/rules/logical-assignment-operators 196 | // TODO, semver-major: enable 197 | 'logical-assignment-operators': ['off', 'always', { 198 | enforceForIfStatements: true, 199 | }], 200 | 201 | // specify the maximum depth that blocks can be nested 202 | 'max-depth': ['off', 4], 203 | 204 | // specify the maximum length of a line in your program 205 | // https://eslint.org/docs/rules/max-len 206 | 'max-len': ['error', 100, 2, { 207 | ignoreUrls: true, 208 | ignoreComments: false, 209 | ignoreRegExpLiterals: true, 210 | ignoreStrings: true, 211 | ignoreTemplateLiterals: true, 212 | }], 213 | 214 | // specify the max number of lines in a file 215 | // https://eslint.org/docs/rules/max-lines 216 | 'max-lines': ['off', { 217 | max: 300, 218 | skipBlankLines: true, 219 | skipComments: true 220 | }], 221 | 222 | // enforce a maximum function length 223 | // https://eslint.org/docs/rules/max-lines-per-function 224 | 'max-lines-per-function': ['off', { 225 | max: 50, 226 | skipBlankLines: true, 227 | skipComments: true, 228 | IIFEs: true, 229 | }], 230 | 231 | // specify the maximum depth callbacks can be nested 232 | 'max-nested-callbacks': 'off', 233 | 234 | // limits the number of parameters that can be used in the function declaration. 235 | 'max-params': ['off', 3], 236 | 237 | // specify the maximum number of statement allowed in a function 238 | 'max-statements': ['off', 10], 239 | 240 | // restrict the number of statements per line 241 | // https://eslint.org/docs/rules/max-statements-per-line 242 | 'max-statements-per-line': ['off', { max: 1 }], 243 | 244 | // enforce a particular style for multiline comments 245 | // https://eslint.org/docs/rules/multiline-comment-style 246 | 'multiline-comment-style': ['off', 'starred-block'], 247 | 248 | // require multiline ternary 249 | // https://eslint.org/docs/rules/multiline-ternary 250 | // TODO: enable? 251 | 'multiline-ternary': ['off', 'never'], 252 | 253 | // require a capital letter for constructors 254 | 'new-cap': ['error', { 255 | newIsCap: true, 256 | newIsCapExceptions: [], 257 | capIsNew: false, 258 | capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'], 259 | }], 260 | 261 | // disallow the omission of parentheses when invoking a constructor with no arguments 262 | // https://eslint.org/docs/rules/new-parens 263 | 'new-parens': 'error', 264 | 265 | // allow/disallow an empty newline after var statement 266 | 'newline-after-var': 'off', 267 | 268 | // https://eslint.org/docs/rules/newline-before-return 269 | 'newline-before-return': 'off', 270 | 271 | // enforces new line after each method call in the chain to make it 272 | // more readable and easy to maintain 273 | // https://eslint.org/docs/rules/newline-per-chained-call 274 | 'newline-per-chained-call': ['error', { ignoreChainWithDepth: 4 }], 275 | 276 | // disallow use of the Array constructor 277 | 'no-array-constructor': 'error', 278 | 279 | // disallow use of bitwise operators 280 | // https://eslint.org/docs/rules/no-bitwise 281 | 'no-bitwise': 'error', 282 | 283 | // disallow use of the continue statement 284 | // https://eslint.org/docs/rules/no-continue 285 | 'no-continue': 'error', 286 | 287 | // disallow comments inline after code 288 | 'no-inline-comments': 'off', 289 | 290 | // disallow if as the only statement in an else block 291 | // https://eslint.org/docs/rules/no-lonely-if 292 | 'no-lonely-if': 'error', 293 | 294 | // disallow un-paren'd mixes of different operators 295 | // https://eslint.org/docs/rules/no-mixed-operators 296 | 'no-mixed-operators': ['error', { 297 | // the list of arithmetic groups disallows mixing `%` and `**` 298 | // with other arithmetic operators. 299 | groups: [ 300 | ['%', '**'], 301 | ['%', '+'], 302 | ['%', '-'], 303 | ['%', '*'], 304 | ['%', '/'], 305 | ['/', '*'], 306 | ['&', '|', '<<', '>>', '>>>'], 307 | ['==', '!=', '===', '!=='], 308 | ['&&', '||'], 309 | ], 310 | allowSamePrecedence: false 311 | }], 312 | 313 | // disallow mixed spaces and tabs for indentation 314 | 'no-mixed-spaces-and-tabs': 'error', 315 | 316 | // disallow use of chained assignment expressions 317 | // https://eslint.org/docs/rules/no-multi-assign 318 | 'no-multi-assign': ['error'], 319 | 320 | // disallow multiple empty lines, only one newline at the end, and no new lines at the beginning 321 | // https://eslint.org/docs/rules/no-multiple-empty-lines 322 | 'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }], 323 | 324 | // disallow negated conditions 325 | // https://eslint.org/docs/rules/no-negated-condition 326 | 'no-negated-condition': 'off', 327 | 328 | // disallow nested ternary expressions 329 | 'no-nested-ternary': 'error', 330 | 331 | // disallow use of the Object constructor 332 | 'no-new-object': 'error', 333 | 334 | // disallow use of unary operators, ++ and -- 335 | // https://eslint.org/docs/rules/no-plusplus 336 | 'no-plusplus': 'error', 337 | 338 | // disallow certain syntax forms 339 | // https://eslint.org/docs/rules/no-restricted-syntax 340 | 'no-restricted-syntax': [ 341 | 'error', 342 | { 343 | selector: 'ForInStatement', 344 | message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', 345 | }, 346 | { 347 | selector: 'ForOfStatement', 348 | message: 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.', 349 | }, 350 | { 351 | selector: 'LabeledStatement', 352 | message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', 353 | }, 354 | { 355 | selector: 'WithStatement', 356 | message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', 357 | }, 358 | ], 359 | 360 | // disallow space between function identifier and application 361 | // deprecated in favor of func-call-spacing 362 | 'no-spaced-func': 'off', 363 | 364 | // disallow tab characters entirely 365 | 'no-tabs': 'error', 366 | 367 | // disallow the use of ternary operators 368 | 'no-ternary': 'off', 369 | 370 | // disallow trailing whitespace at the end of lines 371 | 'no-trailing-spaces': ['error', { 372 | skipBlankLines: false, 373 | ignoreComments: false, 374 | }], 375 | 376 | // disallow dangling underscores in identifiers 377 | // https://eslint.org/docs/rules/no-underscore-dangle 378 | 'no-underscore-dangle': ['error', { 379 | allow: [], 380 | allowAfterThis: false, 381 | allowAfterSuper: false, 382 | enforceInMethodNames: true, 383 | }], 384 | 385 | // disallow the use of Boolean literals in conditional expressions 386 | // also, prefer `a || b` over `a ? a : b` 387 | // https://eslint.org/docs/rules/no-unneeded-ternary 388 | 'no-unneeded-ternary': ['error', { defaultAssignment: false }], 389 | 390 | // disallow whitespace before properties 391 | // https://eslint.org/docs/rules/no-whitespace-before-property 392 | 'no-whitespace-before-property': 'error', 393 | 394 | // enforce the location of single-line statements 395 | // https://eslint.org/docs/rules/nonblock-statement-body-position 396 | 'nonblock-statement-body-position': ['error', 'beside', { overrides: {} }], 397 | 398 | // require padding inside curly braces 399 | 'object-curly-spacing': ['error', 'always'], 400 | 401 | // enforce line breaks between braces 402 | // https://eslint.org/docs/rules/object-curly-newline 403 | 'object-curly-newline': ['error', { 404 | ObjectExpression: { minProperties: 4, multiline: true, consistent: true }, 405 | ObjectPattern: { minProperties: 4, multiline: true, consistent: true }, 406 | ImportDeclaration: { minProperties: 4, multiline: true, consistent: true }, 407 | ExportDeclaration: { minProperties: 4, multiline: true, consistent: true }, 408 | }], 409 | 410 | // enforce "same line" or "multiple line" on object properties. 411 | // https://eslint.org/docs/rules/object-property-newline 412 | 'object-property-newline': ['error', { 413 | allowAllPropertiesOnSameLine: true, 414 | }], 415 | 416 | // allow just one var statement per function 417 | 'one-var': ['error', 'never'], 418 | 419 | // require a newline around variable declaration 420 | // https://eslint.org/docs/rules/one-var-declaration-per-line 421 | 'one-var-declaration-per-line': ['error', 'always'], 422 | 423 | // require assignment operator shorthand where possible or prohibit it entirely 424 | // https://eslint.org/docs/rules/operator-assignment 425 | 'operator-assignment': ['error', 'always'], 426 | 427 | // Requires operator at the beginning of the line in multiline statements 428 | // https://eslint.org/docs/rules/operator-linebreak 429 | 'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }], 430 | 431 | // disallow padding within blocks 432 | 'padded-blocks': ['error', { 433 | blocks: 'never', 434 | classes: 'never', 435 | switches: 'never', 436 | }, { 437 | allowSingleLineBlocks: true, 438 | }], 439 | 440 | // Require or disallow padding lines between statements 441 | // https://eslint.org/docs/rules/padding-line-between-statements 442 | 'padding-line-between-statements': 'off', 443 | 444 | // Disallow the use of Math.pow in favor of the ** operator 445 | // https://eslint.org/docs/rules/prefer-exponentiation-operator 446 | 'prefer-exponentiation-operator': 'error', 447 | 448 | // Prefer use of an object spread over Object.assign 449 | // https://eslint.org/docs/rules/prefer-object-spread 450 | 'prefer-object-spread': 'error', 451 | 452 | // require quotes around object literal property names 453 | // https://eslint.org/docs/rules/quote-props.html 454 | 'quote-props': ['error', 'as-needed', { keywords: false, unnecessary: true, numbers: false }], 455 | 456 | // specify whether double or single quotes should be used 457 | quotes: ['error', 'single', { avoidEscape: true }], 458 | 459 | // do not require jsdoc 460 | // https://eslint.org/docs/rules/require-jsdoc 461 | 'require-jsdoc': 'off', 462 | 463 | // require or disallow use of semicolons instead of ASI 464 | semi: ['error', 'always'], 465 | 466 | // enforce spacing before and after semicolons 467 | 'semi-spacing': ['error', { before: false, after: true }], 468 | 469 | // Enforce location of semicolons 470 | // https://eslint.org/docs/rules/semi-style 471 | 'semi-style': ['error', 'last'], 472 | 473 | // requires object keys to be sorted 474 | 'sort-keys': ['off', 'asc', { caseSensitive: false, natural: true }], 475 | 476 | // sort variables within the same declaration block 477 | 'sort-vars': 'off', 478 | 479 | // require or disallow space before blocks 480 | 'space-before-blocks': 'error', 481 | 482 | // require or disallow space before function opening parenthesis 483 | // https://eslint.org/docs/rules/space-before-function-paren 484 | 'space-before-function-paren': ['error', { 485 | anonymous: 'always', 486 | named: 'never', 487 | asyncArrow: 'always' 488 | }], 489 | 490 | // require or disallow spaces inside parentheses 491 | 'space-in-parens': ['error', 'never'], 492 | 493 | // require spaces around operators 494 | 'space-infix-ops': 'error', 495 | 496 | // Require or disallow spaces before/after unary operators 497 | // https://eslint.org/docs/rules/space-unary-ops 498 | 'space-unary-ops': ['error', { 499 | words: true, 500 | nonwords: false, 501 | overrides: { 502 | }, 503 | }], 504 | 505 | // require or disallow a space immediately following the // or /* in a comment 506 | // https://eslint.org/docs/rules/spaced-comment 507 | 'spaced-comment': ['error', 'always', { 508 | line: { 509 | exceptions: ['-', '+'], 510 | markers: ['=', '!', '/'], // space here to support sprockets directives, slash for TS /// comments 511 | }, 512 | block: { 513 | exceptions: ['-', '+'], 514 | markers: ['=', '!', ':', '::'], // space here to support sprockets directives and flow comment types 515 | balanced: true, 516 | } 517 | }], 518 | 519 | // Enforce spacing around colons of switch statements 520 | // https://eslint.org/docs/rules/switch-colon-spacing 521 | 'switch-colon-spacing': ['error', { after: true, before: false }], 522 | 523 | // Require or disallow spacing between template tags and their literals 524 | // https://eslint.org/docs/rules/template-tag-spacing 525 | 'template-tag-spacing': ['error', 'never'], 526 | 527 | // require or disallow the Unicode Byte Order Mark 528 | // https://eslint.org/docs/rules/unicode-bom 529 | 'unicode-bom': ['error', 'never'], 530 | 531 | // require regex literals to be wrapped in parentheses 532 | 'wrap-regex': 'off' 533 | } 534 | }; 535 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/rules/variables.js: -------------------------------------------------------------------------------- 1 | const confusingBrowserGlobals = require('confusing-browser-globals'); 2 | 3 | module.exports = { 4 | rules: { 5 | // enforce or disallow variable initializations at definition 6 | 'init-declarations': 'off', 7 | 8 | // disallow the catch clause parameter name being the same as a variable in the outer scope 9 | 'no-catch-shadow': 'off', 10 | 11 | // disallow deletion of variables 12 | 'no-delete-var': 'error', 13 | 14 | // disallow labels that share a name with a variable 15 | // https://eslint.org/docs/rules/no-label-var 16 | 'no-label-var': 'error', 17 | 18 | // disallow specific globals 19 | 'no-restricted-globals': [ 20 | 'error', 21 | { 22 | name: 'isFinite', 23 | message: 24 | 'Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite', 25 | }, 26 | { 27 | name: 'isNaN', 28 | message: 29 | 'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan', 30 | }, 31 | ].concat(confusingBrowserGlobals.map((g) => ({ 32 | name: g, 33 | message: `Use window.${g} instead. https://github.com/facebook/create-react-app/blob/HEAD/packages/confusing-browser-globals/README.md`, 34 | }))), 35 | 36 | // disallow declaration of variables already declared in the outer scope 37 | 'no-shadow': 'error', 38 | 39 | // disallow shadowing of names such as arguments 40 | 'no-shadow-restricted-names': 'error', 41 | 42 | // disallow use of undeclared variables unless mentioned in a /*global */ block 43 | 'no-undef': 'error', 44 | 45 | // disallow use of undefined when initializing variables 46 | 'no-undef-init': 'error', 47 | 48 | // disallow use of undefined variable 49 | // https://eslint.org/docs/rules/no-undefined 50 | // TODO: enable? 51 | 'no-undefined': 'off', 52 | 53 | // disallow declaration of variables that are not used in the code 54 | 'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }], 55 | 56 | // disallow use of variables before they are defined 57 | 'no-use-before-define': ['error', { functions: true, classes: true, variables: true }], 58 | } 59 | }; 60 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | // disabled because I find it tedious to write tests while following this rule 4 | "no-shadow": 0, 5 | // tests uses `t` for tape 6 | "id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}], 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/test/requires.js: -------------------------------------------------------------------------------- 1 | /* eslint strict: 0, global-require: 0 */ 2 | 3 | 'use strict'; 4 | 5 | const test = require('tape'); 6 | 7 | test('all entry points parse', (t) => { 8 | t.doesNotThrow(() => require('..'), 'index does not throw'); 9 | t.doesNotThrow(() => require('../legacy'), 'legacy does not throw'); 10 | t.doesNotThrow(() => require('../whitespace'), 'whitespace does not throw'); 11 | 12 | t.end(); 13 | }); 14 | -------------------------------------------------------------------------------- /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 | import index from '..'; 6 | 7 | const files = { ...{ index } }; // object spread is to test parsing 8 | 9 | const rulesDir = path.join(__dirname, '../rules'); 10 | fs.readdirSync(rulesDir).forEach((name) => { 11 | // eslint-disable-next-line import/no-dynamic-require 12 | files[name] = require(path.join(rulesDir, name)); // eslint-disable-line global-require 13 | }); 14 | 15 | Object.keys(files).forEach(( 16 | name, // trailing function comma is to test parsing 17 | ) => { 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/whitespace-async.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const { isArray } = Array; 4 | const { entries } = Object; 5 | const { ESLint } = require('eslint'); 6 | 7 | const baseConfig = require('.'); 8 | const whitespaceRules = require('./whitespaceRules'); 9 | 10 | const severities = ['off', 'warn', 'error']; 11 | 12 | function getSeverity(ruleConfig) { 13 | if (isArray(ruleConfig)) { 14 | return getSeverity(ruleConfig[0]); 15 | } 16 | if (typeof ruleConfig === 'number') { 17 | return severities[ruleConfig]; 18 | } 19 | return ruleConfig; 20 | } 21 | 22 | async function onlyErrorOnRules(rulesToError, config) { 23 | const errorsOnly = { ...config }; 24 | const cli = new ESLint({ 25 | useEslintrc: false, 26 | baseConfig: config 27 | }); 28 | const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules; 29 | 30 | entries(baseRules).forEach((rule) => { 31 | const ruleName = rule[0]; 32 | const ruleConfig = rule[1]; 33 | const severity = getSeverity(ruleConfig); 34 | 35 | if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { 36 | if (isArray(ruleConfig)) { 37 | errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); 38 | } else if (typeof ruleConfig === 'number') { 39 | errorsOnly.rules[ruleName] = 1; 40 | } else { 41 | errorsOnly.rules[ruleName] = 'warn'; 42 | } 43 | } 44 | }); 45 | 46 | return errorsOnly; 47 | } 48 | 49 | onlyErrorOnRules(whitespaceRules, baseConfig).then((config) => console.log(JSON.stringify(config))); 50 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/whitespace.js: -------------------------------------------------------------------------------- 1 | /* eslint global-require: 0 */ 2 | 3 | const { isArray } = Array; 4 | const { entries } = Object; 5 | const { CLIEngine } = require('eslint'); 6 | 7 | if (CLIEngine) { 8 | /* eslint no-inner-declarations: 0 */ 9 | const whitespaceRules = require('./whitespaceRules'); 10 | 11 | const baseConfig = require('.'); 12 | 13 | const severities = ['off', 'warn', 'error']; 14 | 15 | function getSeverity(ruleConfig) { 16 | if (isArray(ruleConfig)) { 17 | return getSeverity(ruleConfig[0]); 18 | } 19 | if (typeof ruleConfig === 'number') { 20 | return severities[ruleConfig]; 21 | } 22 | return ruleConfig; 23 | } 24 | 25 | function onlyErrorOnRules(rulesToError, config) { 26 | const errorsOnly = { ...config }; 27 | const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); 28 | const baseRules = cli.getConfigForFile(require.resolve('./')).rules; 29 | 30 | entries(baseRules).forEach((rule) => { 31 | const ruleName = rule[0]; 32 | const ruleConfig = rule[1]; 33 | const severity = getSeverity(ruleConfig); 34 | 35 | if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { 36 | if (isArray(ruleConfig)) { 37 | errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); 38 | } else if (typeof ruleConfig === 'number') { 39 | errorsOnly.rules[ruleName] = 1; 40 | } else { 41 | errorsOnly.rules[ruleName] = 'warn'; 42 | } 43 | } 44 | }); 45 | 46 | return errorsOnly; 47 | } 48 | 49 | module.exports = onlyErrorOnRules(whitespaceRules, baseConfig); 50 | } else { 51 | const path = require('path'); 52 | const { execSync } = require('child_process'); 53 | 54 | // NOTE: ESLint adds runtime statistics to the output (so it's no longer JSON) if TIMING is set 55 | module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'), { 56 | env: { 57 | ...process.env, 58 | TIMING: undefined, 59 | } 60 | }))); 61 | } 62 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb-base/whitespaceRules.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'array-bracket-newline', 3 | 'array-bracket-spacing', 4 | 'array-element-newline', 5 | 'arrow-spacing', 6 | 'block-spacing', 7 | 'comma-spacing', 8 | 'computed-property-spacing', 9 | 'dot-location', 10 | 'eol-last', 11 | 'func-call-spacing', 12 | 'function-paren-newline', 13 | 'generator-star-spacing', 14 | 'implicit-arrow-linebreak', 15 | 'indent', 16 | 'key-spacing', 17 | 'keyword-spacing', 18 | 'line-comment-position', 19 | 'linebreak-style', 20 | 'multiline-ternary', 21 | 'newline-per-chained-call', 22 | 'no-irregular-whitespace', 23 | 'no-mixed-spaces-and-tabs', 24 | 'no-multi-spaces', 25 | 'no-regex-spaces', 26 | 'no-spaced-func', 27 | 'no-trailing-spaces', 28 | 'no-whitespace-before-property', 29 | 'nonblock-statement-body-position', 30 | 'object-curly-newline', 31 | 'object-curly-spacing', 32 | 'object-property-newline', 33 | 'one-var-declaration-per-line', 34 | 'operator-linebreak', 35 | 'padded-blocks', 36 | 'padding-line-between-statements', 37 | 'rest-spread-spacing', 38 | 'semi-spacing', 39 | 'semi-style', 40 | 'space-before-blocks', 41 | 'space-before-function-paren', 42 | 'space-in-parens', 43 | 'space-infix-ops', 44 | 'space-unary-ops', 45 | 'spaced-comment', 46 | 'switch-colon-spacing', 47 | 'template-tag-spacing', 48 | 'import/newline-after-import' 49 | ]; 50 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["airbnb"] 3 | } 4 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/.editorconfig: -------------------------------------------------------------------------------- 1 | ../../.editorconfig -------------------------------------------------------------------------------- /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/.npmrc: -------------------------------------------------------------------------------- 1 | ../../.npmrc -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 19.0.4 / 2021-12-25 2 | ================== 3 | - republish to fix #2529 4 | 5 | 19.0.3 / 2021-12-24 6 | ================== 7 | - [patch] set `namedComponents` option to match style guide 8 | - [deps] update `eslint-plugin-react` 9 | 10 | 19.0.2 / 2021-12-02 11 | ================== 12 | - [meta] fix "exports" path (#2525) 13 | - [Tests] re-enable tests disabled for the eslint 8 upgrade 14 | 15 | 19.0.1 / 2021-11-22 16 | ================== 17 | - [fix] `whitespace`: update to support eslint 8 (#2517) 18 | - [deps] update `eslint-plugin-react` 19 | - [dev deps] update `tape` 20 | 21 | 19.0.0 / 2021-11-10 22 | ================== 23 | - [breaking] support `eslint` 8; drop `eslint` < 7 24 | - [patch] Explain why `react/jsx-key` is turned off (#2474) 25 | - [fix] bump eslint-plugin-react-hooks peer dependency version (#2356) 26 | - [patch] Alphabetize the rules for react-a11y.js (#2407) 27 | - [Docs] HTTP => HTTPS (#2489) 28 | - [readme] clarify hooks requirement (#2482) 29 | - [deps] update `eslint-config-airbnb-base`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, `safe-publish-latest`, `eslint-plugin-import`, `object.entries` 30 | - [meta] add `--no-save` to link scripts 31 | - [meta] use `prepublishOnly` script for npm 7+ 32 | - [dev deps] update `@babel/runtime`, `tape` 33 | 34 | 18.2.1 / 2020-11-06 35 | ================== 36 | - [patch] remove deprecated `jsx-a11y/accessible-emoji` rule (#2322) 37 | - [patch] Fix ignoreNonDOM typo in jsx-a11y/aria-role rule (#2318) 38 | - [patch] Fixed `handle` and `on` ordering in `sort-comp` rule (#2287) 39 | - [deps] update `eslint-plugin-jsx-a11y`, `eslint-plugin-react` 40 | - [deps] update `eslint-config-airbnb-base`, `object.assign` 41 | - [dev deps] update `@babel/runtime`, `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react` 42 | 43 | 18.2.0 / 2020-06-18 44 | ================== 45 | - [new] add `eslint` `v7` (#2240) 46 | - [minor] Allow using `eslint-plugin-react-hooks` v3 and v4 (#2235, #2207) 47 | - [minor] Fix typo in no-multiple-empty-lines rule (#2168) 48 | - [patch] set `explicitSpread` to ignore for `react/jsx-props-no-spreading` (#2237) 49 | - [patch] relax `eslint-plugin-react-hooks` down to v2.3, due to a controversial change in v2.5 50 | - [readme] fix typo (#2194) 51 | - [deps] update `eslint-config-airbnb-base`, `eslint-plugin-jsx-a11y`, `eslint-plugin-import`, `eslint-plugin-react`, `babel-preset-airbnb`, `eslint-find-rules`, `in-publish`, `tape`, `object.entries` 52 | - [tests] fix for eslint 7 53 | 54 | 18.1.0 / 2020-03-12 55 | ================== 56 | - [minor] Support eslint-plugin-react-hooks@2 (#2090) 57 | - [minor] add new disabled rules, update eslint 58 | - [fix] `whitespace`: only set erroring rules to "warn" 59 | - [patch] Remove duplicate `componentDidCatch` (#2108) 60 | - [patch] Add `static-variables` to `sort-comp` rule (#2109) 61 | - [readme] clarify hooks section in readme (#2074) 62 | - [deps] update `eslint`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, `eslint-config-airbnb-base`, `eslint-plugin-import`, `object.entries` 63 | - [dev deps] update `@babel/runtime`, `babel-preset-airbnb`, `safe-publish-latest`, `tape` 64 | - [tests] re-enable eslint rule `prefer-destructuring` internally (#2110) 65 | - [tests] fix eslint errors from c66cfc3 (#2112) 66 | 67 | 18.0.1 / 2019-08-13 68 | ================== 69 | - [patch] `react/state-in-constructor`: fix incorrect configuration 70 | 71 | 18.0.0 / 2019-08-10 72 | ================== 73 | - [breaking] add eslint v6, drop eslint v4 74 | - [deps] [breaking] update `eslint-config-airbnb-base`, `eslint-plugin-react`, `eslint-find-rules`, `eslint-plugin-import` 75 | - [breaking] Remove rules/strict from 'extends' (#1962) 76 | - [breaking] set react version to "detect" 77 | - [breaking] disable `label-has-for`; enable `control-has-associated-label` 78 | - [breaking] enable `react/jsx-props-no-spreading` 79 | - [breaking] enable `react/jsx-fragments` 80 | - [minor] enable `react/static-property-placement` 81 | - [minor] enable `react/state-in-constructor` 82 | - [minor] enable `react/jsx-curly-newline` 83 | - [react] Add missing/unsafe lifecycle methods to react/sort-comp rule (#2043) 84 | - [react] add componentDidCatch to lifecycle for react/sort-comp (#2060) 85 | - [react] add `react-hooks` plugin (#2022) 86 | - [dev deps] update babel-related deps to latest 87 | - [tests] only run tests in non-lint per-package travis job 88 | - [tests] use `eclint` instead of `editorconfig-tools` 89 | - [meta] add disabled config for new react and a11y rules 90 | 91 | 92 | 17.1.1 / 2019-07-01 93 | ================== 94 | - [patch] Turn off `react/no-multi-comp` (#2006) 95 | - [patch] extend `no-underscore-dangle` to allow for redux dev tools in the main config instead (#1996) 96 | - [meta] add disabled `jsx-fragments` rule 97 | - [deps] update `eslint-config-airbnb-base`, `object.entries`, `eslint-plugin-import`, `eslint-plugin-react`, `eslint-plugin-jsx-a11y`, `babel-preset-airbnb`, `tape` (#2005, etc) 98 | - [docs] correct JavaScript capitalization (#2046) 99 | - [docs] fix docs for whitespace config (#1914, #1871) 100 | - [readme] Improve eslint config setup instructions for yarn (#2001) 101 | 102 | 17.1.0 / 2018-08-13 103 | ================== 104 | - [new] add eslint v5 support 105 | - [minor] enable `label-has-associated-control` rule 106 | - [patch] re-enabling `jsx-one-expression-per-line` allowing single children, ignore DOM components on `jsx-no-bind` 107 | - [deps] update `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-react`, `eslint-plugin-import`, `safe-publish-latest`, `eslint-plugin-jsx-a11y`, `eslint-find-rules` 108 | - [docs] fix readme typo (#1855) 109 | 110 | 17.0.0 / 2018-06-21 111 | ================== 112 | - [breaking] update `eslint-config-airbnb-base` to v13 113 | - [breaking] enable `no-useless-path-segments` (#1743) 114 | - [breaking] update `eslint-plugin-react` to `v7.6`; update rule configs (#1737) 115 | - [breaking] bump react pragma to v16; update `class-methods-use-this`'s `exceptMethods` to include `componentDidCatch` (#1704) 116 | - [new] Adds config entry point with only whitespace rules enabled (#1749, #1751) 117 | - [patch] set `forbid-foreign-prop-types` to "warn" 118 | - [patch] Add new methods introduced in react@16.3 (#1831) 119 | - [patch] `label-has-for`: Remove redundant component (#1802) 120 | - [patch] Add 'to' as a specialLink to the 'anchor-is-valid' a11y rule (#1648) 121 | - [patch] disable `no-did-mount-set-state`, since it’s necessary for server-rendering. 122 | - [deps] update `eslint`, `eslint-plugin-react`, `eslint-plugin-import`, 123 | - [dev deps] update `babel-preset-airbnb`, `tape`, `eslint-find-rules` 124 | - [meta] add ES2015-2018 in npm package keywords (#1587) 125 | - [meta] Add licenses to sub packages (#1746) 126 | - [docs] add `npx` shortcut (#1694) 127 | - [docs] Use HTTPS for links to ESLint documentation (#1628) 128 | 129 | 16.1.0 / 2017-10-16 130 | ================== 131 | - [deps] update `eslint-config-airbnb-base`, `eslint` to v4.9 132 | 133 | 16.0.0 / 2017-10-06 134 | ================== 135 | - [breaking] [deps] require `eslint` `v4`, update `eslint-config-airbnb-base` 136 | - [breaking] [deps] Upgrade `eslint-plugin-jsx-a11y` to `v6`; enable more a11y rules (#1482) 137 | - [breaking] enable/add react rules: `react/jsx-curly-brace-presence`, `react/no-typos`, `react/no-unused-state`, `react/no-redundant-should-component-update`, `react/default-props-match-prop-types` 138 | - [new] add `propWrapperFunctions` default settings for `eslint-plugin-react` 139 | - [new] Enable `react/jsx-closing-tag-location` (#1533) 140 | - [deps] update `eslint` v4, `eslint-plugin-react`, `tape` 141 | - [docs] Specify yarn-specific install instructions (#1511) 142 | 143 | 15.1.0 / 2017-07-24 144 | ================== 145 | - [deps] allow eslint v3 or v4 (#1447) 146 | - [deps] update `eslint-plugin-import`, `eslint-config-airbnb-base` 147 | 148 | 15.0.2 / 2017-07-04 149 | ================== 150 | - [fix] jsx should be enabled via parserOptions, not via a root ecmaFeatures 151 | - [deps] update `babel-preset-airbnb`, `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `tape` 152 | 153 | 15.0.1 / 2017-05-15 154 | ================== 155 | - [fix] set default React version to 15.0 (#1415) 156 | 157 | 15.0.0 / 2017-05-14 158 | ================== 159 | - [breaking] set default React version to 0.15 160 | - [breaking] `update eslint-plugin-jsx-a11y` to v5, enable new rules 161 | - [breaking] `update eslint-plugin-react` to v7, enable new rules 162 | - [minor] enable rules: `jsx-max-props-per-line`, `void-dom-elements-no-children` 163 | - [patch] Turn `ignorePureComponents` option on for react/prefer-stateless-function (#1378, #1398) 164 | - [deps] update `eslint`, `eslint-plugin-react`, `eslint-config-airbnb-base` 165 | 166 | 14.1.0 / 2017-02-05 167 | ================== 168 | - [patch] allow `eslint-plugin-jsx-a11y` to be v3 or v4. Remove `no-marquee` rule temporarily. 169 | - [deps] update `eslint-config-airbnb-base`, `babel-preset-airbnb`, `eslint` 170 | 171 | 14.0.0 / 2017-01-08 172 | ================== 173 | - [breaking] enable `react/no-array-index-key`, `react/require-default-props` 174 | - [breaking] [deps] update `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, `eslint-config-airbnb-base` 175 | - [breaking] [deps] update `eslint-plugin-jsx-a11y` to v3 (#1166) 176 | - [docs] add note about `install-peerdeps` (#1234) 177 | - [docs] Updated instructions to support non-bash users (#1214) 178 | 179 | 13.0.0 / 2016-11-06 180 | ================== 181 | - [breaking] Enable `import/no-webpack-loader-syntax` rule (#1123) 182 | - [patch] `class-methods-use-this`: exempt React `getChildContext` (#1094) 183 | - [patch] set `react/no-unused-prop-types` skipShapeProps (#1099) 184 | - [deps] [breaking] update `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `eslint-plugin-import` 185 | - [dev deps] update `babel-preset-airbnb`, `eslint`, `eslint-find-rules`, `tape`, `safe-publish-latest` 186 | - [Tests] on `node` `v7` 187 | - [docs] ensure latest version of config is installed (#1121) 188 | 189 | 12.0.0 / 2016-09-24 190 | ================== 191 | - [breaking] Enable react rules: `react/no-unescaped-entities`, `react/no-children-prop` 192 | - [breaking] [deps] update `eslint-config-airbnb-base` 193 | - [patch] disable deprecated and redundant `react/require-extension` rule (#978) 194 | 195 | 11.2.0 / 2016-09-23 196 | ================== 197 | - [new] set `ecmaVersion` to 2017; enable object rest/spread; update `babel-preset-airbnb` 198 | - [deps] update `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `eslint-find-rules`, `safe-publish-latest` 199 | 200 | 11.1.0 / 2016-09-11 201 | ================== 202 | - [deps] update `eslint-config-airbnb-base`, `eslint` 203 | 204 | 11.0.0 / 2016-09-08 205 | ================== 206 | - [breaking] enable `react` rules: `react/no-danger-with-children`, `react/no-unused-prop-types`, `react/style-prop-object`, `react/forbid-prop-types`, `react/jsx-no-duplicate-props`; set `react/no-danger` to “warn” 207 | - [breaking] enable `jsx-a11y` rules: `jsx-a11y/anchor-has-content`, `jsx-a11y/tabindex-no-positive`, `jsx-a11y/no-static-element-interactions` 208 | - [deps] update `eslint`, `eslint-plugin-react`, `eslint-config-airbnb-base`, `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y` 209 | - [patch] set `ignoreCase` to `true` in disabled rules. 210 | - [docs] use “#” in example command rather than version numbers (#984) 211 | 212 | 10.0.1 / 2016-08-12 213 | ================== 214 | - [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-jsx-a11y`, `eslint-plugin-import`, `eslint-config-airbnb-base` 215 | 216 | 10.0.0 / 2016-08-01 217 | ================== 218 | - [breaking] enable jsx-a11y rules: 219 | - `jsx-a11y/heading-has-content` 220 | - `jsx-a11y/html-has-lang` 221 | - `jsx-a11y/lang` 222 | - `jsx-a11y/no-marquee` 223 | - `jsx-a11y/scope` 224 | - `jsx-a11y/href-no-hash` 225 | - `jsx-a11y/label-has-for` 226 | - [breaking] enable aria rules: 227 | - `jsx-a11y/aria-props` 228 | - `jsx-a11y/aria-proptypes` 229 | - `jsx-a11y/aria-unsupported-elements` 230 | - `jsx-a11y/role-has-required-aria-props` 231 | - `jsx-a11y/role-supports-aria-props` 232 | - [breaking] enable react rules: 233 | - `react/jsx-filename-extension` 234 | - `react/jsx-no-comment-textnodes` 235 | - `react/jsx-no-target-blank` 236 | - `react/require-extension` 237 | - `react/no-render-return-value` 238 | - `react/no-find-dom-node` 239 | - `react/no-deprecated` 240 | - [deps] [breaking] update `eslint` to v3, `eslint-config-airbnb-base` to v5, `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y` to v2, `eslint-plugin-react` to v6, `tape`. drop node < 4 support. 241 | - [deps] update `eslint-config-airbnb-base`, `eslint-plugin-react`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `babel-tape-runner`, add `babel-preset-airbnb`. ensure react is `>=` 0.13.0 242 | - [patch] loosen `jsx-pascal-case` rule to allow all caps component names 243 | - [tests] stop testing < node 4 244 | - [tests] use `in-publish` because coffeescript screwed up the prepublish script for everyone 245 | - [tests] Only run `eslint-find-rules` on prepublish, not in tests 246 | - [tests] Even though the base config may not be up to date in the main package, let’s `npm link` the base package into the main one for the sake of travis-ci tests 247 | - [docs] update the peer dep install command to dynamically look up the right version numbers when installing peer deps 248 | - add `safe-publish-latest` to `prepublish` 249 | 250 | 9.0.1 / 2016-05-08 251 | ================== 252 | - [patch] update `eslint-config-airbnb-base` to v3.0.1 253 | 254 | 9.0.0 / 2016-05-07 255 | ================== 256 | - [breaking] update `eslint-config-airbnb-base` to v3 257 | - [deps] update `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y` 258 | 259 | 8.0.0 / 2016-04-21 260 | ================== 261 | - [breaking] Migrate non-React rules to a separate linter config (`eslint-config-airbnb-base`) 262 | - [breaking] disallow empty methods 263 | - [breaking] disallow empty restructuring patterns 264 | - [breaking] enable `no-restricted-syntax` rule 265 | - [breaking] enable `global-require` rule 266 | - [breaking] [react] enable `react/jsx-curly-spacing` rule ([#693](https://github.com/airbnb/javascript/issues/693)) 267 | - [semver-minor] [react] Add `react/jsx-first-prop-new-line` rule 268 | - [semver-minor] [react] enable `jsx-equals-spacing` rule 269 | - [semver-minor] [react] enable `jsx-indent` rule 270 | - [semver-minor] enforce spacing inside single-line blocks 271 | - [semver-minor] enforce `no-underscore-dangle` 272 | - [semver-minor] Enable import/no-unresolved and import/export rules ([#825](https://github.com/airbnb/javascript/issues/825)) 273 | - [semver-patch] Enable `no-useless-concat` rule which `prefer-template` already covers 274 | - [semver-patch] Allow `== null` ([#542](https://github.com/airbnb/javascript/issues/542)) 275 | - [dev deps / peer deps] update `eslint`, `eslint-plugin-react`, `eslint-plugin-import` 276 | - [dev deps / peer deps] update `eslint-plugin-jsx-a11y` and rename rules ([#838](https://github.com/airbnb/javascript/issues/838)) 277 | - [refactor] [react] separate a11y rules to their own file 278 | - [refactor] Add missing disabled rules. 279 | - [tests] Add `eslint-find-rules` to prevent missing rules 280 | 281 | 7.0.0 / 2016-04-11 282 | ================== 283 | - [react] [breaking] Add accessibility rules to the React style guide + `eslint-plugin-a11y` 284 | - [breaking] enable `react/require-render-return` 285 | - [breaking] Add `no-dupe-class-members` rule + section ([#785](https://github.com/airbnb/javascript/issues/785)) 286 | - [breaking] error on debugger statements 287 | - [breaking] add `no-useless-escape` rule 288 | - [breaking] add `no-duplicate-imports` rule 289 | - [semver-minor] enable `jsx-pascal-case` rule 290 | - [deps] update `eslint`, `react` 291 | - [dev deps] update `eslint`, `eslint-plugin-react` 292 | 293 | 6.2.0 / 2016-03-22 294 | ================== 295 | - [new] Allow arrow functions in JSX props 296 | - [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)) 297 | - [dev deps] update `tape`, `eslint`, `eslint-plugin-react` 298 | - [peer deps] update `eslint`, `eslint-plugin-react` 299 | 300 | 6.1.0 / 2016-02-22 301 | ================== 302 | - [new] enable [`react/prefer-stateless-function`][react/prefer-stateless-function] 303 | - [dev deps] update `react-plugin-eslint`, `eslint`, `tape` 304 | 305 | 6.0.2 / 2016-02-22 306 | ================== 307 | - [fix] disable [`no-confusing-arrow`][no-confusing-arrow] due to an `eslint` bug ([#752](https://github.com/airbnb/javascript/issues/752)) 308 | 309 | 6.0.1 / 2016-02-21 310 | ================== 311 | - [fix] disable [`newline-per-chained-call`][newline-per-chained-call] due to an `eslint` bug ([#748](https://github.com/airbnb/javascript/issues/748)) 312 | 313 | 6.0.0 / 2016-02-21 314 | ================== 315 | - [breaking] enable [`array-callback-return`][array-callback-return] 316 | - [breaking] enable [`no-confusing-arrow`][no-confusing-arrow] 317 | - [breaking] enable [`no-new-symbol`][no-new-symbol] 318 | - [breaking] enable [`no-restricted-imports`][no-restricted-imports] 319 | - [breaking] enable [`no-useless-constructor`][no-useless-constructor] 320 | - [breaking] enable [`prefer-rest-params`][prefer-rest-params] 321 | - [breaking] enable [`template-curly-spacing`][template-curly-spacing] 322 | - [breaking] enable [`newline-per-chained-call`][newline-per-chained-call] 323 | - [breaking] enable [`one-var-declaration-per-line`][one-var-declaration-per-line] 324 | - [breaking] enable [`no-self-assign`][no-self-assign] 325 | - [breaking] enable [`no-whitespace-before-property`][no-whitespace-before-property] 326 | - [breaking] [react] enable [`react/jsx-space-before-closing`][react/jsx-space-before-closing] 327 | - [breaking] [react] enable `static-methods` at top of [`react/sort-comp`][react/sort-comp] 328 | - [breaking] [react] don't `ignoreTranspilerName` for [`react/display-name`][react/display-name] 329 | - [peer+dev deps] update `eslint`, `eslint-plugin-react` ([#730](https://github.com/airbnb/javascript/issues/730)) 330 | 331 | 5.0.1 / 2016-02-13 332 | ================== 333 | - [fix] `eslint` peerDep should not include breaking changes 334 | 335 | 5.0.0 / 2016-02-03 336 | ================== 337 | - [breaking] disallow unneeded ternary expressions 338 | - [breaking] Avoid lexical declarations in case/default clauses 339 | - [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` 340 | 341 | 4.0.0 / 2016-01-22 342 | ================== 343 | - [breaking] require outer IIFE wrapping; flesh out guide section 344 | - [minor] Add missing [`arrow-body-style`][arrow-body-style], [`prefer-template`][prefer-template] rules ([#678](https://github.com/airbnb/javascript/issues/678)) 345 | - [minor] Add [`prefer-arrow-callback`][prefer-arrow-callback] to ES6 rules (to match the guide) ([#677](https://github.com/airbnb/javascript/issues/677)) 346 | - [Tests] run `npm run lint` as part of tests; fix errors 347 | - [Tests] use `parallelshell` to parallelize npm run-scripts 348 | 349 | 3.1.0 / 2016-01-07 350 | ================== 351 | - [minor] Allow multiple stateless components in a single file 352 | 353 | 3.0.2 / 2016-01-06 354 | ================== 355 | - [fix] Ignore URLs in [`max-len`][max-len] ([#664](https://github.com/airbnb/javascript/issues/664)) 356 | 357 | 3.0.1 / 2016-01-06 358 | ================== 359 | - [fix] because we use babel, keywords should not be quoted 360 | 361 | 3.0.0 / 2016-01-04 362 | ================== 363 | - [breaking] enable [`quote-props`][quote-props] rule ([#632](https://github.com/airbnb/javascript/issues/632)) 364 | - [breaking] Define a max line length of 100 characters ([#639](https://github.com/airbnb/javascript/issues/639)) 365 | - [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)) 366 | - [breaking] update best-practices config to prevent parameter object manipulation ([#627](https://github.com/airbnb/javascript/issues/627)) 367 | - [minor] Enable [`react/no-is-mounted`][react/no-is-mounted] rule (#635, #633) 368 | - [minor] Sort [`react/prefer-es6-class`][react/prefer-es6-class] alphabetically ([#634](https://github.com/airbnb/javascript/issues/634)) 369 | - [minor] enable [`react/prefer-es6-class`][react/prefer-es6-class] rule 370 | - Permit strict mode in "legacy" config 371 | - [react] add missing rules from `eslint-plugin-react` (enforcing where necessary) ([#581](https://github.com/airbnb/javascript/issues/581)) 372 | - [dev deps] update `eslint-plugin-react` 373 | 374 | 2.1.1 / 2015-12-15 375 | ================== 376 | - [fix] Remove deprecated [`react/jsx-quotes`][react/jsx-quotes] ([#622](https://github.com/airbnb/javascript/issues/622)) 377 | 378 | 2.1.0 / 2015-12-15 379 | ================== 380 | - [fix] use `require.resolve` to allow nested `extend`s ([#582](https://github.com/airbnb/javascript/issues/582)) 381 | - [new] enable [`object-shorthand`][object-shorthand] rule ([#621](https://github.com/airbnb/javascript/issues/621)) 382 | - [new] enable [`arrow-spacing`][arrow-spacing] rule ([#517](https://github.com/airbnb/javascript/issues/517)) 383 | - [docs] flesh out react rule defaults ([#618](https://github.com/airbnb/javascript/issues/618)) 384 | 385 | 2.0.0 / 2015-12-03 386 | ================== 387 | - [breaking] [`space-before-function-paren`][space-before-function-paren]: require function spacing: `function (` ([#605](https://github.com/airbnb/javascript/issues/605)) 388 | - [breaking] [`indent`][indent]: Fix switch statement indentation rule ([#606](https://github.com/airbnb/javascript/issues/606)) 389 | - [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)) 390 | - [breaking] [`object-curly-spacing`][object-curly-spacing]: require padding inside curly braces ([#594](https://github.com/airbnb/javascript/issues/594)) 391 | - [breaking] [`space-in-parens`][space-in-parens]: disallow spaces in parens ([#594](https://github.com/airbnb/javascript/issues/594)) 392 | 393 | 1.0.2 / 2015-11-25 394 | ================== 395 | - [breaking] [`no-multiple-empty-lines`][no-multiple-empty-lines]: only allow 1 blank line at EOF ([#578](https://github.com/airbnb/javascript/issues/578)) 396 | - [new] `restParams`: enable rest params ([#592](https://github.com/airbnb/javascript/issues/592)) 397 | 398 | 1.0.1 / 2015-11-25 399 | ================== 400 | - *erroneous publish* 401 | 402 | 1.0.0 / 2015-11-08 403 | ================== 404 | - require `eslint` `v1.0.0` or higher 405 | - remove `babel-eslint` dependency 406 | 407 | 0.1.1 / 2015-11-05 408 | ================== 409 | - remove [`id-length`][id-length] rule ([#569](https://github.com/airbnb/javascript/issues/569)) 410 | - enable [`no-mixed-spaces-and-tabs`][no-mixed-spaces-and-tabs] ([#539](https://github.com/airbnb/javascript/issues/539)) 411 | - enable [`no-const-assign`][no-const-assign] ([#560](https://github.com/airbnb/javascript/issues/560)) 412 | - enable [`space-before-keywords`][space-before-keywords] ([#554](https://github.com/airbnb/javascript/issues/554)) 413 | 414 | 0.1.0 / 2015-11-05 415 | ================== 416 | - switch to modular rules files courtesy the [eslint-config-default][ecd] project and [@taion][taion]. [PR][pr-modular] 417 | - export `eslint-config-airbnb/legacy` for ES5-only users. `eslint-config-airbnb/legacy` does not require the `babel-eslint` parser. [PR][pr-legacy] 418 | 419 | 0.0.9 / 2015-09-24 420 | ================== 421 | - add rule [`no-undef`][no-undef] 422 | - add rule [`id-length`][id-length] 423 | 424 | 0.0.8 / 2015-08-21 425 | ================== 426 | - now has a changelog 427 | - now is modular (see instructions above for with react and without react versions) 428 | 429 | 0.0.7 / 2015-07-30 430 | ================== 431 | - TODO: fill in 432 | 433 | 434 | [ecd]: https://github.com/walmartlabs/eslint-config-defaults 435 | [taion]: https://github.com/taion 436 | [pr-modular]: https://github.com/airbnb/javascript/pull/526 437 | [pr-legacy]: https://github.com/airbnb/javascript/pull/527 438 | 439 | [array-bracket-spacing]: https://eslint.org/docs/rules/array-bracket-spacing 440 | [array-callback-return]: https://eslint.org/docs/rules/array-callback-return 441 | [arrow-body-style]: https://eslint.org/docs/rules/arrow-body-style 442 | [arrow-spacing]: https://eslint.org/docs/rules/arrow-spacing 443 | [computed-property-spacing]: https://eslint.org/docs/rules/computed-property-spacing 444 | [id-length]: https://eslint.org/docs/rules/id-length 445 | [indent]: https://eslint.org/docs/rules/indent 446 | [max-len]: https://eslint.org/docs/rules/max-len 447 | [newline-per-chained-call]: https://eslint.org/docs/rules/newline-per-chained-call 448 | [no-confusing-arrow]: https://eslint.org/docs/rules/no-confusing-arrow 449 | [no-const-assign]: https://eslint.org/docs/rules/no-const-assign 450 | [no-mixed-spaces-and-tabs]: https://eslint.org/docs/rules/no-mixed-spaces-and-tabs 451 | [no-multiple-empty-lines]: https://eslint.org/docs/rules/no-multiple-empty-lines 452 | [no-new-symbol]: https://eslint.org/docs/rules/no-new-symbol 453 | [no-restricted-imports]: https://eslint.org/docs/rules/no-restricted-imports 454 | [no-self-assign]: https://eslint.org/docs/rules/no-self-assign 455 | [no-undef]: https://eslint.org/docs/rules/no-undef 456 | [no-useless-constructor]: https://eslint.org/docs/rules/no-useless-constructor 457 | [no-whitespace-before-property]: https://eslint.org/docs/rules/no-whitespace-before-property 458 | [object-curly-spacing]: https://eslint.org/docs/rules/object-curly-spacing 459 | [object-shorthand]: https://eslint.org/docs/rules/object-shorthand 460 | [one-var-declaration-per-line]: https://eslint.org/docs/rules/one-var-declaration-per-line 461 | [prefer-arrow-callback]: https://eslint.org/docs/rules/prefer-arrow-callback 462 | [prefer-rest-params]: https://eslint.org/docs/rules/prefer-rest-params 463 | [prefer-template]: https://eslint.org/docs/rules/prefer-template 464 | [quote-props]: https://eslint.org/docs/rules/quote-props 465 | [space-before-function-paren]: https://eslint.org/docs/rules/space-before-function-paren 466 | [space-before-keywords]: https://eslint.org/docs/rules/space-before-keywords 467 | [space-in-parens]: https://eslint.org/docs/rules/space-in-parens 468 | [template-curly-spacing]: https://eslint.org/docs/rules/template-curly-spacing 469 | 470 | [react/jsx-space-before-closing]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/jsx-space-before-closing.md 471 | [react/sort-comp]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/sort-comp.md 472 | [react/display-name]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/display-name.md 473 | [react/jsx-no-bind]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/jsx-no-bind.md 474 | [react/no-is-mounted]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/no-is-mounted.md 475 | [react/prefer-es6-class]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/prefer-es6-class.md 476 | [react/jsx-quotes]: https://github.com/jsx-eslint/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md 477 | [react/prefer-stateless-function]: https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/prefer-stateless-function.md 478 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012 Airbnb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-airbnb 2 | 3 | [![npm version](https://badge.fury.io/js/eslint-config-airbnb.svg)](https://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 most of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, and `eslint-plugin-jsx-a11y`. Note that it does not enable our React Hooks rules. To enable those, see the [`eslint-config-airbnb/hooks` section](#eslint-config-airbnbhooks). 14 | 15 | If you don't need React, see [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base). 16 | 17 | 1. Install the correct versions of each package, which are listed by the command: 18 | 19 | ```sh 20 | npm info "eslint-config-airbnb@latest" peerDependencies 21 | ``` 22 | 23 | If using **npm 5+**, use this shortcut 24 | 25 | ```sh 26 | npx install-peerdeps --dev eslint-config-airbnb 27 | ``` 28 | 29 | If using **yarn**, you can also use the shortcut described above if you have npm 5+ installed on your machine, as the command will detect that you are using yarn and will act accordingly. 30 | Otherwise, run `npm info "eslint-config-airbnb@latest" peerDependencies` to list the peer dependencies and versions, then run `yarn add --dev @` for each listed peer dependency. 31 | 32 | If using **npm < 5**, Linux/OSX users can run 33 | 34 | ```sh 35 | ( 36 | export PKG=eslint-config-airbnb; 37 | npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest" 38 | ) 39 | ``` 40 | 41 | Which produces and runs a command like: 42 | 43 | ```sh 44 | npm install --save-dev eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# eslint-plugin-react-hooks@^#.#.# 45 | ``` 46 | 47 | If using **npm < 5**, Windows users can either install all the peer dependencies manually, or use the [install-peerdeps](https://github.com/nathanhleung/install-peerdeps) cli tool. 48 | 49 | ```sh 50 | npm install -g install-peerdeps 51 | install-peerdeps --dev eslint-config-airbnb 52 | ``` 53 | The cli will produce and run a command like: 54 | 55 | ```sh 56 | npm install --save-dev eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# eslint-plugin-react-hooks@^#.#.# 57 | ``` 58 | 59 | 2. Add `"extends": "airbnb"` to your `.eslintrc` 60 | 61 | ### eslint-config-airbnb/hooks 62 | 63 | This entry point enables the linting rules for React hooks (requires v16.8+). To use, add `"extends": ["airbnb", "airbnb/hooks"]` to your `.eslintrc`. 64 | 65 | ### eslint-config-airbnb/whitespace 66 | 67 | This entry point only errors on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js). 68 | 69 | ### eslint-config-airbnb/base 70 | 71 | This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base). 72 | 73 | ### eslint-config-airbnb/legacy 74 | 75 | This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base). 76 | 77 | See [Airbnb's JavaScript styleguide](https://github.com/airbnb/javascript) and 78 | the [ESlint config docs](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) 79 | for more information. 80 | 81 | ## Improving this config 82 | 83 | 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? 84 | 85 | You can run tests with `npm test`. 86 | 87 | You can make sure this module lints with itself using `npm run lint`. 88 | -------------------------------------------------------------------------------- /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/hooks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | './rules/react-hooks.js', 4 | ].map(require.resolve), 5 | rules: {} 6 | }; 7 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'eslint-config-airbnb-base', 4 | './rules/react', 5 | './rules/react-a11y', 6 | ].map(require.resolve), 7 | rules: {} 8 | }; 9 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/legacy.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['eslint-config-airbnb-base/legacy'].map(require.resolve), 3 | rules: {}, 4 | }; 5 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-airbnb", 3 | "version": "19.0.4", 4 | "description": "Airbnb's ESLint config, following our styleguide", 5 | "main": "index.js", 6 | "exports": { 7 | ".": "./index.js", 8 | "./base": "./base.js", 9 | "./hooks": "./hooks.js", 10 | "./legacy": "./legacy.js", 11 | "./whitespace": "./whitespace.js", 12 | "./rules/react": "./rules/react.js", 13 | "./rules/react-a11y": "./rules/react-a11y.js", 14 | "./rules/react-hooks": "./rules/react-hooks.js", 15 | "./package.json": "./package.json" 16 | }, 17 | "scripts": { 18 | "prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", 19 | "lint": "eslint .", 20 | "pretests-only": "node ./test/requires", 21 | "tests-only": "babel-tape-runner ./test/test-*.js", 22 | "prepublishOnly": "eslint-find-rules --unused && npm test && safe-publish-latest", 23 | "prepublish": "not-in-publish || npm run prepublishOnly", 24 | "pretest": "npm run --silent lint", 25 | "test": "npm run --silent tests-only", 26 | "link:eslint": "cd node_modules/eslint && npm link --production && cd -", 27 | "pretravis": "npm run link:eslint && cd ../eslint-config-airbnb-base && npm link --no-save eslint && npm install && npm link && cd - && npm link --no-save eslint-config-airbnb-base", 28 | "travis": "npm run --silent tests-only", 29 | "posttravis": "npm unlink --no-save eslint-config-airbnb-base eslint >/dev/null &" 30 | }, 31 | "repository": { 32 | "type": "git", 33 | "url": "https://github.com/airbnb/javascript" 34 | }, 35 | "keywords": [ 36 | "eslint", 37 | "eslintconfig", 38 | "config", 39 | "airbnb", 40 | "javascript", 41 | "styleguide", 42 | "es2015", 43 | "es2016", 44 | "es2017", 45 | "es2018" 46 | ], 47 | "author": "Jake Teton-Landis (https://twitter.com/@jitl)", 48 | "contributors": [ 49 | { 50 | "name": "Jake Teton-Landis", 51 | "url": "https://twitter.com/jitl" 52 | }, 53 | { 54 | "name": "Jordan Harband", 55 | "email": "ljharb@gmail.com", 56 | "url": "http://ljharb.codes" 57 | }, 58 | { 59 | "name": "Harrison Shoff", 60 | "url": "https://twitter.com/hshoff" 61 | } 62 | ], 63 | "license": "MIT", 64 | "bugs": { 65 | "url": "https://github.com/airbnb/javascript/issues" 66 | }, 67 | "homepage": "https://github.com/airbnb/javascript", 68 | "dependencies": { 69 | "eslint-config-airbnb-base": "^15.0.0" 70 | }, 71 | "devDependencies": { 72 | "@babel/runtime": "^7.25.6", 73 | "babel-preset-airbnb": "^4.5.0", 74 | "babel-tape-runner": "^3.0.0", 75 | "eclint": "^2.8.1", 76 | "eslint": "^7.32.0 || ^8.2.0", 77 | "eslint-find-rules": "^4.1.0", 78 | "eslint-plugin-import": "^2.30.0", 79 | "eslint-plugin-jsx-a11y": "^6.10.0", 80 | "eslint-plugin-react": "^7.36.1", 81 | "eslint-plugin-react-hooks": "^5.1.0", 82 | "in-publish": "^2.0.1", 83 | "react": ">= 0.13.0", 84 | "safe-publish-latest": "^2.0.0", 85 | "tape": "^5.9.0" 86 | }, 87 | "peerDependencies": { 88 | "eslint": "^7.32.0 || ^8.2.0", 89 | "eslint-plugin-import": "^2.30.0", 90 | "eslint-plugin-jsx-a11y": "^6.10.0", 91 | "eslint-plugin-react": "^7.36.1", 92 | "eslint-plugin-react-hooks": "^5.1.0" 93 | }, 94 | "engines": { 95 | "node": "^10.12.0 || ^12.22.0 || ^14.17.0 || >=16.0.0" 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/rules/react-a11y.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | 'jsx-a11y', 4 | 'react' 5 | ], 6 | 7 | parserOptions: { 8 | ecmaFeatures: { 9 | jsx: true, 10 | }, 11 | }, 12 | 13 | rules: { 14 | // ensure emoji are accessible 15 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/accessible-emoji.md 16 | // disabled; rule is deprecated 17 | 'jsx-a11y/accessible-emoji': 'off', 18 | 19 | // Enforce that all elements that require alternative text have meaningful information 20 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md 21 | 'jsx-a11y/alt-text': ['error', { 22 | elements: ['img', 'object', 'area', 'input[type="image"]'], 23 | img: [], 24 | object: [], 25 | area: [], 26 | 'input[type="image"]': [], 27 | }], 28 | 29 | // Enforce that anchors have content 30 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md 31 | 'jsx-a11y/anchor-has-content': ['error', { components: [] }], 32 | 33 | // ensure tags are valid 34 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/0745af376cdc8686d85a361ce36952b1fb1ccf6e/docs/rules/anchor-is-valid.md 35 | 'jsx-a11y/anchor-is-valid': ['error', { 36 | components: ['Link'], 37 | specialLink: ['to'], 38 | aspects: ['noHref', 'invalidHref', 'preferButton'], 39 | }], 40 | 41 | // elements with aria-activedescendant must be tabbable 42 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-activedescendant-has-tabindex.md 43 | 'jsx-a11y/aria-activedescendant-has-tabindex': 'error', 44 | 45 | // Enforce all aria-* props are valid. 46 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-props.md 47 | 'jsx-a11y/aria-props': 'error', 48 | 49 | // Enforce ARIA state and property values are valid. 50 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-proptypes.md 51 | 'jsx-a11y/aria-proptypes': 'error', 52 | 53 | // Require ARIA roles to be valid and non-abstract 54 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md 55 | 'jsx-a11y/aria-role': ['error', { ignoreNonDOM: false }], 56 | 57 | // Enforce that elements that do not support ARIA roles, states, and 58 | // properties do not have those attributes. 59 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-unsupported-elements.md 60 | 'jsx-a11y/aria-unsupported-elements': 'error', 61 | 62 | // Ensure the autocomplete attribute is correct and suitable for the form field it is used with 63 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/29c68596b15c4ff0a40daae6d4a2670e36e37d35/docs/rules/autocomplete-valid.md 64 | 'jsx-a11y/autocomplete-valid': ['off', { 65 | inputComponents: [], 66 | }], 67 | 68 | // require onClick be accompanied by onKeyUp/onKeyDown/onKeyPress 69 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/click-events-have-key-events.md 70 | 'jsx-a11y/click-events-have-key-events': 'error', 71 | 72 | // Enforce that a control (an interactive element) has a text label. 73 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/control-has-associated-label.md 74 | 'jsx-a11y/control-has-associated-label': ['error', { 75 | labelAttributes: ['label'], 76 | controlComponents: [], 77 | ignoreElements: [ 78 | 'audio', 79 | 'canvas', 80 | 'embed', 81 | 'input', 82 | 'textarea', 83 | 'tr', 84 | 'video', 85 | ], 86 | ignoreRoles: [ 87 | 'grid', 88 | 'listbox', 89 | 'menu', 90 | 'menubar', 91 | 'radiogroup', 92 | 'row', 93 | 'tablist', 94 | 'toolbar', 95 | 'tree', 96 | 'treegrid', 97 | ], 98 | depth: 5, 99 | }], 100 | 101 | // ensure tags have content and are not aria-hidden 102 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/heading-has-content.md 103 | 'jsx-a11y/heading-has-content': ['error', { components: [''] }], 104 | 105 | // require HTML elements to have a "lang" prop 106 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/html-has-lang.md 107 | 'jsx-a11y/html-has-lang': 'error', 108 | 109 | // ensure iframe elements have a unique title 110 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/iframe-has-title.md 111 | 'jsx-a11y/iframe-has-title': 'error', 112 | 113 | // Prevent img alt text from containing redundant words like "image", "picture", or "photo" 114 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md 115 | 'jsx-a11y/img-redundant-alt': 'error', 116 | 117 | // Elements with an interactive role and interaction handlers must be focusable 118 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/interactive-supports-focus.md 119 | 'jsx-a11y/interactive-supports-focus': 'error', 120 | 121 | // Enforce that a label tag has a text label and an associated control. 122 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/b800f40a2a69ad48015ae9226fbe879f946757ed/docs/rules/label-has-associated-control.md 123 | 'jsx-a11y/label-has-associated-control': ['error', { 124 | labelComponents: [], 125 | labelAttributes: [], 126 | controlComponents: [], 127 | assert: 'both', 128 | depth: 25 129 | }], 130 | 131 | // require HTML element's lang prop to be valid 132 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/lang.md 133 | 'jsx-a11y/lang': 'error', 134 | 135 | // media elements must have captions 136 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/media-has-caption.md 137 | 'jsx-a11y/media-has-caption': ['error', { 138 | audio: [], 139 | video: [], 140 | track: [], 141 | }], 142 | 143 | // require that mouseover/out come with focus/blur, for keyboard-only users 144 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md 145 | 'jsx-a11y/mouse-events-have-key-events': 'error', 146 | 147 | // Prevent use of `accessKey` 148 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md 149 | 'jsx-a11y/no-access-key': 'error', 150 | 151 | // prohibit autoFocus prop 152 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md 153 | 'jsx-a11y/no-autofocus': ['error', { ignoreNonDOM: true }], 154 | 155 | // prevent distracting elements, like and 156 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-distracting-elements.md 157 | 'jsx-a11y/no-distracting-elements': ['error', { 158 | elements: ['marquee', 'blink'], 159 | }], 160 | 161 | // WAI-ARIA roles should not be used to convert an interactive element to non-interactive 162 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-interactive-element-to-noninteractive-role.md 163 | 'jsx-a11y/no-interactive-element-to-noninteractive-role': ['error', { 164 | tr: ['none', 'presentation'], 165 | }], 166 | 167 | // A non-interactive element does not support event handlers (mouse and key handlers) 168 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-interactions.md 169 | 'jsx-a11y/no-noninteractive-element-interactions': ['error', { 170 | handlers: [ 171 | 'onClick', 172 | 'onMouseDown', 173 | 'onMouseUp', 174 | 'onKeyPress', 175 | 'onKeyDown', 176 | 'onKeyUp', 177 | ] 178 | }], 179 | 180 | // WAI-ARIA roles should not be used to convert a non-interactive element to interactive 181 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-to-interactive-role.md 182 | 'jsx-a11y/no-noninteractive-element-to-interactive-role': ['error', { 183 | ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'], 184 | ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'], 185 | li: ['menuitem', 'option', 'row', 'tab', 'treeitem'], 186 | table: ['grid'], 187 | td: ['gridcell'], 188 | }], 189 | 190 | // Tab key navigation should be limited to elements on the page that can be interacted with. 191 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-tabindex.md 192 | 'jsx-a11y/no-noninteractive-tabindex': ['error', { 193 | tags: [], 194 | roles: ['tabpanel'], 195 | allowExpressionValues: true, 196 | }], 197 | 198 | // require onBlur instead of onChange 199 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md 200 | 'jsx-a11y/no-onchange': 'off', 201 | 202 | // ensure HTML elements do not specify redundant ARIA roles 203 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-redundant-roles.md 204 | 'jsx-a11y/no-redundant-roles': ['error', { 205 | nav: ['navigation'], 206 | }], 207 | 208 | // Enforce that DOM elements without semantic behavior not have interaction handlers 209 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md 210 | 'jsx-a11y/no-static-element-interactions': ['error', { 211 | handlers: [ 212 | 'onClick', 213 | 'onMouseDown', 214 | 'onMouseUp', 215 | 'onKeyPress', 216 | 'onKeyDown', 217 | 'onKeyUp', 218 | ] 219 | }], 220 | 221 | // Enforce that elements with ARIA roles must have all required attributes 222 | // for that role. 223 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-has-required-aria-props.md 224 | 'jsx-a11y/role-has-required-aria-props': 'error', 225 | 226 | // Enforce that elements with explicit or implicit roles defined contain 227 | // only aria-* properties supported by that role. 228 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-supports-aria-props.md 229 | 'jsx-a11y/role-supports-aria-props': 'error', 230 | 231 | // only allow to have the "scope" attr 232 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/scope.md 233 | 'jsx-a11y/scope': 'error', 234 | 235 | // Enforce tabIndex value is not greater than zero. 236 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/tabindex-no-positive.md 237 | 'jsx-a11y/tabindex-no-positive': 'error', 238 | 239 | // ---------------------------------------------------- 240 | // Rules that no longer exist in eslint-plugin-jsx-a11y 241 | // ---------------------------------------------------- 242 | 243 | // require that JSX labels use "htmlFor" 244 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md 245 | // deprecated: replaced by `label-has-associated-control` rule 246 | 'jsx-a11y/label-has-for': ['off', { 247 | components: [], 248 | required: { 249 | every: ['nesting', 'id'], 250 | }, 251 | allowChildren: false, 252 | }], 253 | 254 | // Ensures anchor text is not ambiguous 255 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/anchor-ambiguous-text.md 256 | // TODO: semver-major, enable 257 | 'jsx-a11y/anchor-ambiguous-text': 'off', 258 | 259 | // Enforce that aria-hidden="true" is not set on focusable elements. 260 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/no-aria-hidden-on-focusable.md 261 | // TODO: semver-major, enable 262 | 'jsx-a11y/no-aria-hidden-on-focusable': 'off', 263 | 264 | // Enforces using semantic DOM elements over the ARIA role property. 265 | // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/prefer-tag-over-role.md 266 | // TODO: semver-major, enable 267 | 'jsx-a11y/prefer-tag-over-role': 'off', 268 | }, 269 | }; 270 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/rules/react-hooks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | 'react-hooks', 4 | ], 5 | 6 | parserOptions: { 7 | ecmaFeatures: { 8 | jsx: true, 9 | }, 10 | }, 11 | 12 | rules: { 13 | // Enforce Rules of Hooks 14 | // https://github.com/facebook/react/blob/c11015ff4f610ac2924d1fc6d569a17657a404fd/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js 15 | 'react-hooks/rules-of-hooks': 'error', 16 | 17 | // Verify the list of the dependencies for Hooks like useEffect and similar 18 | // https://github.com/facebook/react/blob/1204c789776cb01fbaf3e9f032e7e2ba85a44137/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js 19 | 'react-hooks/exhaustive-deps': 'error', 20 | }, 21 | }; 22 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | // disabled because I find it tedious to write tests while following this rule 4 | "no-shadow": 0, 5 | 6 | // tests uses `t` for tape 7 | "id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/test/requires.js: -------------------------------------------------------------------------------- 1 | /* eslint strict: 0, global-require: 0 */ 2 | 3 | 'use strict'; 4 | 5 | const test = require('tape'); 6 | 7 | test('all entry points parse', (t) => { 8 | t.doesNotThrow(() => require('..'), 'index does not throw'); 9 | t.doesNotThrow(() => require('../base'), 'base does not throw'); 10 | t.doesNotThrow(() => require('../legacy'), 'legacy does not throw'); 11 | t.doesNotThrow(() => require('../whitespace'), 'whitespace does not throw'); 12 | t.doesNotThrow(() => require('../hooks'), 'hooks does not throw'); 13 | 14 | t.end(); 15 | }); 16 | -------------------------------------------------------------------------------- /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 | const rulesDir = path.join(__dirname, '../rules'); 10 | fs.readdirSync(rulesDir).forEach((name) => { 11 | if (name === 'react.js' || name === 'react-a11y.js') { 12 | return; 13 | } 14 | 15 | // eslint-disable-next-line import/no-dynamic-require 16 | files[name] = require(path.join(rulesDir, name)); // eslint-disable-line global-require 17 | }); 18 | 19 | Object.keys(files).forEach((name) => { 20 | const config = files[name]; 21 | 22 | test(`${name}: does not reference react`, (t) => { 23 | t.plan(2); 24 | 25 | // scan plugins for react and fail if it is found 26 | const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') 27 | && config.plugins.indexOf('react') !== -1; 28 | t.notOk(hasReactPlugin, 'there is no react plugin'); 29 | 30 | // scan rules for react/ and fail if any exist 31 | const reactRuleIds = Object.keys(config.rules) 32 | .filter((ruleId) => ruleId.indexOf('react/') === 0); 33 | t.deepEquals(reactRuleIds, [], 'there are no react/ rules'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/test/test-react-order.js: -------------------------------------------------------------------------------- 1 | import test from 'tape'; 2 | import { CLIEngine, ESLint } from 'eslint'; 3 | import eslintrc from '..'; 4 | import reactRules from '../rules/react'; 5 | import reactA11yRules from '../rules/react-a11y'; 6 | 7 | const rules = { 8 | // It is okay to import devDependencies in tests. 9 | 'import/no-extraneous-dependencies': [2, { devDependencies: true }], 10 | // this doesn't matter for tests 11 | 'lines-between-class-members': 0, 12 | // otherwise we need some junk in our fixture code 13 | 'react/no-unused-class-component-methods': 0, 14 | }; 15 | const cli = new (CLIEngine || ESLint)({ 16 | useEslintrc: false, 17 | baseConfig: eslintrc, 18 | ...(CLIEngine ? { rules } : { overrideConfig: { rules } }), 19 | }); 20 | 21 | async function lint(text) { 22 | // @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles 23 | // @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeontext 24 | const linter = CLIEngine ? cli.executeOnText(text) : await cli.lintText(text); 25 | return (CLIEngine ? linter.results : linter)[0]; 26 | } 27 | 28 | function wrapComponent(body) { 29 | return `\ 30 | import React from 'react'; 31 | 32 | export default class MyComponent extends React.Component { 33 | /* eslint no-empty-function: 0, class-methods-use-this: 0 */ 34 | ${body}} 35 | `; 36 | } 37 | 38 | test('validate react methods order', (t) => { 39 | t.test('make sure our eslintrc has React and JSX linting dependencies', (t) => { 40 | t.plan(2); 41 | t.deepEqual(reactRules.plugins, ['react']); 42 | t.deepEqual(reactA11yRules.plugins, ['jsx-a11y', 'react']); 43 | }); 44 | 45 | t.test('passes a good component', async (t) => { 46 | const result = await lint(wrapComponent(` 47 | componentDidMount() {} 48 | handleSubmit() {} 49 | onButtonAClick() {} 50 | setFoo() {} 51 | getFoo() {} 52 | setBar() {} 53 | someMethod() {} 54 | renderDogs() {} 55 | render() { return
; } 56 | `)); 57 | 58 | t.notOk(result.warningCount, 'no warnings'); 59 | t.deepEquals(result.messages, [], 'no messages in results'); 60 | t.notOk(result.errorCount, 'no errors'); 61 | }); 62 | 63 | t.test('order: when random method is first', async (t) => { 64 | const result = await lint(wrapComponent(` 65 | someMethod() {} 66 | componentDidMount() {} 67 | setFoo() {} 68 | getFoo() {} 69 | setBar() {} 70 | renderDogs() {} 71 | render() { return
; } 72 | `)); 73 | 74 | t.ok(result.errorCount, 'fails'); 75 | t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort'); 76 | }); 77 | 78 | t.test('order: when random method after lifecycle methods', async (t) => { 79 | const result = await lint(wrapComponent(` 80 | componentDidMount() {} 81 | someMethod() {} 82 | setFoo() {} 83 | getFoo() {} 84 | setBar() {} 85 | renderDogs() {} 86 | render() { return
; } 87 | `)); 88 | 89 | t.ok(result.errorCount, 'fails'); 90 | t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort'); 91 | }); 92 | 93 | t.test('order: when handler method with `handle` prefix after method with `on` prefix', async (t) => { 94 | const result = await lint(wrapComponent(` 95 | componentDidMount() {} 96 | onButtonAClick() {} 97 | handleSubmit() {} 98 | setFoo() {} 99 | getFoo() {} 100 | render() { return
; } 101 | `)); 102 | 103 | t.ok(result.errorCount, 'fails'); 104 | t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort'); 105 | }); 106 | 107 | t.test('order: when lifecycle methods after event handler methods', async (t) => { 108 | const result = await lint(wrapComponent(` 109 | handleSubmit() {} 110 | componentDidMount() {} 111 | setFoo() {} 112 | getFoo() {} 113 | render() { return
; } 114 | `)); 115 | 116 | t.ok(result.errorCount, 'fails'); 117 | t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort'); 118 | }); 119 | 120 | t.test('order: when event handler methods after getters and setters', async (t) => { 121 | const result = await lint(wrapComponent(` 122 | componentDidMount() {} 123 | setFoo() {} 124 | getFoo() {} 125 | handleSubmit() {} 126 | render() { return
; } 127 | `)); 128 | 129 | t.ok(result.errorCount, 'fails'); 130 | t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort'); 131 | }); 132 | }); 133 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/whitespace-async.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const { isArray } = Array; 4 | const { entries } = Object; 5 | const { ESLint } = require('eslint'); 6 | 7 | const baseConfig = require('.'); 8 | const whitespaceRules = require('./whitespaceRules'); 9 | 10 | const severities = ['off', 'warn', 'error']; 11 | 12 | function getSeverity(ruleConfig) { 13 | if (isArray(ruleConfig)) { 14 | return getSeverity(ruleConfig[0]); 15 | } 16 | if (typeof ruleConfig === 'number') { 17 | return severities[ruleConfig]; 18 | } 19 | return ruleConfig; 20 | } 21 | 22 | async function onlyErrorOnRules(rulesToError, config) { 23 | const errorsOnly = { ...config }; 24 | const cli = new ESLint({ 25 | useEslintrc: false, 26 | baseConfig: config 27 | }); 28 | const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules; 29 | 30 | entries(baseRules).forEach((rule) => { 31 | const ruleName = rule[0]; 32 | const ruleConfig = rule[1]; 33 | const severity = getSeverity(ruleConfig); 34 | 35 | if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { 36 | if (isArray(ruleConfig)) { 37 | errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); 38 | } else if (typeof ruleConfig === 'number') { 39 | errorsOnly.rules[ruleName] = 1; 40 | } else { 41 | errorsOnly.rules[ruleName] = 'warn'; 42 | } 43 | } 44 | }); 45 | 46 | return errorsOnly; 47 | } 48 | 49 | onlyErrorOnRules(whitespaceRules, baseConfig).then((config) => console.log(JSON.stringify(config))); 50 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/whitespace.js: -------------------------------------------------------------------------------- 1 | /* eslint global-require: 0 */ 2 | 3 | const { isArray } = Array; 4 | const { entries } = Object; 5 | const { CLIEngine } = require('eslint'); 6 | 7 | if (CLIEngine) { 8 | /* eslint no-inner-declarations: 0 */ 9 | const whitespaceRules = require('./whitespaceRules'); 10 | 11 | const baseConfig = require('.'); 12 | 13 | const severities = ['off', 'warn', 'error']; 14 | 15 | function getSeverity(ruleConfig) { 16 | if (isArray(ruleConfig)) { 17 | return getSeverity(ruleConfig[0]); 18 | } 19 | if (typeof ruleConfig === 'number') { 20 | return severities[ruleConfig]; 21 | } 22 | return ruleConfig; 23 | } 24 | 25 | function onlyErrorOnRules(rulesToError, config) { 26 | const errorsOnly = { ...config }; 27 | const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); 28 | const baseRules = cli.getConfigForFile(require.resolve('./')).rules; 29 | 30 | entries(baseRules).forEach((rule) => { 31 | const ruleName = rule[0]; 32 | const ruleConfig = rule[1]; 33 | const severity = getSeverity(ruleConfig); 34 | 35 | if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { 36 | if (isArray(ruleConfig)) { 37 | errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); 38 | } else if (typeof ruleConfig === 'number') { 39 | errorsOnly.rules[ruleName] = 1; 40 | } else { 41 | errorsOnly.rules[ruleName] = 'warn'; 42 | } 43 | } 44 | }); 45 | 46 | return errorsOnly; 47 | } 48 | 49 | module.exports = onlyErrorOnRules(whitespaceRules, baseConfig); 50 | } else { 51 | const path = require('path'); 52 | const { execSync } = require('child_process'); 53 | 54 | // NOTE: ESLint adds runtime statistics to the output (so it's no longer JSON) if TIMING is set 55 | module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'), { 56 | env: { 57 | ...process.env, 58 | TIMING: undefined, 59 | } 60 | }))); 61 | } 62 | -------------------------------------------------------------------------------- /packages/eslint-config-airbnb/whitespaceRules.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'array-bracket-newline', 3 | 'array-bracket-spacing', 4 | 'array-element-newline', 5 | 'arrow-spacing', 6 | 'block-spacing', 7 | 'comma-spacing', 8 | 'computed-property-spacing', 9 | 'dot-location', 10 | 'eol-last', 11 | 'func-call-spacing', 12 | 'function-paren-newline', 13 | 'generator-star-spacing', 14 | 'implicit-arrow-linebreak', 15 | 'indent', 16 | 'key-spacing', 17 | 'keyword-spacing', 18 | 'line-comment-position', 19 | 'linebreak-style', 20 | 'multiline-ternary', 21 | 'newline-per-chained-call', 22 | 'no-irregular-whitespace', 23 | 'no-mixed-spaces-and-tabs', 24 | 'no-multi-spaces', 25 | 'no-regex-spaces', 26 | 'no-spaced-func', 27 | 'no-trailing-spaces', 28 | 'no-whitespace-before-property', 29 | 'nonblock-statement-body-position', 30 | 'object-curly-newline', 31 | 'object-curly-spacing', 32 | 'object-property-newline', 33 | 'one-var-declaration-per-line', 34 | 'operator-linebreak', 35 | 'padded-blocks', 36 | 'padding-line-between-statements', 37 | 'rest-spread-spacing', 38 | 'semi-spacing', 39 | 'semi-style', 40 | 'space-before-blocks', 41 | 'space-before-function-paren', 42 | 'space-in-parens', 43 | 'space-infix-ops', 44 | 'space-unary-ops', 45 | 'spaced-comment', 46 | 'switch-colon-spacing', 47 | 'template-tag-spacing', 48 | 'import/newline-after-import', 49 | 50 | // eslint-plugin-react rules 51 | 'react/jsx-child-element-spacing', 52 | 'react/jsx-closing-bracket-location', 53 | 'react/jsx-closing-tag-location', 54 | 'react/jsx-curly-spacing', 55 | 'react/jsx-equals-spacing', 56 | 'react/jsx-first-prop-newline', 57 | 'react/jsx-indent', 58 | 'react/jsx-indent-props', 59 | 'react/jsx-max-props-per-line', 60 | 'react/jsx-one-expression-per-line', 61 | 'react/jsx-space-before-closing', 62 | 'react/jsx-tag-spacing', 63 | 'react/jsx-wrap-multilines', 64 | ]; 65 | -------------------------------------------------------------------------------- /react/README.md: -------------------------------------------------------------------------------- 1 | # Airbnb React/JSX Style Guide 2 | 3 | *A mostly reasonable approach to React and JSX* 4 | 5 | This style guide is mostly based on the standards that are currently prevalent in JavaScript, although some conventions (i.e async/await or static class fields) may still be included or prohibited on a case-by-case basis. Currently, anything prior to stage 3 is not included nor recommended in this guide. 6 | 7 | ## Table of Contents 8 | 9 | 1. [Basic Rules](#basic-rules) 10 | 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless) 11 | 1. [Mixins](#mixins) 12 | 1. [Naming](#naming) 13 | 1. [Declaration](#declaration) 14 | 1. [Alignment](#alignment) 15 | 1. [Quotes](#quotes) 16 | 1. [Spacing](#spacing) 17 | 1. [Props](#props) 18 | 1. [Refs](#refs) 19 | 1. [Parentheses](#parentheses) 20 | 1. [Tags](#tags) 21 | 1. [Methods](#methods) 22 | 1. [Ordering](#ordering) 23 | 1. [`isMounted`](#ismounted) 24 | 25 | ## Basic Rules 26 | 27 | - Only include one React component per file. 28 | - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint: [`react/no-multi-comp`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless). 29 | - Always use JSX syntax. 30 | - Do not use `React.createElement` unless you’re initializing the app from a file that is not JSX. 31 | - [`react/forbid-prop-types`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md) will allow `arrays` and `objects` only if it is explicitly noted what `array` and `object` contains, using `arrayOf`, `objectOf`, or `shape`. 32 | 33 | ## Class vs `React.createClass` vs stateless 34 | 35 | - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass`. eslint: [`react/prefer-es6-class`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) 36 | 37 | ```jsx 38 | // bad 39 | const Listing = React.createClass({ 40 | // ... 41 | render() { 42 | return
{this.state.hello}
; 43 | } 44 | }); 45 | 46 | // good 47 | class Listing extends React.Component { 48 | // ... 49 | render() { 50 | return
{this.state.hello}
; 51 | } 52 | } 53 | ``` 54 | 55 | And if you don’t have state or refs, prefer normal functions (not arrow functions) over classes: 56 | 57 | ```jsx 58 | // bad 59 | class Listing extends React.Component { 60 | render() { 61 | return
{this.props.hello}
; 62 | } 63 | } 64 | 65 | // bad (relying on function name inference is discouraged) 66 | const Listing = ({ hello }) => ( 67 |
{hello}
68 | ); 69 | 70 | // good 71 | function Listing({ hello }) { 72 | return
{hello}
; 73 | } 74 | ``` 75 | 76 | ## Mixins 77 | 78 | - [Do not use mixins](https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html). 79 | 80 | > Why? Mixins introduce implicit dependencies, cause name clashes, and cause snowballing complexity. Most use cases for mixins can be accomplished in better ways via components, higher-order components, or utility modules. 81 | 82 | ## Naming 83 | 84 | - **Extensions**: Use `.jsx` extension for React components. eslint: [`react/jsx-filename-extension`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md) 85 | - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`. 86 | - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) 87 | 88 | ```jsx 89 | // bad 90 | import reservationCard from './ReservationCard'; 91 | 92 | // good 93 | import ReservationCard from './ReservationCard'; 94 | 95 | // bad 96 | const ReservationItem = ; 97 | 98 | // good 99 | const reservationItem = ; 100 | ``` 101 | 102 | - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name: 103 | 104 | ```jsx 105 | // bad 106 | import Footer from './Footer/Footer'; 107 | 108 | // bad 109 | import Footer from './Footer/index'; 110 | 111 | // good 112 | import Footer from './Footer'; 113 | ``` 114 | 115 | - **Higher-order Component Naming**: Use a composite of the higher-order component’s name and the passed-in component’s name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`. 116 | 117 | > Why? A component’s `displayName` may be used by developer tools or in error messages, and having a value that clearly expresses this relationship helps people understand what is happening. 118 | 119 | ```jsx 120 | // bad 121 | export default function withFoo(WrappedComponent) { 122 | return function WithFoo(props) { 123 | return ; 124 | } 125 | } 126 | 127 | // good 128 | export default function withFoo(WrappedComponent) { 129 | function WithFoo(props) { 130 | return ; 131 | } 132 | 133 | const wrappedComponentName = WrappedComponent.displayName 134 | || WrappedComponent.name 135 | || 'Component'; 136 | 137 | WithFoo.displayName = `withFoo(${wrappedComponentName})`; 138 | return WithFoo; 139 | } 140 | ``` 141 | 142 | - **Props Naming**: Avoid using DOM component prop names for different purposes. 143 | 144 | > Why? People expect props like `style` and `className` to mean one specific thing. Varying this API for a subset of your app makes the code less readable and less maintainable, and may cause bugs. 145 | 146 | ```jsx 147 | // bad 148 | 149 | 150 | // bad 151 | 152 | 153 | // good 154 | 155 | ``` 156 | 157 | ## Declaration 158 | 159 | - Do not use `displayName` for naming components. Instead, name the component by reference. 160 | 161 | ```jsx 162 | // bad 163 | export default React.createClass({ 164 | displayName: 'ReservationCard', 165 | // stuff goes here 166 | }); 167 | 168 | // good 169 | export default class ReservationCard extends React.Component { 170 | } 171 | ``` 172 | 173 | ## Alignment 174 | 175 | - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) [`react/jsx-closing-tag-location`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md) 176 | 177 | ```jsx 178 | // bad 179 | 181 | 182 | // good 183 | 187 | 188 | // if props fit in one line then keep it on the same line 189 | 190 | 191 | // children get indented normally 192 | 196 | 197 | 198 | 199 | // bad 200 | {showButton && 201 |