Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit ce5c848

Browse files
rolandjitsudanbucholtz
authored andcommitted
feature(lint): update to latest version of tslint, lint app-scripts source
* chore: ignore WebStorm config files * chore: upgrade internal tslint dependencies - update tslint-eslint-rules - run tslint with --type-check flag * fix(interfaces): remove unnecessary semicolons * fix: remove unnecessary semicolons * chore: use stylish formatter for tslint * fix: fix tslint errors * chore: update mock-fs (allows using Node v7+) * feat(lint): upgrade to TSLint v5 * feat(lint): add ENV_TYPE_CHECK_ON_LINT and default to true * test(lint): cleanup a little * refactor(lint): improve linting logic * fix(lint): make CLI argument the same as the env var * feat(lint): add support for enabling type check during lint * test(lint): more cleanup * fix(lint): set project dir to context {rootDir} * chore: update tslint * chore(lint): add typeCheck() fn * chore: fix tslint errors * feat: implement and run type check if enabled * refactor(lint): rename generateFormattedErrorMsg() to generateErrorMessageForFiles() * fix(lint): filter duplicate file names * docs(lint): update note * chore(lint): add some TODOs * feat(lint): set default value for --typeCheck to false * docs(lint): document --typeCheck flag * fix(lint): don't create a new instance of BuildError when throwing after linting failed * fix(lint): set --typeCheckOnLint to null as default instead of false * test(lint): fix typeCheckOnLint flag tests * test(lint): add tests for generateErrorMessageForFiles(), getFileNames() and removeDuplicateFileNames() * chore(lint): remove some TODOs * fix(lint): properly pass CLI arguments to linter * feat(lint): properly disable type check during builds * fix(lint): allow null TSLint config file * chore: revert string change
1 parent fa26de1 commit ce5c848

32 files changed

+440
-326
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ dist
4545
.vscode
4646
*.sw[mnpcod]
4747

