Skip to content

Commit

Permalink
fix(eslint): Fix eslint warnings for @typescript-eslint/no-use-before…
Browse files Browse the repository at this point in the history
…-define
  • Loading branch information
christopherthielen committed Feb 14, 2019
1 parent aa4e8df commit e1b6663
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ export interface IAppengineConfigFileConfigurerCtrlCommand {
sourceType: string;
}

class ConfigArtifact implements IArtifactAccountPair {
public $scope: IScope;
public controller: ExpectedArtifactSelectorViewController;
public delegate: NgAppengineConfigArtifactDelegate;
public id: string;
public account: string;

constructor($scope: IScope, artifact = { id: '', account: '' }) {
const unserializable = { configurable: false, enumerable: false, writable: false };
this.id = artifact.id;
this.account = artifact.account;
Object.defineProperty(this, '$scope', { ...unserializable, value: $scope });
const delegate = new NgAppengineConfigArtifactDelegate(this);
const controller = new ExpectedArtifactSelectorViewController(delegate);
Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate });
Object.defineProperty(this, 'controller', { ...unserializable, value: controller });
}
}

class AppengineConfigFileConfigurerCtrl implements IController {
private artifactAccounts: IArtifactAccount[] = [];
public command: IAppengineConfigFileConfigurerCtrlCommand;
Expand Down Expand Up @@ -78,25 +97,6 @@ class AppengineConfigFileConfigurerCtrl implements IController {
}
}

class ConfigArtifact implements IArtifactAccountPair {
public $scope: IScope;
public controller: ExpectedArtifactSelectorViewController;
public delegate: NgAppengineConfigArtifactDelegate;
public id: string;
public account: string;

constructor($scope: IScope, artifact = { id: '', account: '' }) {
const unserializable = { configurable: false, enumerable: false, writable: false };
this.id = artifact.id;
this.account = artifact.account;
Object.defineProperty(this, '$scope', { ...unserializable, value: $scope });
const delegate = new NgAppengineConfigArtifactDelegate(this);
const controller = new ExpectedArtifactSelectorViewController(delegate);
Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate });
Object.defineProperty(this, 'controller', { ...unserializable, value: controller });
}
}

