Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move samples and template from TSLint to ESLint #561

Merged
merged 15 commits into from Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions docs/development-environment/linting-and-code-style.md
@@ -1,14 +1,30 @@
# Linting and Code Style

FoalTS comes up with a pre configuration for the linter [TSLint](https://palantir.github.io/tslint/).
FoalTS comes up with a pre configuration for the linter [ESLint](https://eslint.org/) with [typescript-eslint](https://typescript-eslint.io/).

> *TSLint is an extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely supported across modern editors & build systems and can be customized with your own lint rules, configurations, and formatters.*
> *ESLint is an open source project originally created by Nicholas C. Zakas in June 2013. Its goal is to provide a pluggable linting utility for JavaScript..*
>
> Source: https://palantir.github.io/tslint/
> Source: https://eslint.org/

This configuration is stored in the json file `tslint.json`.
> * `@typescript-eslint/parser` - An ESLint-specific parser which leverages `typescript-estree` and is designed to be used as a replacement for ESLint's default parser, `espree`.
> * `@typescript-eslint/eslint-plugin` - An ESLint-specific plugin which, when used in conjunction with `@typescript-eslint/parser`, allows for TypeScript-specific linting rules to run.
>
> Source: https://typescript-eslint.io

Previously, FoalTS used TSLint, but it has since been [deprecated](https://medium.com/palantir/tslint-in-2019-1a144c2317a9).

> In order to avoid bifurcating the linting tool space for TypeScript, we therefore plan to deprecate TSLint and focus our efforts instead on improving ESLint’s TypeScript support.
>
> Source: https://medium.com/palantir/tslint-in-2019-1a144c2317a9

This configuration is stored in the js file `.eslintrc.js`.

You can run the linting with this command:
```sh
npm run lint
```

And if the linting issues can be fixed, you can also fix them with this command:
fer22f marked this conversation as resolved.
Show resolved Hide resolved
```sh
npm run lint:fix
```
Binary file removed docs/development-environment/tslint.gif
Binary file not shown.
20 changes: 16 additions & 4 deletions docs/development-environment/vscode.md
Expand Up @@ -10,11 +10,23 @@ But using VS Code is not mandatory to develop a FoalTS app. So feel free to use

## Configuring the linting

In order to directly print the tslint errors in VS Code and auto-fix the problems on save you need to install the `TSLint` extension.
In order to directly print the ESLint errors in VS Code and auto-fix the problems on save you need to install the `ESLint` extension which can be found in the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).

> *To open the menu with the search bar, use `Cmd`+`Shift`+`P` or `Ctrl`+`Shift`+`P`.*
It can be installed by launching VS Code Quick Open (`Ctrl+P` or `Cmd+P`), pasting the following command, and pressing enter:

![TSLint installation and configuration](./tslint.gif)
```
fer22f marked this conversation as resolved.
Show resolved Hide resolved
ext install dbaeumer.vscode-eslint
```
fer22f marked this conversation as resolved.
Show resolved Hide resolved

Then, you will need to activate it for TypeScript on your settings (`Ctrl+,` or `Cmd+,`):

1. Editing `eslint.validate` so that it has `"typescript"` with `"autoFix": true` by adding this to your `settings.json`:
```
"eslint.validate": [
{ "language": "typescript", "autoFix": true }
],
```
2. Activating `eslint.autoFixOnSave` if you want it to auto fix when you save (keep in mind it doesn't work with `files.autoSave` set to `afterDelay`).

## Debugging with VS Code

Expand All @@ -30,4 +42,4 @@ Now you can add a breakpoint in your code and start the app in debug mode.

The generated files also include configurations to run your unit and end-to-end tests (available since v1.0.0).

![Debug configurations](./debug-configurations.png)
![Debug configurations](./debug-configurations.png)
4 changes: 2 additions & 2 deletions docs/tutorials/mongodb-todo-list/1-installation.md
Expand Up @@ -35,7 +35,7 @@ my-app/
scripts/
package.json
tsconfig.*.json
tslint.json
.eslintrc.js
```

The outer `my-app` root directory is just a container for your project.
Expand All @@ -48,7 +48,7 @@ The outer `my-app` root directory is just a container for your project.
- The inner `scripts/` folder contains scripts intended to be called from the command line (ex: create-user).
- The `package.json` lists the dependencies and commands of the project.
- The `tsconfig.*.json` files list the TypeScript compiler configuration for each `npm` command.
- Finally the linting configuration can be found in the `tslint.json` file.
- Finally the linting configuration can be found in the `.eslintrc.js` file.

> **TypeScript**
>
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/multi-user-todo-list/6-todos-and-ownership.md
Expand Up @@ -48,7 +48,7 @@ Update the api controller.
})
async deleteTodo(ctx: Context) {
const todo = await getRepository(Todo).findOne({
id: (ctx.request.params as any).id,
id: +ctx.request.params.id,
// Do not return the todo if it does not belong to the current user.
owner: ctx.user
});
Expand All @@ -60,4 +60,4 @@ Update the api controller.
}
```

The application is now working properly.
The application is now working properly.
4 changes: 2 additions & 2 deletions docs/tutorials/simple-todo-list/1-installation.md
Expand Up @@ -34,7 +34,7 @@ my-app/
ormconfig.js
package.json
tsconfig.*.json
tslint.json
.eslintrc.js
```

The outer `my-app` root directory is just a container for your project.
Expand All @@ -48,7 +48,7 @@ The outer `my-app` root directory is just a container for your project.
- The `ormconfig.js` file defines the configuration and credentials of the database(s) connection(s). They can also be passed through environment variables.
- The `package.json` lists the dependencies and commands of the project.
- The `tsconfig.*.json` files list the TypeScript compiler configuration for each `npm` command.
- Finally the linting configuration can be found in the `tslint.json` file.
- Finally the linting configuration can be found in the `.eslintrc.js` file.

> **TypeScript**
>
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/simple-todo-list/5-the-rest-api.md
Expand Up @@ -72,7 +72,7 @@ Add the create and delete features.
@Delete('/todos/:id')
async deleteTodo(ctx: Context) {
// Get the todo with the id given in the URL if it exists.
const todo = await getRepository(Todo).findOne({ id: parseInt(ctx.request.params.id, 10) });
const todo = await getRepository(Todo).findOne({ id: +ctx.request.params.id });

// Return a 404 Not Found response if no such todo exists.
if (!todo) {
Expand Down
Expand Up @@ -56,7 +56,7 @@ export class ApiController {
type: 'object',
})
async deleteTodo(ctx: Context) {
const todo = await getRepository(Todo).findOne({ id: (ctx.request.params as any).id });
const todo = await getRepository(Todo).findOne({ id: +ctx.request.params.id });
if (!todo) {
return new HttpResponseNotFound();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Expand Up @@ -12,7 +12,7 @@
"dev:test:run-script": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --watch-extensions ts \"./src/run-script/**/*.spec.ts\"",
"test:create-secret": "mocha --file \"./src/test.ts\" --require ts-node/register \"./src/create-secret/**/*.spec.ts\"",
"dev:test:create-secret": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --watch-extensions ts \"./src/create-secret/**/*.spec.ts\"",
"build": "rimraf lib && tsc -p tsconfig-build.json && copyfiles -u 3 \"src/generate/templates/**/*\" lib/generate/templates",
"build": "rimraf lib && tsc -p tsconfig-build.json && copyfiles -a -u 3 \"src/generate/templates/**/*\" lib/generate/templates",
"prepublish": "npm run build"
},
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/generate/generators/app/create-app.spec.ts
Expand Up @@ -191,7 +191,7 @@ describe('createApp', () => {
.validateSpec('tsconfig.migrations.json')
.validateSpec('tsconfig.scripts.json')
.validateSpec('tsconfig.test.json')
.validateSpec('tslint.json');
.validateSpec('.eslintrc.js');
});
it('should render the root templates (YAML option).', async () => {
await createApp({ name: 'test-fooBar', yaml: true });
Expand All @@ -207,7 +207,7 @@ describe('createApp', () => {
.validateSpec('tsconfig.migrations.json')
.validateSpec('tsconfig.scripts.json')
.validateSpec('tsconfig.test.json')
.validateSpec('tslint.json');
.validateSpec('.eslintrc.js');
});

it('should render the root templates (MongoDB option).', async () => {
Expand All @@ -224,7 +224,7 @@ describe('createApp', () => {
.shouldNotExist('tsconfig.migrations.json')
.validateSpec('tsconfig.scripts.json')
.validateSpec('tsconfig.test.json')
.validateSpec('tslint.json');
.validateSpec('.eslintrc.js');
});

it('should render the root templates (MongoDB & YAML options).', async () => {
Expand All @@ -241,7 +241,7 @@ describe('createApp', () => {
.shouldNotExist('tsconfig.migrations.json')
.validateSpec('tsconfig.scripts.json')
.validateSpec('tsconfig.test.json')
.validateSpec('tslint.json');
.validateSpec('.eslintrc.js');
});

});
2 changes: 1 addition & 1 deletion packages/cli/src/generate/generators/app/create-app.ts
Expand Up @@ -106,7 +106,7 @@ export async function createApp({ name, autoInstall, initRepo, mongodb = false,
.copyFileFromTemplatesOnlyIf(!mongodb, 'tsconfig.migrations.json')
.copyFileFromTemplates('tsconfig.scripts.json')
.copyFileFromTemplates('tsconfig.test.json')
.copyFileFromTemplates('tslint.json')
.copyFileFromTemplates('.eslintrc.js')
// Config
.mkdirIfDoesNotExist('config')
.renderTemplateOnlyIf(!mongodb && !yaml, 'config/default.json', locals)
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/generate/specs/app/.eslintrc.js
@@ -0,0 +1,47 @@
module.exports = {
env: {
'browser': true,
'es6': true,
'node': true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module'
},
plugins: [
'@typescript-eslint'
],
rules: {
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/explicit-member-accessibility': [
'error', { 'accessibility': 'no-public' }
],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-empty-function': 'off',
fer22f marked this conversation as resolved.
Show resolved Hide resolved
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/quotes': ['error', 'single'],
'arrow-parens': ['error', 'as-needed'],
'max-classes-per-file': 'off',
'no-console': 'off',
'no-duplicate-imports': 'error',
'no-empty': 'off',
'no-shadow': 'off',
'comma-dangle': 'off',
'sort-keys': 'off',
'@typescript-eslint/no-unused-vars': ['error', { 'args': 'none' }],
fer22f marked this conversation as resolved.
Show resolved Hide resolved
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/require-await': 'off'
fer22f marked this conversation as resolved.
Show resolved Hide resolved
},
ignorePatterns: [
'src/migrations/*.ts'
]
};
14 changes: 6 additions & 8 deletions packages/cli/src/generate/specs/app/package.json
Expand Up @@ -8,24 +8,20 @@
"start": "node ./build/index.js",
"start:w": "supervisor -w ./build --no-restart-on error ./build/index.js",
"develop": "npm run build:app && concurrently \"npm run build:app:w\" \"npm run start:w\"",

"build:test": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.test.json",
"build:test:w": "tsc -p tsconfig.test.json -w",
"start:test": "mocha --file \"./build/test.js\" \"./build/**/*.spec.js\"",
"start:test:w": "mocha --file \"./build/test.js\" -w \"./build/**/*.spec.js\"",
"test": "npm run build:test && concurrently \"npm run build:test:w\" \"npm run start:test:w\"",

"build:e2e": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.e2e.json",
"build:e2e:w": "tsc -p tsconfig.e2e.json -w",
"start:e2e": "mocha --file \"./build/e2e.js\" \"./build/e2e/**/*.js\"",
"start:e2e:w": "mocha --file \"./build/e2e.js\" -w \"./build/e2e/**/*.js\"",
"e2e": "npm run build:e2e && concurrently \"npm run build:e2e:w\" \"npm run start:e2e:w\"",

"build:scripts": "tsc -p tsconfig.scripts.json",
"build:scripts:w": "tsc -p tsconfig.scripts.json -w",

"lint": "tslint -c tslint.json -p tsconfig.json",

"lint": "eslint --ext ts src",
"lint:fix": "eslint --ext ts --fix src",
fer22f marked this conversation as resolved.
Show resolved Hide resolved
"build:migrations": "tsc -p tsconfig.migrations.json",
"migration:generate": "./node_modules/.bin/typeorm migration:generate",
"migration:run": "./node_modules/.bin/typeorm migration:run",
Expand All @@ -49,7 +45,9 @@
"mocha": "^5.2.0",
"supertest": "^3.3.0",
"supervisor": "^0.12.0",
"tslint": "^5.10.0",
"eslint": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"typescript": "~3.5.3"
}
}
}
13 changes: 6 additions & 7 deletions packages/cli/src/generate/specs/app/package.mongodb.json
Expand Up @@ -8,23 +8,20 @@
"start": "node ./build/index.js",
"start:w": "supervisor -w ./build --no-restart-on error ./build/index.js",
"develop": "npm run build:app && concurrently \"npm run build:app:w\" \"npm run start:w\"",

"build:test": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.test.json",
"build:test:w": "tsc -p tsconfig.test.json -w",
"start:test": "mocha --file \"./build/test.js\" \"./build/**/*.spec.js\"",
"start:test:w": "mocha --file \"./build/test.js\" -w \"./build/**/*.spec.js\"",
"test": "npm run build:test && concurrently \"npm run build:test:w\" \"npm run start:test:w\"",

"build:e2e": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.e2e.json",
"build:e2e:w": "tsc -p tsconfig.e2e.json -w",
"start:e2e": "mocha --file \"./build/e2e.js\" \"./build/e2e/**/*.js\"",
"start:e2e:w": "mocha --file \"./build/e2e.js\" -w \"./build/e2e/**/*.js\"",
"e2e": "npm run build:e2e && concurrently \"npm run build:e2e:w\" \"npm run start:e2e:w\"",

"build:scripts": "tsc -p tsconfig.scripts.json",
"build:scripts:w": "tsc -p tsconfig.scripts.json -w",

"lint": "tslint -c tslint.json -p tsconfig.json"
"lint": "eslint --ext ts src",
"lint:fix": "eslint --ext ts --fix src"
},
"engines": {
"node": ">=8"
Expand All @@ -44,7 +41,9 @@
"mocha": "^5.2.0",
"supertest": "^3.3.0",
"supervisor": "^0.12.0",
"tslint": "^5.10.0",
"eslint": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"typescript": "~3.5.3"
}
}
}
13 changes: 6 additions & 7 deletions packages/cli/src/generate/specs/app/package.mongodb.yaml.json
Expand Up @@ -8,23 +8,20 @@
"start": "node ./build/index.js",
"start:w": "supervisor -w ./build --no-restart-on error ./build/index.js",
"develop": "npm run build:app && concurrently \"npm run build:app:w\" \"npm run start:w\"",

"build:test": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.test.json",
"build:test:w": "tsc -p tsconfig.test.json -w",
"start:test": "mocha --file \"./build/test.js\" \"./build/**/*.spec.js\"",
"start:test:w": "mocha --file \"./build/test.js\" -w \"./build/**/*.spec.js\"",
"test": "npm run build:test && concurrently \"npm run build:test:w\" \"npm run start:test:w\"",

"build:e2e": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.e2e.json",
"build:e2e:w": "tsc -p tsconfig.e2e.json -w",
"start:e2e": "mocha --file \"./build/e2e.js\" \"./build/e2e/**/*.js\"",
"start:e2e:w": "mocha --file \"./build/e2e.js\" -w \"./build/e2e/**/*.js\"",
"e2e": "npm run build:e2e && concurrently \"npm run build:e2e:w\" \"npm run start:e2e:w\"",

"build:scripts": "tsc -p tsconfig.scripts.json",
"build:scripts:w": "tsc -p tsconfig.scripts.json -w",

"lint": "tslint -c tslint.json -p tsconfig.json"
"lint": "eslint --ext ts src",
"lint:fix": "eslint --ext ts --fix src"
},
"engines": {
"node": ">=8"
Expand All @@ -45,7 +42,9 @@
"mocha": "^5.2.0",
"supertest": "^3.3.0",
"supervisor": "^0.12.0",
"tslint": "^5.10.0",
"eslint": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"typescript": "~3.5.3"
}
}
}
14 changes: 6 additions & 8 deletions packages/cli/src/generate/specs/app/package.yaml.json
Expand Up @@ -8,24 +8,20 @@
"start": "node ./build/index.js",
"start:w": "supervisor -w ./build --no-restart-on error ./build/index.js",
"develop": "npm run build:app && concurrently \"npm run build:app:w\" \"npm run start:w\"",

"build:test": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.test.json",
"build:test:w": "tsc -p tsconfig.test.json -w",
"start:test": "mocha --file \"./build/test.js\" \"./build/**/*.spec.js\"",
"start:test:w": "mocha --file \"./build/test.js\" -w \"./build/**/*.spec.js\"",
"test": "npm run build:test && concurrently \"npm run build:test:w\" \"npm run start:test:w\"",

"build:e2e": "copy-cli \"src/**/*.html\" build && tsc -p tsconfig.e2e.json",
"build:e2e:w": "tsc -p tsconfig.e2e.json -w",
"start:e2e": "mocha --file \"./build/e2e.js\" \"./build/e2e/**/*.js\"",
"start:e2e:w": "mocha --file \"./build/e2e.js\" -w \"./build/e2e/**/*.js\"",
"e2e": "npm run build:e2e && concurrently \"npm run build:e2e:w\" \"npm run start:e2e:w\"",

"build:scripts": "tsc -p tsconfig.scripts.json",
"build:scripts:w": "tsc -p tsconfig.scripts.json -w",

"lint": "tslint -c tslint.json -p tsconfig.json",

"lint": "eslint --ext ts src",
"lint:fix": "eslint --ext ts --fix src",
"build:migrations": "tsc -p tsconfig.migrations.json",
"migration:generate": "./node_modules/.bin/typeorm migration:generate",
"migration:run": "./node_modules/.bin/typeorm migration:run",
Expand All @@ -50,7 +46,9 @@
"mocha": "^5.2.0",
"supertest": "^3.3.0",
"supervisor": "^0.12.0",
"tslint": "^5.10.0",
"eslint": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"typescript": "~3.5.3"
}
}
}