• Use camelCase when naming objects, functions, and instances. eslint: camelcase

    1. // bad
    2. const OBJEcttsssss = {};
    3. const this_is_my_object = {};
    4. function c() {}
    5. // good
    6. const thisIsMyObject = {};
    7. function thisIsMyFunction() {}

  • Use PascalCase only when naming constructors or classes. eslint: new-cap

    1. // bad
    2. function user(options) {
    3. this.name = options.name;
    4. }
    5. const bad = new user({
    6. name: 'nope',
    7. });
    8. // good
    9. class User {
    10. constructor(options) {
    11. this.name = options.name;
    12. }
    13. }
    14. const good = new User({
    15. name: 'yup',
    16. });

  • Don’t save references to this. Use arrow functions or Function#bind.

    1. // bad
    2. function foo() {
    3. const self = this;
    4. return function () {
    5. console.log(self);
    6. };
    7. }
    8. const that = this;
    9. return function () {
    10. console.log(that);
    11. };
    12. }
    13. // good
    14. function foo() {
    15. return () => {
    16. console.log(this);
    17. };
    18. }

  • A base filename should exactly match the name of its default export.

    1. // file 1 contents
    2. class CheckBox {
    3. // ...
    4. }
    5. export default CheckBox;
    6. // file 2 contents
    7. export default function fortyTwo() { return 42; }
    8. // file 3 contents
    9. export default function insideDirectory() {}
    10. // in some other file
    11. // bad
    12. import CheckBox from './checkBox'; // PascalCase import/export, camelCase filename
    13. import FortyTwo from './FortyTwo'; // PascalCase import/filename, camelCase export
    14. import InsideDirectory from './InsideDirectory'; // PascalCase import/filename, camelCase export
    15. // bad
    16. import CheckBox from './check_box'; // PascalCase import/export, snake_case filename
    17. import forty_two from './forty_two'; // snake_case import/filename, camelCase export
    18. import inside_directory from './inside_directory'; // snake_case import, camelCase export
    19. import index from './inside_directory/index'; // requiring the index file explicitly
    20. import insideDirectory from './insideDirectory/index'; // requiring the index file explicitly
    21. // good
    22. import insideDirectory from './insideDirectory'; // camelCase export/import/directory name/implicit "index"
    23. // ^ supports both insideDirectory.js and insideDirectory/index.js

  • 23.8 Use PascalCase when you export a constructor / class / singleton / function library / bare object.

    1. const AirbnbStyleGuide = {
    2. es6: {
    3. },
    4. };
    5. export default AirbnbStyleGuide;

  • 23.9 Acronyms and initialisms should always be all capitalized, or all lowercased.

    1. // bad
    2. import SmsContainer from './containers/SmsContainer';
    3. // bad
    4. const HttpRequests = [
    5. // ...
    6. ];
    7. // good
    8. import SMSContainer from './containers/SMSContainer';
    9. // good
    10. const HTTPRequests = [
    11. // ...
    12. ];
    13. // also good
    14. const httpRequests = [
    15. // ...
    16. ];
    17. // best
    18. import TextMessageContainer from './containers/TextMessageContainer';
    19. // best
    20. const requests = [
    21. // ...
    22. ];