Skip to content

Commit

Permalink
chore: replace tslint with eslint (#55)
Browse files Browse the repository at this point in the history
close #52
  • Loading branch information
Yadong Xie committed Apr 21, 2022
1 parent 7305793 commit 2115f29
Show file tree
Hide file tree
Showing 19 changed files with 918 additions and 295 deletions.
31 changes: 31 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,31 @@
module.exports = {
env: {
browser: true,
node: true,
},
extends: ['prettier', 'plugin:prettier/recommended', 'eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
createDefaultProgram: true,
},
plugins: ['@typescript-eslint'],
rules: {
'no-prototype-builtins': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
overrides: [
{
files: ['test/**/*.ts'],
rules: {
'@typescript-eslint/no-empty-function': 'off',
},
},
],
};
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -32,5 +32,5 @@ dist

demo/dist
demo/vendor
dist
.idea
dist-test
1 change: 1 addition & 0 deletions lib/facade/errors.ts
@@ -1,4 +1,5 @@
import { DebugContext } from './lang';

/**
* @license
* Copyright Google Inc. All Rights Reserved.
Expand Down
4 changes: 2 additions & 2 deletions lib/facade/lang.ts
Expand Up @@ -30,11 +30,11 @@ export interface BrowserNodeGlobal {
}

// TODO(jteplitz602): Load WorkerGlobalScope from lib.webworker.d.ts file #3492
declare var WorkerGlobalScope: any /** TODO #9100 */;
declare let WorkerGlobalScope: any /** TODO #9100 */;
// CommonJS / Node have global context exposed as "global" variable.
// We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
// the global "global" var for now.
declare var global: any /** TODO #9100 */;
declare let global: any /** TODO #9100 */;

let globalScope: BrowserNodeGlobal;
if (typeof window === 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion lib/forward_ref.ts
Expand Up @@ -35,7 +35,7 @@ export interface ForwardRefFn {
*/
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
(<any>forwardRefFn).__forward_ref__ = forwardRef;
(<any>forwardRefFn).toString = function() {
(<any>forwardRefFn).toString = function () {
return stringify(this());
};
return <Type<any>>(<any>forwardRefFn);
Expand Down
2 changes: 1 addition & 1 deletion lib/provider.ts
Expand Up @@ -32,7 +32,7 @@ import { Type } from './facade/type';
*
* @stable
*/
export interface TypeProvider extends Type<any> {}
export type TypeProvider = Type<any>;

/**
* @whatItDoes Configures the {@link Injector} to return a value for a token.
Expand Down
8 changes: 4 additions & 4 deletions lib/reflection/reflection_capabilities.ts
Expand Up @@ -167,7 +167,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
if ((<any>typeOrFunc).propDecorators && (<any>typeOrFunc).propDecorators !== parentCtor.propDecorators) {
const propDecorators = (<any>typeOrFunc).propDecorators;
const propMetadata = <{ [key: string]: any[] }>{};
Object.keys(propDecorators).forEach(prop => {
Object.keys(propDecorators).forEach((prop) => {
propMetadata[prop] = convertTsickleDecoratorIntoMetadata(propDecorators[prop]);
});
return propMetadata;
Expand All @@ -188,13 +188,13 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
const propMetadata: { [key: string]: any[] } = {};
if (parentCtor !== Object) {
const parentPropMetadata = this.propMetadata(parentCtor);
Object.keys(parentPropMetadata).forEach(propName => {
Object.keys(parentPropMetadata).forEach((propName) => {
propMetadata[propName] = parentPropMetadata[propName];
});
}
const ownPropMetadata = this._ownPropMetadata(typeOrFunc, parentCtor);
if (ownPropMetadata) {
Object.keys(ownPropMetadata).forEach(propName => {
Object.keys(ownPropMetadata).forEach((propName) => {
const decorators: any[] = [];
if (propMetadata.hasOwnProperty(propName)) {
decorators.push(...propMetadata[propName]);
Expand Down Expand Up @@ -250,7 +250,7 @@ function convertTsickleDecoratorIntoMetadata(decoratorInvocations: any[]): any[]
if (!decoratorInvocations) {
return [];
}
return decoratorInvocations.map(decoratorInvocation => {
return decoratorInvocations.map((decoratorInvocation) => {
const decoratorType = decoratorInvocation.type;
const annotationCls = decoratorType.annotationCls;
const annotationArgs = decoratorInvocation.args ? decoratorInvocation.args : [];
Expand Down
9 changes: 5 additions & 4 deletions lib/reflective_errors.ts
Expand Up @@ -29,7 +29,7 @@ function findFirstClosedCycle(keys: any[]): any[] {
function constructResolvingPath(keys: any[]): string {
if (keys.length > 1) {
const reversed = findFirstClosedCycle(keys.slice().reverse());
const tokenStrs = reversed.map(k => stringify(k.token));
const tokenStrs = reversed.map((k) => stringify(k.token));
return ' (' + tokenStrs.join(' -> ') + ')';
}

Expand Down Expand Up @@ -80,7 +80,7 @@ function addKey(this: InjectionError, injector: ReflectiveInjector, key: Reflect
* ```
*/
export function noProviderError(injector: ReflectiveInjector, key: ReflectiveKey): InjectionError {
return injectionError(injector, key, function(this: InjectionError) {
return injectionError(injector, key, function (this: InjectionError) {
const first = stringify(this.keys[0].token);
return `No provider for ${first}!${constructResolvingPath(this.keys)}`;
});
Expand All @@ -103,7 +103,7 @@ export function noProviderError(injector: ReflectiveInjector, key: ReflectiveKey
* Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed.
*/
export function cyclicDependencyError(injector: ReflectiveInjector, key: ReflectiveKey): InjectionError {
return injectionError(injector, key, function(this: InjectionError) {
return injectionError(injector, key, function (this: InjectionError) {
return `Cannot instantiate cyclic dependency!${constructResolvingPath(this.keys)}`;
});
}
Expand Down Expand Up @@ -143,7 +143,7 @@ export function instantiationError(
return injectionError(
injector,
key,
function(this: InjectionError) {
function (this: InjectionError) {
const first = stringify(this.keys[0].token);
return `${getOriginalError(this).message}: Error during instantiation of ${first}!${constructResolvingPath(this.keys)}.`;
},
Expand Down Expand Up @@ -247,6 +247,7 @@ export function outOfBoundsError(index: number) {
* ])).toThrowError();
* ```
*/

export function mixingMultiProvidersWithRegularProvidersError(provider1: any, provider2: any): Error {
return Error(`Cannot mix multi providers and regular providers, got: ${provider1} ${provider2}`);
}
8 changes: 4 additions & 4 deletions lib/reflective_injector.ts
Expand Up @@ -283,7 +283,7 @@ export abstract class ReflectiveInjector implements Injector {
// tslint:disable-next-line:class-name
export class ReflectiveInjector_ implements ReflectiveInjector {
/** @internal */
_constructionCounter: number = 0;
_constructionCounter = 0;
/** @internal */
public _providers: ResolvedReflectiveProvider[];
/** @internal */
Expand Down Expand Up @@ -372,8 +372,8 @@ export class ReflectiveInjector_ implements ReflectiveInjector {

let deps: any[];
try {
deps = ResolvedReflectiveFactory.dependencies.map(dep => this._getByReflectiveDependency(dep));
} catch (e) {
deps = ResolvedReflectiveFactory.dependencies.map((dep) => this._getByReflectiveDependency(dep));
} catch (e: any) {
if (e.addKey) {
e.addKey(this, provider.key);
}
Expand All @@ -383,7 +383,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
let obj: any;
try {
obj = factory(...deps);
} catch (e) {
} catch (e: any) {
throw instantiationError(this, e, e.stack, provider.key);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/reflective_provider.ts
Expand Up @@ -178,7 +178,7 @@ export function mergeResolvedReflectiveProviders(
}

function _normalizeProviders(providers: Provider[], res: Provider[]): NormalizedProvider[] {
providers.forEach(b => {
providers.forEach((b) => {
if (b instanceof Type) {
res.push({ provide: b, useClass: b });
} else if (b && typeof b === 'object' && (b as any).provide !== undefined) {
Expand All @@ -197,19 +197,19 @@ export function constructDependencies(typeOrFunc: any, dependencies?: any[]): Re
if (!dependencies) {
return _dependenciesFor(typeOrFunc);
} else {
const params: any[][] = dependencies.map(t => [t]);
return dependencies.map(t => _extractToken(typeOrFunc, t, params));
const params: any[][] = dependencies.map((t) => [t]);
return dependencies.map((t) => _extractToken(typeOrFunc, t, params));
}
}

function _dependenciesFor(typeOrFunc: any): ReflectiveDependency[] {
const params = reflector.parameters(typeOrFunc);

if (!params) return [];
if (params.some(p => p == null)) {
if (params.some((p) => p == null)) {
throw noAnnotationError(typeOrFunc, params);
}
return params.map(p => _extractToken(typeOrFunc, p, params));
return params.map((p) => _extractToken(typeOrFunc, p, params));
}

function _extractToken(typeOrFunc: any, metadata: any[] | any, params: any[][]): ReflectiveDependency {
Expand Down
2 changes: 1 addition & 1 deletion lib/util/resolve_dependencies.ts
Expand Up @@ -60,7 +60,7 @@ export function resolveDependencies(...inputs: Constructor[]) {
ReflectiveInjector.resolve([klass])
.reduce((a, x: ResolvedReflectiveProvider) => a.concat(x.resolvedFactories), [] as ResolvedReflectiveFactory[])
.reduce((a, r: ResolvedReflectiveFactory) => a.concat(r.dependencies), [] as ReflectiveDependency[])
.forEach(d => resolver(d.key.token as Constructor));
.forEach((d) => resolver(d.key.token as Constructor));
}

for (const input of inputs) {
Expand Down
27 changes: 15 additions & 12 deletions package.json
Expand Up @@ -17,25 +17,28 @@
"tslib": "^2.0.0"
},
"devDependencies": {
"@types/jasmine": "^3.4.0",
"@types/node": "^14.14.6",
"jasmine": "^3.4.0",
"prettier": "1.18.2",
"@types/jasmine": "^4.0.3",
"@types/node": "^17.0.24",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jasmine": "^4.1.0",
"prettier": "^2.6.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"rollup": "^1.19.4",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.00",
"typescript": "^4.0.0"
"rimraf": "^3.0.2",
"rollup": "^2.70.2",
"typescript": "^4.6.3"
},
"scripts": {
"prebuild": "npm run verify && npm t",
"build": "rimraf dist && tsc && rollup -c rollup.config.js -i dist/index.js > dist/injection.bundle.js && node tools/copy.js",
"pretest": "rimraf dist/test && tsc -p tsconfig-es5.test.json && tsc -p tsconfig-es2015.test.json",
"test": "jasmine",
"format": "prettier \"**/*.{js,ts,md,css,less,sass,scss}\"",
"lint": "tslint -p tsconfig.json",
"verify": "tsc -p tools && npm run format -- -l && npm run lint"
"format": "eslint -c .eslintrc.js lib/**/*.ts --fix && eslint -c .eslintrc.js test/*.ts --fix",
"lint": "eslint -c .eslintrc.js lib/**/*.ts && eslint -c .eslintrc.js test/*.ts",
"verify": "tsc -p tools && npm run format && npm run lint"
},
"keywords": [
"DI",
Expand Down
3 changes: 2 additions & 1 deletion test/forward_ref_spec.ts 100644 → 100755
Expand Up @@ -7,9 +7,10 @@
*/

import { Type } from '../lib/facade/type';

import { forwardRef, resolveForwardRef } from '../lib';

describe('forwardRef', function() {
describe('forwardRef', function () {
it('should wrap and unwrap the reference', () => {
const ref = forwardRef(() => String);
expect(ref instanceof Type).toBe(true);
Expand Down
Empty file modified test/injector_spec.ts 100644 → 100755
Empty file.

0 comments on commit 2115f29

Please sign in to comment.