Skip to content

Commit ce6aa21

Browse files
Introduce TSLint (#3)
* Introduce TSLint + rules matching AMP Project * Remove dist from git
1 parent 073e1fb commit ce6aa21

File tree

6 files changed

+51
-84
lines changed

6 files changed

+51
-84
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules/*
22
yarn.lock
33
yarn-error.log
44
.vscode/*
5-
.DS_Store
5+
.DS_Store
6+
dist/

dist/index.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

dist/index.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"scripts": {
2020
"pretest": "yarn build",
2121
"test": "ava test/*.js",
22-
"build": "rimraf dist && tsc -p tsconfig.json"
22+
"build": "rimraf dist && tsc -p tsconfig.json",
23+
"lint": "tslint -c tslint.json -p tsconfig.json"
2324
},
2425
"dependencies": {
2526
"google-closure-compiler": "^20180610.0.2",
@@ -35,18 +36,20 @@
3536
"rimraf": "^2.6.2",
3637
"rollup": "^0.62.0",
3738
"sourcemap-validator": "^1.1.0",
39+
"tslint": "5.10.0",
3840
"typescript": "^2.9.2"
3941
},
4042
"lint-staged": {
4143
"*.ts": [
44+
"yarn lint --fix",
4245
"prettier --config .prettierrc --write",
4346
"git add"
4447
]
4548
},
4649
"husky": {
4750
"hooks": {
48-
"pre-commit": "lint-staged",
49-
"pre-push": "yarn test"
51+
"pre-push": "yarn test",
52+
"pre-commit": "lint-staged"
5053
}
5154
}
5255
}

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { sync } from 'temp-write';
1919
import { readFileSync } from 'fs';
2020
import { OutputOptions, RawSourceMap, Plugin } from 'rollup';
2121

22-
export function defaultCompileOptions(outputOptions: OutputOptions): CompileOptions {
22+
export const defaultCompileOptions = (outputOptions: OutputOptions): CompileOptions => {
2323
// Defaults for Rollup Projects are slightly different than Closure Compiler defaults.
2424
// - Users of Rollup tend to transpile their code before handing it to a minifier,
2525
// so no transpile is default.
@@ -28,7 +28,7 @@ export function defaultCompileOptions(outputOptions: OutputOptions): CompileOpti
2828
// - When Rollup is configured to output an iife, ensure Closure Compiler does not
2929
// mangle the name of the iife wrapper.
3030

31-
let options: CompileOptions = {
31+
const options: CompileOptions = {
3232
language_out: 'NO_TRANSPILE',
3333
assume_function_wrapper: outputOptions.format === 'es' ? true : false,
3434
warning_level: 'QUIET',
@@ -43,10 +43,10 @@ export function defaultCompileOptions(outputOptions: OutputOptions): CompileOpti
4343
export default function closureCompiler(compileOptions: CompileOptions = {}): Plugin {
4444
return {
4545
name: 'closure-compiler',
46-
transformBundle: function(
46+
transformBundle: (
4747
code: string,
4848
outputOptions: OutputOptions,
49-
): Promise<{ code: string; map: RawSourceMap } | void> {
49+
): Promise<{ code: string; map: RawSourceMap } | void> => {
5050
const temp = {
5151
js: sync(code),
5252
map: sync(''),
@@ -57,12 +57,12 @@ export default function closureCompiler(compileOptions: CompileOptions = {}): Pl
5757
create_source_map: temp.map,
5858
});
5959

60-
const compile: Promise<string> = new Promise(function(resolve, reject) {
61-
new compiler(compileOptions).run(function(
60+
const compile: Promise<string> = new Promise((resolve, reject) => {
61+
new compiler(compileOptions).run((
6262
exitCode: number,
6363
stdOut: string,
6464
stdErr: string,
65-
) {
65+
) => {
6666
if (exitCode !== 0) {
6767
reject(new Error(`Google Closure Compiler exit ${exitCode}: ${stdErr}`));
6868
} else {

tslint.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"rules": {
3+
"variable-name": [
4+
true,
5+
"ban-keywords",
6+
"check-format",
7+
"allow-trailing-underscore",
8+
"allow-leading-underscore"
9+
],
10+
"triple-equals": [true, "allow-null-check"],
11+
"prefer-const": true,
12+
"use-isnan": true,
13+
"radix": true,
14+
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"],
15+
"object-literal-shorthand": true,
16+
"no-debugger": true,
17+
"no-duplicate-variable": true,
18+
"no-eval": true,
19+
"no-string-throw": true,
20+
"no-unused-expression": true,
21+
"no-var-keyword": true,
22+
"ban": [
23+
true,
24+
"alert",
25+
{"name": "parseInt", "message": "tsstyle#type-coercion"},
26+
{"name": "parseFloat", "message": "tsstyle#type-coercion"},
27+
{"name": "Array", "message": "tsstyle#array-constructor"}
28+
],
29+
"ban-types": [true,
30+
["Object", "Use {} instead."],
31+
["String", "Use 'string' instead."],
32+
["Number", "Use 'number' instead."],
33+
["Boolean", "Use 'boolean' instead."]
34+
]
35+
}
36+
}

0 commit comments

Comments
 (0)