style: enforce disallowance of object constructor (#33211)
Applying the `prefer-literal` tslint rule to object enforces the style guide rule https://google.github.io/styleguide/jsguide.html#features-objects-ctor PR Close #33211
This commit is contained in:
parent
d4b83681f1
commit
c60d7563a8
|
@ -114,7 +114,7 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
});
|
||||
|
||||
describe('Promise', () => {
|
||||
const message = new Object();
|
||||
const message = {};
|
||||
let pipe: AsyncPipe;
|
||||
let resolve: (result: any) => void;
|
||||
let reject: (error: any) => void;
|
||||
|
|
|
@ -33,7 +33,7 @@ export const INJECTOR = new InjectionToken<Injector>(
|
|||
-1 as any // `-1` is used by Ivy DI system as special value to recognize it as `Injector`.
|
||||
);
|
||||
|
||||
const _THROW_IF_NOT_FOUND = new Object();
|
||||
const _THROW_IF_NOT_FOUND = {};
|
||||
export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
|
||||
|
||||
export const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath';
|
||||
|
|
|
@ -16,7 +16,7 @@ import {ReflectiveDependency, ResolvedReflectiveFactory, ResolvedReflectiveProvi
|
|||
|
||||
|
||||
// Threshold for the dynamic version
|
||||
const UNDEFINED = new Object();
|
||||
const UNDEFINED = {};
|
||||
|
||||
/**
|
||||
* A ReflectiveDependency injection container used for instantiating objects and resolving
|
||||
|
|
|
@ -18,7 +18,7 @@ import {stringify} from '../util/stringify';
|
|||
import {DepDef, DepFlags, NgModuleData, NgModuleDefinition, NgModuleProviderDef, NodeFlags} from './types';
|
||||
import {splitDepsDsl, tokenKey} from './util';
|
||||
|
||||
const UNDEFINED_VALUE = new Object();
|
||||
const UNDEFINED_VALUE = {};
|
||||
|
||||
const InjectorRefTokenKey = tokenKey(Injector);
|
||||
const INJECTORRefTokenKey = tokenKey(INJECTOR);
|
||||
|
|
|
@ -26,7 +26,7 @@ import {DepFlags, ElementData, NgModuleData, NgModuleDefinition, NodeDef, NodeFl
|
|||
import {markParentViewsForCheck, resolveDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util';
|
||||
import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach';
|
||||
|
||||
const EMPTY_CONTEXT = new Object();
|
||||
const EMPTY_CONTEXT = {};
|
||||
|
||||
// Attention: this function is called as top level function.
|
||||
// Putting any logic in here will destroy closure tree shaking!
|
||||
|
|
|
@ -16,41 +16,41 @@ import {devModeEqual} from '@angular/core/src/change_detection/change_detection_
|
|||
expect(devModeEqual(['one'], ['one', 'two'])).toBe(false);
|
||||
expect(devModeEqual(['one', 'two'], ['one'])).toBe(false);
|
||||
expect(devModeEqual(['one'], 'one')).toBe(false);
|
||||
expect(devModeEqual(['one'], new Object())).toBe(false);
|
||||
expect(devModeEqual(['one'], {})).toBe(false);
|
||||
expect(devModeEqual('one', ['one'])).toBe(false);
|
||||
expect(devModeEqual(new Object(), ['one'])).toBe(false);
|
||||
expect(devModeEqual({}, ['one'])).toBe(false);
|
||||
});
|
||||
|
||||
it('should compare primitive numbers', () => {
|
||||
expect(devModeEqual(1, 1)).toBe(true);
|
||||
expect(devModeEqual(1, 2)).toBe(false);
|
||||
expect(devModeEqual(new Object(), 2)).toBe(false);
|
||||
expect(devModeEqual(1, new Object())).toBe(false);
|
||||
expect(devModeEqual({}, 2)).toBe(false);
|
||||
expect(devModeEqual(1, {})).toBe(false);
|
||||
});
|
||||
|
||||
it('should compare primitive strings', () => {
|
||||
expect(devModeEqual('one', 'one')).toBe(true);
|
||||
expect(devModeEqual('one', 'two')).toBe(false);
|
||||
expect(devModeEqual(new Object(), 'one')).toBe(false);
|
||||
expect(devModeEqual('one', new Object())).toBe(false);
|
||||
expect(devModeEqual({}, 'one')).toBe(false);
|
||||
expect(devModeEqual('one', {})).toBe(false);
|
||||
});
|
||||
|
||||
it('should compare primitive booleans', () => {
|
||||
expect(devModeEqual(true, true)).toBe(true);
|
||||
expect(devModeEqual(true, false)).toBe(false);
|
||||
expect(devModeEqual(new Object(), true)).toBe(false);
|
||||
expect(devModeEqual(true, new Object())).toBe(false);
|
||||
expect(devModeEqual({}, true)).toBe(false);
|
||||
expect(devModeEqual(true, {})).toBe(false);
|
||||
});
|
||||
|
||||
it('should compare null', () => {
|
||||
expect(devModeEqual(null, null)).toBe(true);
|
||||
expect(devModeEqual(null, 1)).toBe(false);
|
||||
expect(devModeEqual(new Object(), null)).toBe(false);
|
||||
expect(devModeEqual(null, new Object())).toBe(false);
|
||||
expect(devModeEqual({}, null)).toBe(false);
|
||||
expect(devModeEqual(null, {})).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for other objects',
|
||||
() => { expect(devModeEqual(new Object(), new Object())).toBe(true); });
|
||||
() => { expect(devModeEqual({}, {})).toBe(true); });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import {compViewDef, createAndGetRootNodes} from './helper';
|
|||
});
|
||||
|
||||
it('should add debug information to the renderer', () => {
|
||||
const someContext = new Object();
|
||||
const someContext = {};
|
||||
const {view, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef([anchorDef(NodeFlags.None, null, null, 0)]), someContext);
|
||||
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement);
|
||||
|
|
|
@ -62,7 +62,7 @@ const removeEventListener = 'removeEventListener';
|
|||
});
|
||||
|
||||
it('should add debug information to the renderer', () => {
|
||||
const someContext = new Object();
|
||||
const someContext = {};
|
||||
const {view, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef([elementDef(0, NodeFlags.None, null, null, 0, 'div')]), someContext);
|
||||
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement);
|
||||
|
|
|
@ -16,8 +16,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
|
|||
describe(`Embedded Views`, () => {
|
||||
|
||||
it('should create embedded views with the right context', () => {
|
||||
const parentContext = new Object();
|
||||
const childContext = new Object();
|
||||
const parentContext = {};
|
||||
const childContext = {};
|
||||
|
||||
const {view: parentView} = createAndGetRootNodes(
|
||||
compViewDef([
|
||||
|
|
|
@ -41,7 +41,7 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRoot
|
|||
});
|
||||
|
||||
it('should add debug information to the renderer', () => {
|
||||
const someContext = new Object();
|
||||
const someContext = {};
|
||||
const {view, rootNodes} =
|
||||
createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])]), someContext);
|
||||
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asTextData(view, 0).renderText);
|
||||
|
|
|
@ -459,7 +459,7 @@ export declare abstract class Injector {
|
|||
abstract get<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
/** @deprecated */ abstract get(token: any, notFoundValue?: any): any;
|
||||
static NULL: Injector;
|
||||
static THROW_IF_NOT_FOUND: Object;
|
||||
static THROW_IF_NOT_FOUND: {};
|
||||
static ɵprov: never;
|
||||
/** @deprecated */ static create(providers: StaticProvider[], parent?: Injector): Injector;
|
||||
static create(options: {
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
"no-duplicate-variable": true,
|
||||
"no-jasmine-focus": true,
|
||||
"no-var-keyword": true,
|
||||
"prefer-literal": [
|
||||
true,
|
||||
"object"
|
||||
],
|
||||
"require-internal-with-underscore": true,
|
||||
"no-toplevel-property-access": [
|
||||
true,
|
||||
|
|
Loading…
Reference in New Issue