Skip to content

Commit

Permalink
Add tslint and fix lint errors.
Browse files Browse the repository at this point in the history
Add BinPackParameters clang-format option.
  • Loading branch information
aomarks committed Aug 10, 2018
1 parent 76eceba commit 87e2718
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 12 deletions.
1 change: 0 additions & 1 deletion .clang-format
Expand Up @@ -7,4 +7,3 @@ AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -6,9 +6,10 @@
"scripts": {
"clean": "rimraf lib/",
"format": "find src/ -name '*.ts' -print | xargs clang-format --style=file -i",
"lint": "tslint --project . --format stylish",
"build": "npm run clean && tsc",
"prepack": "npm run build",
"test": "npm run build && wct --npm --module_resolution=node"
"test": "npm run build && npm run lint && wct --npm --module_resolution=node"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +30,7 @@
"@webcomponents/webcomponentsjs": "^2.0.4",
"clang-format": "^1.2.4",
"rimraf": "^2.6.2",
"tslint": "^5.11.0",
"typescript": "^3.0.1",
"wct-browser-legacy": "^1.0.1",
"web-component-tester": "^6.7.1"
Expand Down
6 changes: 2 additions & 4 deletions src/declarative-event-listeners.ts
Expand Up @@ -28,8 +28,7 @@ export interface DeclarativeEventListenersConstructor {
new(...args: any[]): {};

_addDeclarativeEventListener:
(target: string|EventTarget,
eventName: string,
(target: string|EventTarget, eventName: string,
handler: (ev: Event) => void) => void;
}

Expand Down Expand Up @@ -77,8 +76,7 @@ export const DeclarativeEventListeners = dedupingMixin(
* @param {function} handler Function which receives the notification.
*/
static _addDeclarativeEventListener(
target: string|EventTarget,
eventName: string,
target: string|EventTarget, eventName: string,
handler: (ev: Event) => void): void {
if (!this.hasOwnProperty('listeners')) {
this.listeners = [];
Expand Down
3 changes: 1 addition & 2 deletions src/decorators.ts
Expand Up @@ -16,8 +16,7 @@ export interface ElementConstructor extends Function {
properties?: {[prop: string]: PropertyOptions};
observers?: string[];
_addDeclarativeEventListener?:
(target: string|EventTarget,
eventName: string,
(target: string|EventTarget, eventName: string,
handler: (ev: Event) => void) => void;
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/decorators-test.ts
Expand Up @@ -50,7 +50,7 @@ suite('TypeScript Decorators', function() {
MixinBehaviorsTestElement;
chai.assert.instanceOf(el, MixinBehaviorsTestElement);
chai.assert.equal(el.elementProperty, 'elementPropertyValue');
chai.assert.equal((el as any).behaviorProperty, 'behaviorPropertyValue');
chai.assert.equal(el.behaviorProperty, 'behaviorPropertyValue');
});

test('throws when element names do not match', function() {
Expand All @@ -76,7 +76,9 @@ suite('TypeScript Decorators', function() {

test('merges multiple definitions', function() {
chai.assert.deepEqual(
(TestElement as any).properties.computedWithOptions, {
// tslint:disable-next-line:no-any The properties config is not typed.
(TestElement as any).properties.computedWithOptions,
{
computed: '__computecomputedWithOptions(dependencyOne)',
readOnly: true,
type: String
Expand Down
4 changes: 4 additions & 0 deletions src/test/elements/mixin-behaviors-test-element.ts
Expand Up @@ -31,3 +31,7 @@ export class MixinBehaviorsTestElement extends mixinBehaviors
observerProperty() {
}
}

export interface MixinBehaviorsTestElement {
behaviorProperty: string;
}
4 changes: 2 additions & 2 deletions src/test/elements/test-element.ts
Expand Up @@ -69,7 +69,7 @@ export class TestElement extends PolymerElement {

lastChange: string|undefined;

lastMultiChange: any[] = [];
lastMultiChange: Array<number|string> = [];

@query('#num') numDiv!: HTMLDivElement;

Expand All @@ -82,7 +82,7 @@ export class TestElement extends PolymerElement {

ready() {
super.ready();
this._setReadOnlyString('initial value')
this._setReadOnlyString('initial value');
}

@observe('aNum', 'aString')
Expand Down
61 changes: 61 additions & 0 deletions tslint.json
@@ -0,0 +1,61 @@
{
"rules": {
"arrow-parens": true,
"class-name": true,
"indent": [
true,
"spaces"
],
"no-any": true,
"prefer-const": true,
"no-duplicate-variable": true,
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"quotemark": [
true,
"single",
"avoid-escape"
],
"semicolon": [
true,
"always"
],
"trailing-comma": [
true,
"multiline"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}

0 comments on commit 87e2718

Please sign in to comment.