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

Commit

Permalink
feature(lint): update to latest version of tslint, lint app-scripts s…
Browse files Browse the repository at this point in the history
…ource

* 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
  • Loading branch information
rolandjitsu authored and danbucholtz committed May 10, 2017
1 parent fa26de1 commit ce5c848
Show file tree
Hide file tree
Showing 32 changed files with 440 additions and 326 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ dist
.vscode
*.sw[mnpcod]

bin/ion-dev.css
bin/ion-dev.css

# WebStorm
.idea
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ npm run build --rollup ./config/rollup.config.js
| output js file | `ionic_output_js_file_name` | `--outputJsFileName` | `main.js` | name of js file generated in `buildDir` |
| output css file | `ionic_output_css_file_name` | `--outputCssFileName` | `main.css` | name of css file generated in `buildDir` |
| 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 |
| 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 |
| write AoT files to disk | `ionic_aot_write_to_disk` | `--aotWriteToDisk` | `null` | Set to `true` to write files to disk for debugging |
| 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 |
| 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 |
Expand Down Expand Up @@ -174,6 +175,7 @@ These environment variables are automatically set to [Node's `process.env`](http
| `IONIC_WEBPACK_FACTORY` | The absolute path to Ionic's `webpack-factory` script |
| `IONIC_WEBPACK_LOADER` | The absolute path to Ionic's custom webpack loader |
| `IONIC_BAIL_ON_LINT_ERROR` | Boolean determining whether to exit with a non-zero status code on error |
| `IONIC_TYPE_CHECK_ON_LINT` | Boolean determining whether to type check code during lint or not |
| `IONIC_AOT_WRITE_TO_DISK` | `--aotWriteToDisk` | `null` | Set to `true` to write files to disk for debugging |
| `IONIC_PRINT_ORIGINAL_DEPENDENCY_TREE` | boolean to print out the original dependency tree calculated during the optimize step |
| `IONIC_PRINT_MODIFIED_DEPENDENCY_TREE` | boolean to print out the modified dependency tree after purging unused modules |
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"changelog": "./node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s",
"clean": "rimraf ./dist",
"github-release": "node ./scripts/create-github-release.js",
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
"lint": "tslint -c ./tslint.json --project ./tsconfig.json --type-check -t stylish",
"nightly": "npm run build && node ./scripts/publish-nightly.js",
"sass": "node-sass ./src/dev-client/sass/ion-dev.scss --output ./bin/ --output-style compressed",
"sass-watch": "npm run sass && node-sass ./src/dev-client/sass/ion-dev.scss --watch --output ./bin/ --output-style compressed",
Expand Down Expand Up @@ -55,8 +55,8 @@
"rollup-plugin-node-resolve": "3.0.0",
"rollup-pluginutils": "2.0.1",
"tiny-lr": "1.0.3",
"tslint": "3.15.1",
"tslint-eslint-rules": "1.5.0",
"tslint": "^5.2.0",
"tslint-eslint-rules": "4.0.0",
"uglify-js": "2.8.22",
"webpack": "2.2.1",
"ws": "1.1.1",
Expand All @@ -80,7 +80,7 @@
"@types/fs-extra": "^0.0.37",
"@types/glob": "^5.0.30",
"@types/jest": "^16.0.1",
"@types/mock-fs": "^3.6.29",
"@types/mock-fs": "^3.6.30",
"@types/node": "^7.0.4",
"@types/node-sass": "^3.10.32",
"@types/rewire": "^2.5.27",
Expand All @@ -91,7 +91,7 @@
"github": "0.2.4",
"ionic-cz-conventional-changelog": "1.0.0",
"jest": "^18.0.0",
"mock-fs": "3.11.0",
"mock-fs": "4.3.0",
"rewire": "^2.5.2",
"rimraf": "2.5.4",
"rxjs": "^5.0.1",
Expand Down
2 changes: 0 additions & 2 deletions src/babili.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as babili from './babili';
import * as configUtil from './util/config';
import * as crossSpawn from 'cross-spawn';
import { EventEmitter } from 'events';

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

Expand Down
2 changes: 1 addition & 1 deletion src/babili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function babili(context: BuildContext, configFile?: string) {


export function babiliWorker(context: BuildContext, configFile: string) {
const babiliConfig: BabiliConfig = fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
// TODO - figure out source maps??
return runBabili(context);
}
Expand Down
8 changes: 4 additions & 4 deletions src/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('build', () => {
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(() => {
return Promise.resolve({
"options": {
"sourceMap": true
'options': {
'sourceMap': true
}
});
});
Expand Down Expand Up @@ -207,8 +207,8 @@ describe('test project requirements before building', () => {
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
spyOn(transpile, transpile.transpile.name).and.returnValue(Promise.resolve());
spyOn(transpile, transpile.getTsConfigAsync.name).and.returnValue(Promise.resolve({
"options": {
"sourceMap": true
'options': {
'sourceMap': true
}
}));

Expand Down
4 changes: 2 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function buildProject(context: BuildContext) {
if (getBooleanPropertyValue(Constants.ENV_ENABLE_LINT)) {
// kick off the tslint after everything else
// nothing needs to wait on its completion unless bailing on lint error is enabled
const result = lint(context);
const result = lint(context, null, false);
if (getBooleanPropertyValue(Constants.ENV_BAIL_ON_LINT_ERROR)) {
return result;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ export function buildUpdate(changedFiles: ChangedFile[], context: BuildContext)
// a ts file changed, so let's lint it too, however
// this task should run as an after thought
if (getBooleanPropertyValue(Constants.ENV_ENABLE_LINT)) {
lintUpdate(changedFiles, context);
lintUpdate(changedFiles, context, false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function copyConfigToWatchConfig(context: BuildContext): Watcher {
};
}

interface CopySrcToDestResult {
export interface CopySrcToDestResult {
success: boolean;
src: string;
dest: string;
Expand All @@ -299,7 +299,7 @@ export interface CopyConfig {
export interface CopyToFrom {
absoluteSourcePath: string;
absoluteDestPath: string;
};
}

export interface CopyOptions {
// https://www.npmjs.com/package/fs-extra
Expand Down
2 changes: 1 addition & 1 deletion src/dev-server/lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export let LabAppView = (req: any, res: any) => {
};

export let ApiCordovaProject = (req: any, res: any) => {
let cordovaContext = buildCordovaConfig((err: any) => {
buildCordovaConfig((err: any) => {
res.status(400).json({ status: 'error', message: 'Unable to load config.xml' });
}, (config: CordovaProject) => {
res.json(config);
Expand Down
6 changes: 3 additions & 3 deletions src/generators/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ export function generateTemplates(context: BuildContext, request: HydratedGenera
export interface GeneratorOption {
type: string;
multiple: boolean;
};
}

export interface GeneratorRequest {
type?: string;
name?: string;
includeSpec?: boolean;
includeNgModule?: boolean;
};
}

export interface GeneratorTabRequest extends GeneratorRequest {
tabs?: HydratedGeneratorRequest[];
Expand All @@ -222,4 +222,4 @@ export interface HydratedGeneratorRequest extends GeneratorRequest {
tabVariables?: string;
dirToRead?: string;
dirToWrite?: string;
};
}
8 changes: 4 additions & 4 deletions src/highlight/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function highlightError(htmlInput: string, errorCharStart: number, errorL

if (isValidEscape) {
chars[htmlIndex] = escapeChars;
for (var i = 0; i < escapeChars.length - 1; i++) {
for (let i = 0; i < escapeChars.length - 1; i++) {
chars.splice(htmlIndex + 1, 1);
}
}
Expand Down Expand Up @@ -717,7 +717,7 @@ function typescript(hljs: any) {
}
]
};
};
}


hljs.registerLanguage('scss', scss);
Expand Down Expand Up @@ -818,7 +818,7 @@ function scss(hljs: any) {
}
]
};
};
}


hljs.registerLanguage('xml', xml);
Expand Down Expand Up @@ -924,4 +924,4 @@ function xml(hljs: any) {
}
]
};
};
}
31 changes: 8 additions & 23 deletions src/lint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as lint from './lint';
import * as workerClient from './worker-client';
import * as Constants from './util/constants';

import * as workerClient from './worker-client';
import { lint } from './lint';

let originalEnv = process.env;

describe('lint task', () => {
describe('lint', () => {

beforeEach(() => {
originalEnv = process.env;
process.env = {};
Expand All @@ -17,40 +15,27 @@ describe('lint task', () => {
process.env = originalEnv;
});

it('Should return resolved promise', (done: Function) => {
// arrange
it('should return a resolved promise', (done: Function) => {
spyOn(workerClient, workerClient.runWorker.name).and.returnValue(Promise.resolve());
// act
const promise = lint.lint(null);

// assert
promise.then(() => {
lint(null).then(() => {
done();
});
});

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

// assert
promise.then(() => {
lint(null).then(() => {
done();
});
});

it('Should return rejected promise when bail on error is set', (done: Function) => {

it('should return rejected promise when bailOnLintError is set', (done: Function) => {
spyOn(workerClient, workerClient.runWorker.name).and.returnValue(Promise.reject(new Error('Simulating an error')));
process.env[Constants.ENV_BAIL_ON_LINT_ERROR] = 'true';

// act
const promise = lint.lint(null);

// assert
promise.catch(() => {
lint(null).catch(() => {
done();
});
});
Expand Down
Loading

0 comments on commit ce5c848

Please sign in to comment.