Skip to content

Commit

Permalink
typescript config
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Racco committed Apr 15, 2020
1 parent 573164f commit 95103c1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Mandatory in any project

1. [A language version manager](#language-version-manager);
1. [Editorconfig](#editorconfig);
1. [A linting tool](#linting-tool);
- [MIKAMAI Dress Code](#mikamai-dress-code)
- [Mandatory in any project](#mandatory-in-any-project)
- [Language version manager](#language-version-manager)
- [Editorconfig](#editorconfig)
- [Linting tool](#linting-tool)

### Language version manager

Expand All @@ -19,4 +21,5 @@ We use [Editorconfig](http://editorconfig.org) to keep the same coding standard
### Linting tool

For Javascript we use [ESLint](https://eslint.org/). See [our configuration](eslint/).
For Typescript projects we use [ESLint](https://eslint.org/) and [Prettier](https://prettier.io/). See [our configuration](typescript/).
For Ruby we use [RuboCop](https://github.com/bbatsov/rubocop). See [our configuration](rubocop/);
1 change: 1 addition & 0 deletions typescript/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules
23 changes: 23 additions & 0 deletions typescript/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
6 changes: 6 additions & 0 deletions typescript/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: false,
singleQuote: true,
trailingComma: 'all',
};
34 changes: 34 additions & 0 deletions typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Typescript configuration

Typescript projects configuration is done via eslint and prettier, following their recommended configuration.

## Installation

```bash
$ npm install -D eslint eslint-config-prettier eslint-plugin-prettier prettier @typescript-eslint/eslint-plugin @typescript-eslint/parser
$ curl -o .eslintrc.js https://github.com/mikamai/dress-code/raw/master/typescript/.eslintrc.js
$ curl -o .prettierrc.js https://github.com/mikamai/dress-code/raw/master/typescript/.prettierrc.js
$ curl -O https://github.com/mikamai/dress-code/raw/master/eslint/.eslintignore
```

You also need to specify the path pattern to eslint command. Add a `lint` script in your package.json to run `eslint . --ext .ts`

## Customization

Remember to add an env property detailing your target env, so that eslint will not raise unexistent errors. For example, for a browser library, you would add:

```json
"env": {
"browser": true
}
```

## Tests

Tests may follow different rules, and usually it would be enough to just add some overrides. There are some cases (like with mocha and jest) when you also need to set a specific env (which cannot be set in overrides). In this case, define a new `.eslintrc.js` file in your `tests` folder. It will inherit the file in the root folder by default. For example:

```json
"env": {
"jest": true
}
```

0 comments on commit 95103c1

Please sign in to comment.