refactor(all): additional tslint rules

This commit is contained in:
Manu Mtz.-Almeida
2018-09-01 17:21:42 +02:00
parent ba2230510e
commit e7416435d8
42 changed files with 419 additions and 380 deletions

View File

@ -43,6 +43,7 @@
"stylelint-order": "^0.8.1",
"tslint": "^5.10.0",
"tslint-ionic-rules": "0.0.17",
"tslint-react": "^3.6.0",
"typescript": "^2.9.2",
"yargs": "^12.0.1"
},

File diff suppressed because it is too large Load Diff

View File

@ -329,8 +329,8 @@ export class Alert implements OverlayInterface {
disabled={i.disabled}
tabIndex={0}
role="checkbox"
class="alert-tappable alert-checkbox alert-checkbox-button">
class="alert-tappable alert-checkbox alert-checkbox-button"
>
<div class="alert-button-inner">
<div class="alert-checkbox-icon">
<div class="alert-checkbox-inner"></div>
@ -359,9 +359,11 @@ export class Alert implements OverlayInterface {
onClick={() => this.rbClick(i)}
aria-checked={i.checked ? 'true' : null}
disabled={i.disabled}
id={i.id} tabIndex={0}
id={i.id}
tabIndex={0}
class="alert-radio-button alert-tappable alert-radio"
role="radio">
role="radio"
>
<div class="alert-button-inner">
<div class="alert-radio-icon"><div class="alert-radio-inner"></div></div>
<div class="alert-radio-label">
@ -394,7 +396,8 @@ export class Alert implements OverlayInterface {
id={i.id}
disabled={i.disabled}
tabIndex={0}
class="alert-input"/>
class="alert-input"
/>
</div>
))}
</div>

View File

