saadq / lynt

✨ A zero config JavaScript linter with support for Typescript, Flow, and React.
MIT License
384 stars 6 forks source link

Add an example to api docs where typescript is used #6

Open saadq opened 6 years ago

saadq commented 6 years ago

The current API docs: https://github.com/saadq/lynt#api

There should be an example that shows how project works with the TypeScript flag. By default, if no project flag is passed and the files argument is an empty array, lynt will assume that project is in the current working directory . and will look for a tsconfig.json there.

import lynt from 'lynt'

const options = {
  typescript: true
}

const results = lynt([], options) // Will look for `./tsconfig.json` and use that to know which files to lint in the project.

A project option can be explicitly passed if tsconfig.json isn't in the current directory (like in ./config/tsconfig.json):

import lynt from 'lynt'

const options = {
  typescript: true,
  project: './config'
}

const results = lynt([], options) // Will look for `./config/tsconfig.json` and use that to know which files to lint in the project.

If files are given, a project flag should not be passed in (because it will just ignore the files and just use the tsconfig in the project to know which files to lint). However, passing files when using the typescript option will make you opt-out of some lint rules that require type information from the whole project, so passing in files is not recommended.

// Not recommended

import lynt from 'lynt'

const files = ['./foo.ts', './bar.ts']

const options = {
  typescript: true
}

const results = lynt(files, options) 
tunnckoCore commented 6 years ago

Yea i was wondering about that option and know kinda understand what is about, so consider to rename it? Might make more sense to be such as tsroot, typescript-root, tsconfig-root or whatever.. don't know exactly.

saadq commented 6 years ago

Those might be more explicit, but I want to keep the name project because it will be familiar to TSLint users. The flag for giving a path to your tsconfig.json with TSLint is also called --project https://palantir.github.io/tslint/usage/cli/#cli-usage