# Linter

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 [TSLint](https://palantir.github.io/tslint/) 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:

{% code title="packages/api/index.ts " %}

```typescript
var test = function () {
    return 'hello world'
}
```

{% endcode %}

```
$ 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 [all the available rules](https://palantir.github.io/tslint/rules/).

### 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:

{% code title="packages/api/tslint.json" %}

```typescript
{
    "extends": ["../../tslint.json"]
}

```

{% endcode %}

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

{% hint style="info" %}
[`linter`](https://github.com/florianherrengt/book-code/tree/linter) branch available on GitHub.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tutorial.specian.co.uk/project-setup/linter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
