New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
2
Weekly downloads
 
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 Unused Parameters: Remove them. To prevent them make sure to use noUnusedParameters in your tsconfig.json file.

    We may end up with parameters that are not used when we refactor. If we keep them we risk having incorrect documentation and all sort of confusions.

    In some cases, when creating listeners a function may require a certain signature which will undoubtedly bring us unused parameters. When this is the case simply name the placeholder variables with a leading underscore.

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

⬆ back to top

Arrow Functions

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

    Why? It creates a version of the function that executes in the context of this, which is usually what you want, and is a more concise syntax.

    Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.

    // 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 Braces: 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 Cuddled Elses: 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 Spaces: Use soft tabs set to 2 spaces.

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

  • 4.2 In Braces: Add spaces inside curly braces.

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

⬆ back to top

Commas

  • 5.1 Leading Trailing: 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 Use Them: Always use modules (import/export) over a non-standard module system. You can always transpile to your preferred module system.

    Why? Modules are the future

    // 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 Single Export: Do not use default exports. Use a single named export which declares all the classes, functions, objects and interfaces that the module is exporting.

    Why? Named imports/exports promote clarity. In addition, current tooling differs on the correct way to handle default imports/exports. Avoiding them all together can help avoid tooling bugs and conflicts.

    Using a single named export allows us to see in one place all the objects that we are 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