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

feat: introduce eslint with typescript-eslint to replace tslint #2492

Merged
merged 4 commits into from
Jun 3, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
coverage/
api-docs/
/sandbox
**/*.d.ts
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ packages/tsdocs/fixtures/monorepo/docs
/sandbox/*
!/sandbox/README.md
!/sandbox/example/

# ESLint cache
.eslintcache

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ matrix:
env: TASK=code-lint
# Running Code Linter -- Requires @loopback/build so it's bootstrapped
script:
- lerna bootstrap --scope @loopback/build --scope @loopback/tslint-config --scope @loopback/eslint-config
- lerna bootstrap --scope @loopback/build --scope @loopback/eslint-config
- npm run lint
- node_js: "8"
os: linux
Expand Down
14 changes: 11 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"tslint.ignoreDefinitionFiles": true,
"tslint.nodePath": "./packages/build/node_modules",
"typescript.tsdk": "./packages/build/node_modules/typescript/lib"
"typescript.tsdk": "./packages/build/node_modules/typescript/lib",
"eslint.autoFixOnSave": true,
"eslint.run": "onSave",
"eslint.nodePath": "./packages/build/node_modules",
"eslint.validate": [
"javascript",
{
"language": "typescript",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this suspicious. Could you please explain what does it mean to validate javascript files using typescript language?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint. The setting is an array. It basically says javascript is validated and typescript is validated and auto-fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Can you capture this in a code comment please? I believe settings.json allow comments.

"autoFix": true
}
]
}
9 changes: 5 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"args": [
"test"
],
"problemMatcher": ["$tsc", "$tslint5"]
"problemMatcher": ["$tsc", "$eslint-stylish", "$eslint-compact"]
},
{
"label": "Lint all packages",
Expand All @@ -47,10 +47,11 @@
"lint"
],
"problemMatcher": [
"$tslint5",
"$eslint-stylish",
"$eslint-compact",
{
// compilation errors - relative paths
"owner": "tslint",
"owner": "eslint",
"fileLocation": [
"relative",
"${workspaceRoot}"
Expand All @@ -66,7 +67,7 @@
},
{
// compilation errors - absolute paths
"owner": "tslint",
"owner": "eslint",
"fileLocation": "absolute",
"severity": "error",
"pattern": {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/src/__tests__/benchmark.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DUMMY_STATS: EndpointStats = {

describe('Benchmark (SLOW)', function() {
// Unfortunately, the todo app requires one second to start
// tslint:disable-next-line:no-invalid-this
// eslint-disable-next-line no-invalid-this
this.timeout(5000);
it('works', async () => {
const bench = new Benchmark();
Expand All @@ -37,7 +37,7 @@ describe('Benchmark (SLOW)', function() {
async execute(
title: string,
urlPath: string,
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
options?: any,
): Promise<EndpointStats> {
if (!options) options = {};
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/rest-routing/routing-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function givenRouter(router: RestRouter, spec: OpenApiSpec, count: number) {
// Make it not found
group = 'groupX';
}
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const request: any = {
method: 'get',
path: `/my/hello/${group}/version_${i}`,
Expand Down
6 changes: 3 additions & 3 deletions bin/build-docs-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ REPO_ROOT=$DIR/..
pushd $REPO_ROOT >/dev/null

# Update apidocs
lerna bootstrap --scope @loopback/tsdocs
lerna bootstrap
lerna run --scope @loopback/docs prepack

# Clean up sandbox/loopback.io directory
Expand All @@ -31,8 +31,8 @@ rm -rf sandbox/loopback.io/
# Shadow clone the `strongloop/loopback.io` github repo
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io

# Bootstrap the `loopback.io` package
lerna bootstrap --scope loopback.io-workflow-scripts --scope @loopback/docs
# Add loopback.io-workflow-scripts with @loopback/docs linked
lerna bootstrap --scope @loopback/docs --scope loopback.io-workflow-scripts

pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null

Expand Down
2 changes: 1 addition & 1 deletion bin/run-lerna.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function run(argv, options) {
const rootPath = project.rootPath;

process.env.LERNA_ROOT_PATH = rootPath;
let args = argv.slice(2);
const args = argv.slice(2);

return build.runCLI('lerna/cli', args, options);
}
Expand Down
37 changes: 31 additions & 6 deletions bin/sync-dev-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@ async function syncDevDeps() {
const buildDeps = require(path.join(rootPath, 'packages/build/package.json'))
.dependencies;

const masterDeps = {
typescript: buildDeps.typescript,
tslint: buildDeps.tslint,
};
const deps = [
'typescript',
'eslint',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
'eslint-plugin-eslint-plugin',
];
const masterDeps = {};
for (const d of deps) {
if (buildDeps[d] == null) {
console.error(
'Dependency %s is missing in packages/build/package.json',
d,
);
}
masterDeps[d] = buildDeps[d];
}

// Update typescript & tslint dependencies in individual packages
// Update typescript & eslint dependencies in individual packages
for (const pkg of packages) {
if (pkg.name === '@loopback/build') continue;
const pkgFile = pkg.manifestLocation;
updatePackageJson(pkgFile, masterDeps);
}
Expand All @@ -48,9 +62,20 @@ async function syncDevDeps() {
*/
function updatePackageJson(pkgFile, masterDeps) {
const data = readJsonFile(pkgFile);
const isExample = data.name.startsWith('@loopback/example-');
const isRoot = data.name === 'loopback-next';

let modified = false;
if (isExample && data.devDependencies && data.devDependencies.tslint) {
delete data.devDependencies.tslint;
modified = true;
}
for (const dep in masterDeps) {
if (data.devDependencies && dep in data.devDependencies) {
if (
data.devDependencies &&
// Force update for examples and loopback-next
(isExample || isRoot || dep in data.devDependencies)
) {
modified = modified || data.devDependencies[dep] !== masterDeps[dep];
data.devDependencies[dep] = masterDeps[dep];
}
Expand Down
4 changes: 2 additions & 2 deletions docs/site/Application-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lb4 [app] [options] [<name>]

`--outDir` : Project root directory for the application.

`--tslint` : Add TSLint to LoopBack4 application project.
`--eslint` : Add ESLint to LoopBack4 application project.

`--prettier` : Add Prettier to LoopBack4 application project.

Expand Down Expand Up @@ -65,7 +65,7 @@ The tool will prompt you for:
help format, test, and build a LoopBack4 application. Defaults to `true` for
all of the modules. The prompted modules are:

- [`tslint`](https://www.npmjs.com/package/tslint)
- [`eslint`](https://www.npmjs.com/package/eslint)
- [`prettier`](https://www.npmjs.com/package/prettier)
- [`mocha`](https://www.npmjs.com/package/mocha)
- [`@loopback/build`](https://www.npmjs.com/package/@loopback/build)
Expand Down
26 changes: 13 additions & 13 deletions docs/site/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See [Monorepo overview](./MONOREPO.md) for a list of all packages.
- [Making breaking changes](#making-breaking-changes)
- [Releasing new versions](#releasing-new-versions)
- [Adding a new package](#adding-a-new-package)
- [Upgrading TypeScript/tslint](#upgrading-typescripttslint)
- [Upgrading TypeScript/eslint](#upgrading-typescripteslint)
- [How to test infrastructure changes](#how-to-test-infrastructure-changes)

## Setting up development environment
Expand Down Expand Up @@ -91,7 +91,7 @@ It does all you need:
- Compile TypeScript
- Run all tests
- Check code formatting using [Prettier](https://prettier.io/)
- Lint the code using [TSLint](https://palantir.github.io/tslint/)
- Lint the code using [ESLint](https://typescript-eslint.io/)

## Coding rules

Expand All @@ -107,8 +107,8 @@ It does all you need:

We use two tools to keep our codebase healthy:

- [TSLint](https://palantir.github.io/tslint/) to statically analyse our source
code and detect common problems.
- [ESLint](https://typescript-eslint.io/) to statically analyse our source code
and detect common problems.
- [Prettier](https://prettier.io/) to keep our code always formatted the same
way, avoid style discussions in code reviews, and save everybody's time an
energy.
Expand Down Expand Up @@ -427,7 +427,7 @@ The `release` script will automatically perform the tasks for all packages:
- Install/link dependencies
- Transpile TypeScript files into JavaScript
- Run mocha tests
- Check lint (tslint and prettier) issues
- Check lint (eslint and prettier) issues

If all steps are successful, it prompts you to publish packages into npm
repository.
Expand Down Expand Up @@ -501,19 +501,19 @@ Please register the new package in the following files:
[@raymondfeng](https://github.com/raymondfeng) to enlist the new package on
<http://apidocs.loopback.io/>.

## Upgrading TypeScript/tslint
## Upgrading TypeScript/eslint

In order to support tslint extensions with a peer dependency on tslint, we have
to specify `typescript` and `tslint` dependency in multiple places in our
In order to support eslint extensions with a peer dependency on eslint, we have
to specify `typescript` and `eslint` dependency in multiple places in our
monorepo.

Steps to upgrade `typescript` or `tslint` to a newer version:
Steps to upgrade `typescript` or `eslint` to a newer version:

1. Update the dependencies in `@loopback/build`, this is the source of truth for
the rest of the monorepo.

```shell
$ (cd packages/build && npm update typescript tslint)
$ (cd packages/build && npm update typescript eslint)
```

2. Propagate the change to other places to keep everything consistent.
Expand All @@ -524,7 +524,7 @@ Steps to upgrade `typescript` or `tslint` to a newer version:

## How to test infrastructure changes

When making changes to project infrastructure, e.g. modifying `tsc` or `tslint`
When making changes to project infrastructure, e.g. modifying `tsc` or `eslint`
configuration, it's important to verify that all usage scenarios keep working.

### Verify TypeScript setup
Expand All @@ -545,7 +545,7 @@ configuration, it's important to verify that all usage scenarios keep working.
5. Test integration with supported IDEs:
- [VS Code](./VSCODE.md#how-to-verify-typescript-setup)

### Verify TSLint setup
### Verify ESLint setup

1. Open any existing TypeScript file, e.g. `packages/src/index.ts`

Expand All @@ -568,7 +568,7 @@ configuration, it's important to verify that all usage scenarios keep working.

5. Test integration with supported IDEs:

- [VS Code](./VSCODE.md#how-to-verify-tslint-setup)
- [VS Code](./VSCODE.md#how-to-verify-eslint-setup)

### tsconfig files

Expand Down
4 changes: 2 additions & 2 deletions docs/site/Extension-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lb4 extension [options] [<name>]

`--outDir` : Project root directory for the extension.

`--tslint` : Add TSLint to LoopBack4 extension project.
`--eslint` : Add ESLint to LoopBack4 extension project.

`--prettier` : Add Prettier to LoopBack4 extension project.

Expand Down Expand Up @@ -56,7 +56,7 @@ The tool will prompt you for:
help format, test, and build a LoopBack4 extension. Defaults to `true` for all
of the modules. The prompted modules are:

- [`tslint`](https://www.npmjs.com/package/tslint)
- [`eslint`](https://www.npmjs.com/package/eslint)
- [`prettier`](https://www.npmjs.com/package/prettier)
- [`mocha`](https://www.npmjs.com/package/mocha)
- [`@loopback/build`](https://www.npmjs.com/package/@loopback/build)
Expand Down
4 changes: 2 additions & 2 deletions docs/site/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Answer the prompts as follows:
? Project root directory: (getting-started)
? Application class name: StarterApplication
? Select features to enable in the project:
❯◉ Enable tslint: add a linter with pre-configured lint rules
❯◉ Enable eslint: add a linter with pre-configured lint rules
◉ Enable prettier: install prettier to format code conforming to rules
◉ Enable mocha: install mocha to run tests
◉ Enable loopbackBuild: use @loopback/build helpers (e.g. lb-tslint)
◉ Enable loopbackBuild: use @loopback/build helpers (e.g. lb-eslint)
◉ Enable vscode: add VSCode config files
◉ Enable docker: include Dockerfile and .dockerignore
◉ Enable repositories: include repository imports and RepositoryMixin
Expand Down
2 changes: 1 addition & 1 deletion docs/site/OpenAPI-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ additional model files are generated:
{% include code-caption.html content="src/models/perform-search-body.model.ts" %}

```ts
/* tslint:disable:no-any */
/* eslint-disable @typescript-eslint/no-explicit-any */
import {model, property} from '@loopback/repository';

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Parsing-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class FileUploadController {
else {
resolve({
files: request.files,
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fields: (request as any).fields,
});
}
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Testing-your-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ const Dredd = require('dredd');

describe('API (acceptance)', () => {
let app: HelloWorldApplication;
// tslint:disable no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
let dredd: any;
before(initEnvironment);
after(async () => {
Expand Down