class AppengineConfigFileConfigurerComponent implements ng.IComponentOptions {
public bindings: any = { command: '=' };
public controller: any = AppengineConfigFileConfigurerCtrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bootstrapModule.run(($uiRouter: UIRouter) => {
let visualizerEnabled: 'true' | 'false' = 'false';
let VisualizerPlugin: { new (): UIRouterPlugin } = null;

const loadVisualizer = () => {
function loadVisualizer() {
// Auto-collapse certain states with lots of children
const collapseGlobs = ['home.*', 'home.*.application.*', 'home.*.application.insight.*'].map(
globStr => new Glob(globStr),
Expand All @@ -25,9 +25,9 @@ bootstrapModule.run(($uiRouter: UIRouter) => {
return import('@uirouter/visualizer')
.then((vis: any) => (VisualizerPlugin = vis.Visualizer))
.then(createVisualizer);
};
}

const createVisualizer = () => {
function createVisualizer() {
if (visualizerEnabled !== 'true') {
return;
}
Expand All @@ -40,14 +40,14 @@ bootstrapModule.run(($uiRouter: UIRouter) => {
} else {
loadVisualizer();
}
};
}

const destroyVisualizer = () => {
function destroyVisualizer() {
const plugin = $uiRouter.getPlugin('visualizer');
plugin && $uiRouter.dispose(plugin);
};
}

const toggleVisualizer = (trans: Transition) => {
function toggleVisualizer(trans: Transition) {
const enabled: 'true' | 'false' = trans.paramsChanged().vis;
if (enabled === undefined) {
return null;
Expand All @@ -66,7 +66,7 @@ bootstrapModule.run(($uiRouter: UIRouter) => {
}

return trans.targetState().withParams({ vis: undefined });
};
}

(window as any).vis = createVisualizer;
$uiRouter.transitionService.onStart({}, toggleVisualizer);
Expand Down
40 changes: 20 additions & 20 deletions app/scripts/modules/core/src/overrideRegistry/Overrides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ import * as React from 'react';
import { CloudProviderRegistry } from 'core/cloudProvider';
import { OverrideRegistry } from 'core/overrideRegistry';

/**
* Registers a component as a replacement for some other component.
*
* This is a Class Decorator which should be applied to a React Component Class.
* The component class will be used instead of the OverridableComponent with the same key.
*
* If an (optional) cloudProvider is specified, the component override takes effect only for that cloud provider.
* If an (optional) cloudProviderVersion is specified, the component override takes effect only for a specific version of that cloud provider.
*
* @Overrides('overrideKey', "aws", "v2")
* class MyOverridingCmp extends React.Component {
* render() { return <h1>Overridden component</h1> }
* }
*/
export function Overrides(key: string, cloudProvider?: string, cloudProviderVersion?: string) {
return function<P, T extends React.ComponentClass<P>>(targetComponent: T): void {
overrideRegistrationQueue.register(targetComponent, key, cloudProvider, cloudProviderVersion);
};
}

/**
* This queues OverrideComponent registration until the registries are ready.
*/
Expand Down Expand Up @@ -61,3 +41,23 @@ export class RegistrationQueue {
}

export const overrideRegistrationQueue = new RegistrationQueue();

/**
* Registers a component as a replacement for some other component.
*
* This is a Class Decorator which should be applied to a React Component Class.
* The component class will be used instead of the OverridableComponent with the same key.
*
* If an (optional) cloudProvider is specified, the component override takes effect only for that cloud provider.
* If an (optional) cloudProviderVersion is specified, the component override takes effect only for a specific version of that cloud provider.
*
* @Overrides('overrideKey', "aws", "v2")
* class MyOverridingCmp extends React.Component {
* render() { return <h1>Overridden component</h1> }
* }
*/
export function Overrides(key: string, cloudProvider?: string, cloudProviderVersion?: string) {
return function<P, T extends React.ComponentClass<P>>(targetComponent: T): void {
overrideRegistrationQueue.register(targetComponent, key, cloudProvider, cloudProviderVersion);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ import {
} from 'core/artifact';
import { UUIDGenerator } from 'core/utils';

class InputArtifact implements IArtifactAccountPair {
public $scope: IScope;
public controller: ExpectedArtifactSelectorViewController;
public delegate: NgBakeManifestArtifactDelegate;
public id: string;
public account: string;

constructor($scope: IScope, artifact = { id: '', account: '' }) {
const unserializable = { configurable: false, enumerable: false, writable: false };
Object.defineProperty(this, '$scope', { ...unserializable, value: $scope });
const delegate = new NgBakeManifestArtifactDelegate(this);
const controller = new ExpectedArtifactSelectorViewController(delegate);
Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate });
Object.defineProperty(this, 'controller', { ...unserializable, value: controller });
this.id = artifact.id;
this.account = artifact.account;
}
}

export class BakeManifestConfigCtrl implements IController {
public artifactControllers: any[];
public artifactAccounts: IArtifactAccount[] = [];
Expand Down Expand Up @@ -105,22 +124,3 @@ export class BakeManifestConfigCtrl implements IController {
);
}
}

class InputArtifact implements IArtifactAccountPair {
public $scope: IScope;
public controller: ExpectedArtifactSelectorViewController;
public delegate: NgBakeManifestArtifactDelegate;
public id: string;
public account: string;

constructor($scope: IScope, artifact = { id: '', account: '' }) {
const unserializable = { configurable: false, enumerable: false, writable: false };
Object.defineProperty(this, '$scope', { ...unserializable, value: $scope });
const delegate = new NgBakeManifestArtifactDelegate(this);
const controller = new ExpectedArtifactSelectorViewController(delegate);
Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate });
Object.defineProperty(this, 'controller', { ...unserializable, value: controller });
this.id = artifact.id;
this.account = artifact.account;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import * as React from 'react';
import { isFinite } from 'lodash';
import { IArtifact, IArtifactEditorProps } from 'core/domain';

export const CustomArtifactEditor = (props: IArtifactEditorProps) => {
if (props.singleColumn) {
return SingleColumnCustomArtifactEditor(props);
} else {
return MultiColumnCustomArtifactEditor(props);
}
};

const input = (artifact: IArtifact, field: keyof IArtifact, onChange: (a: IArtifact) => void) => (
<input
type="text"
Expand Down Expand Up @@ -80,3 +72,11 @@ const MultiColumnCustomArtifactEditor = (props: IArtifactEditorProps) => {
</div>
);
};

export const CustomArtifactEditor = (props: IArtifactEditorProps) => {
if (props.singleColumn) {
return SingleColumnCustomArtifactEditor(props);
} else {
return MultiColumnCustomArtifactEditor(props);
}
};
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import * as spel2js from 'spel2js';

export function parseSpelExpressions(template: string): spel2js.SpelExpression[] {
const spelExpressions = new TemplateAwareExpressionParser().parseExpressions(template);

// A Monkey patch which adds the current context when an exception occurs
spelExpressions.forEach(expr => {
const getValue = expr._compiledExpression.getValue;
expr._compiledExpression.getValue = function() {
const state = arguments[0];
try {
return getValue.apply(expr._compiledExpression, arguments);
} catch (err) {
err.state = state;
throw err;
}
};
});

return spelExpressions;
}

const literalExpression = (literalString: string) =>
spel2js.SpelExpressionEvaluator.compile(`'${literalString.replace(/'/g, "''")}'`);

Expand Down Expand Up @@ -218,13 +198,7 @@ class TemplateAwareExpressionParser {
case ')': {
if (!stack.length) {
throw new Error(
"Found closing '" +
ch +
"' at position " +
pos +
" without an opening '" +
Bracket.theOpenBracketFor(ch) +
"'",
`Found closing '${ch}' at position ${pos} without an opening '${Bracket.theOpenBracketFor(ch)}'`,
);
}

Expand Down Expand Up @@ -268,3 +242,23 @@ class TemplateAwareExpressionParser {
return pos;
}
}

export function parseSpelExpressions(template: string): spel2js.SpelExpression[] {
const spelExpressions = new TemplateAwareExpressionParser().parseExpressions(template);

// A Monkey patch which adds the current context when an exception occurs
spelExpressions.forEach(expr => {
const getValue = expr._compiledExpression.getValue;
expr._compiledExpression.getValue = function() {
const state = arguments[0];
try {
return getValue.apply(expr._compiledExpression, arguments);
} catch (err) {
err.state = state;
throw err;
}
};
});

return spelExpressions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ const isError = (maybeError: any): boolean => {
return !!maybeError;
};

const createItemBuilder = (arrayBuilder: IValidationBuilder, index: number): IArrayItemValidationBuilder => {
return {
item(itemLabel) {
return arrayBuilder.field(`[${index}]`, itemLabel);
},
field(name, itemLabel) {
return arrayBuilder.field(`[${index}].${name}`, itemLabel);
},
result: arrayBuilder.result,
arrayForEach: arrayBuilder.arrayForEach,
};
};

// Utility to provide a builder for array items. The provided iteratee will be invoked for every array item.
const arrayForEach = (builder: (values: any) => IValidationBuilder, iteratee: IArrayItemValidator) => {
return (array: any[], arrayLabel?: string) => {
// Silently ignore non-arrays (usually undefined). If strict type checking is desired, it should be done by a previous validator.
if (!Array.isArray(array)) {
return false;
}
const arrayBuilder = builder(array);
array.forEach((item: any, index: number) => {
const itemBuilder = createItemBuilder(arrayBuilder, index);
iteratee && iteratee(itemBuilder, item, index, array, arrayLabel);
});
return arrayBuilder.result();
};
};

const buildValidatorsSync = (values: any): IValidationBuilder => {
const isArray = Array.isArray(values);
const synchronousErrors: INamedValidatorResult[] = [];
Expand Down Expand Up @@ -165,35 +194,6 @@ export const buildValidators = (values: any, async?: boolean): IValidationBuilde
return async ? buildValidatorsAsync(values) : buildValidatorsSync(values);
};

const createItemBuilder = (arrayBuilder: IValidationBuilder, index: number): IArrayItemValidationBuilder => {
return {
item(itemLabel) {
return arrayBuilder.field(`[${index}]`, itemLabel);
},
field(name, itemLabel) {
return arrayBuilder.field(`[${index}].${name}`, itemLabel);
},
result: arrayBuilder.result,
arrayForEach: arrayBuilder.arrayForEach,
};
};

// Utility to provide a builder for array items. The provided iteratee will be invoked for every array item.
const arrayForEach = (builder: (values: any) => IValidationBuilder, iteratee: IArrayItemValidator) => {
return (array: any[], arrayLabel?: string) => {
// Silently ignore non-arrays (usually undefined). If strict type checking is desired, it should be done by a previous validator.
if (!Array.isArray(array)) {
return false;
}
const arrayBuilder = builder(array);
array.forEach((item: any, index: number) => {
const itemBuilder = createItemBuilder(arrayBuilder, index);
iteratee && iteratee(itemBuilder, item, index, array, arrayLabel);
});
return arrayBuilder.result();
};
};

export const composeValidators = (validators: IValidator[]): IValidator => {
const validatorList = validators.filter(x => !!x);
if (!validatorList.length) {
Expand Down

0 comments on commit e1b6663

Please sign in to comment.