Giter Site home page Giter Site logo

node-ts / code-standards Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 7.0 8 KB

An opinionated set of linting and build configurations for typescript projects to build modern, maintainable TypeScript projects.

tslint lint code-style code-standards typescript node configuration bootstrap

code-standards's Introduction

@node-ts/code-standards

CircleCI

An opinionated set of linting and build configurations for typescript projects to build modern, maintainable TypeScript projects.

Linting

The linting rules aim to produce terse, neat and consistent TypeScript code. This is valuable in any repo that has more than one contributor, but single author projects may also find it useful.

Below shows a small example of the code produced with this style:

// Enforce ES6 style imports
import { S3 } from 'aws-sdk' // single quotes, no semicolon on the end of lines

export class ObjectStorageService {

  constructor ( // double-space indents
    private readonly s3 = new S3()
  ) {
  }

  async upload (bucket: string, key: string, body: Buffer): Promise<void> { // enforce complete method signature
    const putObjectRequest: S3.Types.PutObjectRequest = { // prefer const
      Bucket: bucket,
      Key: key,
      Body: body
    }
    await this.s3.putObject(putObjectRequest).promise()
  }

}
// All files end with a new line (LF)

TypeScript Configuration

TypeScript options have been set in tsconfig.json that target Node v8 and up. These options can be overridden for web projects that target browsers.

Installation

  1. Install into your project along with tslint and typescript

    npm i @node-ts/code-standards tslint typescript --save-dev
  2. Copy .editorconfig into the root of your project. This will let your code editor confirm to many of the whitespacing rules automatically. See Editor Config on setting up your code editor for the first time.

  3. Create a tslint.json file in the root of your project with the following contents:

    {
      "extends": "./node_modules/@node-ts/code-standards/tslint.json"
    }
  4. Create a tsconfig.json file in the root of your project with the following contents. You may wish to extend this with further options

    {
      "extends": "./node_modules/@node-ts/code-standards/tsconfig.json"
    }
  5. Add the following to the scripts block in your project's package.json:

    {
      "lint": "tslint --project tsconfig.json 'src/**/*.ts'",
      "lint:fix": "npm lint --fix"
    }

IDE Configuration

IDE defaults for line spacing, whitespace etc can be set by placing an .editorconfig file (like the one in this package) into the root of your project. This is used by the Editor Config plugin of your preferred browser to set such defaults for your project.

This helps ensure any characters inserted by your editor conforms to the linting rules in this package.

Overriding Rules

Individual rules can be overridden if they do not suit the particular project they're being imported into. This is common for web sites that need to transpile slightly differently to a regular node application.

In tslint.json

Individual linting rules cna be overridden by specifying the updated rule in your local tslint.json file as such:

{
  "extends": "./node_modules/@node-ts/code-standards/tslint.json",
  "rules": {
    "semicolon": [true, "always"]
  }
}

In tsconfig.json

Similar to linting, TypeScript configuration options can be overridden by specifying the updated values in the local tsconfig.json file.

For example:

{
  "extends": "./node_modules/@node-ts/code-standards/tsconfig.json",
  "compilerOptions": {
    "target": "es6",
    "lib": ["es7"]
  }
}

code-standards's People

Contributors

adenhertog avatar

Stargazers

 avatar

Watchers

 avatar  avatar

code-standards's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.