Skip to content

Commit

Permalink
feat: replace tslint with eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed May 31, 2019
1 parent c7e14ca commit 8fa0671
Show file tree
Hide file tree
Showing 326 changed files with 8,657 additions and 1,198 deletions.
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
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",
"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
9 changes: 3 additions & 6 deletions bin/build-docs-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ DIR=`dirname $0`
REPO_ROOT=$DIR/..
pushd $REPO_ROOT >/dev/null

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

# Clean up sandbox/loopback.io directory
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
# Update apidocs
lerna bootstrap
lerna run --scope @loopback/docs prepack

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
23 changes: 18 additions & 5 deletions bin/sync-dev-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ 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) {
masterDeps[d] = buildDeps[d];
}

// Update typescript & tslint dependencies in individual packages
// Update typescript & eslint dependencies in individual packages
for (const pkg of packages) {
const pkgFile = pkg.manifestLocation;
updatePackageJson(pkgFile, masterDeps);
Expand All @@ -48,6 +55,12 @@ async function syncDevDeps() {
*/
function updatePackageJson(pkgFile, masterDeps) {
const data = readJsonFile(pkgFile);
const isExample = data.name.startsWith('@loopback/example-');

if (isExample && data.devDependencies && data.devDependencies.tslint) {
delete data.devDependencies.tslint;
modified = true;
}
let modified = false;
for (const dep in masterDeps) {
if (data.devDependencies && dep in data.devDependencies) {
Expand Down
2 changes: 1 addition & 1 deletion bin/update-greenkeeper-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if (require.main === module) updateGreenKeeperJson();
function arraysContainSameElements(actual, expected) {
return (
// Same size
actual.length == expected.length &&
actual.length === expected.length &&
// `expected` contains all elements of `actual`
actual.every(e => expected.includes(e)) &&
// `actual` contains all elements of `expected`
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 @@ -503,19 +503,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 @@ -526,7 +526,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 @@ -547,7 +547,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 @@ -570,7 +570,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

0 comments on commit 8fa0671

Please sign in to comment.