Skip to content

feat(lint): add lint command #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ng serve
```
Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

You can configure the default HTTP port and the one used by the LiveReload server with two command-line options :
You can configure the default HTTP port and the one used by the LiveReload server with two command-line options :

```bash
ng serve --port 4201 --live-reload-port 49153
Expand Down Expand Up @@ -176,6 +176,14 @@ ng github-pages:deploy

Checkout [angular-cli-github-pages addon](https://github.com/IgorMinar/angular-cli-github-pages) docs for more info.

### Linting code

You can lint your app code by running `ng lint`.
This will use the `lint` npm script that in generated projects uses `tslint`.

You can modify the `lint` script in `package.json` to run whatever linting tool
you prefer and `ng lint` will still run it.


## Known issues

Expand Down
4 changes: 3 additions & 1 deletion addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"scripts": {
"start": "ng server",
"postinstall": "typings install --ambient"
"postinstall": "typings install --ambient",
"lint": "tslint src/**/*.ts"
},
"private": true,
"dependencies": {
Expand All @@ -31,6 +32,7 @@
"karma-chrome-launcher": "^0.2.1",
"karma-jasmine": "^0.3.6",
"protractor": "^3.0.0",
"tslint": "^3.3.0",
"typescript": "^1.7.3",
"typings": "^0.6.6"
}
Expand Down
63 changes: 63 additions & 0 deletions addon/ng2/blueprints/ng2/files/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"rules": {
"max-line-length": [true, 100],
"no-inferrable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"eofline": true,
"no-duplicate-variable": true,
"no-eval": true,
"no-arg": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-bitwise": true,
"no-shadowed-variable": true,
"no-unused-expression": true,
"no-unused-variable": true,
"one-line": [
true,
"check-catch",
"check-else",
"check-open-brace",
"check-whitespace"
],
"quotemark": [
true,
"single",
"avoid-escape"
],
"semicolon": true,
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"curly": true,
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-trailing-underscore"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}
20 changes: 20 additions & 0 deletions addon/ng2/commands/lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* jshint node: true */
'use strict';

var Command = require('ember-cli/lib/models/command');
var LintTask = require('../tasks/lint');

module.exports = Command.extend({
name: 'lint',
description: 'Lints code in existing project',
works: 'insideProject',
run: function() {
var lintTask = new LintTask({
ui: this.ui,
analytics: this.analytics,
project: this.project
});

return lintTask.run();
}
});
3 changes: 2 additions & 1 deletion addon/ng2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
'init' : require('./commands/init'),
'install' : require('./commands/install'),
'uninstall' : require('./commands/uninstall'),
'test' : require('./commands/test')
'test' : require('./commands/test'),
'lint' : require('./commands/lint')
};
}
};
23 changes: 23 additions & 0 deletions addon/ng2/tasks/lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* jshint node: true */
'use strict';

var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
var exec = Promise.denodeify(require('child_process').exec);

module.exports = Task.extend({
run: function() {
var chalk = require('chalk');
var ui = this.ui;

return exec('npm run lint')
.then(function() {
ui.writeLine(chalk.green('Successfully linted files.'));
})
.catch(function( /*error*/ ) {
ui.writeLine(chalk.red(
'Couldn\'t do \'npm run lint\'. Please check this script exists in your package.json.'
));
});
}
});