Skip to content
This repository was archived by the owner on Feb 2, 2018. It is now read-only.

Commit a15b46b

Browse files
committed
build: use prettier to format the code
Add a build step to `npm run test` to verify that all code has been formatted by prettier. Developers can run `npm run lint:fix` to get the formatting fixed for them.
1 parent 02dc502 commit a15b46b

File tree

6 files changed

+30
-75
lines changed

6 files changed

+30
-75
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
dist6
3+
api-docs

.prettierrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"eslintIntegration": true,
32
"bracketSpacing": false,
43
"singleQuote": true,
54
"printWidth": 80,

.vscode/tasks.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
{
77
"taskName": "Watch and compile TypeScript",
88
"command": "npm",
9-
"args": [
10-
"--silent",
11-
"run",
12-
"build:watch"
13-
],
9+
"args": ["--silent", "run", "build:watch"],
1410
"type": "process",
1511
"isBackground": true,
1612
"problemMatcher": "$tsc-watch",
@@ -28,11 +24,7 @@
2824
{
2925
"taskName": "Test and lint",
3026
"command": "npm",
31-
"args": [
32-
"--silent",
33-
"run",
34-
"test:dev"
35-
],
27+
"args": ["--silent", "run", "test:dev"],
3628
"type": "process",
3729
"group": {
3830
"kind": "test",

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
"build:lib6": "tsc --target es2015 --outDir dist6",
1313
"build:watch": "tsc --watch",
1414
"clean": "rm -rf dist dist6",
15-
"lint": "tslint -c tslint.full.json --project tsconfig.json --type-check",
16-
"lint:fix": "npm run lint -- --fix",
15+
"lint": "npm run prettier:check && npm run tslint",
16+
"lint:fix": "npm run prettier:fix && npm run tslint:fix",
17+
"prettier:cli": "prettier \"**/*.ts\" \"**/*.js\" \"**/*.json\"",
18+
"prettier:check": "npm run prettier:cli -- -l",
19+
"prettier:fix": "npm run prettier:cli -- --write",
20+
"tslint": "tslint -c tslint.full.json --project tsconfig.json --type-check",
21+
"tslint:fix": "npm run lint -- --fix",
1722
"prepublish": "npm run build",
1823
"pretest": "npm run clean && npm run build",
1924
"test": "mocha",
@@ -44,6 +49,7 @@
4449
"@loopback/testlab": "^4.0.0-alpha.9",
4550
"@types/mocha": "^2.2.43",
4651
"mocha": "^3.5.3",
52+
"prettier": "^1.7.4",
4753
"tslint": "^5.7.0",
4854
"typescript": "^2.5.2"
4955
}

tslint.full.json

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
{
2-
"$schema": "http://json.schemastore.org/tslint",
3-
"extends": [
4-
"./tslint.json"
5-
],
6-
// This configuration files enabled rules which require type checking
7-
// and therefore cannot be run by Visual Studio Code TSLint extension
8-
// See https://github.com/Microsoft/vscode-tslint/issues/70
9-
"rules": {
10-
// These rules find errors related to TypeScript features.
11-
12-
13-
// These rules catch common errors in JS programming or otherwise
14-
// confusing constructs that are prone to producing bugs.
15-
16-
"await-promise": true,
17-
"no-floating-promises": true,
18-
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
19-
}
2+
"$schema": "http://json.schemastore.org/tslint",
3+
"extends": ["./tslint.json"],
4+
// This configuration files enabled rules which require type checking
5+
// and therefore cannot be run by Visual Studio Code TSLint extension
6+
// See https://github.com/Microsoft/vscode-tslint/issues/70
7+
"rules": {
8+
// These rules find errors related to TypeScript features.
9+
10+
// These rules catch common errors in JS programming or otherwise
11+
// confusing constructs that are prone to producing bugs.
12+
13+
"await-promise": true,
14+
"no-floating-promises": true,
15+
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
2016
}
21-
17+
}

tslint.json

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,11 @@
2121
"no-string-throw": true,
2222
"no-unused-expression": true,
2323
"no-var-keyword": true,
24-
"triple-equals": [
25-
true,
26-
"allow-null-check",
27-
"allow-undefined-check"
28-
],
24+
"triple-equals": [true, "allow-null-check", "allow-undefined-check"],
2925
"typeof-compare": true,
3026

3127
// These rules make code maintenance easier
32-
"eofline": true,
33-
"indent": [true, "spaces"],
3428
"no-default-export": true,
35-
"no-trailing-whitespace": true,
36-
"prefer-const": true,
37-
"trailing-comma": [true, {
38-
"multiline": "always",
39-
"singleline": "never"
40-
}],
41-
42-
// These rules enforce consistent style across your codebase:
43-
"arrow-return-shorthand": [true],
44-
"class-name": true,
45-
"comment-format": [true, "check-space"],
46-
"file-header": [true, "Copyright IBM"],
47-
"max-line-length": [true, 80],
48-
"no-consecutive-blank-lines": [true, 2],
49-
"no-unnecessary-callback-wrapper": true,
50-
"one-variable-per-declaration": [true, "ignore-for-loop"],
51-
"prefer-method-signature": true,
52-
"quotemark": [true, "single", "avoid-escape"],
53-
"semicolon": [true, "always"],
54-
"space-before-function-paren": [true, {
55-
"anonymous": "never",
56-
"named": "never",
57-
"asyncArrow": "always",
58-
"method": "never",
59-
"constructor": "never"
60-
}],
61-
"variable-name": [true, "allow-leading-underscore", "ban-keywords", "check-format"],
62-
"whitespace": [
63-
true,
64-
"check-branch",
65-
"check-decl",
66-
"check-separator",
67-
"check-type",
68-
"check-typecast",
69-
"check-preblock"
70-
]
29+
"prefer-const": true
7130
}
7231
}

0 commit comments

Comments
 (0)