48-
bin/ion-dev.css
48+
bin/ion-dev.css
49+
50+
# WebStorm
51+
.idea

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ npm run build --rollup ./config/rollup.config.js
129129
| output js file | `ionic_output_js_file_name` | `--outputJsFileName` | `main.js` | name of js file generated in `buildDir` |
130130
| output css file | `ionic_output_css_file_name` | `--outputCssFileName` | `main.css` | name of css file generated in `buildDir` |
131131
| bail on lint error | `ionic_bail_on_lint_error` | `--bailOnLintError` | `null` | Set to `true` to make stand-alone lint commands fail with non-zero status code |
132+
| enable type checking during lint | `ionic_type_check_on_lint` | `--typeCheckOnLint` | `null` | Set to `true` to enable [type checking](https://palantir.github.io/tslint/usage/type-checking) during lint |
132133
| write AoT files to disk | `ionic_aot_write_to_disk` | `--aotWriteToDisk` | `null` | Set to `true` to write files to disk for debugging |
133134
| print dependency tree | `ionic_print_original_dependency_tree` | `--printOriginalDependencyTree` | `null` | Set to `true` to print out the original dependency tree calculated during the optimize step |
134135
| print modified dependency tree | `ionic_print_modified_dependency_tree` | `--printModifiedDependencyTree` | `null` | Set to `true` to print out the modified dependency tree after purging unused modules |
@@ -174,6 +175,7 @@ These environment variables are automatically set to [Node's `process.env`](http
174175
| `IONIC_WEBPACK_FACTORY` | The absolute path to Ionic's `webpack-factory` script |
175176
| `IONIC_WEBPACK_LOADER` | The absolute path to Ionic's custom webpack loader |
176177
| `IONIC_BAIL_ON_LINT_ERROR` | Boolean determining whether to exit with a non-zero status code on error |
178+
| `IONIC_TYPE_CHECK_ON_LINT` | Boolean determining whether to type check code during lint or not |
177179
| `IONIC_AOT_WRITE_TO_DISK` | `--aotWriteToDisk` | `null` | Set to `true` to write files to disk for debugging |
178180
| `IONIC_PRINT_ORIGINAL_DEPENDENCY_TREE` | boolean to print out the original dependency tree calculated during the optimize step |
179181
| `IONIC_PRINT_MODIFIED_DEPENDENCY_TREE` | boolean to print out the modified dependency tree after purging unused modules |

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"changelog": "./node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s",
2323
"clean": "rimraf ./dist",
2424
"github-release": "node ./scripts/create-github-release.js",
25-
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
25+
"lint": "tslint -c ./tslint.json --project ./tsconfig.json --type-check -t stylish",
2626
"nightly": "npm run build && node ./scripts/publish-nightly.js",
2727
"sass": "node-sass ./src/dev-client/sass/ion-dev.scss --output ./bin/ --output-style compressed",
2828
"sass-watch": "npm run sass && node-sass ./src/dev-client/sass/ion-dev.scss --watch --output ./bin/ --output-style compressed",
@@ -55,8 +55,8 @@
5555
"rollup-plugin-node-resolve": "3.0.0",
5656
"rollup-pluginutils": "2.0.1",
5757
"tiny-lr": "1.0.3",
58-
"tslint": "3.15.1",
59-
"tslint-eslint-rules": "1.5.0",
58+
"tslint": "^5.2.0",
59+
"tslint-eslint-rules": "4.0.0",
6060
"uglify-js": "2.8.22",
6161
"webpack": "2.2.1",
6262
"ws": "1.1.1",
@@ -80,7 +80,7 @@
8080
"@types/fs-extra": "^0.0.37",
8181
"@types/glob": "^5.0.30",
8282
"@types/jest": "^16.0.1",
83-
"@types/mock-fs": "^3.6.29",
83+
"@types/mock-fs": "^3.6.30",
8484
"@types/node": "^7.0.4",
8585
"@types/node-sass": "^3.10.32",
8686
"@types/rewire": "^2.5.27",
@@ -91,7 +91,7 @@
9191
"github": "0.2.4",
9292
"ionic-cz-conventional-changelog": "1.0.0",
9393
"jest": "^18.0.0",
94-
"mock-fs": "3.11.0",
94+
"mock-fs": "4.3.0",
9595
"rewire": "^2.5.2",
9696
"rimraf": "2.5.4",
9797
"rxjs": "^5.0.1",

src/babili.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as babili from './babili';
2-
import * as configUtil from './util/config';
32
import * as crossSpawn from 'cross-spawn';
4-
import { EventEmitter } from 'events';
53

64
describe('babili function', () => {
75

src/babili.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function babili(context: BuildContext, configFile?: string) {
2121

2222

2323
export function babiliWorker(context: BuildContext, configFile: string) {
24-
const babiliConfig: BabiliConfig = fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
24+
fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
2525
// TODO - figure out source maps??
2626
return runBabili(context);
2727
}

src/build.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ describe('build', () => {
2020
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
2121
spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(() => {
2222
return Promise.resolve({
23-
"options": {
24-
"sourceMap": true
23+
'options': {
24+
'sourceMap': true
2525
}
2626
});
2727
});
@@ -207,8 +207,8 @@ describe('test project requirements before building', () => {
207207
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
208208
spyOn(transpile, transpile.transpile.name).and.returnValue(Promise.resolve());
209209
spyOn(transpile, transpile.getTsConfigAsync.name).and.returnValue(Promise.resolve({
210-
"options": {
211-
"sourceMap": true
210+
'options': {
211+
'sourceMap': true
212212
}
213213
}));
214214

src/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function buildProject(context: BuildContext) {
127127
if (getBooleanPropertyValue(Constants.ENV_ENABLE_LINT)) {
128128
// kick off the tslint after everything else
129129
// nothing needs to wait on its completion unless bailing on lint error is enabled
130-
const result = lint(context);
130+
const result = lint(context, null, false);
131131
if (getBooleanPropertyValue(Constants.ENV_BAIL_ON_LINT_ERROR)) {
132132
return result;
133133
}
@@ -184,7 +184,7 @@ export function buildUpdate(changedFiles: ChangedFile[], context: BuildContext)
184184
// a ts file changed, so let's lint it too, however
185185
// this task should run as an after thought
186186
if (getBooleanPropertyValue(Constants.ENV_ENABLE_LINT)) {
187-
lintUpdate(changedFiles, context);
187+
lintUpdate(changedFiles, context, false);
188188
}
189189
}
190190

src/copy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export function copyConfigToWatchConfig(context: BuildContext): Watcher {
276276
};
277277
}
278278

279-
interface CopySrcToDestResult {
279+
export interface CopySrcToDestResult {
280280
success: boolean;
281281
src: string;
282282
dest: string;
@@ -299,7 +299,7 @@ export interface CopyConfig {
299299
export interface CopyToFrom {
300300
absoluteSourcePath: string;
301301
absoluteDestPath: string;
302-
};
302+
}
303303

304304
export interface CopyOptions {
305305
// https://www.npmjs.com/package/fs-extra

src/dev-server/lab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export let LabAppView = (req: any, res: any) => {
1010
};
1111

1212
export let ApiCordovaProject = (req: any, res: any) => {
13-
let cordovaContext = buildCordovaConfig((err: any) => {
13+
buildCordovaConfig((err: any) => {
1414
res.status(400).json({ status: 'error', message: 'Unable to load config.xml' });
1515
}, (config: CordovaProject) => {
1616
res.json(config);

src/generators/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ export function generateTemplates(context: BuildContext, request: HydratedGenera
202202
export interface GeneratorOption {
203203
type: string;
204204
multiple: boolean;
205-
};
205+
}
206206

207207
export interface GeneratorRequest {
208208
type?: string;
209209
name?: string;
210210
includeSpec?: boolean;
211211
includeNgModule?: boolean;
212-
};
212+
}
213213

214214
export interface GeneratorTabRequest extends GeneratorRequest {
215215
tabs?: HydratedGeneratorRequest[];
@@ -222,4 +222,4 @@ export interface HydratedGeneratorRequest extends GeneratorRequest {
222222
tabVariables?: string;
223223
dirToRead?: string;
224224
dirToWrite?: string;
225-
};
225+
}

src/highlight/highlight.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export function highlightError(htmlInput: string, errorCharStart: number, errorL
190190

191191
if (isValidEscape) {
192192
chars[htmlIndex] = escapeChars;
193-
for (var i = 0; i < escapeChars.length - 1; i++) {
193+
for (let i = 0; i < escapeChars.length - 1; i++) {
194194
chars.splice(htmlIndex + 1, 1);
195195
}
196196
}
@@ -717,7 +717,7 @@ function typescript(hljs: any) {
717717
}
718718
]
719719
};
720-
};
720+
}
721721

722722

723723
hljs.registerLanguage('scss', scss);
@@ -818,7 +818,7 @@ function scss(hljs: any) {
818818
}
819819
]
820820
};
821-
};
821+
}
822822

823823

824824
hljs.registerLanguage('xml', xml);
@@ -924,4 +924,4 @@ function xml(hljs: any) {
924924
}
925925
]
926926
};
927-
};
927+
}

src/lint.spec.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import * as lint from './lint';
2-
import * as workerClient from './worker-client';
31
import * as Constants from './util/constants';
4-
2+
import * as workerClient from './worker-client';
3+
import { lint } from './lint';
54

65
let originalEnv = process.env;
76

87
describe('lint task', () => {
98
describe('lint', () => {
10-
119
beforeEach(() => {
1210
originalEnv = process.env;
1311
process.env = {};
@@ -17,40 +15,27 @@ describe('lint task', () => {
1715
process.env = originalEnv;
1816
});
1917

20-
it('Should return resolved promise', (done: Function) => {
21-
// arrange
18+
it('should return a resolved promise', (done: Function) => {
2219
spyOn(workerClient, workerClient.runWorker.name).and.returnValue(Promise.resolve());
23-
// act
24-
const promise = lint.lint(null);
2520

26-
// assert
27-
promise.then(() => {
21+
lint(null).then(() => {
2822
done();
2923
});
3024
});
3125

32-
it('Should return resolved promise when bail on error is not set', (done: Function) => {
33-
// arrange
26+
it('should return resolved promise when bailOnLintError is not set', (done: Function) => {
3427
spyOn(workerClient, workerClient.runWorker.name).and.returnValue(Promise.reject(new Error('Simulating an error')));
35-
// act
36-
const promise = lint.lint(null);
3728

38-
// assert
39-
promise.then(() => {
29+
lint(null).then(() => {
4030
done();
4131
});
4232
});
4333

44-
it('Should return rejected promise when bail on error is set', (done: Function) => {
45-
34+
it('should return rejected promise when bailOnLintError is set', (done: Function) => {
4635
spyOn(workerClient, workerClient.runWorker.name).and.returnValue(Promise.reject(new Error('Simulating an error')));
4736
process.env[Constants.ENV_BAIL_ON_LINT_ERROR] = 'true';
4837

49-
// act
50-
const promise = lint.lint(null);
51-
52-
// assert
53-
promise.catch(() => {
38+
lint(null).catch(() => {
5439
done();
5540
});
5641
});

0 commit comments

Comments
 (0)