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:
Danny Skoog 2019-10-17 02:46:50 +02:00 committed by Miško Hevery
parent d4b83681f1
commit c60d7563a8
12 changed files with 26 additions and 22 deletions

View File

@ -114,7 +114,7 @@ import {SpyChangeDetectorRef} from '../spies';
}); });
describe('Promise', () => { describe('Promise', () => {
const message = new Object(); const message = {};
let pipe: AsyncPipe; let pipe: AsyncPipe;
let resolve: (result: any) => void; let resolve: (result: any) => void;
let reject: (error: any) => void; let reject: (error: any) => void;

View File

@ -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`. -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 THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
export const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath'; export const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath';

View File

@ -16,7 +16,7 @@ import {ReflectiveDependency, ResolvedReflectiveFactory, ResolvedReflectiveProvi
// Threshold for the dynamic version // Threshold for the dynamic version
const UNDEFINED = new Object(); const UNDEFINED = {};
/** /**
* A ReflectiveDependency injection container used for instantiating objects and resolving * A ReflectiveDependency injection container used for instantiating objects and resolving

View File

@ -18,7 +18,7 @@ import {stringify} from '../util/stringify';
import {DepDef, DepFlags, NgModuleData, NgModuleDefinition, NgModuleProviderDef, NodeFlags} from './types'; import {DepDef, DepFlags, NgModuleData, NgModuleDefinition, NgModuleProviderDef, NodeFlags} from './types';
import {splitDepsDsl, tokenKey} from './util'; import {splitDepsDsl, tokenKey} from './util';
const UNDEFINED_VALUE = new Object(); const UNDEFINED_VALUE = {};
const InjectorRefTokenKey = tokenKey(Injector); const InjectorRefTokenKey = tokenKey(Injector);
const INJECTORRefTokenKey = tokenKey(INJECTOR); const INJECTORRefTokenKey = tokenKey(INJECTOR);

View File

@ -26,7 +26,7 @@ import {DepFlags, ElementData, NgModuleData, NgModuleDefinition, NodeDef, NodeFl
import {markParentViewsForCheck, resolveDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util'; import {markParentViewsForCheck, resolveDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util';
import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach'; 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. // Attention: this function is called as top level function.
// Putting any logic in here will destroy closure tree shaking! // Putting any logic in here will destroy closure tree shaking!

View File

@ -16,41 +16,41 @@ import {devModeEqual} from '@angular/core/src/change_detection/change_detection_
expect(devModeEqual(['one'], ['one', 'two'])).toBe(false); expect(devModeEqual(['one'], ['one', 'two'])).toBe(false);
expect(devModeEqual(['one', 'two'], ['one'])).toBe(false); expect(devModeEqual(['one', 'two'], ['one'])).toBe(false);
expect(devModeEqual(['one'], '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('one', ['one'])).toBe(false);
expect(devModeEqual(new Object(), ['one'])).toBe(false); expect(devModeEqual({}, ['one'])).toBe(false);
}); });
it('should compare primitive numbers', () => { it('should compare primitive numbers', () => {
expect(devModeEqual(1, 1)).toBe(true); expect(devModeEqual(1, 1)).toBe(true);
expect(devModeEqual(1, 2)).toBe(false); expect(devModeEqual(1, 2)).toBe(false);
expect(devModeEqual(new Object(), 2)).toBe(false); expect(devModeEqual({}, 2)).toBe(false);
expect(devModeEqual(1, new Object())).toBe(false); expect(devModeEqual(1, {})).toBe(false);
}); });
it('should compare primitive strings', () => { it('should compare primitive strings', () => {
expect(devModeEqual('one', 'one')).toBe(true); expect(devModeEqual('one', 'one')).toBe(true);
expect(devModeEqual('one', 'two')).toBe(false); expect(devModeEqual('one', 'two')).toBe(false);
expect(devModeEqual(new Object(), 'one')).toBe(false); expect(devModeEqual({}, 'one')).toBe(false);
expect(devModeEqual('one', new Object())).toBe(false); expect(devModeEqual('one', {})).toBe(false);
}); });
it('should compare primitive booleans', () => { it('should compare primitive booleans', () => {
expect(devModeEqual(true, true)).toBe(true); expect(devModeEqual(true, true)).toBe(true);
expect(devModeEqual(true, false)).toBe(false); expect(devModeEqual(true, false)).toBe(false);
expect(devModeEqual(new Object(), true)).toBe(false); expect(devModeEqual({}, true)).toBe(false);
expect(devModeEqual(true, new Object())).toBe(false); expect(devModeEqual(true, {})).toBe(false);
}); });
it('should compare null', () => { it('should compare null', () => {
expect(devModeEqual(null, null)).toBe(true); expect(devModeEqual(null, null)).toBe(true);
expect(devModeEqual(null, 1)).toBe(false); expect(devModeEqual(null, 1)).toBe(false);
expect(devModeEqual(new Object(), null)).toBe(false); expect(devModeEqual({}, null)).toBe(false);
expect(devModeEqual(null, new Object())).toBe(false); expect(devModeEqual(null, {})).toBe(false);
}); });
it('should return true for other objects', it('should return true for other objects',
() => { expect(devModeEqual(new Object(), new Object())).toBe(true); }); () => { expect(devModeEqual({}, {})).toBe(true); });
}); });
}); });
} }

View File

@ -40,7 +40,7 @@ import {compViewDef, createAndGetRootNodes} from './helper';
}); });
it('should add debug information to the renderer', () => { it('should add debug information to the renderer', () => {
const someContext = new Object(); const someContext = {};
const {view, rootNodes} = createAndGetRootNodes( const {view, rootNodes} = createAndGetRootNodes(
compViewDef([anchorDef(NodeFlags.None, null, null, 0)]), someContext); compViewDef([anchorDef(NodeFlags.None, null, null, 0)]), someContext);
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement); expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement);

View File

@ -62,7 +62,7 @@ const removeEventListener = 'removeEventListener';
}); });
it('should add debug information to the renderer', () => { it('should add debug information to the renderer', () => {
const someContext = new Object(); const someContext = {};
const {view, rootNodes} = createAndGetRootNodes( const {view, rootNodes} = createAndGetRootNodes(
compViewDef([elementDef(0, NodeFlags.None, null, null, 0, 'div')]), someContext); compViewDef([elementDef(0, NodeFlags.None, null, null, 0, 'div')]), someContext);
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement); expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement);

View File

@ -16,8 +16,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
describe(`Embedded Views`, () => { describe(`Embedded Views`, () => {
it('should create embedded views with the right context', () => { it('should create embedded views with the right context', () => {
const parentContext = new Object(); const parentContext = {};
const childContext = new Object(); const childContext = {};
const {view: parentView} = createAndGetRootNodes( const {view: parentView} = createAndGetRootNodes(
compViewDef([ compViewDef([

View File

@ -41,7 +41,7 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRoot
}); });
it('should add debug information to the renderer', () => { it('should add debug information to the renderer', () => {
const someContext = new Object(); const someContext = {};
const {view, rootNodes} = const {view, rootNodes} =
createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])]), someContext); createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])]), someContext);
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asTextData(view, 0).renderText); expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asTextData(view, 0).renderText);

View File

@ -459,7 +459,7 @@ export declare abstract class Injector {
abstract get<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; abstract get<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
/** @deprecated */ abstract get(token: any, notFoundValue?: any): any; /** @deprecated */ abstract get(token: any, notFoundValue?: any): any;
static NULL: Injector; static NULL: Injector;
static THROW_IF_NOT_FOUND: Object; static THROW_IF_NOT_FOUND: {};
static ɵprov: never; static ɵprov: never;
/** @deprecated */ static create(providers: StaticProvider[], parent?: Injector): Injector; /** @deprecated */ static create(providers: StaticProvider[], parent?: Injector): Injector;
static create(options: { static create(options: {

View File

@ -19,6 +19,10 @@
"no-duplicate-variable": true, "no-duplicate-variable": true,
"no-jasmine-focus": true, "no-jasmine-focus": true,
"no-var-keyword": true, "no-var-keyword": true,
"prefer-literal": [
true,
"object"
],
"require-internal-with-underscore": true, "require-internal-with-underscore": true,
"no-toplevel-property-access": [ "no-toplevel-property-access": [
true, true,