@ -41,7 +41,8 @@ export class Anchor {
return (
<a
href={this.href}
onClick={ev => openURL(this.win, this.href, ev, this.routerDirection)}>
onClick={ev => openURL(this.win, this.href, ev, this.routerDirection)}
>
<slot></slot>
</a>
);

View File

@ -25,7 +25,9 @@ export const TRANSFORM_PROPS: {[key: string]: number} = {
'perspective': 1
};
const raf = window.requestAnimationFrame || ((f: FrameRequestCallback) => f(Date.now()));
const raf = window.requestAnimationFrame
? window.requestAnimationFrame.bind(window)
: (f: FrameRequestCallback) => f(Date.now());
export class Animator {
@ -627,10 +629,7 @@ export class Animator {
/**
* Immediately stop at the end of the animation.
*/
stop(stepValue?: number) {
if (stepValue === undefined) {
stepValue = 1;
}
stop(stepValue = 1) {
// ensure all past transition end events have been cleared
this._clearAsync();
this._hasDur = true;
@ -1045,7 +1044,7 @@ export class Animator {
/**
* End the progress animation.
*/
progressEnd(shouldComplete: boolean, currentStepValue: number, dur?: number) {
progressEnd(shouldComplete: boolean, currentStepValue: number, dur = -1) {
if (this._isReverse) {
// if the animation is going in reverse then
// flip the step value: 0 becomes 1, 1 becomes 0
@ -1053,9 +1052,6 @@ export class Animator {
}
const stepValue = shouldComplete ? 1 : 0;
const diff = Math.abs(currentStepValue - stepValue);
if (dur === undefined) {
dur = -1;
}
if (dur < 0) {
dur = this._duration || 0;
} else if (diff < 0.05) {
@ -1178,10 +1174,7 @@ export class Animator {
/**
* Reverse the animation.
*/
reverse(shouldReverse?: boolean): Animator {
if (shouldReverse === undefined) {
shouldReverse = true;
}
reverse(shouldReverse = true): Animator {
const children = this._childAnimations;
if (children) {
for (const child of children) {

View File

@ -77,7 +77,8 @@ export class BackButton {
<button
type="button"
class="back-button-native"
onClick={ev => this.onClick(ev)}>
onClick={ev => this.onClick(ev)}
>
<span class="back-button-inner">
{backButtonIcon && <ion-icon icon={backButtonIcon} lazy={false}/>}
{this.mode === 'ios' && backButtonText && <span class="button-text">{backButtonText}</span>}

View File

@ -177,7 +177,8 @@ export class Button {
onFocus={this.onFocus.bind(this)}
onKeyUp={this.onKeyUp.bind(this)}
onBlur={this.onBlur.bind(this)}
onClick={this.onClick.bind(this)}>
onClick={this.onClick.bind(this)}
>
<span class="button-inner">
<slot name="icon-only"></slot>
<slot name="start"></slot>
@ -212,7 +213,6 @@ function getButtonTypeClassMap(buttonType: string, type: string | undefined, mod
if (type === undefined) {
return {};
}
type = type.toLocaleLowerCase();
return {
[`${buttonType}-${type}`]: true,
[`${buttonType}-${type}-${mode}`]: true

View File

@ -147,7 +147,8 @@ export class Checkbox {
checked={this.checked}
name={this.name}
value={this.value}
disabled={this.disabled} />
disabled={this.disabled}
/>
];
}
}

View File

@ -58,7 +58,8 @@ export class ChipButton {
type="button"
class="chip-button-native"
disabled={this.disabled}
href={this.href}>
href={this.href}
>
<span class="chip-button-inner">
<slot></slot>
</span>

View File

@ -295,7 +295,8 @@ export class Content {
'overscroll': (scrollX || scrollY) && !!forceOverscroll
}}
ref={el => this.scrollEl = el!}
onScroll={ev => this.onScroll(ev)}>
onScroll={ev => this.onScroll(ev)}
>
<slot></slot>
</div>,
<slot name="fixed"></slot>

View File

@ -536,7 +536,8 @@ export class Datetime {
aria-labelledby={this.labelId}
aria-disabled={this.disabled ? 'true' : null}
onClick={this.open.bind(this)}
class="datetime-cover">
class="datetime-cover"
>
{this.mode === 'md' && <ion-ripple-effect />}
</button>
];

View File

@ -216,7 +216,7 @@ dates in JavaScript.
| `hourValues` | -- | Values used to create the list of selectable hours. By default the hour values range from `0` to `23` for 24-hour, or `1` to `12` for 12-hour. However, to control exactly which hours to display, the `hourValues` input can take a number, an array of numbers, or a string of comma separated numbers. | `number[]`, `number`, `string` |
| `max` | `max` | The maximum datetime allowed. Value must be a date string following the [ISO 8601 datetime format standard](https://www.w3.org/TR/NOTE-datetime), `1996-12-19`. The format does not have to be specific to an exact datetime. For example, the maximum could just be the year, such as `1994`. Defaults to the end of this year. | `string` |
| `min` | `min` | The minimum datetime allowed. Value must be a date string following the [ISO 8601 datetime format standard](https://www.w3.org/TR/NOTE-datetime), such as `1996-12-19`. The format does not have to be specific to an exact datetime. For example, the minimum could just be the year, such as `1994`. Defaults to the beginning of the year, 100 years ago from today. | `string` |
| `minuteValues` | -- | Values used to create the list of selectable minutes. By default the mintues range from `0` to `59`. However, to control exactly which minutes to display, the `minuteValues` input can take a number, an array of numbers, or a string of comma separated numbers. For example, if the minute selections should only be every 15 minutes, then this input value would be `minuteValues="0,15,30,45"`. | `number[]`, `number`, `string` |
| `minuteValues` | -- | Values used to create the list of selectable minutes. By default the minutes range from `0` to `59`. However, to control exactly which minutes to display, the `minuteValues` input can take a number, an array of numbers, or a string of comma separated numbers. For example, if the minute selections should only be every 15 minutes, then this input value would be `minuteValues="0,15,30,45"`. | `number[]`, `number`, `string` |
| `mode` | `mode` | The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`. | `Mode` |
| `monthNames` | `month-names` | Full names for each month name. This can be used to provide locale month names. Defaults to English. | `string[]`, `string` |
| `monthShortNames` | `month-short-names` | Short abbreviated names for each month name. This can be used to provide locale month names. Defaults to English. | `string[]`, `string` |

View File

@ -94,7 +94,8 @@ export class FabButton {
<TagType
class="fab-button-native"
disabled={this.disabled}
href={this.href}>
href={this.href}
>
<span class="fab-button-close-icon">
<ion-icon name="close" lazy={false}></ion-icon>
</span>

View File

@ -72,7 +72,8 @@ export class Img {
<img
src={this.loadSrc}
alt={this.alt}
decoding="async"></img>
decoding="async"
/>
);
}
}

View File

@ -369,7 +369,8 @@ export class Input {
type="button"
class="input-clear-icon"
onTouchStart={this.clearTextInput.bind(this)}
onMouseDown={this.clearTextInput.bind(this)}/>
onMouseDown={this.clearTextInput.bind(this)}
/>
];
}
}

View File

@ -12,12 +12,6 @@ import { createColorClasses } from '../../utils/theme';
shadow: true
})
export class ListHeader {
/**
* The color to use from your application's color palette.
* Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
* For more information on colors, see [theming](/docs/theming/basics).
*/
@Prop() color?: Color;
/**
* The mode determines which platform styles to use.
@ -25,6 +19,13 @@ export class ListHeader {
*/
@Prop() mode!: Mode;
/**
* The color to use from your application's color palette.
* Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
* For more information on colors, see [theming](/docs/theming/basics).
*/
@Prop() color?: Color;
hostData() {
return {
class: createColorClasses(this.color)

View File

@ -11,6 +11,7 @@ import { menuRevealAnimation } from './animations/reveal';
styleUrl: 'menu-controller.scss'
})
export class MenuController implements MenuControllerI {
private menus: MenuI[] = [];
private menuAnimations = new Map<string, AnimationBuilder>();
@ -26,7 +27,7 @@ export class MenuController implements MenuControllerI {
* Open the menu.
*/
@Method()
async open(menuId?: string): Promise<boolean> {
async open(menuId?: string | null): Promise<boolean> {
const menu = await this.get(menuId);
if (menu) {
return menu.open();
@ -39,7 +40,7 @@ export class MenuController implements MenuControllerI {
* that is open. If a menu is specified, it will close that menu.
*/
@Method()
async close(menuId?: string): Promise<boolean> {
async close(menuId?: string | null): Promise<boolean> {
const menu = await (menuId !== undefined ? this.get(menuId) : this.getOpen());
if (menu !== undefined) {
return menu.close();
@ -52,7 +53,7 @@ export class MenuController implements MenuControllerI {
* will close.
*/
@Method()
async toggle(menuId?: string): Promise<boolean> {
async toggle(menuId?: string | null): Promise<boolean> {
const menu = await this.get(menuId);
if (menu) {
return menu.toggle();
@ -67,7 +68,7 @@ export class MenuController implements MenuControllerI {
* will also automatically disable all the others that are on the same side.
*/
@Method()
async enable(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement | undefined> {
async enable(shouldEnable: boolean, menuId?: string | null): Promise<HTMLIonMenuElement | undefined> {
const menu = await this.get(menuId);
if (menu) {
menu.disabled = !shouldEnable;
@ -79,7 +80,7 @@ export class MenuController implements MenuControllerI {
* Used to enable or disable the ability to swipe open the menu.
*/
@Method()
async swipeGesture(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement | undefined> {
async swipeGesture(shouldEnable: boolean, menuId?: string | null): Promise<HTMLIonMenuElement | undefined> {
const menu = await this.get(menuId);
if (menu) {
menu.swipeGesture = shouldEnable;
@ -92,8 +93,8 @@ export class MenuController implements MenuControllerI {
* will return true if any menu is currently open.
*/
@Method()
async isOpen(menuId?: string): Promise<boolean> {
if (menuId !== undefined) {
async isOpen(menuId?: string | null): Promise<boolean> {
if (menuId != null) {
const menu = await this.get(menuId);
return (menu !== undefined && menu.isOpen());
} else {
@ -106,7 +107,7 @@ export class MenuController implements MenuControllerI {
* Returns true if the specified menu is enabled.
*/
@Method()
async isEnabled(menuId?: string): Promise<boolean> {
async isEnabled(menuId?: string | null): Promise<boolean> {
const menu = await this.get(menuId);
if (menu) {
return !menu.disabled;
@ -122,7 +123,7 @@ export class MenuController implements MenuControllerI {
* return `null`.
*/
@Method()
async get(menuId?: string): Promise<HTMLIonMenuElement | undefined> {
async get(menuId?: string | null): Promise<HTMLIonMenuElement | undefined> {
if (Build.isDev) {
if (menuId === 'left') {
console.error('menu.side=left is deprecated, use "start" instead');
@ -145,7 +146,7 @@ export class MenuController implements MenuControllerI {
// so try to get the first menu side found
return this.find(m => m.side === menuId);
} else if (menuId !== undefined) {
} else if (menuId != null) {
// the menuId was not left or right
// so try to get the menu by its "id"
return this.find(m => m.menuId === menuId);

View File

@ -6,8 +6,8 @@ import { Component, Listen, Prop, State } from '@stencil/core';
shadow: true
})
export class MenuToggle {
@Prop({ context: 'document' })
doc!: Document;
@Prop({ context: 'document' }) doc!: Document;
@State() visible = false;

View File

@ -315,13 +315,14 @@ export class PickerColumnCmp {
<div
class="picker-opts"
style={{ maxWidth: col.optionsWidth! }}
ref={ el => this.optsEl = el }>
ref={el => this.optsEl = el}
>
{ col.options.map((o, index) =>
<Button
type="button"
class={{ 'picker-opt': true, 'picker-opt-disabled': !!o.disabled }}
disable-activated
opt-index={index}>
opt-index={index}
>
{o.text}
</Button>
)}

View File

@ -260,8 +260,10 @@ export class Picker implements OverlayInterface {
<div class={buttonWrapperClass(b)}>
<button
type="button"
ion-activable
onClick={() => this.buttonClick(b)}
class={buttonClass(b)}>
class={buttonClass(b)}
>
{b.text}
</button>
</div>

View File

@ -40,11 +40,11 @@ A Picker is a dialog that displays a row of buttons and columns underneath. It a
## Methods
| Method | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `dismiss` | Dismiss the picker overlay after it has been presented. |
| `getColumn` | Returns the column the matches the specified name |
| `onDidDismiss` | Returns a promise that resolves when the picker did dismiss. It also accepts a callback that is called in the same circustances. |
| `onWillDismiss` | Returns a promise that resolves when the picker will dismiss. It also accepts a callback that is called in the same circustances. |
| `onWillDismiss` | Returns a promise that resolves when the picker will dismiss. It also accepts a callback that is called in the same circumstances. |
| `present` | Present the picker overlay after it has been created. |

View File

@ -197,7 +197,8 @@ export class Radio {
name={this.name}
value={this.value}
disabled={this.disabled}
ref={r => this.nativeInput = (r as any)}/>
ref={r => this.nativeInput = (r as any)}
/>
];
}
}

View File

@ -451,7 +451,8 @@ function renderKnob({ knob, value, ratio, min, max, disabled, pressed, pin, hand
aria-valuemin={min}
aria-valuemax={max}
aria-disabled={disabled ? 'true' : null}
aria-valuenow={value}>
aria-valuenow={value}
>
{pin && <div class="range-pin" role="presentation">{Math.round(value)}</div>}
<div class="range-knob" role="presentation" />
</div>

View File

@ -328,17 +328,19 @@ export class Searchbar {
const clearIcon = this.clearIcon || (this.mode === 'ios' ? 'ios-close-circle' : 'md-close');
const searchIcon = this.searchIcon || 'search';
const cancelButton = (this.showCancelButton)
? <button
const cancelButton = this.showCancelButton && (
<button
type="button"
tabIndex={this.mode === 'ios' && !this.focused ? -1 : undefined}
onClick={this.cancelSearchbar.bind(this)}
class="searchbar-cancel-button">
class="searchbar-cancel-button"
>
{ this.mode === 'md'
? <ion-icon mode={this.mode} icon={this.cancelButtonIcon} lazy={false}></ion-icon>
: this.cancelButtonText }
: this.cancelButtonText
}
</button>
: null;
);
return [
<div class="searchbar-input-container">
@ -353,7 +355,8 @@ export class Searchbar {
value={this.value}
autoComplete={this.autocomplete}
autoCorrect={this.autocorrect}
spellCheck={this.spellcheck}/>
spellCheck={this.spellcheck}
/>
{this.mode === 'md' && cancelButton}
@ -361,11 +364,12 @@ export class Searchbar {
<button
type="button"
no-blur={true}
no-blur
class="searchbar-clear-button"
onClick={this.clearInput.bind(this)}
onMouseDown={this.clearInput.bind(this)}
onTouchStart={this.clearInput.bind(this)}>
onTouchStart={this.clearInput.bind(this)}
>
<ion-icon mode={this.mode} icon={clearIcon} lazy={false} class="searchbar-clear-icon"></ion-icon>
</button>
</div>,

View File

@ -73,7 +73,8 @@ export class SegmentButton {
aria-pressed={this.checked ? 'true' : null}
class="segment-button-native"
disabled={this.disabled}
onClick={() => this.checked = true }>
onClick={() => this.checked = true}
>
<slot></slot>
{this.mode === 'md' && <ion-ripple-effect />}
</button>

View File

@ -9,10 +9,10 @@ SelectOption is a component that is a child element of Select. For more informat
## Properties
| Property | Attribute | Description | Type |
| ---------- | ---------- | ------------------------------------------------------------------------------ | ------------- |
| ---------- | ---------- | ------------------------------------------------------------------------------ | --------- |
| `disabled` | `disabled` | If true, the user cannot interact with the select option. Defaults to `false`. | `boolean` |
| `selected` | `selected` | If true, the element is selected. | `boolean` |
| `value` | -- | The text value of the option. | `any`, `null` |
| `value` | -- | The text value of the option. | `any` |
## Events

View File

@ -22,7 +22,7 @@ export class SelectOption {
/**
* The text value of the option.
*/
@Prop({ mutable: true }) value!: any | null;
@Prop({ mutable: true }) value?: any;
/**
* Emitted when the select option loads.

View File

@ -58,7 +58,8 @@ export class SelectPopover {
<ion-radio
checked={option.checked}
value={option.value}
disabled={option.disabled}>
disabled={option.disabled}
>
</ion-radio>
</ion-item>
)}

View File

@ -369,6 +369,7 @@ export class Select {
const interfaceOptions = this.interfaceOptions;
const inputType = (this.multiple ? 'checkbox' : 'radio');
const alertOpts: AlertOptions = {
...interfaceOptions,
@ -484,7 +485,9 @@ export class Select {
<div
role="textbox"
aria-multiline="false"
class={ selectTextClasses }>{ selectText }
class={selectTextClasses}
>
{selectText}
</div>,
<div class="select-icon" role="presentation">
<div class="select-icon-inner"></div>
@ -500,7 +503,8 @@ export class Select {
onKeyUp={this.onKeyUp.bind(this)}
onFocus={this.onFocus.bind(this)}
onBlur={this.onBlur.bind(this)}
class="select-cover">
class="select-cover"
>
<slot></slot>
{this.mode === 'md' && <ion-ripple-effect />}
</button>

View File

@ -25,8 +25,8 @@
<ion-item>
<ion-label>Gender</ion-label>
<ion-select id="gender" placeholder="Select One">
<ion-select-option value="f">Female</ion-select-option>
<ion-select-option value="m">Male</ion-select-option>
<ion-select-option value="fn">Female</ion-select-option>
<ion-select-option value="ml">Male</ion-select-option>
</ion-select>
</ion-item>

View File

@ -131,7 +131,8 @@ export class Tabbar {
this.ionTabbarClick.emit(tab);
}
ev.preventDefault();
}}>
}}
>
{icon && <ion-icon class="tab-btn-icon" icon={icon} lazy={false}></ion-icon>}
{label && <span class="tab-btn-text">{label}</span>}
{badge && <ion-badge class="tab-btn-badge" color={badgeColor}>{badge}</ion-badge>}

View File

@ -312,7 +312,8 @@ export class Tabs implements NavOutlet {
highlight={this.tabbarHighlight}
placement={this.tabbarPlacement}
layout={this.tabbarLayout}
translucent={this.translucent}>
translucent={this.translucent}
>
</ion-tabbar>
)
];

View File

@ -203,7 +203,8 @@ export class Toggle {
name={this.name}
value={this.value}
disabled={this.disabled}
ref={r => this.nativeInput = (r as any)}/>,
ref={r => this.nativeInput = (r as any)}
/>,
<slot></slot>
];
}

View File

@ -243,9 +243,9 @@ export function calcCells(
export function calcHeightIndex(buf: Uint32Array, cells: Cell[], index: number): number {
let acum = buf[index];
for (; index < buf.length; index++) {
buf[index] = acum;
acum += cells[index].height;
for (let i = index; i < buf.length; i++) {
buf[i] = acum;
acum += cells[i].height;
}
return acum;
}

View File

@ -159,9 +159,10 @@ export class VirtualScroll {
if (!this.items) {
return;
}
if (len === -1) {
len = this.items.length - offset;
}
const length = (len === -1)
? this.items.length - offset
: len;
const max = this.lastItemLen;
let j = 0;
if (offset > 0 && offset < max) {
@ -182,7 +183,7 @@ export class VirtualScroll {
this.approxHeaderHeight,
this.approxFooterHeight,
this.approxItemHeight,
j, offset, len
j, offset, length
);
console.debug('[virtual] cells recalculated', cells.length);
this.cells = inplaceUpdate(this.cells, cells, offset);

View File

@ -1,5 +1,11 @@
{
"extends": "tslint-ionic-rules/strict",
"extends": ["tslint-ionic-rules/strict", "tslint-react"],
"linterOptions": {
"exclude": [
"**/*.spec.ts",
"**/*.spec.tsx"
]
},
"rules": {
"no-conditional-assignment": false,
"no-non-null-assertion": false,
@ -8,9 +14,15 @@
"trailing-comma": false,
"no-null-keyword": false,
"no-console": false,
"no-unbound-method": true,
"strict-type-predicates": true,
"await-promise": true,
"strict-boolean-expressions": [true, "allow-null-union", "allow-undefined-union", "allow-boolean-or-undefined"]
"jsx-key": false,
"jsx-self-close": false,
"jsx-curly-spacing": [true, "never"],
"jsx-boolean-value": [true, "never"],
"jsx-no-bind": false,
"jsx-no-lambda": false,
"jsx-no-multiline-js": false,
"jsx-wrap-multiline": false
}
}