Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ioffice/tslint-config-ioffice

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ioffice/tslint-config-ioffice

IOFFICE TypeScript Style Guide

  • 0.0.1-beta.1804261152
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

iOffice TypeScript Style Guide

Table of Contents

  1. Functions
    1. Unused Parameters
  2. Arrow Functions
    1. Use Them
  3. Blocks
    1. Braces
    2. Cuddled Elses
  4. Whitespace
    1. Spaces
    2. In Braces
  5. Commas
    1. Leading Trailing
  6. Modules
    1. Use Them
    2. Single Export

Functions

  • 1.1 Remove them. To prevent them make sure to use noUnusedParameters in your tsconfig.json file.

    // bad
    function foo(a, b, c) {
      return a + b;
    }
    
    // good
    function foo(a, b) {
      return a + b;
    }
    

⬆ back to top

Arrow Functions

  • 2.1 When you must use function expressions (as when passing an anonymous function), use arrow function notation.

    // bad
    [1, 2, 3].map(function (x) {
      const y = x + 1;
      return x * y;
    });
    
    // good
    [1, 2, 3].map((x) => {
      const y = x + 1;
      return x * y;
    });
    
    // good
    [0, null, 1, null, 2].filter(x => x !== null);
    

⬆ back to top

Blocks

  • 3.1 Use braces with all multi-line blocks.

    // bad
    if (test)
      return false;
    
    // good
    if (test) return false;
    
    // good
    if (test) {
      return false;
    }
    
    // bad
    function foo() { return false; }
    
    // good
    function bar() {
      return false;
    }
    

  • 3.2 If you're using multi-line blocks with if and else, put else on the same line as your if block's closing brace.

    // bad
    if (test) {
      thing1();
      thing2();
    }
    else {
      thing3();
    }
    
    // good
    if (test) {
      thing1();
      thing2();
    } else {
      thing3();
    }
    

⬆ back to top

Whitespace

  • 4.1 Use soft tabs set to 2 spaces.

    // bad
    function foo() {
        const name;
    }
    
    // bad
    function bar() {
     const name;
    }
    
    // good
    function baz() {
      const name;
    }
    

  • 4.2 Add spaces inside curly braces.

    // bad
    const foo = {clark: 'kent'};
    
    // good
    const foo = { clark: 'kent' };
    

⬆ back to top

Commas

  • 5.1 Leading commas: Nope.

    // bad
    const story = [
      once
      , upon
      , aTime
    ];
    
    // good
    const story = [
      once,
      upon,
      aTime,
    ];
    
    // bad
    const hero = {
      firstName: 'Ada'
      , lastName: 'Lovelace'
      , birthYear: 1815
      , superPower: 'computers'
    };
    
    // good
    const hero = {
      firstName: 'Ada',
      lastName: 'Lovelace',
      birthYear: 1815,
      superPower: 'computers',
    };
    

⬆ back to top

Modules

  • 6.1 Always use modules (import/export) over a non-standard module system. You can always transpile to your preferred module system.

    // bad
    const iOfficeStyleGuide = require('./iOfficeStyleGuide');
    module.exports = iOfficeStyleGuide.ts;
    
    // ok
    import * as iOfficeStyleGuide from './iOfficeStyleGuide';
    const ts = iOfficeStyleGuide.ts;
    export {
      ts,
    };
    
    // best
    import { ts } from './iOfficeStyleGuide';
    export {
      ts,
    };
    

  • 6.2 Do not use default exports. Use a single named export which declares all the classes, functions, objects and interfaces that the module is exporting.

    // bad
    export class A {}
    export class B {}
    export default A;
    
    // good
    class C {}
    class D {}
    export {
      C,
      D,
    };
    
    // bad
    export default function() {
    }
    
    // good
    function A() {
    }
    export { A };
    
    // good
    function A() {
    }
    export { A };
    

⬆ back to top

Keywords

FAQs

Package last updated on 26 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc