💻
Building and hosting a WebApp
  • Getting started
  • Project setup
    • Requirements
    • Files organisation
    • Lerna
    • Linter
    • Prettier
    • GitHook
    • Testing
    • Conclusion
  • Backend
    • Files organisation
    • Environment config
    • Express API
    • Security
    • Database
    • GraphQL
    • User authentication
    • Conclusion
  • Frontend
    • Create React App
    • Files organisation
    • Styles
    • Apollo Hooks
    • Form management
    • User authentication
    • Writing tests
    • Types generation
    • Conclusion
  • DevOps
    • CI/CD
    • AWS
      • Managing secrets
      • Pricing
      • RDS
      • S3
      • Route53
      • CloudFront
      • Serverless
      • Security
      • CloudFormation
    • Conclusion
  • 🚧Stripe payment
  • 🚧File upload
Powered by GitBook
On this page

Was this helpful?

  1. Project setup

Linter

PreviousLernaNextPrettier

Last updated 5 years ago

Was this helpful?

A linter is the equivalent of a grammar check for code. It doesn't mean the code is correct, but it helps maintain consistency across the code base.

For this project, we will be using for Typescript.

Let's start by adding typescript and tslint and creating a tslint.json file at the root of the project.

$ yarn add tslint typescript
$ tslint --init

Create a file in packages/api/index.ts with invalid code structure:

packages/api/index.ts
var test = function () {
    return 'hello world'
}
$ tslint packages/api/index.ts

ERROR: packages/api/index.ts:1:1 - Forbidden 'var' keyword, use 'let' or 'const' instead
ERROR: packages/api/index.ts:1:12 - non-arrow functions are forbidden
ERROR: packages/api/index.ts:1:20 - Spaces before function parens are disallowed
ERROR: packages/api/index.ts:2:12 - ' should be "
ERROR: packages/api/index.ts:2:25 - Missing semicolon
ERROR: packages/api/index.ts:3:2 - file should end with a newline
ERROR: packages/api/index.ts:3:2 - Missing semicolon

Have a look at .

Project specific configuration

The Node API and React app tslint.json configuration could be different. We can share common rules between the project from the root.

$ cd packages/api
yarn add tslint typescript
tslint --init

Replace the content of packages/api/tslint.json with:

packages/api/tslint.json
{
    "extends": ["../../tslint.json"]
}

You can do the same with web but we'll come back to it later.

branch available on GitHub.

TSLint
all the available rules
linter