Skip to content

Commit e844359

Browse files
author
Martynas Žilinskas
authored
tslint new rules (#94)
1 parent 4b43a5c commit e844359

File tree

91 files changed

+404
-635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+404
-635
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ notifications:
66
node_js:
77
- stable
88
before_install:
9-
- "npm install -g npm@^4.6.1"
9+
- "npm install -g npm@^5.0.3"
1010
- "npm install -g typescript@^2.3"
1111
script:
1212
- npm run generate

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"generate": "rush generate",
66
"tools-build": "npm run rush-tools -- run gulp-build -e simplr-mvdir",
77
"source-build": "npm run rush-tools -- run build -e simplr-mvdir",
8-
"test": "npm run rush-tools -- run test-tsc -e simplr-mvdir",
8+
"test": "npm run rush-tools -- run test -e simplr-mvdir",
99
"rush-tools": "ts-node ./tools/rush-tools.ts",
1010
"publish": "npm run rush-tools -- publish"
1111
},

packages/simplr-forms-dom/__tests__/components/clear.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Clear button", () => {
1515
sandbox = Sinon.sandbox.create();
1616
});
1717

18-
afterEach(function () {
18+
afterEach(() => {
1919
sandbox.restore();
2020
});
2121

@@ -34,11 +34,11 @@ describe("Clear button", () => {
3434

3535
it("clears fields by fieldsIds", () => {
3636
const callback = sandbox.stub(FormStore.prototype, "ClearFields");
37-
let fieldsIds: string[] = [];
37+
const fieldsIds: string[] = [];
3838
for (let i = 0; i < 5; i++) {
3939
fieldsIds.push(`text-${i}`);
4040
}
41-
let fields: JSX.Element[] = [];
41+
const fields: JSX.Element[] = [];
4242
fieldsIds.forEach(value => {
4343
fields.push(<Text name={value} key={value} />);
4444
});

packages/simplr-forms-dom/__tests__/components/reset.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Reset button", () => {
1515
sandbox = Sinon.sandbox.create();
1616
});
1717

18-
afterEach(function () {
18+
afterEach(() => {
1919
sandbox.restore();
2020
});
2121

@@ -34,11 +34,11 @@ describe("Reset button", () => {
3434

3535
it("reset fields by fieldsIds", () => {
3636
const callback = sandbox.spy(FormStore.prototype, "ResetFields");
37-
let fieldsIds: string[] = [];
37+
const fieldsIds: string[] = [];
3838
for (let i = 0; i < 5; i++) {
3939
fieldsIds.push(`text-${i}`);
4040
}
41-
let fields: JSX.Element[] = [];
41+
const fields: JSX.Element[] = [];
4242
fieldsIds.forEach(value => {
4343
fields.push(<Text name={value} key={value} />);
4444
});

packages/simplr-forms-dom/__tests__/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
"strict": true,
1313
"noEmit": true,
1414
"noUnusedLocals": true,
15+
"importHelpers": true,
1516
"lib": [
1617
"dom",
1718
"dom.iterable",
1819
"es6"
20+
],
21+
"typeRoots": [
22+
"../node_modules/@types/"
1923
]
2024
},
2125
"exclude": [

packages/simplr-forms-dom/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"watch": "webpack -w",
1313
"uglifyjs": "uglifyjs ./dist/simplr-forms-dom.js -o ./dist/simplr-forms-dom.min.js --compress --mangle",
1414
"release": "npm run build && npm run uglifyjs",
15-
"test": "jest",
16-
"test-tslint": "tslint --config ./tslint.json --project . --exclude ./__tests__/* && echo TsLint test successfully passed.",
15+
"test": "jest && npm run test-tsc && npm run test-tslint",
16+
"test-tslint": "tslint --config ./tslint.json --project tsconfig.json && echo TsLint test successfully passed.",
1717
"test-tsc": "tsc -p . --noEmit",
1818
"test-watch": "jest --watchAll",
1919
"test-coverage": "npm test -- --coverage",
@@ -43,6 +43,7 @@
4343
"gulp": "github:gulpjs/gulp#4.0",
4444
"jest": "^20.0.4",
4545
"jest-enzyme": "^3.2.0",
46+
"react-test-renderer": "^15.6.1",
4647
"simplr-mvdir": "0.0.1-beta.8",
4748
"sinon": "^2.3.4",
4849
"source-map-loader": "^0.2.1",

packages/simplr-forms-dom/src/abstractions/base-dom-field.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BaseField, BaseFieldState } from "simplr-forms";
2-
import { FieldProps } from "simplr-forms/contracts";
32
import {
43
DomFieldProps,
54
DomFieldTemplateCallback,
@@ -8,7 +7,7 @@ import {
87
} from "../contracts/field";
98
import { FormProps } from "../contracts/form";
109

11-
export interface BaseDomFieldState extends BaseFieldState { }
10+
export type BaseDomFieldState = BaseFieldState;
1211

1312
export abstract class BaseDomField<TProps extends DomFieldProps, TState extends BaseDomFieldState, TUnderlyingElement = any>
1413
extends BaseField<TProps, TState> {

packages/simplr-forms-dom/src/abstractions/base-form-button.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { recordify, TypedRecord } from "typed-immutable-record";
33
import { Iterable } from "immutable";
44

55
import { BaseContainer, BaseContainerProps } from "simplr-forms";
6-
import { FormError } from "simplr-forms/contracts";
76

87
export interface BaseFormButtonProps extends BaseContainerProps, React.HTMLProps<HTMLButtonElement> {
98
disableOnError?: boolean;
@@ -49,12 +48,10 @@ export abstract class BaseFormButton<TProps extends BaseFormButtonProps, TState
4948
// Type 'Readonly<TState>' cannot be converted to type 'Iterable<string, any>'.
5049
const stateIterable = this.state as any as Iterable<string, any>;
5150
if (!newStateRecord.equals(stateIterable)) {
52-
this.setState((prevState) => {
53-
// newStateRecord becomes an empty object after setState
54-
// This happens because of an underlying Immutable.Record
55-
// not enumerating properties in for..in
56-
return newState;
57-
});
51+
// newStateRecord becomes an empty object after setState
52+
// This happens because of an underlying Immutable.Record
53+
// not enumerating properties in for..in
54+
this.setState(() => newState);
5855
}
5956
}
6057

@@ -120,5 +117,5 @@ export abstract class BaseFormButton<TProps extends BaseFormButtonProps, TState
120117
return className.length > 0 ? className : undefined;
121118
}
122119

123-
abstract render(): JSX.Element | null;
120+
public abstract render(): JSX.Element | null;
124121
}

packages/simplr-forms-dom/src/components/checkbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CheckBox extends BaseDomField<CheckBoxProps, BaseDomFieldState, HTM
3333
return event.currentTarget.checked;
3434
}
3535

36-
protected OnChangeHandler: React.ChangeEventHandler<HTMLInputElement> = (event) => {
36+
protected OnChangeHandler: React.ChangeEventHandler<HTMLInputElement> = event => {
3737
this.OnValueChange(this.GetValueFromEvent(event));
3838

3939
const newValue = this.FormStore.GetField(this.FieldId).Value;
@@ -58,7 +58,7 @@ export class CheckBox extends BaseDomField<CheckBoxProps, BaseDomFieldState, HTM
5858
return false;
5959
}
6060

61-
renderField(): JSX.Element | null {
61+
public renderField(): JSX.Element {
6262
return <input
6363
ref={this.SetElementRef}
6464
type="checkbox"

packages/simplr-forms-dom/src/components/clear.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import * as React from "react";
2-
import { recordify, TypedRecord } from "typed-immutable-record";
3-
4-
import { BaseContainer, BaseContainerProps } from "simplr-forms";
52

63
import {
74
BaseFormButton,
@@ -23,7 +20,7 @@ export class Clear extends BaseFormButton<ClearProps, BaseFormButtonStateRecord>
2320
}
2421
}
2522

26-
render(): JSX.Element | null {
23+
public render(): JSX.Element {
2724
// TODO: Pass all other props.
2825
return <button
2926
type="button"

0 commit comments

Comments
 (0)