chore: eslint cleanup (#10160)

This commit is contained in:
farfromrefuge
2023-01-09 17:40:20 +00:00
committed by GitHub
parent bff35e5163
commit 0632215793
18 changed files with 97 additions and 71 deletions

View File

@ -24,7 +24,22 @@
{
"files": ["*.ts", "*.tsx"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier", "plugin:@nrwl/nx/typescript"],
"rules": {}
"rules": {
"no-empty": "off",
"no-useless-escape": "off",
"no-inner-declarations": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-inferrable-types": "off"
}
},
{
"files": ["*.js", "*.jsx"],

View File

@ -38,7 +38,7 @@ export namespace CoreTypes {
};
export type KeyboardInputType = 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer';
export module KeyboardType {
export namespace KeyboardType {
export const datetime = 'datetime';
export const phone = 'phone';
export const number = 'number';
@ -47,7 +47,7 @@ export namespace CoreTypes {
export const integer = 'integer';
}
export type AutofillType = 'username' | 'password' | 'none' | string;
export module AutofillType {
export namespace AutofillType {
export const username = 'username';
export const password = 'password';
export const newUsername = 'newUsername';
@ -57,7 +57,7 @@ export namespace CoreTypes {
}
export type ReturnKeyButtonType = 'done' | 'next' | 'go' | 'search' | 'send';
export module ReturnKeyType {
export namespace ReturnKeyType {
export const done = 'done';
export const next = 'next';
export const go = 'go';
@ -66,7 +66,7 @@ export namespace CoreTypes {
}
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right' | 'justify';
export module TextAlignment {
export namespace TextAlignment {
export const left = 'left';
export const center = 'center';
export const right = 'right';
@ -74,14 +74,14 @@ export namespace CoreTypes {
}
export type TextDecorationType = 'none' | 'underline' | 'line-through' | 'underline line-through';
export module TextDecoration {
export namespace TextDecoration {
export const none = 'none';
export const underline = 'underline';
export const lineThrough = 'line-through';
}
export type TextTransformType = 'initial' | 'none' | 'capitalize' | 'uppercase' | 'lowercase';
export module TextTransform {
export namespace TextTransform {
export const none = 'none';
export const capitalize = 'capitalize';
export const uppercase = 'uppercase';
@ -89,7 +89,7 @@ export namespace CoreTypes {
}
export type WhiteSpaceType = 'initial' | 'normal' | 'nowrap';
export module WhiteSpace {
export namespace WhiteSpace {
export const normal = 'normal';
export const nowrap = 'nowrap';
}
@ -97,20 +97,20 @@ export namespace CoreTypes {
export type MaxLinesType = number;
export type OrientationType = 'horizontal' | 'vertical';
export module Orientation {
export namespace Orientation {
export const horizontal = 'horizontal';
export const vertical = 'vertical';
}
export type DeviceOrientationType = 'portrait' | 'landscape' | 'unknown';
export module DeviceOrientation {
export namespace DeviceOrientation {
export const portrait = 'portrait';
export const landscape = 'landscape';
export const unknown = 'unknown';
}
export type HorizontalAlignmentType = 'left' | 'center' | 'right' | 'stretch';
export module HorizontalAlignment {
export namespace HorizontalAlignment {
export const left = 'left';
export const center = 'center';
export const right = 'right';
@ -120,7 +120,7 @@ export namespace CoreTypes {
}
export type VerticalAlignmentType = 'top' | 'middle' | 'bottom' | 'stretch';
export module VerticalAlignment {
export namespace VerticalAlignment {
export const top = 'top';
export const middle = 'middle';
export const bottom = 'bottom';
@ -143,7 +143,7 @@ export namespace CoreTypes {
}
export type ImageStretchType = 'none' | 'aspectFill' | 'aspectFit' | 'fill';
export module ImageStretch {
export namespace ImageStretch {
export const none: ImageStretchType = 'none';
export const aspectFill: ImageStretchType = 'aspectFill';
export const aspectFit: ImageStretchType = 'aspectFit';
@ -151,7 +151,7 @@ export namespace CoreTypes {
}
export type VisibilityType = 'visible' | 'hidden' | 'collapse' | 'collapsed';
export module Visibility {
export namespace Visibility {
export const visible: VisibilityType = 'visible';
export const collapse: VisibilityType = 'collapse';
export const collapsed: VisibilityType = 'collapsed';
@ -161,30 +161,30 @@ export namespace CoreTypes {
const parseStrict = makeParser<CoreTypes.VisibilityType>(isValid);
}
export module FontAttributes {
export namespace FontAttributes {
export const Normal = 0;
export const Bold = 1;
export const Italic = 1 << 1;
}
export module DeviceType {
export namespace DeviceType {
export const Phone: string = 'Phone';
export const Tablet: string = 'Tablet';
}
export type UpdateTextTriggerType = 'focusLost' | 'textChanged';
export module UpdateTextTrigger {
export namespace UpdateTextTrigger {
export const focusLost: UpdateTextTriggerType = 'focusLost';
export const textChanged: UpdateTextTriggerType = 'textChanged';
}
export module Accuracy {
export namespace Accuracy {
export const any: number = 300;
export const high: number = 3;
}
export type DockType = 'left' | 'top' | 'right' | 'bottom';
export module Dock {
export namespace Dock {
export const left: DockType = 'left';
export const top: DockType = 'top';
export const right: DockType = 'right';
@ -192,48 +192,48 @@ export namespace CoreTypes {
}
export type AutocapitalizationInputType = 'none' | 'words' | 'sentences' | 'allcharacters';
export module AutocapitalizationType {
export namespace AutocapitalizationType {
export const none: AutocapitalizationInputType = 'none';
export const words: AutocapitalizationInputType = 'words';
export const sentences: AutocapitalizationInputType = 'sentences';
export const allCharacters: AutocapitalizationInputType = 'allcharacters';
}
export module NavigationBarVisibility {
export namespace NavigationBarVisibility {
export const auto: string = 'auto';
export const never: string = 'never';
export const always: string = 'always';
}
export module AndroidActionBarIconVisibility {
export namespace AndroidActionBarIconVisibility {
export const auto: string = 'auto';
export const never: string = 'never';
export const always: string = 'always';
}
export module AndroidActionItemPosition {
export namespace AndroidActionItemPosition {
export const actionBar: string = 'actionBar';
export const actionBarIfRoom: string = 'actionBarIfRoom';
export const popup: string = 'popup';
}
export module IOSActionItemPosition {
export namespace IOSActionItemPosition {
export const left: string = 'left';
export const right: string = 'right';
}
export module ImageFormat {
export namespace ImageFormat {
export const png: string = 'png';
export const jpeg: string = 'jpeg';
export const jpg: string = 'jpg';
}
export module FontStyle {
export namespace FontStyle {
export const normal: string = 'normal';
export const italic: string = 'italic';
}
export module FontWeight {
export namespace FontWeight {
export const thin: string = '100';
export const extraLight: string = '200';
export const light: string = '300';
@ -246,7 +246,7 @@ export namespace CoreTypes {
}
export type BackgroundRepeatType = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';
export module BackgroundRepeat {
export namespace BackgroundRepeat {
export const repeat: BackgroundRepeatType = 'repeat';
export const repeatX: BackgroundRepeatType = 'repeat-x';
export const repeatY: BackgroundRepeatType = 'repeat-y';
@ -257,26 +257,26 @@ export namespace CoreTypes {
let animation: typeof animationModule;
export module AnimationCurve {
export namespace AnimationCurve {
export const ease = 'ease';
export const easeIn = 'easeIn';
export const easeOut = 'easeOut';
export const easeInOut = 'easeInOut';
export const linear = 'linear';
export const spring = 'spring';
export function cubicBezier(x1: number, y1: number, x2: number, y2: number): Object {
export function cubicBezier(x1: number, y1: number, x2: number, y2: number) {
animation = animation || require('../ui/animation');
return new animation.CubicBezierAnimationCurve(x1, y1, x2, y2);
}
}
export module StatusBarStyle {
export namespace StatusBarStyle {
export const light = 'light';
export const dark = 'dark';
}
export module SystemAppearance {
export namespace SystemAppearance {
export const light = 'light';
export const dark = 'dark';
}

View File

@ -460,6 +460,7 @@ function parseArgumentsList<T>(text: string, start: number, argument: (value: st
return { start, end, value };
}
// eslint-disable-next-line no-constant-condition
for (let index = 0; true; index++) {
const arg = argument(text, end, index);
if (!arg) {

View File

@ -95,7 +95,7 @@ export class ObservableArray<T> extends Observable {
}
*[Symbol.iterator]() {
for (let item of this._array) {
for (const item of this._array) {
yield item;
}
}

View File

@ -362,7 +362,7 @@ export function initGlobal() {
}
}
declare var jest: any;
declare const jest: any;
function isTestingEnv() {
return typeof jest !== 'undefined';
}

View File

@ -22,13 +22,14 @@ export class ActionBarBase extends View implements ActionBarDefinition {
public effectiveContentInsetLeft: number;
public effectiveContentInsetRight: number;
get navigationButton(): NavigationButton {
return this._navigationButton;
}
disposeNativeView() {
this._actionItems = null;
super.disposeNativeView();
}
get navigationButton(): NavigationButton {
return this._navigationButton;
}
set navigationButton(value: NavigationButton) {
if (this._navigationButton !== value) {
if (this._navigationButton) {

View File

@ -51,8 +51,8 @@ const logicalOperators = {
const expressionParsers = {
'ArrayExpression': (expression: ASTExpression, model, isBackConvert: boolean, changedModel) => {
const parsed = [];
for (let element of expression.elements) {
let value = convertExpressionToValue(element, model, isBackConvert, changedModel);
for (const element of expression.elements) {
const value = convertExpressionToValue(element, model, isBackConvert, changedModel);
element.type == 'SpreadElement' ? parsed.push(...value) : parsed.push(value);
}
return parsed;
@ -116,8 +116,8 @@ const expressionParsers = {
}
const parsedArgs = [];
for (let argument of expression.arguments) {
let value = convertExpressionToValue(argument, model, isBackConvert, changedModel);
for (const argument of expression.arguments) {
const value = convertExpressionToValue(argument, model, isBackConvert, changedModel);
argument.type == 'SpreadElement' ? parsedArgs.push(...value) : parsedArgs.push(value);
}
return expression.optional ? callback?.(...parsedArgs) : callback(...parsedArgs);
@ -181,8 +181,8 @@ const expressionParsers = {
'NewExpression': (expression: ASTExpression, model, isBackConvert: boolean, changedModel) => {
const callback = convertExpressionToValue(expression.callee, model, isBackConvert, changedModel);
const parsedArgs = [];
for (let argument of expression.arguments) {
let value = convertExpressionToValue(argument, model, isBackConvert, changedModel);
for (const argument of expression.arguments) {
const value = convertExpressionToValue(argument, model, isBackConvert, changedModel);
argument.type == 'SpreadElement' ? parsedArgs.push(...value) : parsedArgs.push(value);
}
@ -194,7 +194,7 @@ const expressionParsers = {
},
'ObjectExpression': (expression: ASTExpression, model, isBackConvert: boolean, changedModel) => {
const parsedObject = {};
for (let property of expression.properties) {
for (const property of expression.properties) {
const value = convertExpressionToValue(property, model, isBackConvert, changedModel);
Object.assign(parsedObject, value);
}
@ -217,7 +217,7 @@ const expressionParsers = {
const length = expression.quasis.length;
for (let i = 0; i < length; i++) {
let q = expression.quasis[i];
const q = expression.quasis[i];
parsedText += convertExpressionToValue(q, model, isBackConvert, changedModel);
if (!q.tail) {
parsedText += convertExpressionToValue(expression.expressions[i], model, isBackConvert, changedModel);
@ -262,7 +262,7 @@ export function parseExpression(expressionText: string): ASTExpression {
if (expression == null) {
const program: any = parse(expressionText, { ecmaVersion: 2020 });
const statements = program.body;
for (let statement of statements) {
for (const statement of statements) {
if (statement.type == 'ExpressionStatement') {
expression = statement.expression;
break;

View File

@ -415,7 +415,7 @@ export class Binding {
}
// Clear added props
for (let prop of addedProps) {
for (const prop of addedProps) {
delete context[prop];
}
addedProps.length = 0;

View File

@ -229,7 +229,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
newInputType = android.text.InputType.TYPE_CLASS_NUMBER;
break;
default:
default: {
const inputType = +value;
if (!isNaN(inputType)) {
newInputType = inputType;
@ -238,6 +238,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
}
break;
}
}
this._setInputType(newInputType);
}

View File

@ -60,7 +60,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
newKeyboardType = UIKeyboardType.NumberPad;
break;
default:
default: {
const kt = +value;
if (!isNaN(kt)) {
newKeyboardType = <UIKeyboardType>kt;
@ -69,6 +69,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
}
break;
}
}
this.nativeTextViewProtected.keyboardType = newKeyboardType;
}
@ -104,10 +105,12 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
break;
case 'none':
newTextContentType = null;
default:
break;
default: {
newTextContentType = value;
break;
}
}
this.nativeTextViewProtected.textContentType = newTextContentType;
}
@ -152,7 +155,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
case 'send':
newValue = UIReturnKeyType.Send;
break;
default:
default: {
const rkt = +value;
if (!isNaN(rkt)) {
newValue = <UIKeyboardType>rkt;
@ -161,6 +164,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
}
break;
}
}
this.nativeTextViewProtected.returnKeyType = newValue;
}

View File

@ -439,7 +439,7 @@ export class Frame extends FrameBase {
const newFragmentTag = `fragment${fragmentId}[${navDepth}]`;
const newFragment = this.createFragment(newEntry, newFragmentTag);
const transaction = manager.beginTransaction();
let animated = currentEntry ? this._getIsAnimatedNavigation(newEntry.entry) : false;
const animated = currentEntry ? this._getIsAnimatedNavigation(newEntry.entry) : false;
// NOTE: Don't use transition for the initial navigation (same as on iOS)
// On API 21+ transition won't be triggered unless there was at least one
// layout pass so we will wait forever for transitionCompleted handler...

View File

@ -84,7 +84,7 @@ export class Frame extends FrameBase {
}
let navigationTransition: NavigationTransition;
let animated = this.currentPage ? this._getIsAnimatedNavigation(backstackEntry.entry) : false;
const animated = this.currentPage ? this._getIsAnimatedNavigation(backstackEntry.entry) : false;
if (animated) {
navigationTransition = this._getNavigationTransition(backstackEntry.entry);
if (navigationTransition) {
@ -183,7 +183,7 @@ export class Frame extends FrameBase {
}
private pushViewControllerAnimated(viewController: UIViewController, animated: boolean, isModal: boolean) {
let transitionCoordinator = this._ios.controller.transitionCoordinator;
const transitionCoordinator = this._ios.controller.transitionCoordinator;
if (!isModal && transitionCoordinator) {
transitionCoordinator.animateAlongsideTransitionCompletion(null, () => {
this._ios.controller.pushViewControllerAnimated(viewController, animated);

View File

@ -78,15 +78,15 @@ export class ItemSpec extends Observable implements ItemSpecDefinition {
private _value: number;
private _unitType: GridUnitType;
constructor() {
constructor(...args) {
super();
if (arguments.length === 0) {
if (args.length === 0) {
this._value = 1;
this._unitType = GridUnitType.STAR;
} else if (arguments.length === 2) {
const value = arguments[0];
const type = arguments[1];
const value = args[0];
const type = args[1];
if (typeof value === 'number' && typeof type === 'string') {
if (value < 0 || isNaN(value) || !isFinite(value)) {
throw new Error(`Value should not be negative, NaN or Infinity: ${value}`);
@ -381,9 +381,9 @@ rowSpanProperty.register(View);
export type GridUnitType = 'pixel' | 'star' | 'auto';
export namespace GridUnitType {
export const PIXEL: 'pixel' = 'pixel';
export const STAR: 'star' = 'star';
export const AUTO: 'auto' = 'auto';
export const PIXEL = 'pixel';
export const STAR = 'star';
export const AUTO = 'auto';
export const isValid = makeValidator<GridUnitType>(PIXEL, STAR, AUTO);
export const parse = makeParser<GridUnitType>(isValid);
}

View File

@ -109,7 +109,7 @@ export class RootLayout extends RootLayoutBase {
backgroundColorAnimator.addUpdateListener(
new android.animation.ValueAnimator.AnimatorUpdateListener({
onAnimationUpdate(animator: android.animation.ValueAnimator) {
let argb = (<java.lang.Integer>animator.getAnimatedValue()).intValue();
const argb = (<java.lang.Integer>animator.getAnimatedValue()).intValue();
view.backgroundColor = new Color(argb);
},
})

View File

@ -734,6 +734,7 @@ function normalizeTransformation({ property, value }: Transformation): Transform
}
function convertTransformValue(property: string, stringValue: string): TransformationValue {
/* eslint-disable prefer-const */
let [x, y, z] = stringValue.split(',').map(parseFloat);
if (property === 'translate') {
y ??= IDENTITY_TRANSFORMATION.translate.y;

View File

@ -159,11 +159,11 @@ export function debounce(fn: any, delay = 300) {
};
}
export function throttle(fn: any, delay = 300) {
export function throttle(fn: Function, delay = 300) {
let waiting = false;
return function () {
return function (...args) {
if (!waiting) {
fn.apply(this, arguments);
fn.apply(this, args);
waiting = true;
setTimeout(function () {
waiting = false;

View File

@ -34,9 +34,10 @@ export function dataDeserialize(nativeData?: any) {
}
case 'org.json.JSONObject': {
store = {};
let i = nativeData.keys();
const i = nativeData.keys();
let key;
while (i.hasNext()) {
let key = i.next();
key = i.next();
store[key] = dataDeserialize(nativeData.get(key));
}
break;

View File

@ -36,8 +36,8 @@ export function dataDeserialize(nativeData?: any) {
case 'NSNull':
return null;
case 'NSMutableDictionary':
case 'NSDictionary':
let obj = {};
case 'NSDictionary': {
const obj = {};
const length = nativeData.count;
const keysArray = nativeData.allKeys as NSArray<any>;
for (let i = 0; i < length; i++) {
@ -45,14 +45,16 @@ export function dataDeserialize(nativeData?: any) {
obj[nativeKey] = dataDeserialize(nativeData.objectForKey(nativeKey));
}
return obj;
}
case 'NSMutableArray':
case 'NSArray':
let array = [];
case 'NSArray': {
const array = [];
const len = nativeData.count;
for (let i = 0; i < len; i++) {
array[i] = dataDeserialize(nativeData.objectAtIndex(i));
}
return array;
}
default:
return nativeData;
}